/* * Copyright (c) 2023 JIUYILIAN Co., Ltd. * 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 class VStateMessage { public: VStateMessage() = default; virtual ~VStateMessage() = default; }; class VStateMachineParam { public: VStateMachineParam() = default; virtual ~VStateMachineParam() = default; virtual int GetMessageName() const = 0; virtual const std::shared_ptr &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(VStateMachineParam *msg) = 0; std::string GetStateName() { return mStateName; } private: std::string mStateName; }; class VStateMachine { public: VStateMachine() = default; virtual ~VStateMachine() = default; virtual bool InitialStateMachine() { return false; } virtual void StatePlus(State *state, State *upper) {} virtual void SetFirstState(State *firstState) {} virtual void StartStateMachine() {} virtual void SendMessage(int msgName) {} virtual void StopHandlerThread() {} virtual void SendMessage(int msgName, const std::shared_ptr &messageObj) {} virtual void MessageExecutedLater(int msgName, const std::shared_ptr &messageObj, int64_t delayTimeMs) {} virtual void SwitchState(State *targetState) {} virtual void StopTimer(int timerName) {} virtual void DelayMessage(VStateMachineParam *msg) {} }; class IStateMachine { public: IStateMachine() = default; virtual ~IStateMachine() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); virtual const StatusCode CreateStateMachine(std::shared_ptr &stateMachine) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } }; bool CreateStateMachine(void); #endif