Backup:HunttingCamera module.
This commit is contained in:
parent
c01a4f636f
commit
0c4f039918
|
@ -1,2 +1,3 @@
|
||||||
add_subdirectory(main)
|
add_subdirectory(main)
|
||||||
|
add_subdirectory(HunttingCamera)
|
||||||
add_subdirectory(MissionManager)
|
add_subdirectory(MissionManager)
|
70
application/HunttingCamera/CMakeLists.txt
Normal file
70
application/HunttingCamera/CMakeLists.txt
Normal file
|
@ -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})
|
8
application/HunttingCamera/build/huntting_camera.cmake
Normal file
8
application/HunttingCamera/build/huntting_camera.cmake
Normal file
|
@ -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)
|
24
application/HunttingCamera/main.cpp
Normal file
24
application/HunttingCamera/main.cpp
Normal 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.
|
||||||
|
*/
|
||||||
|
#include "ILog.h"
|
||||||
|
#include "MainThread.h"
|
||||||
|
#include <thread>
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
MainThread::GetInstance()->Init();
|
||||||
|
MainThread::GetInstance()->Runing();
|
||||||
|
MainThread::GetInstance()->UnInit();
|
||||||
|
return 0;
|
||||||
|
}
|
68
application/HunttingCamera/src/MainThread.cpp
Normal file
68
application/HunttingCamera/src/MainThread.cpp
Normal file
|
@ -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 <thread>
|
||||||
|
MainThread::MainThread() { mMainThreadRuning = false; }
|
||||||
|
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<MainThread>();
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
39
application/HunttingCamera/src/MainThread.h
Normal file
39
application/HunttingCamera/src/MainThread.h
Normal file
|
@ -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 <memory>
|
||||||
|
class MainThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MainThread();
|
||||||
|
virtual ~MainThread() = default;
|
||||||
|
static std::shared_ptr<MainThread> &GetInstance(std::shared_ptr<MainThread> *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
|
|
@ -15,8 +15,6 @@ include_directories(
|
||||||
#link_directories(
|
#link_directories(
|
||||||
#)
|
#)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
set(TARGET_NAME MissionManager)
|
set(TARGET_NAME MissionManager)
|
||||||
|
@ -42,4 +40,21 @@ add_custom_command(
|
||||||
COMMAND make MissionManager_code_check
|
COMMAND make MissionManager_code_check
|
||||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
)
|
)
|
||||||
|
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()
|
endif()
|
||||||
|
|
||||||
|
define_file_name(${TARGET_NAME})
|
|
@ -15,8 +15,9 @@
|
||||||
#ifndef I_MISSION_MANAGER
|
#ifndef I_MISSION_MANAGER
|
||||||
#define I_MISSION_MANAGER
|
#define I_MISSION_MANAGER
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
bool CreateMissionManagerModule(void);
|
||||||
enum class MissionEvent
|
enum class MissionEvent
|
||||||
{
|
{
|
||||||
TEST = 0,
|
TEST = 0,
|
||||||
|
@ -41,9 +42,7 @@ class VMissionDataV2 : public VMissionData
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value)
|
VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
virtual ~VMissionDataV2() = default;
|
virtual ~VMissionDataV2() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -58,5 +57,4 @@ public:
|
||||||
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||||
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||||
};
|
};
|
||||||
bool CreateMissionManagerModule(void);
|
|
||||||
#endif
|
#endif
|
|
@ -18,8 +18,7 @@ const bool NOT_EXECUTED = false;
|
||||||
const bool EXECUTED = true;
|
const bool EXECUTED = true;
|
||||||
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
if (nullptr == msg)
|
if (nullptr == msg) {
|
||||||
{
|
|
||||||
LogError("nullptr pointer.\n");
|
LogError("nullptr pointer.\n");
|
||||||
return NOT_EXECUTED;
|
return NOT_EXECUTED;
|
||||||
}
|
}
|
||||||
|
@ -27,8 +26,7 @@ bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||||
std::shared_ptr<MissionData> message = std::dynamic_pointer_cast<MissionData>(msg->GetMessageObj());
|
std::shared_ptr<MissionData> message = std::dynamic_pointer_cast<MissionData>(msg->GetMessageObj());
|
||||||
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
|
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
|
||||||
iter = mEventHandle.find(event);
|
iter = mEventHandle.find(event);
|
||||||
if (iter != mEventHandle.end())
|
if (iter != mEventHandle.end()) {
|
||||||
{
|
|
||||||
return mEventHandle[event](msg);
|
return mEventHandle[event](msg);
|
||||||
}
|
}
|
||||||
return NOT_EXECUTED;
|
return NOT_EXECUTED;
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
*/
|
*/
|
||||||
#ifndef DATAPROCESSING_H
|
#ifndef DATAPROCESSING_H
|
||||||
#define DATAPROCESSING_H
|
#define DATAPROCESSING_H
|
||||||
#include "IStateMachine.h"
|
|
||||||
#include "IMissionManager.h"
|
#include "IMissionManager.h"
|
||||||
|
#include "IStateMachine.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
|
using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
|
||||||
|
@ -27,10 +27,7 @@ enum class InternalStateEvent
|
||||||
class MissionData : public VStateMachineData
|
class MissionData : public VStateMachineData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MissionData(const std::shared_ptr<VMissionData> &data)
|
MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data) {}
|
||||||
: mMissionData(data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
virtual ~MissionData() = default;
|
virtual ~MissionData() = default;
|
||||||
const std::shared_ptr<VMissionData> mMissionData;
|
const std::shared_ptr<VMissionData> mMissionData;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,15 +17,12 @@
|
||||||
std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<IMissionManager> *impl)
|
std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<IMissionManager> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<IMissionManager>();
|
static auto instance = std::make_shared<IMissionManager>();
|
||||||
if (impl)
|
if (impl) {
|
||||||
{
|
if (instance.use_count() == 1) {
|
||||||
if (instance.use_count() == 1)
|
|
||||||
{
|
|
||||||
LogInfo("Instance changed succeed.\n");
|
LogInfo("Instance changed succeed.\n");
|
||||||
instance = *impl;
|
instance = *impl;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
LogError("Can't changing the instance becase of using by some one.\n");
|
LogError("Can't changing the instance becase of using by some one.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> &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;
|
|
||||||
}
|
|
57
application/MissionManager/src/MissionManagerMakePtr.cpp
Normal file
57
application/MissionManager/src/MissionManagerMakePtr.cpp
Normal file
|
@ -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<IMissionManager>();
|
||||||
|
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>();
|
||||||
|
IMissionManager::GetInstance(&instance);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
std::shared_ptr<MissionManagerMakePtr> &MissionManagerMakePtr::GetInstance(std::shared_ptr<MissionManagerMakePtr> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<MissionManagerMakePtr>();
|
||||||
|
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<IMissionManager> &instance)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
std::shared_ptr<State> MissionManagerMakePtr::CreateTopState(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<State> state = std::make_shared<TopState>();
|
||||||
|
return state;
|
||||||
|
}
|
|
@ -18,12 +18,12 @@
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
class MissionManagerMakeImpl
|
class MissionManagerMakePtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MissionManagerMakeImpl() = default;
|
MissionManagerMakePtr() = default;
|
||||||
virtual ~MissionManagerMakeImpl() = default;
|
virtual ~MissionManagerMakePtr() = default;
|
||||||
static std::shared_ptr<MissionManagerMakeImpl> &GetInstance(std::shared_ptr<MissionManagerMakeImpl> *impl = nullptr);
|
static std::shared_ptr<MissionManagerMakePtr> &GetInstance(std::shared_ptr<MissionManagerMakePtr> *impl = nullptr);
|
||||||
virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance);
|
virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance);
|
||||||
virtual std::shared_ptr<State> CreateTopState(void);
|
virtual std::shared_ptr<State> CreateTopState(void);
|
||||||
};
|
};
|
|
@ -14,13 +14,12 @@
|
||||||
*/
|
*/
|
||||||
#include "MissionStateMachine.h"
|
#include "MissionStateMachine.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
|
#include "MissionManagerMakePtr.h"
|
||||||
#include "TopState.h"
|
#include "TopState.h"
|
||||||
#include "MissionManagerMakeImpl.h"
|
|
||||||
std::shared_ptr<MissionStateMachine> &MissionStateMachine::GetInstance(std::shared_ptr<MissionStateMachine> *impl)
|
std::shared_ptr<MissionStateMachine> &MissionStateMachine::GetInstance(std::shared_ptr<MissionStateMachine> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<MissionStateMachine>();
|
static auto instance = std::make_shared<MissionStateMachine>();
|
||||||
if (impl)
|
if (impl) {
|
||||||
{
|
|
||||||
instance = *impl;
|
instance = *impl;
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -28,25 +27,21 @@ std::shared_ptr<MissionStateMachine> &MissionStateMachine::GetInstance(std::shar
|
||||||
void MissionStateMachine::Init(void)
|
void MissionStateMachine::Init(void)
|
||||||
{
|
{
|
||||||
auto code = IStateMachine::GetInstance()->CreateStateMachine(mStateMachine);
|
auto code = IStateMachine::GetInstance()->CreateStateMachine(mStateMachine);
|
||||||
if (IsCodeOK(code))
|
if (IsCodeOK(code)) {
|
||||||
{
|
|
||||||
LogError("Create state machine failed.\n");
|
LogError("Create state machine failed.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!mStateMachine->InitialStateMachine())
|
if (!mStateMachine->InitialStateMachine()) {
|
||||||
{
|
|
||||||
LogError("State machine init failed.\n");
|
LogError("State machine init failed.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// mStartMission = IDeviceManager::GetInstance()->GetIpcMission();
|
// mStartMission = IDeviceManager::GetInstance()->GetIpcMission();
|
||||||
// RunStateMachine(mStartMission);
|
// RunStateMachine(mStartMission);
|
||||||
}
|
}
|
||||||
void MissionStateMachine::UnInit(void)
|
void MissionStateMachine::UnInit(void) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
// void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
// void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||||
// {
|
// {
|
||||||
// LogInfo("Make all states and start the state machine.\n");
|
// 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());
|
// mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
*/
|
*/
|
||||||
#ifndef MISSIONSTATEMACHINE_H
|
#ifndef MISSIONSTATEMACHINE_H
|
||||||
#define MISSIONSTATEMACHINE_H
|
#define MISSIONSTATEMACHINE_H
|
||||||
#include "IStateMachine.h"
|
|
||||||
#include "IMissionManager.h"
|
|
||||||
#include "IDeviceManager.h"
|
#include "IDeviceManager.h"
|
||||||
|
#include "IMissionManager.h"
|
||||||
|
#include "IStateMachine.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
enum class MissionState
|
enum class MissionState
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,16 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "TopState.h"
|
#include "TopState.h"
|
||||||
TopState::TopState() : State("TopState")
|
TopState::TopState() : State("TopState") {}
|
||||||
{
|
void TopState::GoInState() {}
|
||||||
}
|
void TopState::GoOutState() {}
|
||||||
void TopState::GoInState()
|
bool TopState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); }
|
||||||
{
|
|
||||||
}
|
|
||||||
void TopState::GoOutState()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
bool TopState::ExecuteStateMsg(VStateMachineData *msg)
|
|
||||||
{
|
|
||||||
return DataProcessing::EventHandle(msg);
|
|
||||||
}
|
|
|
@ -14,11 +14,9 @@
|
||||||
*/
|
*/
|
||||||
#ifndef TOPSTATE_H
|
#ifndef TOPSTATE_H
|
||||||
#define TOPSTATE_H
|
#define TOPSTATE_H
|
||||||
#include "IStateMachine.h"
|
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
class TopState
|
#include "IStateMachine.h"
|
||||||
: public State,
|
class TopState : public State, public DataProcessing
|
||||||
public DataProcessing
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TopState();
|
TopState();
|
||||||
|
|
|
@ -14,8 +14,6 @@ link_directories(
|
||||||
${HAL_SOURCE_PATH}/include
|
${HAL_SOURCE_PATH}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aux_source_directory(./ SRC_FILES)
|
aux_source_directory(./ SRC_FILES)
|
||||||
# aux_source_directory(./src SRC_FILES)
|
# aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,7 @@ public:
|
||||||
virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m);
|
virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m);
|
||||||
virtual StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m);
|
virtual StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m);
|
||||||
virtual StatusCode SetDateTime(AppSetDateTime ¶m);
|
virtual StatusCode SetDateTime(AppSetDateTime ¶m);
|
||||||
|
virtual StatusCode SetTimeZone(const unsigned int &zone);
|
||||||
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
||||||
};
|
};
|
||||||
typedef struct app_param
|
typedef struct app_param
|
||||||
|
|
|
@ -38,6 +38,10 @@ StatusCode inline VAppMonitor::SetDateTime(AppSetDateTime ¶m)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
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)
|
StatusCode inline VAppMonitor::UploadFile(AppUploadFile ¶m)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
|
|
@ -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_SD_CARD_INFO = "/app/getsdinfo";
|
||||||
const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo";
|
const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo";
|
||||||
const char *APP_SET_DATE_TIME = "/app/setsystime";
|
const char *APP_SET_DATE_TIME = "/app/setsystime";
|
||||||
|
const char *APP_SET_TIME_ZONE = "/app/settimezone";
|
||||||
const char *APP_UPLOAD_FILE = "/upload";
|
const char *APP_UPLOAD_FILE = "/upload";
|
||||||
|
constexpr bool SET_REQUEST_RESPONSE = true;
|
||||||
SixFrameHandle::SixFrameHandle()
|
SixFrameHandle::SixFrameHandle()
|
||||||
{
|
{
|
||||||
mAppMonitor = std::make_shared<VAppMonitor>();
|
mAppMonitor = std::make_shared<VAppMonitor>();
|
||||||
|
@ -37,6 +39,7 @@ SixFrameHandle::SixFrameHandle()
|
||||||
mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3);
|
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_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_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[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3);
|
||||||
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _);
|
// 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;
|
char *resultStr = nullptr;
|
||||||
AppSetDateTime param = RequestSetDateTimeParse(url);
|
AppSetDateTime param = RequestSetDateTimeParse(url);
|
||||||
mAppMonitor->SetDateTime(param);
|
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<VParseUrl> &parse) {
|
||||||
|
std::shared_ptr<ParseUrl<std::string>> parseyImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||||
|
if ("timezone" == key) {
|
||||||
|
parseyImpl->mData = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
|
||||||
|
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||||
|
std::shared_ptr<ParseUrl<std::string>> parseyImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(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);
|
// ResponseGetBatteryInfo(result, param);
|
||||||
resultStr = cJSON_Print(result);
|
resultStr = cJSON_Print(result);
|
||||||
responseHandle(resultStr, context);
|
responseHandle(resultStr, context);
|
||||||
|
@ -250,11 +284,20 @@ void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle respon
|
||||||
free(resultStr);
|
free(resultStr);
|
||||||
cJSON_Delete(result);
|
cJSON_Delete(result);
|
||||||
}
|
}
|
||||||
cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result)
|
cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result, const bool requestSet)
|
||||||
{
|
{
|
||||||
const char *RESPONSE_RESULT = "result";
|
const char *RESPONSE_RESULT = "result";
|
||||||
cJSON *resultCJSON = cJSON_CreateObject();
|
cJSON *resultCJSON = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(result));
|
cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(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;
|
return resultCJSON;
|
||||||
}
|
}
|
||||||
void SixFrameHandle::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
void SixFrameHandle::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||||
|
|
|
@ -69,10 +69,12 @@ private:
|
||||||
void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m);
|
void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m);
|
||||||
AppSetDateTime RequestSetDateTimeParse(const std::string &url);
|
AppSetDateTime RequestSetDateTimeParse(const std::string &url);
|
||||||
void RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context);
|
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);
|
void RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cJSON *MakeResponseResult(const ResposeResult result);
|
cJSON *MakeResponseResult(const ResposeResult result, const bool requestSet = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||||
|
|
|
@ -15,8 +15,6 @@ include_directories(
|
||||||
#link_directories(
|
#link_directories(
|
||||||
#)
|
#)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
aux_source_directory(./src/OpenHarmony SRC_FILES_OPENHARMONY)
|
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")
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
StateMahince_code_check
|
StateMachine_code_check
|
||||||
COMMAND ${CLANG_TIDY_EXE}
|
COMMAND ${CLANG_TIDY_EXE}
|
||||||
-checks='${CLANG_TIDY_CHECKS}'
|
-checks='${CLANG_TIDY_CHECKS}'
|
||||||
--header-filter=.*
|
--header-filter=.*
|
||||||
|
@ -37,9 +35,15 @@ add_custom_target(
|
||||||
-p ${PLATFORM_PATH}/cmake-shell
|
-p ${PLATFORM_PATH}/cmake-shell
|
||||||
WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/StateMachine
|
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)
|
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
StateMahince_code_format
|
StateMachine_code_format
|
||||||
COMMAND ${CLANG_FORMAT_EXE}
|
COMMAND ${CLANG_FORMAT_EXE}
|
||||||
-style=file
|
-style=file
|
||||||
-i ${SRC_FILES} ${HEADER_FILES}
|
-i ${SRC_FILES} ${HEADER_FILES}
|
||||||
|
@ -48,8 +52,10 @@ add_custom_target(
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${TARGET_NAME}
|
TARGET ${TARGET_NAME}
|
||||||
PRE_BUILD
|
PRE_BUILD
|
||||||
COMMAND make StateMahince_code_check
|
COMMAND make StateMachine_code_check
|
||||||
COMMAND make StateMahince_code_format
|
COMMAND make StateMachine_code_format
|
||||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
define_file_name(${TARGET_NAME})
|
|
@ -17,7 +17,7 @@
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
bool CreateStateMachine(void);
|
||||||
class VStateMessage
|
class VStateMessage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -73,10 +73,6 @@ public:
|
||||||
IStateMachine() = default;
|
IStateMachine() = default;
|
||||||
virtual ~IStateMachine() = default;
|
virtual ~IStateMachine() = default;
|
||||||
static std::shared_ptr<IStateMachine> &GetInstance(std::shared_ptr<IStateMachine> *impl = nullptr);
|
static std::shared_ptr<IStateMachine> &GetInstance(std::shared_ptr<IStateMachine> *impl = nullptr);
|
||||||
virtual const StatusCode CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine)
|
virtual const StatusCode CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine);
|
||||||
{
|
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
bool CreateStateMachine(void);
|
|
||||||
#endif
|
#endif
|
|
@ -18,21 +18,18 @@
|
||||||
std::shared_ptr<IStateMachine> &IStateMachine::GetInstance(std::shared_ptr<IStateMachine> *impl)
|
std::shared_ptr<IStateMachine> &IStateMachine::GetInstance(std::shared_ptr<IStateMachine> *impl)
|
||||||
{
|
{
|
||||||
static std::shared_ptr<IStateMachine> instance = std::make_shared<IStateMachine>();
|
static std::shared_ptr<IStateMachine> instance = std::make_shared<IStateMachine>();
|
||||||
static bool instanceChanging = false;
|
if (impl) {
|
||||||
if (impl && false == instanceChanging) {
|
|
||||||
instanceChanging = true;
|
|
||||||
if (instance.use_count() == 1) {
|
if (instance.use_count() == 1) {
|
||||||
LogInfo("Instance change succeed.\n");
|
LogInfo("Instance changed succeed.\n");
|
||||||
instance = *impl;
|
instance = *impl;
|
||||||
}
|
}
|
||||||
else {
|
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<IStateMachine> tmporaryInstance = std::make_shared<IStateMachine>();
|
|
||||||
return tmporaryInstance;
|
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
const StatusCode IStateMachine::CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
|
@ -133,4 +133,16 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetDateTime)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
IAppManager::GetInstance()->UnInit();
|
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<VAppMonitor> 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
|
} // namespace AppManagerTest
|
|
@ -32,6 +32,7 @@ protected:
|
||||||
void MockGetSdCardInfo(void);
|
void MockGetSdCardInfo(void);
|
||||||
void MockGetBatteryInfo(void);
|
void MockGetBatteryInfo(void);
|
||||||
void MockSetDateTime(void);
|
void MockSetDateTime(void);
|
||||||
|
void MockSetTimeZone(void);
|
||||||
void MockUploadFiles(void);
|
void MockUploadFiles(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -99,6 +99,18 @@ void AppManagerTestTool::MockSetDateTime(void)
|
||||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
ServersMock::GetInstance()->MockSetDateTime();
|
ServersMock::GetInstance()->MockSetDateTime();
|
||||||
}
|
}
|
||||||
|
void AppManagerTestTool::MockSetTimeZone(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(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)
|
void AppManagerTestTool::MockUploadFiles(void)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
|
@ -104,6 +104,20 @@ StatusCode AppMonitorTest::SetDateTimeTrace(AppSetDateTime ¶m)
|
||||||
LogInfo("AppMonitorTest::SetDateTimeTrace\n");
|
LogInfo("AppMonitorTest::SetDateTimeTrace\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
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)
|
StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m)
|
||||||
{
|
{
|
||||||
LogInfo("AppMonitorTest::UploadFile\n");
|
LogInfo("AppMonitorTest::UploadFile\n");
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
||||||
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
||||||
StatusCode SetDateTime(AppSetDateTime ¶m) override;
|
StatusCode SetDateTime(AppSetDateTime ¶m) override;
|
||||||
|
StatusCode SetTimeZone(const unsigned int &zone) override;
|
||||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -36,6 +37,7 @@ protected:
|
||||||
virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m);
|
virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m);
|
||||||
virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo ¶m);
|
virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo ¶m);
|
||||||
virtual StatusCode SetDateTimeTrace(AppSetDateTime ¶m);
|
virtual StatusCode SetDateTimeTrace(AppSetDateTime ¶m);
|
||||||
|
virtual StatusCode SetTimeZoneTrace(const unsigned int &zone);
|
||||||
virtual StatusCode UploadFileTrace(AppUploadFile ¶m);
|
virtual StatusCode UploadFileTrace(AppUploadFile ¶m);
|
||||||
};
|
};
|
||||||
class AppMonitorMock : public AppMonitorTest
|
class AppMonitorMock : public AppMonitorTest
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
extern const char *APP_GET_PRODUCT_INFO;
|
extern const char *APP_GET_PRODUCT_INFO;
|
||||||
extern const char *APP_GET_DEVICE_ATTR;
|
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_MEDIA_INFO;
|
||||||
extern const char *APP_GET_SD_CARD_INFO;
|
extern const char *APP_GET_SD_CARD_INFO;
|
||||||
extern const char *APP_GET_BATTERY_INFO;
|
extern const char *APP_GET_BATTERY_INFO;
|
||||||
extern const char *APP_SET_DATE_TIME;
|
extern const char *APP_SET_DATE_TIME;
|
||||||
|
extern const char *APP_SET_TIME_ZONE;
|
||||||
|
extern const char *APP_UPLOAD_FILE;
|
||||||
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<ServersMock>();
|
static auto instance = std::make_shared<ServersMock>();
|
||||||
|
@ -156,6 +157,23 @@ void ServersMock::MockSetDateTime(void)
|
||||||
DeleteServersHttp(http);
|
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
|
#ifndef PLATFORM_PATH
|
||||||
#error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}")
|
#error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}")
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
virtual void MockGetSdCardInfo(void);
|
virtual void MockGetSdCardInfo(void);
|
||||||
virtual void MockGetBatteryInfo(void);
|
virtual void MockGetBatteryInfo(void);
|
||||||
virtual void MockSetDateTime(void);
|
virtual void MockSetDateTime(void);
|
||||||
|
virtual void MockSetTimeZone(void);
|
||||||
virtual void MockUploadFiles(void);
|
virtual void MockUploadFiles(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user