From 0c4f039918477187700f25d2322659148b20e7b6 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Mon, 4 Mar 2024 04:49:07 -0800 Subject: [PATCH] Backup:HunttingCamera module. --- application/CMakeLists.txt | 1 + application/HunttingCamera/CMakeLists.txt | 70 +++++++++++++++++++ .../build/huntting_camera.cmake | 8 +++ application/HunttingCamera/main.cpp | 24 +++++++ application/HunttingCamera/src/MainThread.cpp | 68 ++++++++++++++++++ application/HunttingCamera/src/MainThread.h | 39 +++++++++++ application/MissionManager/CMakeLists.txt | 21 +++++- .../MissionManager/include/IMissionManager.h | 8 +-- .../MissionManager/src/DataProcessing.cpp | 6 +- .../MissionManager/src/DataProcessing.h | 7 +- .../MissionManager/src/IMissionManager.cpp | 13 ++-- .../src/MissionManagerMakeImpl.cpp | 34 --------- .../src/MissionManagerMakePtr.cpp | 57 +++++++++++++++ ...agerMakeImpl.h => MissionManagerMakePtr.h} | 8 +-- .../src/MissionStateMachine.cpp | 17 ++--- .../MissionManager/src/MissionStateMachine.h | 4 +- application/MissionManager/src/TopState.cpp | 17 ++--- application/MissionManager/src/TopState.h | 6 +- application/main/CMakeLists.txt | 2 - middleware/AppManager/include/IAppManager.h | 1 + middleware/AppManager/src/IAppManager.cpp | 4 ++ .../src/Protocol/SixFrame/SixFrameHandle.cpp | 47 ++++++++++++- .../src/Protocol/SixFrame/SixFrameHandle.h | 4 +- middleware/StateMachine/CMakeLists.txt | 22 +++--- .../StateMachine/include/IStateMachine.h | 8 +-- middleware/StateMachine/src/IStateMachine.cpp | 17 ++--- .../AppManager/src/AppManager_Test.cpp | 12 ++++ .../tool/include/AppManagerTestTool.h | 1 + .../tool/src/AppManagerTestTool.cpp | 12 ++++ .../AppManager/tool/src/AppMonitorMock.cpp | 14 ++++ .../AppManager/tool/src/AppMonitorMock.h | 2 + .../AppManager/tool/src/ServersMock.cpp | 20 +++++- .../AppManager/tool/src/ServersMock.h | 1 + 33 files changed, 452 insertions(+), 123 deletions(-) create mode 100644 application/HunttingCamera/CMakeLists.txt create mode 100644 application/HunttingCamera/build/huntting_camera.cmake create mode 100644 application/HunttingCamera/main.cpp create mode 100644 application/HunttingCamera/src/MainThread.cpp create mode 100644 application/HunttingCamera/src/MainThread.h delete mode 100644 application/MissionManager/src/MissionManagerMakeImpl.cpp create mode 100644 application/MissionManager/src/MissionManagerMakePtr.cpp rename application/MissionManager/src/{MissionManagerMakeImpl.h => MissionManagerMakePtr.h} (77%) diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index a165827..a3f2acc 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(main) +add_subdirectory(HunttingCamera) add_subdirectory(MissionManager) \ No newline at end of file diff --git a/application/HunttingCamera/CMakeLists.txt b/application/HunttingCamera/CMakeLists.txt new file mode 100644 index 0000000..36846c6 --- /dev/null +++ b/application/HunttingCamera/CMakeLists.txt @@ -0,0 +1,70 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${APPLICATION_SOURCE_PATH}/HunttingCamera/build/huntting_camera.cmake) +set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) +set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) + +include_directories( + ${HUNTTING_MAIN_INCLUDE_PATH} +) + +link_directories( + ${LIBS_OUTPUT_PATH} + ${HAL_SOURCE_PATH}/include +) + +aux_source_directory(. SRC_FILES) +aux_source_directory(./src MAIN_SRC_FILE_THIS) + +# Mark src files for test. +# file(GLOB_RECURSE MAIN_SRC_FILE_THIS src/*.cpp src/*.c) +# set(MAIN_SRC_FILE "${MAIN_SRC_FILE_THIS}" CACHE STRING INTERNAL FORCE) + +set(TARGET_LIB HunttingMainLib) +add_library(${TARGET_LIB} STATIC ${MAIN_SRC_FILE_THIS}) +set(TARGET_NAME HunttingCamera_x86) +add_executable(${TARGET_NAME} ${SRC_FILES}) + +target_link_libraries(${TARGET_LIB} ${HUNTTING_LINK_LIB}) +target_link_libraries(${TARGET_NAME} ${TARGET_LIB}) +if(${TEST_COVERAGE} MATCHES "true") + target_link_libraries(${TARGET_NAME} gcov) +endif() + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + HunttingCamera_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${MAIN_SRC_FILE_THIS} + ${CLANG_TIDY_CONFIG} + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/HunttingCamera +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make HunttingCamera_code_check + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + HunttingCamera_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${MAIN_SRC_FILE_THIS} ${HEADER_FILES} + WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/HunttingCamera +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make HunttingCamera_code_check + COMMAND make HunttingCamera_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_LIB}) +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/application/HunttingCamera/build/huntting_camera.cmake b/application/HunttingCamera/build/huntting_camera.cmake new file mode 100644 index 0000000..e14f6ed --- /dev/null +++ b/application/HunttingCamera/build/huntting_camera.cmake @@ -0,0 +1,8 @@ + +set(HUNTTING_MAIN_INCLUDE_PATH "${APPLICATION_SOURCE_PATH}/HunttingCamera/src") +set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include") +set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include") +set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${APPLICATION_SOURCE_PATH}/MissionManager/include") +set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/include") + +set(HUNTTING_LINK_LIB MissionManager StatusCode Log Hal pthread dl) \ No newline at end of file diff --git a/application/HunttingCamera/main.cpp b/application/HunttingCamera/main.cpp new file mode 100644 index 0000000..8c1b801 --- /dev/null +++ b/application/HunttingCamera/main.cpp @@ -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. + */ +#include "ILog.h" +#include "MainThread.h" +#include +int main(int argc, char *argv[]) +{ + MainThread::GetInstance()->Init(); + MainThread::GetInstance()->Runing(); + MainThread::GetInstance()->UnInit(); + return 0; +} \ No newline at end of file diff --git a/application/HunttingCamera/src/MainThread.cpp b/application/HunttingCamera/src/MainThread.cpp new file mode 100644 index 0000000..8e838d6 --- /dev/null +++ b/application/HunttingCamera/src/MainThread.cpp @@ -0,0 +1,68 @@ +/* + * 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 "MainThread.h" +#include "IHalCpp.h" +#include "ILog.h" +#include "IMissionManager.h" +#include +MainThread::MainThread() { mMainThreadRuning = false; } +std::shared_ptr &MainThread::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + 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; +} +StatusCode MainThread::Init(void) +{ + CreateLogModule(); + ILogInit(LOG_EASYLOGGING); + CustomizationInit(); + mMainThreadRuning = true; + CreateAllModules(); + // IHalInit(); + IHalCpp::GetInstance()->Init(); + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode MainThread::UnInit(void) +{ + IHalCpp::GetInstance()->UnInit(); + DestoryAllModules(); + ILogUnInit(); + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode MainThread::CreateAllModules(void) +{ + // CreateLogModule(); + // CreateHalModule(); + CreateHalCppModule(); + CreateMissionManagerModule(); + return CreateStatusCode(STATUS_CODE_OK); +} +void MainThread::DestoryAllModules(void) {} +void MainThread::ResetAllPtrMaker(void) {} +void MainThread::Runing(void) +{ + while (mMainThreadRuning) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } +} \ No newline at end of file diff --git a/application/HunttingCamera/src/MainThread.h b/application/HunttingCamera/src/MainThread.h new file mode 100644 index 0000000..4ced64c --- /dev/null +++ b/application/HunttingCamera/src/MainThread.h @@ -0,0 +1,39 @@ +/* + * 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 MAIN_THREAD_H +#define MAIN_THREAD_H +#include "StatusCode.h" +#include +class MainThread +{ +public: + MainThread(); + virtual ~MainThread() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual StatusCode Init(void); + virtual StatusCode UnInit(void); + void Runing(void); + void Exit(void) { mMainThreadRuning = false; } + virtual void CustomizationInit(void) {} + +private: + StatusCode CreateAllModules(void); + void DestoryAllModules(void); + void ResetAllPtrMaker(void); + +private: + bool mMainThreadRuning; +}; +#endif // !MAIN_THREAD_H \ No newline at end of file diff --git a/application/MissionManager/CMakeLists.txt b/application/MissionManager/CMakeLists.txt index e4b9251..57e3b73 100644 --- a/application/MissionManager/CMakeLists.txt +++ b/application/MissionManager/CMakeLists.txt @@ -15,8 +15,6 @@ include_directories( #link_directories( #) - - aux_source_directory(./src SRC_FILES) set(TARGET_NAME MissionManager) @@ -42,4 +40,21 @@ add_custom_command( COMMAND make MissionManager_code_check WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ ) -endif() \ No newline at end of file +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + MissionManager_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/MissionManager +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make MissionManager_code_check + COMMAND make MissionManager_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/application/MissionManager/include/IMissionManager.h b/application/MissionManager/include/IMissionManager.h index 1b28260..1e28b62 100644 --- a/application/MissionManager/include/IMissionManager.h +++ b/application/MissionManager/include/IMissionManager.h @@ -15,8 +15,9 @@ #ifndef I_MISSION_MANAGER #define I_MISSION_MANAGER #include "StatusCode.h" -#include #include +#include +bool CreateMissionManagerModule(void); enum class MissionEvent { TEST = 0, @@ -41,9 +42,7 @@ class VMissionDataV2 : public VMissionData { public: - VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value) - { - } + VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value) {} virtual ~VMissionDataV2() = default; public: @@ -58,5 +57,4 @@ public: virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } }; -bool CreateMissionManagerModule(void); #endif \ No newline at end of file diff --git a/application/MissionManager/src/DataProcessing.cpp b/application/MissionManager/src/DataProcessing.cpp index 30ed4b9..099988d 100644 --- a/application/MissionManager/src/DataProcessing.cpp +++ b/application/MissionManager/src/DataProcessing.cpp @@ -18,8 +18,7 @@ const bool NOT_EXECUTED = false; const bool EXECUTED = true; bool DataProcessing::EventHandle(VStateMachineData *msg) { - if (nullptr == msg) - { + if (nullptr == msg) { LogError("nullptr pointer.\n"); return NOT_EXECUTED; } @@ -27,8 +26,7 @@ bool DataProcessing::EventHandle(VStateMachineData *msg) std::shared_ptr message = std::dynamic_pointer_cast(msg->GetMessageObj()); InternalStateEvent event = static_cast(message->mMissionData->mEvent); iter = mEventHandle.find(event); - if (iter != mEventHandle.end()) - { + if (iter != mEventHandle.end()) { return mEventHandle[event](msg); } return NOT_EXECUTED; diff --git a/application/MissionManager/src/DataProcessing.h b/application/MissionManager/src/DataProcessing.h index 9e1b1c4..7f170e2 100644 --- a/application/MissionManager/src/DataProcessing.h +++ b/application/MissionManager/src/DataProcessing.h @@ -14,8 +14,8 @@ */ #ifndef DATAPROCESSING_H #define DATAPROCESSING_H -#include "IStateMachine.h" #include "IMissionManager.h" +#include "IStateMachine.h" #include #include using DataProcessingFunc = std::function; @@ -27,10 +27,7 @@ enum class InternalStateEvent class MissionData : public VStateMachineData { public: - MissionData(const std::shared_ptr &data) - : mMissionData(data) - { - } + MissionData(const std::shared_ptr &data) : mMissionData(data) {} virtual ~MissionData() = default; const std::shared_ptr mMissionData; }; diff --git a/application/MissionManager/src/IMissionManager.cpp b/application/MissionManager/src/IMissionManager.cpp index f17c6da..f253fb1 100644 --- a/application/MissionManager/src/IMissionManager.cpp +++ b/application/MissionManager/src/IMissionManager.cpp @@ -3,9 +3,9 @@ * 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. @@ -17,15 +17,12 @@ std::shared_ptr &IMissionManager::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); - if (impl) - { - if (instance.use_count() == 1) - { + if (impl) { + if (instance.use_count() == 1) { LogInfo("Instance changed succeed.\n"); instance = *impl; } - else - { + else { LogError("Can't changing the instance becase of using by some one.\n"); } } diff --git a/application/MissionManager/src/MissionManagerMakeImpl.cpp b/application/MissionManager/src/MissionManagerMakeImpl.cpp deleted file mode 100644 index cc54e35..0000000 --- a/application/MissionManager/src/MissionManagerMakeImpl.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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::GetInstance(std::shared_ptr *impl) -{ - static auto instance = std::make_shared(); - if (impl) - { - instance = *impl; - } - return instance; -} -const StatusCode MissionManagerMakeImpl::CreateMissionManagerInstance(std::shared_ptr &instance) -{ - return CreateStatusCode(STATUS_CODE_OK); -} -std::shared_ptr MissionManagerMakeImpl::CreateTopState(void) -{ - std::shared_ptr state = std::make_shared(); - return state; -} \ No newline at end of file diff --git a/application/MissionManager/src/MissionManagerMakePtr.cpp b/application/MissionManager/src/MissionManagerMakePtr.cpp new file mode 100644 index 0000000..47cae50 --- /dev/null +++ b/application/MissionManager/src/MissionManagerMakePtr.cpp @@ -0,0 +1,57 @@ +/* + * 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 "MissionManagerMakePtr.h" +#include "ILog.h" +#include "TopState.h" +bool CreateMissionManagerModule(void) +{ + auto instance = std::make_shared(); + StatusCode code = MissionManagerMakePtr::GetInstance()->CreateMissionManagerInstance(instance); + if (IsCodeOK(code)) { + LogInfo("CreateMcuManager is ok.\n"); + IMissionManager::GetInstance(&instance); + return true; + } + return false; +} +bool DestroyMissionManagerModule(void) +{ + auto instance = std::make_shared(); + IMissionManager::GetInstance(&instance); + return true; +} +std::shared_ptr &MissionManagerMakePtr::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + 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; +} +const StatusCode MissionManagerMakePtr::CreateMissionManagerInstance(std::shared_ptr &instance) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +std::shared_ptr MissionManagerMakePtr::CreateTopState(void) +{ + std::shared_ptr state = std::make_shared(); + return state; +} \ No newline at end of file diff --git a/application/MissionManager/src/MissionManagerMakeImpl.h b/application/MissionManager/src/MissionManagerMakePtr.h similarity index 77% rename from application/MissionManager/src/MissionManagerMakeImpl.h rename to application/MissionManager/src/MissionManagerMakePtr.h index a6cb99b..bd3e708 100644 --- a/application/MissionManager/src/MissionManagerMakeImpl.h +++ b/application/MissionManager/src/MissionManagerMakePtr.h @@ -18,12 +18,12 @@ #include "IStateMachine.h" #include "StatusCode.h" #include -class MissionManagerMakeImpl +class MissionManagerMakePtr { public: - MissionManagerMakeImpl() = default; - virtual ~MissionManagerMakeImpl() = default; - static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + MissionManagerMakePtr() = default; + virtual ~MissionManagerMakePtr() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr &instance); virtual std::shared_ptr CreateTopState(void); }; diff --git a/application/MissionManager/src/MissionStateMachine.cpp b/application/MissionManager/src/MissionStateMachine.cpp index 7685a54..4a7403d 100644 --- a/application/MissionManager/src/MissionStateMachine.cpp +++ b/application/MissionManager/src/MissionStateMachine.cpp @@ -14,13 +14,12 @@ */ #include "MissionStateMachine.h" #include "ILog.h" +#include "MissionManagerMakePtr.h" #include "TopState.h" -#include "MissionManagerMakeImpl.h" std::shared_ptr &MissionStateMachine::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); - if (impl) - { + if (impl) { instance = *impl; } return instance; @@ -28,25 +27,21 @@ std::shared_ptr &MissionStateMachine::GetInstance(std::shar void MissionStateMachine::Init(void) { auto code = IStateMachine::GetInstance()->CreateStateMachine(mStateMachine); - if (IsCodeOK(code)) - { + if (IsCodeOK(code)) { LogError("Create state machine failed.\n"); return; } - if (!mStateMachine->InitialStateMachine()) - { + if (!mStateMachine->InitialStateMachine()) { LogError("State machine init failed.\n"); return; } // mStartMission = IDeviceManager::GetInstance()->GetIpcMission(); // RunStateMachine(mStartMission); } -void MissionStateMachine::UnInit(void) -{ -} +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(); +// mStateTree[MissionState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState(); // mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get()); // } diff --git a/application/MissionManager/src/MissionStateMachine.h b/application/MissionManager/src/MissionStateMachine.h index a9b3ba2..04fbf2d 100644 --- a/application/MissionManager/src/MissionStateMachine.h +++ b/application/MissionManager/src/MissionStateMachine.h @@ -14,9 +14,9 @@ */ #ifndef MISSIONSTATEMACHINE_H #define MISSIONSTATEMACHINE_H -#include "IStateMachine.h" -#include "IMissionManager.h" #include "IDeviceManager.h" +#include "IMissionManager.h" +#include "IStateMachine.h" #include enum class MissionState { diff --git a/application/MissionManager/src/TopState.cpp b/application/MissionManager/src/TopState.cpp index c733043..ffd1b94 100644 --- a/application/MissionManager/src/TopState.cpp +++ b/application/MissionManager/src/TopState.cpp @@ -13,16 +13,7 @@ * 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); -} \ No newline at end of file +TopState::TopState() : State("TopState") {} +void TopState::GoInState() {} +void TopState::GoOutState() {} +bool TopState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); } \ No newline at end of file diff --git a/application/MissionManager/src/TopState.h b/application/MissionManager/src/TopState.h index cbc36c5..7367a2e 100644 --- a/application/MissionManager/src/TopState.h +++ b/application/MissionManager/src/TopState.h @@ -14,11 +14,9 @@ */ #ifndef TOPSTATE_H #define TOPSTATE_H -#include "IStateMachine.h" #include "DataProcessing.h" -class TopState - : public State, - public DataProcessing +#include "IStateMachine.h" +class TopState : public State, public DataProcessing { public: TopState(); diff --git a/application/main/CMakeLists.txt b/application/main/CMakeLists.txt index b27a2d5..08946a6 100644 --- a/application/main/CMakeLists.txt +++ b/application/main/CMakeLists.txt @@ -14,8 +14,6 @@ link_directories( ${HAL_SOURCE_PATH}/include ) - - aux_source_directory(./ SRC_FILES) # aux_source_directory(./src SRC_FILES) diff --git a/middleware/AppManager/include/IAppManager.h b/middleware/AppManager/include/IAppManager.h index 8f5c555..addacb1 100644 --- a/middleware/AppManager/include/IAppManager.h +++ b/middleware/AppManager/include/IAppManager.h @@ -134,6 +134,7 @@ public: virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m); virtual StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m); virtual StatusCode SetDateTime(AppSetDateTime ¶m); + virtual StatusCode SetTimeZone(const unsigned int &zone); virtual StatusCode UploadFile(AppUploadFile ¶m); }; typedef struct app_param diff --git a/middleware/AppManager/src/IAppManager.cpp b/middleware/AppManager/src/IAppManager.cpp index 9d2a570..1ffb211 100644 --- a/middleware/AppManager/src/IAppManager.cpp +++ b/middleware/AppManager/src/IAppManager.cpp @@ -38,6 +38,10 @@ StatusCode inline VAppMonitor::SetDateTime(AppSetDateTime ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +StatusCode inline VAppMonitor::SetTimeZone(const unsigned int &zone) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} StatusCode inline VAppMonitor::UploadFile(AppUploadFile ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp index ccdb4d1..a590d5d 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp @@ -27,7 +27,9 @@ const char *APP_GET_MEDIA_INFO = "/app/getmediainfo"; const char *APP_GET_SD_CARD_INFO = "/app/getsdinfo"; const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo"; const char *APP_SET_DATE_TIME = "/app/setsystime"; +const char *APP_SET_TIME_ZONE = "/app/settimezone"; const char *APP_UPLOAD_FILE = "/upload"; +constexpr bool SET_REQUEST_RESPONSE = true; SixFrameHandle::SixFrameHandle() { mAppMonitor = std::make_shared(); @@ -37,6 +39,7 @@ SixFrameHandle::SixFrameHandle() mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3); mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3); mResquesHandleFunc[APP_SET_DATE_TIME] = std::bind(&SixFrameHandle::RequestSetDateTime, this, _1, _2, _3); + mResquesHandleFunc[APP_SET_TIME_ZONE] = std::bind(&SixFrameHandle::RequestSetTimeZone, this, _1, _2, _3); mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3); // mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _); } @@ -231,7 +234,38 @@ void SixFrameHandle::RequestSetDateTime(const std::string &url, ResponseHandle r char *resultStr = nullptr; AppSetDateTime param = RequestSetDateTimeParse(url); mAppMonitor->SetDateTime(param); - cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); + cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE); + // ResponseGetBatteryInfo(result, param); + resultStr = cJSON_Print(result); + responseHandle(resultStr, context); + free(resultStr); + cJSON_Delete(result); +} +int inline SixFrameHandle::RequestSetTimeZoneParse(const std::string &url) +{ + auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr &parse) { + std::shared_ptr> parseyImpl = std::dynamic_pointer_cast>(parse); + if ("timezone" == key) { + parseyImpl->mData = value; + } + }; + std::shared_ptr parse = std::make_shared>(); + ExtractParamsFromUrl(url, parseFunc, parse); + std::shared_ptr> parseyImpl = std::dynamic_pointer_cast>(parse); + if (2 <= parseyImpl->mData.length()) { + LogError("date parse failed.\n"); + return 0; + } + int zone = std::stoi(parseyImpl->mData); + return zone; +} +void SixFrameHandle::RequestSetTimeZone(const std::string &url, ResponseHandle responseHandle, void *context) +{ + LogInfo("RequestGetDeviceAttr.\n"); + char *resultStr = nullptr; + int zone = RequestSetTimeZoneParse(url); + mAppMonitor->SetTimeZone(zone); + cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE); // ResponseGetBatteryInfo(result, param); resultStr = cJSON_Print(result); responseHandle(resultStr, context); @@ -250,11 +284,20 @@ void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle respon free(resultStr); cJSON_Delete(result); } -cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result) +cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result, const bool requestSet) { const char *RESPONSE_RESULT = "result"; cJSON *resultCJSON = cJSON_CreateObject(); cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast(result)); + if (false == requestSet) { + return resultCJSON; + } + if (ResposeResult::SUCCESSFUL == result) { + cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set success."); + } + else { + cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set failed."); // TODO: what the failed string is? + } return resultCJSON; } void SixFrameHandle::SetAppMonitor(std::shared_ptr &monitor) diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h index c695b9d..3b779cb 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h @@ -69,10 +69,12 @@ private: void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m); AppSetDateTime RequestSetDateTimeParse(const std::string &url); void RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context); + int RequestSetTimeZoneParse(const std::string &url); + void RequestSetTimeZone(const std::string &url, ResponseHandle responseHandle, void *context); void RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context); private: - cJSON *MakeResponseResult(const ResposeResult result); + cJSON *MakeResponseResult(const ResposeResult result, const bool requestSet = false); protected: void SetAppMonitor(std::shared_ptr &monitor) override; diff --git a/middleware/StateMachine/CMakeLists.txt b/middleware/StateMachine/CMakeLists.txt index 9736186..f5afe47 100644 --- a/middleware/StateMachine/CMakeLists.txt +++ b/middleware/StateMachine/CMakeLists.txt @@ -15,8 +15,6 @@ include_directories( #link_directories( #) - - aux_source_directory(./src SRC_FILES) aux_source_directory(./src/OpenHarmony SRC_FILES_OPENHARMONY) @@ -27,7 +25,7 @@ target_link_libraries(${TARGET_NAME} ReturnCode Log) if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") add_custom_target( - StateMahince_code_check + StateMachine_code_check COMMAND ${CLANG_TIDY_EXE} -checks='${CLANG_TIDY_CHECKS}' --header-filter=.* @@ -37,19 +35,27 @@ add_custom_target( -p ${PLATFORM_PATH}/cmake-shell WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/StateMachine ) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make StateMachine_code_check + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) file(GLOB_RECURSE HEADER_FILES *.h) add_custom_target( - StateMahince_code_format + StateMachine_code_format COMMAND ${CLANG_FORMAT_EXE} -style=file - -i ${SRC_FILES} ${HEADER_FILES} + -i ${SRC_FILES} ${HEADER_FILES} WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/StateMachine ) add_custom_command( TARGET ${TARGET_NAME} PRE_BUILD - COMMAND make StateMahince_code_check - COMMAND make StateMahince_code_format + COMMAND make StateMachine_code_check + COMMAND make StateMachine_code_format WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ ) -endif() \ No newline at end of file +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/middleware/StateMachine/include/IStateMachine.h b/middleware/StateMachine/include/IStateMachine.h index 5bfec38..3aa4817 100644 --- a/middleware/StateMachine/include/IStateMachine.h +++ b/middleware/StateMachine/include/IStateMachine.h @@ -17,7 +17,7 @@ #include "StatusCode.h" #include #include - +bool CreateStateMachine(void); class VStateMessage { public: @@ -73,10 +73,6 @@ 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); - } + virtual const StatusCode CreateStateMachine(std::shared_ptr &stateMachine); }; -bool CreateStateMachine(void); #endif \ No newline at end of file diff --git a/middleware/StateMachine/src/IStateMachine.cpp b/middleware/StateMachine/src/IStateMachine.cpp index 33a4852..4bec08f 100644 --- a/middleware/StateMachine/src/IStateMachine.cpp +++ b/middleware/StateMachine/src/IStateMachine.cpp @@ -18,21 +18,18 @@ std::shared_ptr &IStateMachine::GetInstance(std::shared_ptr *impl) { static std::shared_ptr instance = std::make_shared(); - static bool instanceChanging = false; - if (impl && false == instanceChanging) { - instanceChanging = true; + if (impl) { if (instance.use_count() == 1) { - LogInfo("Instance change succeed.\n"); + LogInfo("Instance changed succeed.\n"); instance = *impl; } else { - LogError("Instance change failed, using by some one.\n"); + LogError("Can't changing the instance becase of using by some one.\n"); } - instanceChanging = false; - } - if (instanceChanging) { - static std::shared_ptr tmporaryInstance = std::make_shared(); - return tmporaryInstance; } return instance; +} +const StatusCode IStateMachine::CreateStateMachine(std::shared_ptr &stateMachine) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/test/middleware/AppManager/src/AppManager_Test.cpp b/test/middleware/AppManager/src/AppManager_Test.cpp index 6f714c1..cb598f3 100644 --- a/test/middleware/AppManager/src/AppManager_Test.cpp +++ b/test/middleware/AppManager/src/AppManager_Test.cpp @@ -133,4 +133,16 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetDateTime) std::this_thread::sleep_for(std::chrono::milliseconds(1000)); IAppManager::GetInstance()->UnInit(); } +// ../output_files/test/bin/AppManagerTest +// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_SetTimeZone +TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetTimeZone) +{ + std::shared_ptr monitor = AppManagerTestTool::MakeMonitorMock(); + IAppManager::GetInstance()->Init(mAppParam); + IAppManager::GetInstance()->SetAppMonitor(monitor); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + MockSetTimeZone(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + IAppManager::GetInstance()->UnInit(); +} } // namespace AppManagerTest \ No newline at end of file diff --git a/test/middleware/AppManager/tool/include/AppManagerTestTool.h b/test/middleware/AppManager/tool/include/AppManagerTestTool.h index 6b4af59..da37b38 100644 --- a/test/middleware/AppManager/tool/include/AppManagerTestTool.h +++ b/test/middleware/AppManager/tool/include/AppManagerTestTool.h @@ -32,6 +32,7 @@ protected: void MockGetSdCardInfo(void); void MockGetBatteryInfo(void); void MockSetDateTime(void); + void MockSetTimeZone(void); void MockUploadFiles(void); private: diff --git a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp index 2957408..adbf105 100644 --- a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp +++ b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp @@ -99,6 +99,18 @@ void AppManagerTestTool::MockSetDateTime(void) .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); ServersMock::GetInstance()->MockSetDateTime(); } +void AppManagerTestTool::MockSetTimeZone(void) +{ + std::shared_ptr mock = std::dynamic_pointer_cast(mAppMonitorMock); + if (!mock) { + LogError("vMock error.\n"); + return; + } + EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) + .Times(ONLY_BE_CALLED_ONCE) + .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); + ServersMock::GetInstance()->MockSetTimeZone(); +} void AppManagerTestTool::MockUploadFiles(void) { // diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp index f1f68d3..c9dafc9 100644 --- a/test/middleware/AppManager/tool/src/AppMonitorMock.cpp +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.cpp @@ -104,6 +104,20 @@ StatusCode AppMonitorTest::SetDateTimeTrace(AppSetDateTime ¶m) LogInfo("AppMonitorTest::SetDateTimeTrace\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +StatusCode AppMonitorTest::SetTimeZone(const unsigned int &zone) +{ + LogInfo("AppMonitorTest::SetTimeZone = %u\n", zone); + StatusCode code = SetTimeZoneTrace(zone); + if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + return VAppMonitor::SetTimeZone(zone); + } + return code; +} +StatusCode AppMonitorTest::SetTimeZoneTrace(const unsigned int &zone) +{ + LogInfo("AppMonitorTest::SetTimeZoneTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m) { LogInfo("AppMonitorTest::UploadFile\n"); diff --git a/test/middleware/AppManager/tool/src/AppMonitorMock.h b/test/middleware/AppManager/tool/src/AppMonitorMock.h index 136a7a0..a8fde72 100644 --- a/test/middleware/AppManager/tool/src/AppMonitorMock.h +++ b/test/middleware/AppManager/tool/src/AppMonitorMock.h @@ -27,6 +27,7 @@ public: StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override; StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override; StatusCode SetDateTime(AppSetDateTime ¶m) override; + StatusCode SetTimeZone(const unsigned int &zone) override; StatusCode UploadFile(AppUploadFile ¶m) override; protected: @@ -36,6 +37,7 @@ protected: virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m); virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo ¶m); virtual StatusCode SetDateTimeTrace(AppSetDateTime ¶m); + virtual StatusCode SetTimeZoneTrace(const unsigned int &zone); virtual StatusCode UploadFileTrace(AppUploadFile ¶m); }; class AppMonitorMock : public AppMonitorTest diff --git a/test/middleware/AppManager/tool/src/ServersMock.cpp b/test/middleware/AppManager/tool/src/ServersMock.cpp index 91e82ee..6d2b861 100644 --- a/test/middleware/AppManager/tool/src/ServersMock.cpp +++ b/test/middleware/AppManager/tool/src/ServersMock.cpp @@ -18,11 +18,12 @@ #include extern const char *APP_GET_PRODUCT_INFO; extern const char *APP_GET_DEVICE_ATTR; -extern const char *APP_UPLOAD_FILE; extern const char *APP_GET_MEDIA_INFO; extern const char *APP_GET_SD_CARD_INFO; extern const char *APP_GET_BATTERY_INFO; extern const char *APP_SET_DATE_TIME; +extern const char *APP_SET_TIME_ZONE; +extern const char *APP_UPLOAD_FILE; std::shared_ptr &ServersMock::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); @@ -156,6 +157,23 @@ void ServersMock::MockSetDateTime(void) DeleteServersHttp(http); } } +void ServersMock::MockSetTimeZone(void) +{ + LogInfo("APP_SET_TIME_ZONE test start.\n"); + std::string mockRequest = mServerUrl + APP_SET_TIME_ZONE + "?timezone=8"; + ServerHttp *http = NewServersHttp(mockRequest.c_str()); + if (http) { + HttpGet(http); + if (http->reply) { + char *replyStr = (char *)malloc(http->replyLength + 1); + memset(replyStr, 0, http->replyLength + 1); + memcpy(replyStr, http->reply, http->replyLength); + LogInfo("HttpGet response :\n%s\n", replyStr); + free(replyStr); + } + DeleteServersHttp(http); + } +} #ifndef PLATFORM_PATH #error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}") #endif diff --git a/test/middleware/AppManager/tool/src/ServersMock.h b/test/middleware/AppManager/tool/src/ServersMock.h index 4bf7d4c..4562a2b 100644 --- a/test/middleware/AppManager/tool/src/ServersMock.h +++ b/test/middleware/AppManager/tool/src/ServersMock.h @@ -29,6 +29,7 @@ public: virtual void MockGetSdCardInfo(void); virtual void MockGetBatteryInfo(void); virtual void MockSetDateTime(void); + virtual void MockSetTimeZone(void); virtual void MockUploadFiles(void); private: