Add state machine code.

This commit is contained in:
fancy 2023-09-19 07:54:26 -07:00
parent 461fa73bf4
commit cdccef76a7
43 changed files with 642 additions and 49 deletions

View File

@ -76,7 +76,7 @@ if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
endif()
#
# add_subdirectory(application)
add_subdirectory(application)
add_subdirectory(middleware)
add_subdirectory(utils)
add_subdirectory(hal)

View File

@ -0,0 +1 @@
add_subdirectory(MissionManager)

View File

@ -0,0 +1,46 @@
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
include_directories(
./src
./include
${UTILS_SOURCE_PATH}/StatusCode/include
${UTILS_SOURCE_PATH}/Log/include
${MIDDLEWARE_SOURCE_PATH}/StateMachine/include
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
)
#do not rely on any other library
#link_directories(
#)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(./src SRC_FILES)
set(TARGET_NAME MissionManager)
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
target_link_libraries(${TARGET_NAME} StatusCode Log)
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
add_custom_target(
MissionManager_code_check
COMMAND ${CLANG_TIDY_EXE}
-checks='${CLANG_TIDY_CHECKS}'
--header-filter=.*
--system-headers=false
${SRC_FILES}
${CLANG_TIDY_CONFIG}
-p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/MissionManager
)
add_custom_command(
TARGET ${TARGET_NAME}
PRE_BUILD
COMMAND make MissionManager_code_check
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
)
endif()

View File

@ -0,0 +1,62 @@
/*
* 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_MISSION_MANAGER
#define I_MISSION_MANAGER
#include "StatusCode.h"
#include <memory>
#include <functional>
enum class MissionEvent
{
TEST = 0,
END
};
class VMissionData
{
public:
VMissionData(const MissionEvent &event) : mEvent(event)
{
mRetryTimes = 0;
mDelayTimeMs = 0;
}
virtual ~VMissionData() = default;
const MissionEvent mEvent;
int mRetryTimes;
unsigned int mDelayTimeMs;
std::function<void(bool, std::shared_ptr<VMissionData>)> mMissionFinshed;
};
template <typename T>
class VMissionDataV2 : public VMissionData
{
public:
VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value)
{
}
virtual ~VMissionDataV2() = default;
public:
T mData;
};
class IMissionManager
{
public:
IMissionManager() = default;
virtual ~IMissionManager() = default;
static std::shared_ptr<IMissionManager> &GetInstance(std::shared_ptr<IMissionManager> *impl = nullptr);
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
};
bool CreateMissionManagerModule(void);
#endif

View File

@ -0,0 +1,35 @@
/*
* 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.
*/
#include "DataProcessing.h"
#include "ILog.h"
const bool NOT_EXECUTED = false;
const bool EXECUTED = true;
bool DataProcessing::EventHandle(VStateMachineData *msg)
{
if (nullptr == msg)
{
LogError("nullptr pointer.\n");
return NOT_EXECUTED;
}
std::map<InternalStateEvent, DataProcessingFunc>::iterator iter;
std::shared_ptr<MissionData> message = std::dynamic_pointer_cast<MissionData>(msg->GetMessageObj());
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
iter = mEventHandle.find(event);
if (iter != mEventHandle.end())
{
return mEventHandle[event](msg);
}
return NOT_EXECUTED;
}

View File

@ -0,0 +1,47 @@
/*
* 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 DATAPROCESSING_H
#define DATAPROCESSING_H
#include "IStateMachine.h"
#include "IMissionManager.h"
#include <functional>
#include <map>
using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
enum class InternalStateEvent
{
TEST = static_cast<int>(MissionEvent::END),
END
};
class MissionData : public VStateMachineData
{
public:
MissionData(const std::shared_ptr<VMissionData> &data)
: mMissionData(data)
{
}
virtual ~MissionData() = default;
const std::shared_ptr<VMissionData> mMissionData;
};
class DataProcessing
{
public:
DataProcessing() = default;
virtual ~DataProcessing() = default;
bool EventHandle(VStateMachineData *msg);
protected:
std::map<InternalStateEvent, DataProcessingFunc> mEventHandle;
};
#endif

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
#include "IMissionManager.h"
#include "ILog.h"
std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<IMissionManager> *impl)
{
static auto instance = std::make_shared<IMissionManager>();
if (impl)
{
if (instance.use_count() == 1)
{
LogInfo("Instance changed succeed.\n");
instance = *impl;
}
else
{
LogError("Can't changing the instance becase of using by some one.\n");
}
}
return instance;
}

View File

@ -0,0 +1,14 @@
/*
* 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.
*/

View File

@ -0,0 +1,24 @@
/*
* 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 MISSIONMANAGER_H
#define MISSIONMANAGER_H
#include "IMissionManager.h"
class MissionManager : public IMissionManager
{
public:
MissionManager() = default;
virtual ~MissionManager() = default;
};
#endif

View File

@ -0,0 +1,34 @@
/*
* 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.
*/
#include "MissionManagerMakeImpl.h"
#include "TopState.h"
std::shared_ptr<MissionManagerMakeImpl> &MissionManagerMakeImpl::GetInstance(std::shared_ptr<MissionManagerMakeImpl> *impl)
{
static auto instance = std::make_shared<MissionManagerMakeImpl>();
if (impl)
{
instance = *impl;
}
return instance;
}
const StatusCode MissionManagerMakeImpl::CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance)
{
return CreateStatusCode(STATUS_CODE_OK);
}
std::shared_ptr<State> MissionManagerMakeImpl::CreateTopState(void)
{
std::shared_ptr<State> state = std::make_shared<TopState>();
return state;
}

View File

@ -0,0 +1,30 @@
/*
* 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 MISSIONMANAGERMAKEIMPL_H
#define MISSIONMANAGERMAKEIMPL_H
#include "IMissionManager.h"
#include "IStateMachine.h"
#include "StatusCode.h"
#include <memory>
class MissionManagerMakeImpl
{
public:
MissionManagerMakeImpl() = default;
virtual ~MissionManagerMakeImpl() = default;
static std::shared_ptr<MissionManagerMakeImpl> &GetInstance(std::shared_ptr<MissionManagerMakeImpl> *impl = nullptr);
virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance);
virtual std::shared_ptr<State> CreateTopState(void);
};
#endif

View File

@ -0,0 +1,52 @@
/*
* 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.
*/
#include "MissionStateMachine.h"
#include "ILog.h"
#include "TopState.h"
#include "MissionManagerMakeImpl.h"
std::shared_ptr<MissionStateMachine> &MissionStateMachine::GetInstance(std::shared_ptr<MissionStateMachine> *impl)
{
static auto instance = std::make_shared<MissionStateMachine>();
if (impl)
{
instance = *impl;
}
return instance;
}
void MissionStateMachine::Init(void)
{
auto code = IStateMachine::GetInstance()->CreateStateMachine(mStateMachine);
if (IsCodeOK(code))
{
LogError("Create state machine failed.\n");
return;
}
if (!mStateMachine->InitialStateMachine())
{
LogError("State machine init failed.\n");
return;
}
mStartMission = IDeviceManager::GetInstance()->GetIpcMissiony();
RunStateMachine(mStartMission);
}
void MissionStateMachine::UnInit(void)
{
}
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
{
LogInfo("Make all states and start the state machine.\n");
mStateTree[MissionState::TOP_STATE] = MissionManagerMakeImpl::GetInstance()->CreateTopState();
mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
}

View File

@ -0,0 +1,43 @@
/*
* 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 MISSIONSTATEMACHINE_H
#define MISSIONSTATEMACHINE_H
#include "IStateMachine.h"
#include "IMissionManager.h"
#include "IDeviceManager.h"
#include <map>
enum class MissionState
{
TOP_STATE = 0,
END
};
class MissionStateMachine
{
public:
MissionStateMachine() = default;
virtual ~MissionStateMachine() = default;
static std::shared_ptr<MissionStateMachine> &GetInstance(std::shared_ptr<MissionStateMachine> *impl = nullptr);
void Init(void);
void UnInit(void);
private:
void RunStateMachine(const IpcMission &mission);
private:
std::shared_ptr<VStateMachineHandle> mStateMachine;
std::map<MissionState, std::shared_ptr<State>> mStateTree;
IpcMission mStartMission;
};
#endif

View File

@ -0,0 +1,28 @@
/*
* 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.
*/
#include "TopState.h"
TopState::TopState() : State("TopState")
{
}
void TopState::GoInState()
{
}
void TopState::GoOutState()
{
}
bool TopState::ExecuteStateMsg(VStateMachineData *msg)
{
return DataProcessing::EventHandle(msg);
}

View File

@ -0,0 +1,30 @@
/*
* 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 TOPSTATE_H
#define TOPSTATE_H
#include "IStateMachine.h"
#include "DataProcessing.h"
class TopState
: public State,
public DataProcessing
{
public:
TopState();
virtual ~TopState() = default;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(VStateMachineData *msg) override;
};
#endif

View File

@ -187,7 +187,7 @@ participant app
&emsp;&emsp; 通过构建配置文件选择需要实例化的网络服务模块代码。
##### 1.4.3.1.3. 相机状态管理
##### 1.4.3.1.3. 相机任务管理
&emsp;&emsp; 相机主业务逻辑使用状态机机制进行管理。
@ -206,9 +206,9 @@ participant app
&emsp;&emsp; 一些相对中性的业务功能库这些库可以提供给不同的产品需求使用在应用层不同的调用方式可实现不同的产品功能。中间件只能被应用层调用或者向下调用适配层或者调用工具库中间件各模块之间不能互相调用。中间件库接口可以使用C或者C++接口。
##### 1.4.3.2.2. 设管理模块
##### 1.4.3.2.2. 设管理模块
&emsp;&emsp; 应用层唯一的硬件设接口库。包含灯 / 按键 / GPIO / SD卡等。
&emsp;&emsp; 设备统指Linux的设备节点应用层唯一的硬件设接口库。包含灯 / 按键 / GPIO / SD卡 / 串口 / USB等。
##### 1.4.3.2.3. 相机管理模块

View File

@ -1,2 +1,3 @@
add_subdirectory(StateMachine)
add_subdirectory(IpcConfig)
add_subdirectory(IpcConfig)
add_subdirectory(DeviceManager)

View File

@ -0,0 +1,45 @@
include(${CMAKE_SOURCE_DIR}/build/global_config.cmake)
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
include_directories(
./src
./include
${UTILS_SOURCE_PATH}/StatusCode/include
${UTILS_SOURCE_PATH}/Log/include
${UTILS_SOURCE_PATH}/Config/include
)
#do not rely on any other library
#link_directories(
#)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(./src SRC_FILES)
set(TARGET_NAME DeviceManager)
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
target_link_libraries(${TARGET_NAME} StatusCode Log)
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
add_custom_target(
DeviceManager_code_check
COMMAND ${CLANG_TIDY_EXE}
-checks='${CLANG_TIDY_CHECKS}'
--header-filter=.*
--system-headers=false
${SRC_FILES}
${CLANG_TIDY_CONFIG}
-p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell
WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/DeviceManager
)
add_custom_command(
TARGET ${TARGET_NAME}
PRE_BUILD
COMMAND make DeviceManager_code_check
WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
)
endif()

View File

@ -0,0 +1,35 @@
/*
* 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 IDEVICEMANAGER_H
#define IDEVICEMANAGER_H
#include "StatusCode.h"
#include <memory>
enum class IpcMission
{
TEST = 0,
END
};
class IDeviceManager
{
public:
IDeviceManager() = default;
virtual ~IDeviceManager() = default;
static std::shared_ptr<IDeviceManager> &GetInstance(std::shared_ptr<IDeviceManager> *impl = nullptr);
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
virtual const IpcMission GetIpcMissiony(void) { return IpcMission::END; }
};
bool CreateDeviceManagerModule(void);
#endif

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
#include "IDeviceManager.h"
#include "ILog.h"
std::shared_ptr<IDeviceManager> &IDeviceManager::GetInstance(std::shared_ptr<IDeviceManager> *impl)
{
static auto instance = std::make_shared<IDeviceManager>();
if (impl)
{
if (instance.use_count() == 1)
{
LogInfo("Instance changed succeed.\n");
instance = *impl;
}
else
{
LogError("Can't changing the instance becase of using by some one.\n");
}
}
return instance;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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
@ -22,11 +22,11 @@ public:
VStateMessage() = default;
virtual ~VStateMessage() = default;
};
class VStateMachineParam
class VStateMachineData
{
public:
VStateMachineParam() = default;
virtual ~VStateMachineParam() = default;
VStateMachineData() = default;
virtual ~VStateMachineData() = default;
virtual int GetMessageName() const = 0;
virtual const std::shared_ptr<VStateMessage> &GetMessageObj(void) const = 0;
};
@ -39,20 +39,20 @@ public:
public:
virtual void GoInState() = 0;
virtual void GoOutState() = 0;
virtual bool ExecuteStateMsg(VStateMachineParam *msg) = 0;
virtual bool ExecuteStateMsg(VStateMachineData *msg) = 0;
std::string GetStateName() { return mStateName; }
private:
std::string mStateName;
};
class VStateMachine
class VStateMachineHandle
{
public:
VStateMachine() = default;
virtual ~VStateMachine() = default;
VStateMachineHandle() = default;
virtual ~VStateMachineHandle() = default;
virtual bool InitialStateMachine() { return false; }
virtual void StatePlus(State *state, State *upper) {}
virtual void SetFirstState(State *firstState) {}
virtual void SetTopState(State *firstState) {}
virtual void StartStateMachine() {}
virtual void SendMessage(int msgName) {}
virtual void StopHandlerThread() {}
@ -60,7 +60,7 @@ public:
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(VStateMachineParam *msg) {}
virtual void DelayMessage(VStateMachineData *msg) {}
};
class IStateMachine
{
@ -68,7 +68,7 @@ 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<VStateMachine> &stateMachine)
virtual const StatusCode CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -76,7 +76,7 @@ private:
std::list<std::string> stringArray_;
};
class InternalMessage : public VStateMachineParam {
class InternalMessage : public VStateMachineData {
public:
/**
* @Description : Construct a new Internal Message object.

View File

@ -95,14 +95,14 @@ void StateMachine::StateDelete(State *state)
pStateMachineHandler->StateDelete(state);
}
void StateMachine::SetFirstState(State *firstState)
void StateMachine::SetTopState(State *firstState)
{
if (pStateMachineHandler == nullptr) {
LogError("Start StateMachine failed, pStateMachineHandler is nullptr!\n");
return;
}
pStateMachineHandler->SetFirstState(firstState);
pStateMachineHandler->SetTopState(firstState);
}
void StateMachine::SwitchState(State *targetState)
@ -124,7 +124,7 @@ void StateMachine::DelayMessage(const InternalMessage *msg)
pStateMachineHandler->DelayMessage(msg);
}
void StateMachine::DelayMessage(VStateMachineParam *msg)
void StateMachine::DelayMessage(VStateMachineData *msg)
{
if (pStateMachineHandler == nullptr) {
LogError("Start StateMachine failed, pStateMachineHandler is nullptr!\n");
@ -382,7 +382,7 @@ void StateMachineHandler::StateDelete(State *state)
}
}
void StateMachineHandler::SetFirstState(State *firstState)
void StateMachineHandler::SetTopState(State *firstState)
{
pFirstState = firstState;
}
@ -638,7 +638,7 @@ State *StateMachineHandler::ExecuteTreeStateMsg(InternalMessage *msg)
curStateInfo->state->GetStateName().c_str(), msg->GetMessageName());
}
// TODO:
while (curStateInfo->state && (!curStateInfo->state->ExecuteStateMsg((VStateMachineParam *)(msg)))) {
while (curStateInfo->state && (!curStateInfo->state->ExecuteStateMsg((VStateMachineData *)(msg)))) {
curStateInfo = curStateInfo->upperStateInfo;
if (curStateInfo == nullptr) {

View File

@ -28,7 +28,7 @@
#define CMD_SET_OPERATIONAL_MODE 1
class StateMachineHandler;
class StateMachine : public VStateMachine
class StateMachine : public VStateMachineHandle
{
public:
/**
@ -295,7 +295,7 @@ protected:
*
* @param firstState - First state.[in]
*/
void SetFirstState(State *firstState) override;
void SetTopState(State *firstState) override;
/**
* @Description : Transition to orther state.
@ -310,7 +310,7 @@ protected:
* @param msg - Message object.[in]
*/
void DelayMessage(const InternalMessage *msg);
void DelayMessage(VStateMachineParam *msg) override;
void DelayMessage(VStateMachineData *msg) override;
private:
StateMachineHandler *pStateMachineHandler;
@ -372,7 +372,7 @@ public:
*
* @param firstState - Initialization State.[in]
*/
void SetFirstState(State *firstState);
void SetTopState(State *firstState);
/**
* @Description : State transition function.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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
@ -14,7 +14,7 @@
*/
#include "StateMachineImpl.h"
#include "StateMachineMakePtr.h"
const StatusCode StateMachineImpl::CreateStateMachine(std::shared_ptr<VStateMachine> &stateMachine)
const StatusCode StateMachineImpl::CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine)
{
return StateMachineMakePtr::GetInstance()->CreateStateMachine(stateMachine);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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
@ -20,6 +20,6 @@ class StateMachineImpl : public IStateMachine
public:
StateMachineImpl() = default;
~StateMachineImpl() = default;
const StatusCode CreateStateMachine(std::shared_ptr<VStateMachine> &stateMachine) override;
const StatusCode CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine) override;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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
@ -39,7 +39,7 @@ std::shared_ptr<StateMachineMakePtr> &StateMachineMakePtr::GetInstance(std::shar
}
return instance;
}
StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr<VStateMachine> &stateMachine)
StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine)
{
// TODO: need a name ?
auto tmp = std::make_shared<StateMachine>("TODO");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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
@ -23,7 +23,7 @@ public:
StateMachineMakePtr() = default;
virtual ~StateMachineMakePtr() = default;
static std::shared_ptr<StateMachineMakePtr> &GetInstance(std::shared_ptr<StateMachineMakePtr> *impl = nullptr);
virtual StatusCode CreateStateMachine(std::shared_ptr<VStateMachine> &stateMachine);
virtual StatusCode CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine);
virtual StatusCode CreateStateMachine(std::shared_ptr<IStateMachine> &instance);
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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