105 lines
2.7 KiB
C++
105 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2023 Fancy Code.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#ifndef I_STATE_MACHINE_H
|
|
#define I_STATE_MACHINE_H
|
|
#include "StatusCode.h"
|
|
#include <iostream>
|
|
#include <memory>
|
|
bool CreateStateMachine(void);
|
|
bool DestroyStateMachine(void);
|
|
class VStateMessage
|
|
{
|
|
public:
|
|
VStateMessage() = default;
|
|
virtual ~VStateMessage() = default;
|
|
};
|
|
class VStateMachineData
|
|
{
|
|
public:
|
|
VStateMachineData() = default;
|
|
virtual ~VStateMachineData() = default;
|
|
virtual int GetMessageName() const = 0;
|
|
virtual const std::shared_ptr<VStateMessage> &GetMessageObj(void) const = 0;
|
|
};
|
|
class State
|
|
{
|
|
public:
|
|
explicit State(const std::string &name) : mStateName(name)
|
|
{
|
|
}
|
|
virtual ~State() = default;
|
|
|
|
public:
|
|
virtual void GoInState() = 0;
|
|
virtual void GoOutState() = 0;
|
|
virtual bool ExecuteStateMsg(VStateMachineData *msg) = 0;
|
|
std::string GetStateName()
|
|
{
|
|
return mStateName;
|
|
}
|
|
|
|
private:
|
|
std::string mStateName;
|
|
};
|
|
class VStateMachineHandle
|
|
{
|
|
public:
|
|
VStateMachineHandle() = default;
|
|
virtual ~VStateMachineHandle() = default;
|
|
virtual bool InitialStateMachine()
|
|
{
|
|
return false;
|
|
}
|
|
virtual void StatePlus(State *state, State *upper)
|
|
{
|
|
}
|
|
virtual void SetCurrentState(State *firstState)
|
|
{
|
|
}
|
|
virtual void StartStateMachine()
|
|
{
|
|
}
|
|
virtual void SendMessage(int msgName)
|
|
{
|
|
}
|
|
virtual void StopHandlerThread()
|
|
{
|
|
}
|
|
virtual void SendMessage(int msgName, const std::shared_ptr<VStateMessage> &messageObj)
|
|
{
|
|
}
|
|
virtual void MessageExecutedLater(int msgName, const std::shared_ptr<VStateMessage> &messageObj,
|
|
int64_t delayTimeMs)
|
|
{
|
|
}
|
|
virtual void SwitchState(State *targetState)
|
|
{
|
|
}
|
|
virtual void StopTimer(int timerName)
|
|
{
|
|
}
|
|
virtual void DelayMessage(VStateMachineData *msg)
|
|
{
|
|
}
|
|
};
|
|
class IStateMachine
|
|
{
|
|
public:
|
|
IStateMachine() = default;
|
|
virtual ~IStateMachine() = default;
|
|
static std::shared_ptr<IStateMachine> &GetInstance(std::shared_ptr<IStateMachine> *impl = nullptr);
|
|
virtual const StatusCode CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine);
|
|
};
|
|
#endif |