mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Merge branch 'master-develop' of gitee.com:shenzhen-jiuyilian/ipc into master-develop
This commit is contained in:
commit
a2f8103fa5
|
@ -14,8 +14,8 @@ AllowAllConstructorInitializersOnNextLine: true
|
|||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.5.1)
|
||||
|
||||
unset(CLANG_TIDY_EXE CACHE)
|
||||
set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING INTERNAL)
|
||||
include(build/global_config.cmake)
|
||||
|
||||
project(fancycode)
|
||||
|
@ -60,6 +63,8 @@ if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
|||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${ALL_MODEFIED_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
--line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]'
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}
|
||||
)
|
||||
|
|
|
@ -33,7 +33,10 @@ void InitSignalHandle(void)
|
|||
signal(SIGKILL, sigHandler);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
MainThread::MainThread() { mMainThreadRuning = false; }
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
|
@ -87,7 +90,9 @@ void MainThread::DestoryAllModules(void)
|
|||
DestroyMcuManager();
|
||||
DestroyHalCppModule();
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void) {}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning) {
|
||||
|
|
|
@ -25,7 +25,10 @@ public:
|
|||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void) { mMainThreadRuning = false; }
|
||||
void Exit(void)
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
virtual void CustomizationInit(void);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,9 @@ 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:
|
||||
|
|
|
@ -40,17 +40,17 @@ StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m)
|
|||
StatusCode AppMonitor::GetMediaInfo(AppGetMeidaInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetMediaInfo.\n");
|
||||
param.mRtspUrl = "rtsp://192.168.169.1/stream.mp4";
|
||||
param.mRtspUrl = "rtsp://192.168.169.1/live/1";
|
||||
param.mTransport = "tcp";
|
||||
param.mPort = 6035;
|
||||
param.mPort = 554;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetSdCardInfo.\n");
|
||||
param.mStatus = SdCardStatus::CARD_DAMAGED;
|
||||
param.mFree = 0;
|
||||
param.mTotal = 0;
|
||||
param.mStatus = SdCardStatus::NORMAL;
|
||||
param.mFree = 1024 * 32;
|
||||
param.mTotal = 1024 * 32;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||
|
@ -60,7 +60,54 @@ StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
|||
param.mChargeStatus = ChargeStatus::CHARGING;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetDateTime(AppSetDateTime ¶m)
|
||||
StatusCode AppMonitor::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
param.mMicStatus = SwitchStatus::ON;
|
||||
param.mRec = SwitchStatus::OFF;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
param.mPlaybackType = PlaybackType::DOWNLOAD_PLAYBACK;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
param = LockVideoStatus::LOCK;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
AppGetStorageInfo info;
|
||||
info.mIndex = 0;
|
||||
info.mName = "TF card";
|
||||
info.mType = StorageType::SD_CARD_1;
|
||||
info.mFree = 1024 * 32;
|
||||
info.mTotal = 1024 * 32;
|
||||
param.push_back(info);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
||||
AppGetFileList file;
|
||||
file.mCreateTime_s = 123456789;
|
||||
file.mDuration = 182;
|
||||
file.mName = "/DCIM/2024/01/15/20240115140207-20240115140509.mp4";
|
||||
file.mSize = 1024 * 182;
|
||||
file.mType = StorageFileType::VIDEO;
|
||||
param.push_back(file);
|
||||
AppGetFileList file2;
|
||||
file2.mCreateTime_s = 123456789;
|
||||
file2.mDuration = 0;
|
||||
file2.mName = "/34a396526922a33e97906920dbfef2a5.jpg";
|
||||
file2.mSize = 1024;
|
||||
file2.mType = StorageFileType::PICTURE;
|
||||
param.push_back(file2);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
|
@ -70,8 +117,25 @@ StatusCode AppMonitor::SetTimeZone(const unsigned int &zone)
|
|||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::EnterRecorder(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||
{
|
||||
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
|
@ -25,8 +25,17 @@ public:
|
|||
StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override;
|
||||
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
||||
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
||||
StatusCode SetDateTime(AppSetDateTime ¶m) override;
|
||||
StatusCode GetParamValue(AppParamValue ¶m) override;
|
||||
StatusCode GetCapability(AppGetCapability ¶m) override;
|
||||
StatusCode GetLockVideoStatus(LockVideoStatus ¶m) override;
|
||||
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> ¶m) override;
|
||||
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m) override;
|
||||
StatusCode SetDateTime(const AppSetDateTime ¶m) override;
|
||||
StatusCode SetTimeZone(const unsigned int &zone) override;
|
||||
StatusCode SetParamValue(const AppSetParamValue ¶m) override;
|
||||
StatusCode EnterRecorder(void) override;
|
||||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||
StatusCode GetThumbnail(AppGetThumbnail ¶m) override;
|
||||
};
|
||||
#endif
|
|
@ -27,7 +27,9 @@ enum class InternalStateEvent
|
|||
class MissionData : public VStateMachineData
|
||||
{
|
||||
public:
|
||||
MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data) {}
|
||||
MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
||||
{
|
||||
}
|
||||
virtual ~MissionData() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData;
|
||||
};
|
||||
|
|
|
@ -28,5 +28,11 @@ std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<I
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode IMissionManager::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IMissionManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IMissionManager::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IMissionManager::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -15,7 +15,9 @@
|
|||
#include "MissionState.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
MissionState::MissionState(const std::string &name) : State(name) {}
|
||||
MissionState::MissionState(const std::string &name) : State(name)
|
||||
{
|
||||
}
|
||||
void MissionState::GoInState()
|
||||
{
|
||||
//
|
||||
|
@ -26,4 +28,7 @@ void MissionState::GoOutState()
|
|||
//
|
||||
LogInfo(" ========== MissionState::GoOutState.\n");
|
||||
}
|
||||
bool MissionState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); }
|
||||
bool MissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
|
@ -63,7 +63,10 @@ IpcMission MissionStateMachine::GetStartMission(void)
|
|||
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) { mDataReply = IpcMission::END; }
|
||||
McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
mDataReply = IpcMission::END;
|
||||
}
|
||||
virtual ~McuAskIpcMission() = default;
|
||||
};
|
||||
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>();
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
#include "TestMissionState.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
TestMissionState::TestMissionState() : MissionState("TestMissionState") {}
|
||||
TestMissionState::TestMissionState() : MissionState("TestMissionState")
|
||||
{
|
||||
}
|
||||
void TestMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
|
@ -31,4 +33,7 @@ void TestMissionState::GoOutState()
|
|||
MissionState::GoOutState();
|
||||
LogInfo(" ========== TestMissionState::GoOutState.\n");
|
||||
}
|
||||
bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg) { return MissionState::EventHandle(msg); }
|
||||
bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return MissionState::EventHandle(msg);
|
||||
}
|
|
@ -15,7 +15,9 @@
|
|||
#include "TopState.h"
|
||||
#include "ILog.h"
|
||||
#include "MissionStateMachine.h"
|
||||
TopState::TopState() : State("TopState") {}
|
||||
TopState::TopState() : State("TopState")
|
||||
{
|
||||
}
|
||||
void TopState::GoInState()
|
||||
{
|
||||
//
|
||||
|
@ -27,4 +29,7 @@ void TopState::GoOutState()
|
|||
//
|
||||
LogInfo(" ========== opState::GoOutState.\n");
|
||||
}
|
||||
bool TopState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); }
|
||||
bool TopState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
|
@ -16,7 +16,10 @@
|
|||
#include "IHalCpp.h"
|
||||
#include "ILog.h"
|
||||
#include <thread>
|
||||
MainThread::MainThread() { mMainThreadRuning = false; }
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
|
@ -56,8 +59,12 @@ StatusCode MainThread::CreateAllModules(void)
|
|||
CreateHalCppModule();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MainThread::DestoryAllModules(void) {}
|
||||
void MainThread::ResetAllPtrMaker(void) {}
|
||||
void MainThread::DestoryAllModules(void)
|
||||
{
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning) {
|
||||
|
|
|
@ -25,8 +25,13 @@ public:
|
|||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void) { mMainThreadRuning = false; }
|
||||
virtual void CustomizationInit(void) {}
|
||||
void Exit(void)
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
virtual void CustomizationInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
StatusCode CreateAllModules(void);
|
||||
|
|
|
@ -68,6 +68,7 @@ set(CURL_SHARED_LIBS_PATH "/mnt/mmc")
|
|||
# ------------ build curl + openssl ------------ end
|
||||
|
||||
# ------------ build AppManager ------------ #
|
||||
set(APP_MANAGER_HTTP_SERVER_IP "localhost")
|
||||
# set(APP_MANAGER_HTTP_SERVER_IP "localhost")
|
||||
set(APP_MANAGER_HTTP_SERVER_IP "192.168.1.29")
|
||||
set(APP_MANAGER_HTTP_SERVER_PORT "8080")
|
||||
# ------------ build AppManager end ------------ #
|
|
@ -1,6 +1,6 @@
|
|||
set(DEFINE_LINUX "linux")
|
||||
set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR}")
|
||||
set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR_IPCSDK}${SUBMODULE_PATH_OF_IPC_SDK}")
|
||||
# set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR}")
|
||||
# set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR_IPCSDK}${SUBMODULE_PATH_OF_IPC_SDK}")
|
||||
set(EXEC_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/bin")
|
||||
set(LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs")
|
||||
set(EXTERNAL_LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/external")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
include(${CMAKE_SOURCE_DIR}${SUBMODULE_PATH_OF_IPC_SDK}/build/global_config.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
|
|
20
doc/huntting_project_report.md
Normal file
20
doc/huntting_project_report.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# 1. 项目进度汇总
|
||||
|
||||
## 1.1. 软件开发进度
|
||||
|
||||
```mermaid
|
||||
gantt
|
||||
dateFormat YYYY-MM-DD
|
||||
title 软件进度-3月
|
||||
section 3月
|
||||
6帧探RTSP推流 : done, rtsp_media, 2024-03-18,3d
|
||||
SC230AI快启验证(快启报错) : crit, active, 2024-03-21,3d
|
||||
6帧探视频回放 : active, 2024-03-25,3d
|
||||
```
|
||||
|
||||
### 1.1.1. 总结
|
||||
|
||||
* 截至2024-3-25:
|
||||
1. 6侦探协议框架含http和tcp,http协议框架开发完成,rtsp推流到手机APP完成;
|
||||
2. 存在问题:rtsp推流存在卡顿问题,待优化;
|
||||
3. 更换SC230AI调试快启,快启报错,需要提问题单找原厂协助;
|
|
@ -67,7 +67,7 @@ if(EPOLL)
|
|||
target_compile_definitions(httpsrv PRIVATE EPOLL)
|
||||
endif()
|
||||
|
||||
message("${PLATFORM_PATH}/cmake-shell/external${SUBMODULE_PATH_OF_IPC_SDK}/httpserver.h-master/src/libhttpsrv.a")
|
||||
message("${PLATFORM_PATH}/cmake-shell${SUBMODULE_PATH_OF_IPC_SDK}/httpserver.h-master/src/libhttpsrv.a")
|
||||
add_custom_command(
|
||||
TARGET httpsrv
|
||||
POST_BUILD
|
||||
|
|
|
@ -17,16 +17,27 @@
|
|||
#include "StatusCode.h"
|
||||
// #include <stddef.h>
|
||||
#include <string.h>
|
||||
static StatusCode IHalInit(IHal *object) { return IHalCpp::GetInstance()->Init(); }
|
||||
static void IHalFree(void *object) {}
|
||||
static StatusCode IHalUnInit(IHal *object) { return IHalCpp::GetInstance()->UnInit(); }
|
||||
static StatusCode IHalInit(IHal *object)
|
||||
{
|
||||
return IHalCpp::GetInstance()->Init();
|
||||
}
|
||||
static void IHalFree(void *object)
|
||||
{
|
||||
}
|
||||
static StatusCode IHalUnInit(IHal *object)
|
||||
{
|
||||
return IHalCpp::GetInstance()->UnInit();
|
||||
}
|
||||
static IHal default_hal = {
|
||||
.init = IHalInit,
|
||||
.un_init = IHalUnInit,
|
||||
.free = IHalFree,
|
||||
};
|
||||
static IHal *hal_instance = &default_hal;
|
||||
IHal *GetHalIntance(void) { return hal_instance; }
|
||||
IHal *GetHalIntance(void)
|
||||
{
|
||||
return hal_instance;
|
||||
}
|
||||
StatusCode NewIHal(IHal **object)
|
||||
{
|
||||
if (!object || !(*object)) {
|
||||
|
|
|
@ -29,8 +29,14 @@ std::shared_ptr<IHalCpp> &IHalCpp::GetInstance(std::shared_ptr<IHalCpp> *impl)
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
StatusCode IHalCpp::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
StatusCode IHalCpp::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
StatusCode IHalCpp::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
|
|
@ -48,8 +48,14 @@ typedef struct i_hal
|
|||
IHal *GetHalIntance(void);
|
||||
StatusCode NewIHal(IHal **object);
|
||||
void ResetHalImpl(IHal *impl);
|
||||
static inline StatusCode IHalInit(void) { return GetHalIntance()->init(GetHalIntance()); }
|
||||
static inline StatusCode IHalUnInit(void) { return GetHalIntance()->un_init(GetHalIntance()); }
|
||||
static inline StatusCode IHalInit(void)
|
||||
{
|
||||
return GetHalIntance()->init(GetHalIntance());
|
||||
}
|
||||
static inline StatusCode IHalUnInit(void)
|
||||
{
|
||||
return GetHalIntance()->un_init(GetHalIntance());
|
||||
}
|
||||
StatusCode CreateHalModule(void);
|
||||
StatusCode DestroyHalModule(void);
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -40,9 +40,15 @@ class VKeyHal
|
|||
public:
|
||||
VKeyHal() = default;
|
||||
virtual ~VKeyHal() = default;
|
||||
virtual void CheckKeyStatus(void) {}
|
||||
virtual void GetHoldPressingTimeMs(long int &holdTimeMs, VirtualKeyEvent &event) {}
|
||||
virtual void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor) {}
|
||||
virtual void CheckKeyStatus(void)
|
||||
{
|
||||
}
|
||||
virtual void GetHoldPressingTimeMs(long int &holdTimeMs, VirtualKeyEvent &event)
|
||||
{
|
||||
}
|
||||
virtual void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor)
|
||||
{
|
||||
}
|
||||
};
|
||||
class VLedHal
|
||||
{
|
||||
|
@ -55,7 +61,10 @@ class VWifiHal
|
|||
public:
|
||||
VWifiHal() = default;
|
||||
virtual ~VWifiHal() = default;
|
||||
virtual StatusCode OpenApMode(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
virtual StatusCode OpenApMode(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
};
|
||||
class IHalCpp
|
||||
{
|
||||
|
|
|
@ -24,8 +24,14 @@ public:
|
|||
HalMakePtr() = default;
|
||||
virtual ~HalMakePtr() = default;
|
||||
static std::shared_ptr<HalMakePtr> &GetInstance(std::shared_ptr<HalMakePtr> *impl = nullptr);
|
||||
virtual StatusCode Init() { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
virtual StatusCode UnInit() { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
virtual StatusCode Init()
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
virtual StatusCode UnInit()
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
virtual StatusCode CreateHalPtr(IHal **hal);
|
||||
virtual StatusCode CreateHalSharePtr(std::shared_ptr<IHalCpp> &impl);
|
||||
virtual StatusCode CreateWifiHal(std::shared_ptr<VWifiHal> &impl);
|
||||
|
|
|
@ -31,34 +31,12 @@ enum class UploadCommand
|
|||
UPGRADE_CPU = 0,
|
||||
END
|
||||
};
|
||||
typedef struct app_get_product_info
|
||||
enum class ChargeStatus
|
||||
{
|
||||
app_get_product_info() {}
|
||||
std::string mModel;
|
||||
std::string mCompany;
|
||||
std::string mSoc;
|
||||
std::string mSp;
|
||||
} AppGetProductInfo;
|
||||
typedef struct app_get_device_attr
|
||||
{
|
||||
app_get_device_attr() {}
|
||||
std::string mUUID;
|
||||
std::string mSoftVersion;
|
||||
std::string mOtaVersion;
|
||||
std::string mHardwareVersion;
|
||||
std::string mSSID;
|
||||
std::string mBSSID;
|
||||
std::string mCameraNumber;
|
||||
std::string mCurrentCameraID;
|
||||
std::string mWifiReboot;
|
||||
} AppGetDeviceAttr;
|
||||
typedef struct app_get_media_info
|
||||
{
|
||||
app_get_media_info() { mPort = -1; }
|
||||
std::string mRtspUrl;
|
||||
std::string mTransport;
|
||||
int mPort;
|
||||
} AppGetMeidaInfo;
|
||||
UNCHARGED = 0,
|
||||
CHARGING,
|
||||
END
|
||||
};
|
||||
enum class SdCardStatus
|
||||
{
|
||||
NORMAL = 0,
|
||||
|
@ -71,6 +49,143 @@ enum class SdCardStatus
|
|||
FORMATTING = 13,
|
||||
END = 99
|
||||
};
|
||||
enum class LockVideoStatus
|
||||
{
|
||||
UNLOCK = 0,
|
||||
LOCK,
|
||||
END
|
||||
};
|
||||
enum class StorageType
|
||||
{
|
||||
EMMC = 0,
|
||||
SD_CARD_1,
|
||||
SD_CARD_2,
|
||||
END
|
||||
};
|
||||
enum class PlayBackEvent
|
||||
{
|
||||
START = 0,
|
||||
STOP,
|
||||
END
|
||||
};
|
||||
enum class StorageFileType
|
||||
{
|
||||
PICTURE = 1,
|
||||
VIDEO,
|
||||
END
|
||||
};
|
||||
enum class StorageFileEvent
|
||||
{
|
||||
LOOP = 0,
|
||||
PIR,
|
||||
CRASH,
|
||||
EMR,
|
||||
EVENT,
|
||||
PARK,
|
||||
END
|
||||
};
|
||||
enum class SwitchStatus
|
||||
{
|
||||
OFF = 0,
|
||||
ON,
|
||||
END
|
||||
};
|
||||
enum class GpsCapability
|
||||
{
|
||||
NOT_SUPPORT = 0,
|
||||
END
|
||||
};
|
||||
enum class DeviceType
|
||||
{
|
||||
DASH_CAMERA = 0,
|
||||
END
|
||||
};
|
||||
enum class DashAlbum
|
||||
{
|
||||
SUPPORT_PARKING_MONITOR_ALBUM = 0,
|
||||
NOT_SUPPORT_PARKING_MONITOR_ALBUM,
|
||||
END
|
||||
};
|
||||
enum class AppLock
|
||||
{
|
||||
NOT_SUPPORT_APP_LOCK = 0,
|
||||
SUPPORT_APP_LOCK,
|
||||
END
|
||||
};
|
||||
enum class DeleteLock
|
||||
{
|
||||
SUPPORT_DELETE_LOCK = 0,
|
||||
NOT_SUPPORT_DELETE_LOCK,
|
||||
END
|
||||
};
|
||||
enum class DeviceMode
|
||||
{
|
||||
NEED_TO_SWITCH = 0,
|
||||
NOT_NEED_TO_SWITCH,
|
||||
END
|
||||
};
|
||||
enum class PlaybackType
|
||||
{
|
||||
DOWNLOAD_PLAYBACK = 0,
|
||||
RTSP_TCP,
|
||||
RTSP_UDP,
|
||||
END
|
||||
};
|
||||
enum class PhotographCapability
|
||||
{
|
||||
SUPPORT_TAKE_PICTURE = 0,
|
||||
NOT_SUPPORT_TAKE_PICTURE,
|
||||
END
|
||||
};
|
||||
enum class WifiCapability
|
||||
{
|
||||
SUPPORT_MODIFY_SSID_AND_PASSWORD = 0,
|
||||
ONLY_SUPPORT_MODIFY_PASSWORD,
|
||||
NOLY_SUPPORT_MODIFY_SSID,
|
||||
NOT_SUPPORT_MODIFY_ANYTHING,
|
||||
END
|
||||
};
|
||||
enum class FileCopy
|
||||
{
|
||||
NOT_SUPPORT_COPY = 0,
|
||||
SUPPORT_COPY,
|
||||
END
|
||||
};
|
||||
typedef struct app_get_product_info
|
||||
{
|
||||
app_get_product_info()
|
||||
{
|
||||
}
|
||||
std::string mModel;
|
||||
std::string mCompany;
|
||||
std::string mSoc;
|
||||
std::string mSp;
|
||||
} AppGetProductInfo;
|
||||
typedef struct app_get_device_attr
|
||||
{
|
||||
app_get_device_attr()
|
||||
{
|
||||
}
|
||||
std::string mUUID;
|
||||
std::string mSoftVersion;
|
||||
std::string mOtaVersion;
|
||||
std::string mHardwareVersion;
|
||||
std::string mSSID;
|
||||
std::string mBSSID;
|
||||
std::string mCameraNumber;
|
||||
std::string mCurrentCameraID;
|
||||
std::string mWifiReboot;
|
||||
} AppGetDeviceAttr;
|
||||
typedef struct app_get_media_info
|
||||
{
|
||||
app_get_media_info()
|
||||
{
|
||||
mPort = -1;
|
||||
}
|
||||
std::string mRtspUrl;
|
||||
std::string mTransport;
|
||||
int mPort;
|
||||
} AppGetMeidaInfo;
|
||||
typedef struct app_get_sd_card_info
|
||||
{
|
||||
app_get_sd_card_info()
|
||||
|
@ -83,12 +198,6 @@ typedef struct app_get_sd_card_info
|
|||
int mFree;
|
||||
int mTotal;
|
||||
} AppGetSdCardInfo;
|
||||
enum class ChargeStatus
|
||||
{
|
||||
UNCHARGED = 0,
|
||||
CHARGING,
|
||||
END
|
||||
};
|
||||
typedef struct app_get_battery_info
|
||||
{
|
||||
app_get_battery_info()
|
||||
|
@ -99,6 +208,93 @@ typedef struct app_get_battery_info
|
|||
int mCapacity;
|
||||
ChargeStatus mChargeStatus;
|
||||
} AppGetBatteryInfo;
|
||||
typedef struct app_get_param_value
|
||||
{
|
||||
app_get_param_value()
|
||||
{
|
||||
mRec = SwitchStatus::END;
|
||||
mMicStatus = SwitchStatus::END;
|
||||
}
|
||||
SwitchStatus mMicStatus;
|
||||
SwitchStatus mRec;
|
||||
} AppParamValue;
|
||||
typedef struct app_get_capability
|
||||
{
|
||||
app_get_capability()
|
||||
{
|
||||
mGpsCapability = GpsCapability::END;
|
||||
mDeviceType = DeviceType::END;
|
||||
mAlbum = DashAlbum::END;
|
||||
mAppLock = AppLock::END;
|
||||
mDeleteLock = DeleteLock::END;
|
||||
mDeviceMode = DeviceMode::END;
|
||||
mPlaybackType = PlaybackType::END;
|
||||
mPhotographCapability = PhotographCapability::END;
|
||||
mWifiCapability = WifiCapability::END;
|
||||
mFileCopy = FileCopy::END;
|
||||
}
|
||||
GpsCapability mGpsCapability;
|
||||
DeviceType mDeviceType;
|
||||
DashAlbum mAlbum;
|
||||
AppLock mAppLock;
|
||||
DeleteLock mDeleteLock;
|
||||
DeviceMode mDeviceMode;
|
||||
PlaybackType mPlaybackType;
|
||||
PhotographCapability mPhotographCapability;
|
||||
WifiCapability mWifiCapability;
|
||||
FileCopy mFileCopy;
|
||||
} AppGetCapability;
|
||||
typedef struct app_get_storage_info
|
||||
{
|
||||
app_get_storage_info()
|
||||
{
|
||||
mIndex = -1;
|
||||
mType = StorageType::END;
|
||||
mFree = 0;
|
||||
mTotal = 0;
|
||||
}
|
||||
int mIndex;
|
||||
StorageType mType;
|
||||
std::string mName;
|
||||
int mFree;
|
||||
int mTotal;
|
||||
} AppGetStorageInfo;
|
||||
typedef struct app_get_file_info
|
||||
{
|
||||
app_get_file_info()
|
||||
{
|
||||
mStartIndex = 0;
|
||||
mStopIndex = 0;
|
||||
mEvent = StorageFileEvent::END;
|
||||
}
|
||||
int mStartIndex;
|
||||
int mStopIndex;
|
||||
StorageFileEvent mEvent;
|
||||
} AppGetFileInfo;
|
||||
typedef struct app_get_file_list
|
||||
{
|
||||
app_get_file_list()
|
||||
{
|
||||
mDuration = 0;
|
||||
mSize = 0;
|
||||
mCreateTime_s = 0;
|
||||
mType = StorageFileType::END;
|
||||
}
|
||||
std::string mName;
|
||||
int mDuration;
|
||||
int mSize;
|
||||
time_t mCreateTime_s;
|
||||
StorageFileType mType;
|
||||
} AppGetFileList;
|
||||
typedef struct app_set_param_value
|
||||
{
|
||||
app_set_param_value()
|
||||
{
|
||||
mValue = -1;
|
||||
}
|
||||
std::string mName;
|
||||
int mValue;
|
||||
} AppSetParamValue;
|
||||
typedef struct app_set_date_time
|
||||
{
|
||||
app_set_date_time(const unsigned int year, const unsigned int month, const unsigned int day,
|
||||
|
@ -123,6 +319,14 @@ typedef struct app_upload_file
|
|||
const UploadCommand mCommand;
|
||||
ResposeResult mResult;
|
||||
} AppUploadFile;
|
||||
typedef struct app_get_thumbnail
|
||||
{
|
||||
app_get_thumbnail(const std::string file) : mFile(file)
|
||||
{
|
||||
}
|
||||
const std::string mFile;
|
||||
std::string mThumbnail;
|
||||
} AppGetThumbnail;
|
||||
class VAppMonitor
|
||||
{
|
||||
public:
|
||||
|
@ -133,13 +337,24 @@ public:
|
|||
virtual StatusCode GetMediaInfo(AppGetMeidaInfo ¶m);
|
||||
virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m);
|
||||
virtual StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m);
|
||||
virtual StatusCode SetDateTime(AppSetDateTime ¶m);
|
||||
virtual StatusCode GetParamValue(AppParamValue ¶m);
|
||||
virtual StatusCode GetCapability(AppGetCapability ¶m);
|
||||
virtual StatusCode GetLockVideoStatus(LockVideoStatus ¶m);
|
||||
virtual StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> ¶m);
|
||||
virtual StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m);
|
||||
virtual StatusCode SetDateTime(const AppSetDateTime ¶m);
|
||||
virtual StatusCode SetTimeZone(const unsigned int &zone);
|
||||
virtual StatusCode SetParamValue(const AppSetParamValue ¶m);
|
||||
virtual StatusCode EnterRecorder(void);
|
||||
virtual StatusCode AppPlayback(const PlayBackEvent &event);
|
||||
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
||||
virtual StatusCode GetThumbnail(AppGetThumbnail ¶m);
|
||||
};
|
||||
typedef struct app_param
|
||||
{
|
||||
app_param(const char *ip, const int port) : mIP(ip), mPort(port) {}
|
||||
app_param(const char *ip, const int port) : mIP(ip), mPort(port)
|
||||
{
|
||||
}
|
||||
const char *mIP;
|
||||
const int mPort;
|
||||
} AppParam;
|
||||
|
|
|
@ -22,7 +22,10 @@ StatusCode VAppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m)
|
|||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetMediaInfo(AppGetMeidaInfo ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
StatusCode VAppMonitor::GetMediaInfo(AppGetMeidaInfo ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
@ -31,9 +34,54 @@ StatusCode VAppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
|||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetDateTime(AppSetDateTime ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
StatusCode VAppMonitor::SetTimeZone(const unsigned int &zone) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
StatusCode VAppMonitor::UploadFile(AppUploadFile ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
StatusCode VAppMonitor::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetTimeZone(const unsigned int &zone)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::EnterRecorder(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<IAppManager>();
|
||||
|
@ -48,8 +96,14 @@ std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManag
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode IAppManager::Init(const AppParam ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IAppManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IAppManager::Init(const AppParam ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IAppManager::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IAppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
|
|
@ -30,12 +30,18 @@ class IAppProtocolHandle
|
|||
public:
|
||||
IAppProtocolHandle() = default;
|
||||
virtual ~IAppProtocolHandle() = default;
|
||||
virtual void Init(void) {}
|
||||
virtual void UnInit(void) {}
|
||||
virtual void Init(void)
|
||||
{
|
||||
}
|
||||
virtual void UnInit(void)
|
||||
{
|
||||
}
|
||||
virtual void RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||
void *context)
|
||||
{
|
||||
}
|
||||
virtual void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) {}
|
||||
virtual void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||
{
|
||||
}
|
||||
};
|
||||
#endif
|
|
@ -20,15 +20,29 @@ using std::placeholders::_1;
|
|||
using std::placeholders::_2;
|
||||
using std::placeholders::_3;
|
||||
// using std::placeholders::_4;
|
||||
const char *CJSON_INFO_STRING = "info";
|
||||
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
||||
const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr";
|
||||
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";
|
||||
// clang-format off
|
||||
const char *CJSON_INFO_STRING = "info";
|
||||
const char *CJSON_FILES_STRING = "files";
|
||||
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
||||
const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr";
|
||||
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_GET_PARAM_VALUE = "/app/getparamvalue";
|
||||
const char *APP_GET_CAPABILITY = "/app/capability";
|
||||
const char *APP_GET_LOCK_VIDEO_STATUS = "/app/getlockvideostatus";
|
||||
const char *APP_GET_STORAGE_INFO = "/app/getstorageinfo";
|
||||
const char *APP_GET_FILE_LIST = "/app/getfilelist";
|
||||
const char *APP_SET_DATE_TIME = "/app/setsystime";
|
||||
const char *APP_SET_TIME_ZONE = "/app/settimezone";
|
||||
const char *APP_SET_PARAM_VALUE = "/app/setparamvalue";
|
||||
const char *APP_ENTER_RECORDER = "/app/enterrecorder";
|
||||
const char *APP_PLAYBACK = "/app/playback";
|
||||
const char *APP_UPLOAD_FILE = "/upload";
|
||||
const char *APP_GET_THUMBNAIL = "/app/getthumbnail";
|
||||
// /app/getparamvalue?param=rec
|
||||
// /app/exitrecorder
|
||||
// clang-format on
|
||||
constexpr bool SET_REQUEST_RESPONSE = true;
|
||||
SixFrameHandle::SixFrameHandle()
|
||||
{
|
||||
|
@ -38,9 +52,19 @@ SixFrameHandle::SixFrameHandle()
|
|||
mResquesHandleFunc[APP_GET_MEDIA_INFO] = std::bind(&SixFrameHandle::RequestGetMediaInfo, 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_PARAM_VALUE] = std::bind(&SixFrameHandle::RequestGetParamValue, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_GET_CAPABILITY] = std::bind(&SixFrameHandle::RequestGetCapability, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_GET_LOCK_VIDEO_STATUS] =
|
||||
std::bind(&SixFrameHandle::RequestGetLockVideoStatus, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_GET_STORAGE_INFO] = std::bind(&SixFrameHandle::RequestGetStorageInfo, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_GET_FILE_LIST] = std::bind(&SixFrameHandle::RequestGetFileList, 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_SET_PARAM_VALUE] = std::bind(&SixFrameHandle::RequestSetParamValue, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_ENTER_RECORDER] = std::bind(&SixFrameHandle::RequestEnterRecorder, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_PLAYBACK] = std::bind(&SixFrameHandle::RequestPlayback, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_GET_THUMBNAIL] = std::bind(&SixFrameHandle::RequestGetThumbnail, this, _1, _2, _3);
|
||||
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _);
|
||||
}
|
||||
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||
|
@ -95,25 +119,28 @@ void SixFrameHandle::RequestHandle2(const std::string command, const std::string
|
|||
}
|
||||
void SixFrameHandle::DoNothing(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
// responseHandle("Unknown command.", context);
|
||||
char *resultStr = nullptr;
|
||||
cJSON *result = MakeResponseResult(ResposeResult::FAILED);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void SixFrameHandle::RequestGetProductInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetProductInfo.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppGetProductInfo param;
|
||||
mAppMonitor->GetProductInfo(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetProductInfo(result, param);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetProductInfo(cJSON *result, const AppGetProductInfo ¶m)
|
||||
|
@ -128,14 +155,16 @@ void inline SixFrameHandle::ResponseGetProductInfo(cJSON *result, const AppGetPr
|
|||
void SixFrameHandle::RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppGetDeviceAttr param;
|
||||
mAppMonitor->GetDeviceAttr(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetDeviceAttr(result, param);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr ¶m)
|
||||
|
@ -155,15 +184,16 @@ void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDev
|
|||
void SixFrameHandle::RequestGetMediaInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetMediaInfo.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppGetMeidaInfo param;
|
||||
mAppMonitor->GetMediaInfo(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetMediaInfo(result, param);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
LogInfo("resultStr = \n%s\n", resultStr);
|
||||
free(resultStr);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo ¶m)
|
||||
|
@ -173,18 +203,21 @@ void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeid
|
|||
cJSON_AddStringToObject(info, "rtsp", param.mRtspUrl.c_str());
|
||||
cJSON_AddStringToObject(info, "transport", param.mTransport.c_str());
|
||||
cJSON_AddNumberToObject(info, "port", param.mPort);
|
||||
cJSON_AddNumberToObject(info, "page", 1); // TODO: 1 means app will paging to retrieve files.
|
||||
}
|
||||
void SixFrameHandle::RequestGetSdCardInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppGetSdCardInfo param;
|
||||
mAppMonitor->GetSdCardInfo(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetSdCardInfo(result, param);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo ¶m)
|
||||
|
@ -198,14 +231,16 @@ void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdC
|
|||
void SixFrameHandle::RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppGetBatteryInfo param;
|
||||
mAppMonitor->GetBatteryInfo(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetBatteryInfo(result, param);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m)
|
||||
|
@ -215,27 +250,243 @@ void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBa
|
|||
cJSON_AddNumberToObject(info, "charge", static_cast<int>(param.mChargeStatus));
|
||||
cJSON_AddNumberToObject(info, "capacity", param.mCapacity);
|
||||
}
|
||||
AppParamValue inline SixFrameHandle::RequestParamValueParse(const std::string &url)
|
||||
{
|
||||
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) {
|
||||
std::shared_ptr<ParseUrl<AppParamValue>> parseImpl = std::dynamic_pointer_cast<ParseUrl<AppParamValue>>(parse);
|
||||
if ("param" == key) {
|
||||
if ("rec" == value) {
|
||||
parseImpl->mData.mRec = SwitchStatus::ON; // means app want to get mRec value.
|
||||
}
|
||||
}
|
||||
};
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<AppParamValue>>();
|
||||
std::shared_ptr<ParseUrl<AppParamValue>> parseImpl = std::dynamic_pointer_cast<ParseUrl<AppParamValue>>(parse);
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
return parseImpl->mData;
|
||||
}
|
||||
void SixFrameHandle::RequestGetParamValue(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetParamValue.\n");
|
||||
// AppParamValue appGetValue = RequestParamValueParse(url); // TODO:
|
||||
AppParamValue paramDevice;
|
||||
mAppMonitor->GetParamValue(paramDevice);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetParamValue(result, paramDevice);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetParamValue(cJSON *result, const AppParamValue ¶m)
|
||||
{
|
||||
cJSON *info = cJSON_CreateArray();
|
||||
if (nullptr == info) {
|
||||
LogError("cJSON_CreateArray failed.\n");
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
|
||||
cJSON *mic = cJSON_CreateObject();
|
||||
if (nullptr != mic) {
|
||||
cJSON_AddItemToArray(info, mic);
|
||||
cJSON_AddStringToObject(mic, "name", "mic");
|
||||
cJSON_AddNumberToObject(mic, "value", static_cast<int>(param.mMicStatus));
|
||||
}
|
||||
cJSON *rec = cJSON_CreateObject();
|
||||
if (nullptr != rec) {
|
||||
cJSON_AddItemToArray(info, rec);
|
||||
cJSON_AddStringToObject(rec, "name", "rec");
|
||||
cJSON_AddNumberToObject(rec, "value", static_cast<int>(param.mRec));
|
||||
}
|
||||
}
|
||||
void SixFrameHandle::RequestGetCapability(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetCapability.\n");
|
||||
AppGetCapability param;
|
||||
mAppMonitor->GetCapability(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetCapability(result, param);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetCapability(cJSON *result, const AppGetCapability ¶m)
|
||||
{
|
||||
cJSON *info = nullptr;
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info = cJSON_CreateObject());
|
||||
std::ostringstream value;
|
||||
value << static_cast<int>(param.mGpsCapability);
|
||||
value << static_cast<int>(param.mDeviceType);
|
||||
value << static_cast<int>(param.mAlbum);
|
||||
value << static_cast<int>(param.mAppLock);
|
||||
value << static_cast<int>(param.mDeleteLock);
|
||||
value << static_cast<int>(param.mDeviceMode);
|
||||
value << static_cast<int>(param.mPlaybackType);
|
||||
value << static_cast<int>(param.mPhotographCapability);
|
||||
value << static_cast<int>(param.mWifiCapability);
|
||||
value << static_cast<int>(param.mFileCopy);
|
||||
cJSON_AddStringToObject(info, "value", value.str().c_str());
|
||||
}
|
||||
void SixFrameHandle::RequestGetLockVideoStatus(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetLockVideoStatus.\n");
|
||||
LockVideoStatus param;
|
||||
mAppMonitor->GetLockVideoStatus(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetLockVideoStatus(result, param);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetLockVideoStatus(cJSON *result, const LockVideoStatus ¶m)
|
||||
{
|
||||
cJSON *info = nullptr;
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info = cJSON_CreateObject());
|
||||
cJSON_AddNumberToObject(info, "status", static_cast<int>(param));
|
||||
}
|
||||
void SixFrameHandle::RequestGetStorageInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetStorageInfo.\n");
|
||||
std::vector<AppGetStorageInfo> param;
|
||||
mAppMonitor->GetStorageInfo(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetStorageInfo(result, param);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetStorageInfo(cJSON *result, const std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
cJSON *info = cJSON_CreateArray();
|
||||
if (nullptr == info) {
|
||||
LogError("cJSON_CreateArray failed.\n");
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
|
||||
for (const auto &storageInfo : param) {
|
||||
cJSON *storage = nullptr;
|
||||
storage = cJSON_CreateObject();
|
||||
if (nullptr != storage) {
|
||||
cJSON_AddItemToArray(info, storage);
|
||||
cJSON_AddNumberToObject(storage, "index", static_cast<int>(storageInfo.mIndex));
|
||||
cJSON_AddStringToObject(storage, "name", storageInfo.mName.c_str());
|
||||
cJSON_AddNumberToObject(storage, "type", static_cast<int>(storageInfo.mType));
|
||||
cJSON_AddNumberToObject(storage, "free", storageInfo.mFree);
|
||||
cJSON_AddNumberToObject(storage, "total", storageInfo.mTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
AppGetFileInfo inline SixFrameHandle::RequestGetFileListParse(const std::string &url)
|
||||
{
|
||||
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) {
|
||||
std::shared_ptr<ParseUrl<AppGetFileInfo>> parseImpl =
|
||||
std::dynamic_pointer_cast<ParseUrl<AppGetFileInfo>>(parse);
|
||||
if ("folder" == key) {
|
||||
if ("loop" == value) {
|
||||
parseImpl->mData.mEvent = StorageFileEvent::LOOP;
|
||||
}
|
||||
if ("emr" == value) {
|
||||
parseImpl->mData.mEvent = StorageFileEvent::EMR;
|
||||
}
|
||||
if ("event" == value) {
|
||||
parseImpl->mData.mEvent = StorageFileEvent::EVENT;
|
||||
}
|
||||
if ("park" == value) {
|
||||
parseImpl->mData.mEvent = StorageFileEvent::PARK;
|
||||
}
|
||||
}
|
||||
if ("start" == key) {
|
||||
parseImpl->mData.mStartIndex = std::stoi(value);
|
||||
}
|
||||
if ("end" == key) {
|
||||
parseImpl->mData.mStopIndex = std::stoi(value);
|
||||
}
|
||||
};
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<AppGetFileInfo>>();
|
||||
std::shared_ptr<ParseUrl<AppGetFileInfo>> parseImpl = std::dynamic_pointer_cast<ParseUrl<AppGetFileInfo>>(parse);
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
return parseImpl->mData;
|
||||
}
|
||||
void SixFrameHandle::RequestGetFileList(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetFileList.\n");
|
||||
std::vector<AppGetFileList> files;
|
||||
AppGetFileInfo info = RequestGetFileListParse(url);
|
||||
mAppMonitor->GetStorageFileList(info, files);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetFileList(result, files, info);
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> ¶m,
|
||||
const AppGetFileInfo &fileInfo)
|
||||
{
|
||||
cJSON *info = cJSON_CreateArray();
|
||||
cJSON *folder = cJSON_CreateObject();
|
||||
cJSON *files = cJSON_CreateArray();
|
||||
if (nullptr == info || nullptr == folder || nullptr == files) {
|
||||
LogError("cJSON_CreateArray failed.\n");
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
|
||||
cJSON_AddItemToArray(info, folder);
|
||||
for (const auto &fileList : param) {
|
||||
cJSON_AddStringToObject(folder, "folder", PrintfFileEvent(fileInfo));
|
||||
cJSON_AddNumberToObject(folder, "count", param.size());
|
||||
cJSON *file = nullptr;
|
||||
file = cJSON_CreateObject();
|
||||
if (nullptr != file) {
|
||||
cJSON_AddItemToArray(files, file);
|
||||
cJSON_AddStringToObject(file, "name", fileList.mName.c_str());
|
||||
cJSON_AddNumberToObject(file, "duration", fileList.mDuration);
|
||||
cJSON_AddNumberToObject(file, "size", fileList.mSize);
|
||||
cJSON_AddNumberToObject(file, "createtime", fileList.mCreateTime_s);
|
||||
cJSON_AddNumberToObject(file, "type", static_cast<int>(fileList.mType));
|
||||
}
|
||||
}
|
||||
cJSON_AddItemToObject(folder, CJSON_FILES_STRING, files);
|
||||
}
|
||||
AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(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);
|
||||
std::shared_ptr<ParseUrl<std::string>> parseImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
if ("date" == key) {
|
||||
parseyImpl->mData = value;
|
||||
parseImpl->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 (14 != parseyImpl->mData.length()) {
|
||||
std::shared_ptr<ParseUrl<std::string>> parseImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
if (14 != parseImpl->mData.length()) {
|
||||
LogError("date parse failed.\n");
|
||||
return AppSetDateTime(0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
std::string yearStr = parseyImpl->mData.substr(0, 4);
|
||||
std::string monthStr = parseyImpl->mData.substr(4, 2);
|
||||
std::string dayStr = parseyImpl->mData.substr(6, 2);
|
||||
std::string hourStr = parseyImpl->mData.substr(8, 2);
|
||||
std::string minuteStr = parseyImpl->mData.substr(10, 2);
|
||||
std::string secondStr = parseyImpl->mData.substr(12, 2);
|
||||
std::string yearStr = parseImpl->mData.substr(0, 4);
|
||||
std::string monthStr = parseImpl->mData.substr(4, 2);
|
||||
std::string dayStr = parseImpl->mData.substr(6, 2);
|
||||
std::string hourStr = parseImpl->mData.substr(8, 2);
|
||||
std::string minuteStr = parseImpl->mData.substr(10, 2);
|
||||
std::string secondStr = parseImpl->mData.substr(12, 2);
|
||||
unsigned int year = std::stoi(yearStr);
|
||||
unsigned int month = std::stoi(monthStr);
|
||||
unsigned int day = std::stoi(dayStr);
|
||||
|
@ -247,66 +498,181 @@ AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(const std::string
|
|||
void SixFrameHandle::RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppSetDateTime param = RequestSetDateTimeParse(url);
|
||||
mAppMonitor->SetDateTime(param);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE);
|
||||
// ResponseGetBatteryInfo(result, param);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
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);
|
||||
std::shared_ptr<ParseUrl<std::string>> parseImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
if ("timezone" == key) {
|
||||
parseyImpl->mData = value;
|
||||
parseImpl->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()) {
|
||||
std::shared_ptr<ParseUrl<std::string>> parseImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
if (2 <= parseImpl->mData.length()) {
|
||||
LogError("date parse failed.\n");
|
||||
return 0;
|
||||
}
|
||||
int zone = std::stoi(parseyImpl->mData);
|
||||
int zone = std::stoi(parseImpl->mData);
|
||||
return zone;
|
||||
}
|
||||
void SixFrameHandle::RequestSetTimeZone(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
LogInfo("RequestSetTimeZone.\n");
|
||||
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);
|
||||
free(resultStr);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
AppSetParamValue inline SixFrameHandle::RequestSetParamValueParse(const std::string &url)
|
||||
{
|
||||
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) {
|
||||
std::shared_ptr<ParseUrl<AppSetParamValue>> parseImpl =
|
||||
std::dynamic_pointer_cast<ParseUrl<AppSetParamValue>>(parse);
|
||||
if ("switchcam" == key) {
|
||||
parseImpl->mData.mName = "switchcam";
|
||||
parseImpl->mData.mValue = std::stoi(value);
|
||||
}
|
||||
if ("rec" == key) {
|
||||
parseImpl->mData.mName = "rec";
|
||||
parseImpl->mData.mValue = std::stoi(value);
|
||||
}
|
||||
if ("mic" == key) {
|
||||
parseImpl->mData.mName = "mic";
|
||||
parseImpl->mData.mValue = std::stoi(value);
|
||||
}
|
||||
};
|
||||
AppSetParamValue value;
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<AppSetParamValue>>();
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
std::shared_ptr<ParseUrl<AppSetParamValue>> parseImpl =
|
||||
std::dynamic_pointer_cast<ParseUrl<AppSetParamValue>>(parse);
|
||||
return parseImpl->mData;
|
||||
}
|
||||
void SixFrameHandle::RequestSetParamValue(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestSetParamValue.\n");
|
||||
AppSetParamValue value = RequestSetParamValueParse(url);
|
||||
mAppMonitor->SetParamValue(value);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
PlayBackEvent inline SixFrameHandle::RequestPlaybackParse(const std::string &url)
|
||||
{
|
||||
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) {
|
||||
std::shared_ptr<ParseUrl<PlayBackEvent>> parseImpl = std::dynamic_pointer_cast<ParseUrl<PlayBackEvent>>(parse);
|
||||
if ("param" == key) {
|
||||
if ("enter" == value) {
|
||||
parseImpl->mData = PlayBackEvent::START;
|
||||
}
|
||||
if ("exit" == value) {
|
||||
parseImpl->mData = PlayBackEvent::STOP;
|
||||
}
|
||||
}
|
||||
};
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<PlayBackEvent>>();
|
||||
std::shared_ptr<ParseUrl<PlayBackEvent>> parseImpl = std::dynamic_pointer_cast<ParseUrl<PlayBackEvent>>(parse);
|
||||
parseImpl->mData = PlayBackEvent::END;
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
return parseImpl->mData;
|
||||
}
|
||||
void SixFrameHandle::RequestPlayback(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestPlayback.\n");
|
||||
PlayBackEvent value = RequestPlaybackParse(url);
|
||||
mAppMonitor->AppPlayback(value);
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void SixFrameHandle::RequestEnterRecorder(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestEnterRecorder.\n");
|
||||
mAppMonitor->EnterRecorder();
|
||||
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestUpload.\n");
|
||||
char *resultStr = nullptr;
|
||||
AppUploadFile info("path", UploadCommand::UPGRADE_CPU);
|
||||
mAppMonitor->UploadFile(info);
|
||||
cJSON *result = MakeResponseResult(info.mResult);
|
||||
resultStr = cJSON_Print(result);
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
if (nullptr == result) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
std::string inline SixFrameHandle::RequestGetThumbnailParse(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>> parseImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
if ("file" == key) {
|
||||
parseImpl->mData = value;
|
||||
}
|
||||
};
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
|
||||
std::shared_ptr<ParseUrl<std::string>> parseImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
return parseImpl->mData;
|
||||
}
|
||||
void SixFrameHandle::RequestGetThumbnail(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetThumbnail.\n");
|
||||
const std::string file = RequestGetThumbnailParse(url);
|
||||
AppGetThumbnail respon(file);
|
||||
mAppMonitor->GetThumbnail(respon);
|
||||
// respon.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
||||
responseHandle(respon.mThumbnail.c_str(), context);
|
||||
}
|
||||
cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result, const bool requestSet)
|
||||
{
|
||||
const char *RESPONSE_RESULT = "result";
|
||||
cJSON *resultCJSON = cJSON_CreateObject();
|
||||
if (nullptr == resultCJSON) {
|
||||
LogError("cJSON_CreateObject failed.\n");
|
||||
goto END;
|
||||
}
|
||||
cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(result));
|
||||
if (false == requestSet) {
|
||||
return resultCJSON;
|
||||
goto END;
|
||||
}
|
||||
if (ResposeResult::SUCCESSFUL == result) {
|
||||
cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set success.");
|
||||
|
@ -314,8 +680,37 @@ cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result, const bool
|
|||
else {
|
||||
cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set failed."); // TODO: what the failed string is?
|
||||
}
|
||||
END:
|
||||
return resultCJSON;
|
||||
}
|
||||
void SixFrameHandle::ResponseJsonString(cJSON *json, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
char *resultStr = nullptr;
|
||||
resultStr = cJSON_Print(json);
|
||||
if (nullptr != resultStr) {
|
||||
responseHandle(resultStr, context);
|
||||
free(resultStr);
|
||||
}
|
||||
else {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
}
|
||||
}
|
||||
const char *SixFrameHandle::PrintfFileEvent(const AppGetFileInfo &fileInfo)
|
||||
{
|
||||
switch (fileInfo.mEvent) {
|
||||
case StorageFileEvent::LOOP: {
|
||||
return "loop";
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
LogWarning("Unknown event.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "unknown event";
|
||||
}
|
||||
void SixFrameHandle::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||
{
|
||||
if (monitor) {
|
||||
|
|
|
@ -30,18 +30,20 @@ public:
|
|||
VParseUrl() = default;
|
||||
virtual ~VParseUrl() = default;
|
||||
};
|
||||
using ParseUrlResultFunc = void(const std::string &, const std::string &, std::shared_ptr<VParseUrl> &);
|
||||
template <typename T>
|
||||
class ParseUrl : public VParseUrl
|
||||
{
|
||||
|
||||
public:
|
||||
ParseUrl() {}
|
||||
ParseUrl()
|
||||
{
|
||||
}
|
||||
virtual ~ParseUrl() = default;
|
||||
|
||||
public:
|
||||
T mData;
|
||||
};
|
||||
using ParseUrlResultFunc = void(const std::string &, const std::string &, std::shared_ptr<VParseUrl> &);
|
||||
class SixFrameHandle : public IAppProtocolHandle
|
||||
{
|
||||
public:
|
||||
|
@ -68,14 +70,35 @@ private:
|
|||
void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo ¶m);
|
||||
void RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m);
|
||||
AppParamValue RequestParamValueParse(const std::string &url);
|
||||
void RequestGetParamValue(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetParamValue(cJSON *result, const AppParamValue ¶m);
|
||||
void RequestGetCapability(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetCapability(cJSON *result, const AppGetCapability ¶m);
|
||||
void RequestGetLockVideoStatus(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetLockVideoStatus(cJSON *result, const LockVideoStatus ¶m);
|
||||
void RequestGetStorageInfo(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetStorageInfo(cJSON *result, const std::vector<AppGetStorageInfo> ¶m);
|
||||
AppGetFileInfo RequestGetFileListParse(const std::string &url);
|
||||
void RequestGetFileList(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> ¶m, const AppGetFileInfo &fileInfo);
|
||||
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);
|
||||
AppSetParamValue RequestSetParamValueParse(const std::string &url);
|
||||
void RequestSetParamValue(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
PlayBackEvent RequestPlaybackParse(const std::string &url);
|
||||
void RequestPlayback(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void RequestEnterRecorder(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
std::string RequestGetThumbnailParse(const std::string &url);
|
||||
void RequestGetThumbnail(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
|
||||
private:
|
||||
cJSON *MakeResponseResult(const ResposeResult result, const bool requestSet = false);
|
||||
void ResponseJsonString(cJSON *json, ResponseHandle responseHandle, void *context);
|
||||
const char *PrintfFileEvent(const AppGetFileInfo &fileInfo);
|
||||
|
||||
protected:
|
||||
void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
/*
|
||||
* 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 "SixFrameMakePtr.h"
|
||||
#include "ILog.h"
|
||||
#include "SixFrameHandle.h"
|
||||
|
|
|
@ -36,7 +36,9 @@ class VKeyMonitor
|
|||
public:
|
||||
VKeyMonitor() = default;
|
||||
virtual ~VKeyMonitor() = default;
|
||||
virtual void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) {}
|
||||
virtual void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs)
|
||||
{
|
||||
}
|
||||
};
|
||||
class VirtualLedControl
|
||||
{
|
||||
|
|
|
@ -28,8 +28,14 @@ std::shared_ptr<IDeviceManager> &IDeviceManager::GetInstance(std::shared_ptr<IDe
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode IDeviceManager::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IDeviceManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IDeviceManager::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IDeviceManager::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IDeviceManager::ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
|
|
@ -8,7 +8,7 @@ include_directories(
|
|||
./include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/Config/include
|
||||
${UTILS_SOURCE_PATH}/ConfigBase/include
|
||||
)
|
||||
#do not rely on any other library
|
||||
#link_directories(
|
||||
|
|
|
@ -96,30 +96,30 @@ class IIpcConfig
|
|||
public:
|
||||
IIpcConfig() = default;
|
||||
virtual ~IIpcConfig() = default;
|
||||
virtual const StatusCode ConfigFileSave(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
static std::shared_ptr<IIpcConfig> &GetInstance(std::shared_ptr<IIpcConfig> *impl = nullptr);
|
||||
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
virtual const int GetInt(const IpcConfigKey &key) { return -1; }
|
||||
virtual void SetInt(const IpcConfigKey &key, const int &value) {}
|
||||
virtual const short GetShort(const IpcConfigKey &key) { return -1; }
|
||||
virtual void SetShort(const IpcConfigKey &key, const short &value) {}
|
||||
virtual const long GetLong(const IpcConfigKey &key) { return -1; }
|
||||
virtual void SetLong(const IpcConfigKey &key, const long &value) {}
|
||||
virtual const long long GetLLong(const IpcConfigKey &key) { return -1; }
|
||||
virtual void SetLLong(const IpcConfigKey &key, const long long &value) {}
|
||||
virtual const char GetChar(const IpcConfigKey &key) { return '\0'; }
|
||||
virtual void SetChar(const IpcConfigKey &key, const char &value) {}
|
||||
virtual const float GetFloat(const IpcConfigKey &key) { return -1.0; }
|
||||
virtual void SetFloat(const IpcConfigKey &key, const float &value) {}
|
||||
virtual const double GetDouble(const IpcConfigKey &key) { return -1.0; }
|
||||
virtual void SetDouble(const IpcConfigKey &key, const double &value) {}
|
||||
virtual const long double GetLongDouble(const IpcConfigKey &key) { return -1.0; }
|
||||
virtual void SetLongDouble(const IpcConfigKey &key, const long double &value) {}
|
||||
virtual const bool GetBool(const IpcConfigKey &key) { return true; }
|
||||
virtual void SetBool(const IpcConfigKey &key, const bool &value) {}
|
||||
virtual const std::string GetString(const IpcConfigKey &key) { return "undefine"; }
|
||||
virtual void SetString(const IpcConfigKey &key, const std::string string) {}
|
||||
virtual const StatusCode ConfigFileSave(void);
|
||||
virtual const StatusCode Init(void);
|
||||
virtual const StatusCode UnInit(void);
|
||||
virtual const int GetInt(const IpcConfigKey &key);
|
||||
virtual void SetInt(const IpcConfigKey &key, const int &value);
|
||||
virtual const short GetShort(const IpcConfigKey &key);
|
||||
virtual void SetShort(const IpcConfigKey &key, const short &value);
|
||||
virtual const long GetLong(const IpcConfigKey &key);
|
||||
virtual void SetLong(const IpcConfigKey &key, const long &value);
|
||||
virtual const long long GetLLong(const IpcConfigKey &key);
|
||||
virtual void SetLLong(const IpcConfigKey &key, const long long &value);
|
||||
virtual const char GetChar(const IpcConfigKey &key);
|
||||
virtual void SetChar(const IpcConfigKey &key, const char &value);
|
||||
virtual const float GetFloat(const IpcConfigKey &key);
|
||||
virtual void SetFloat(const IpcConfigKey &key, const float &value);
|
||||
virtual const double GetDouble(const IpcConfigKey &key);
|
||||
virtual void SetDouble(const IpcConfigKey &key, const double &value);
|
||||
virtual const long double GetLongDouble(const IpcConfigKey &key);
|
||||
virtual void SetLongDouble(const IpcConfigKey &key, const long double &value);
|
||||
virtual const bool GetBool(const IpcConfigKey &key);
|
||||
virtual void SetBool(const IpcConfigKey &key, const bool &value);
|
||||
virtual const std::string GetString(const IpcConfigKey &key);
|
||||
virtual void SetString(const IpcConfigKey &key, const std::string string);
|
||||
};
|
||||
bool CreateIpcConfig(void);
|
||||
#endif
|
|
@ -27,4 +27,86 @@ std::shared_ptr<IIpcConfig> &IIpcConfig::GetInstance(std::shared_ptr<IIpcConfig>
|
|||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode IIpcConfig::ConfigFileSave(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode IIpcConfig::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode IIpcConfig::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const int IIpcConfig::GetInt(const IpcConfigKey &key)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
void IIpcConfig::SetInt(const IpcConfigKey &key, const int &value)
|
||||
{
|
||||
}
|
||||
const short IIpcConfig::GetShort(const IpcConfigKey &key)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
void IIpcConfig::SetShort(const IpcConfigKey &key, const short &value)
|
||||
{
|
||||
}
|
||||
const long IIpcConfig::GetLong(const IpcConfigKey &key)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
void IIpcConfig::SetLong(const IpcConfigKey &key, const long &value)
|
||||
{
|
||||
}
|
||||
const long long IIpcConfig::GetLLong(const IpcConfigKey &key)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
void IIpcConfig::SetLLong(const IpcConfigKey &key, const long long &value)
|
||||
{
|
||||
}
|
||||
const char IIpcConfig::GetChar(const IpcConfigKey &key)
|
||||
{
|
||||
return '\0';
|
||||
}
|
||||
void IIpcConfig::SetChar(const IpcConfigKey &key, const char &value)
|
||||
{
|
||||
}
|
||||
const float IIpcConfig::GetFloat(const IpcConfigKey &key)
|
||||
{
|
||||
return -1.0;
|
||||
}
|
||||
void IIpcConfig::SetFloat(const IpcConfigKey &key, const float &value)
|
||||
{
|
||||
}
|
||||
const double IIpcConfig::GetDouble(const IpcConfigKey &key)
|
||||
{
|
||||
return -1.0;
|
||||
}
|
||||
void IIpcConfig::SetDouble(const IpcConfigKey &key, const double &value)
|
||||
{
|
||||
}
|
||||
const long double IIpcConfig::GetLongDouble(const IpcConfigKey &key)
|
||||
{
|
||||
return -1.0;
|
||||
}
|
||||
void IIpcConfig::SetLongDouble(const IpcConfigKey &key, const long double &value)
|
||||
{
|
||||
}
|
||||
const bool IIpcConfig::GetBool(const IpcConfigKey &key)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void IIpcConfig::SetBool(const IpcConfigKey &key, const bool &value)
|
||||
{
|
||||
}
|
||||
const std::string IIpcConfig::GetString(const IpcConfigKey &key)
|
||||
{
|
||||
return "undefine";
|
||||
}
|
||||
void IIpcConfig::SetString(const IpcConfigKey &key, const std::string string)
|
||||
{
|
||||
}
|
|
@ -121,7 +121,10 @@ const StatusCode IpcConfig::UnInit(void)
|
|||
CloseConfigFile(mCfg);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode IpcConfig::ConfigFileSave(void) { return ConfigSaveFile(mCfg); }
|
||||
const StatusCode IpcConfig::ConfigFileSave(void)
|
||||
{
|
||||
return ConfigSaveFile(mCfg);
|
||||
}
|
||||
|
||||
const int IpcConfig::GetInt(const IpcConfigKey &key)
|
||||
{
|
||||
|
@ -140,7 +143,7 @@ void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
|
|||
iter = mCfgMapInt.find(key);
|
||||
if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetInt(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -165,7 +168,7 @@ void IpcConfig::SetShort(const IpcConfigKey &key, const short &value)
|
|||
iter = mCfgMapShort.find(key);
|
||||
if (iter != mCfgMapShort.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetShort(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -190,7 +193,7 @@ void IpcConfig::SetLong(const IpcConfigKey &key, const long &value)
|
|||
iter = mCfgMapLong.find(key);
|
||||
if (iter != mCfgMapLong.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetLong(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -215,7 +218,7 @@ void IpcConfig::SetLLong(const IpcConfigKey &key, const long long &value)
|
|||
iter = mCfgMapLLong.find(key);
|
||||
if (iter != mCfgMapLLong.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetLLong(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -240,7 +243,7 @@ void IpcConfig::SetChar(const IpcConfigKey &key, const char &character)
|
|||
iter = mCfgMapChar.find(key);
|
||||
if (iter != mCfgMapChar.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = character;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetChar(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -265,7 +268,7 @@ void IpcConfig::SetFloat(const IpcConfigKey &key, const float &value)
|
|||
iter = mCfgMapFloat.find(key);
|
||||
if (iter != mCfgMapFloat.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetFloat(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -290,7 +293,7 @@ void IpcConfig::SetDouble(const IpcConfigKey &key, const double &value)
|
|||
iter = mCfgMapDouble.find(key);
|
||||
if (iter != mCfgMapDouble.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetDouble(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -338,7 +341,7 @@ void IpcConfig::SetBool(const IpcConfigKey &key, const bool &value)
|
|||
iter = mCfgMapBool.find(key);
|
||||
if (iter != mCfgMapBool.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetBool(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -364,7 +367,7 @@ void IpcConfig::SetString(const IpcConfigKey &key, const std::string string)
|
|||
iter = mCfgMapString.find(key);
|
||||
if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) {
|
||||
strncpy(iter->second.begin()->second, string.c_str(), sizeof(CHAR_STRING)); // const std::strinbg --> char[]
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetString(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
|
@ -399,7 +402,7 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
ConfigSetInt(mCfg, "burst_photo_interval", mAllData.burstPhotoInterval);
|
||||
}
|
||||
|
||||
const char *imageSizeString = NULL;
|
||||
const char *imageSizeString = nullptr;
|
||||
StatusCode imageSizeCode = ConfigGetString(mCfg, "image_size", &(imageSizeString));
|
||||
if (StatusCodeEqual(imageSizeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("image_size doesn't exist, will make it as default.\n");
|
||||
|
@ -409,7 +412,12 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
ConfigSetString(mCfg, "image_size", mAllData.imageSize);
|
||||
}
|
||||
else {
|
||||
strncpy(mAllData.imageSize, imageSizeString, sizeof(mAllData.imageSize));
|
||||
if (nullptr != imageSizeString) {
|
||||
strncpy(mAllData.imageSize, imageSizeString, sizeof(mAllData.imageSize));
|
||||
}
|
||||
else {
|
||||
LogError("image_size get failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
StatusCode videoSizeCode = ConfigGetInt(mCfg, "video_size", &(mAllData.videoSize));
|
||||
|
@ -471,7 +479,7 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
ConfigSetBool(mCfg, "formatting_SD_card", mAllData.formattingSDCard);
|
||||
}
|
||||
|
||||
const char *darkModeString = NULL;
|
||||
const char *darkModeString = nullptr;
|
||||
StatusCode darkModeCode = ConfigGetString(mCfg, "dark_mode", &(darkModeString));
|
||||
if (StatusCodeEqual(darkModeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("dark_mode doesn't exist, will make it as default.\n");
|
||||
|
@ -481,10 +489,15 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
ConfigSetString(mCfg, "dark_mode", mAllData.darkMode);
|
||||
}
|
||||
else {
|
||||
strncpy(mAllData.darkMode, darkModeString, sizeof(mAllData.darkMode));
|
||||
if (nullptr != darkModeString) {
|
||||
strncpy(mAllData.darkMode, darkModeString, sizeof(mAllData.darkMode));
|
||||
}
|
||||
else {
|
||||
LogError("dark_mode get failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
const char *workIntervalString = NULL;
|
||||
const char *workIntervalString = nullptr;
|
||||
StatusCode workIntervalCode = ConfigGetString(mCfg, "work_interval", &(workIntervalString));
|
||||
if (StatusCodeEqual(workIntervalCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("work_interval doesn't exist, will make it as default.\n");
|
||||
|
@ -494,7 +507,12 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
ConfigSetString(mCfg, "work_interval", mAllData.workingInterval);
|
||||
}
|
||||
else {
|
||||
strncpy(mAllData.workingInterval, workIntervalString, sizeof(mAllData.workingInterval));
|
||||
if (nullptr != workIntervalString) {
|
||||
strncpy(mAllData.workingInterval, workIntervalString, sizeof(mAllData.workingInterval));
|
||||
}
|
||||
else {
|
||||
LogError("work_interval get failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
StatusCode shortCode = ConfigGetShort(mCfg, "test_short", &(mAllData.testShort));
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
#ifndef IPCCONFIG_H
|
||||
#define IPCCONFIG_H
|
||||
#include "Config.h"
|
||||
#include "ConfigBase.h"
|
||||
#include "IIpcConfig.h"
|
||||
#include "StatusCode.h"
|
||||
#include <map>
|
||||
|
@ -84,7 +84,7 @@ private:
|
|||
|
||||
private:
|
||||
bool mCfgChanged;
|
||||
VConfig *mCfg;
|
||||
void *mCfg;
|
||||
Config_s mAllData;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>> mCfgMapInt;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<short>>> mCfgMapShort;
|
||||
|
|
|
@ -57,12 +57,26 @@ typedef struct mcu_ask_date_time
|
|||
class VMcuAsk
|
||||
{
|
||||
public:
|
||||
VMcuAsk() { mSerialNumber = 0; }
|
||||
VMcuAsk()
|
||||
{
|
||||
mSerialNumber = 0;
|
||||
}
|
||||
virtual ~VMcuAsk() = default;
|
||||
virtual ASK_RESULT Blocking(void) { return ASK_RESULT::END; }
|
||||
virtual bool NeedReply(void) { return false; }
|
||||
virtual void ReplyFinished(const bool result) {}
|
||||
virtual bool IfTimeout(const unsigned int &integrationTimeMs) { return false; }
|
||||
virtual ASK_RESULT Blocking(void)
|
||||
{
|
||||
return ASK_RESULT::END;
|
||||
}
|
||||
virtual bool NeedReply(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void ReplyFinished(const bool result)
|
||||
{
|
||||
}
|
||||
virtual bool IfTimeout(const unsigned int &integrationTimeMs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -87,7 +101,9 @@ class VMcuMonitor
|
|||
public:
|
||||
VMcuMonitor() = default;
|
||||
virtual ~VMcuMonitor() = default;
|
||||
virtual void RecvIpcMissionEvent(std::shared_ptr<VMcuAsk> &recv, const IpcMission &mission) {}
|
||||
virtual void RecvIpcMissionEvent(std::shared_ptr<VMcuAsk> &recv, const IpcMission &mission)
|
||||
{
|
||||
}
|
||||
};
|
||||
class IMcuManager
|
||||
{
|
||||
|
|
|
@ -28,8 +28,14 @@ std::shared_ptr<IMcuManager> &IMcuManager::GetInstance(std::shared_ptr<IMcuManag
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
const StatusCode IMcuManager::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IMcuManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
const StatusCode IMcuManager::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IMcuManager::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IMcuManager::SetMcuMonitor(std::shared_ptr<VMcuMonitor> &monitor)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
|
|
@ -28,7 +28,9 @@ McuDevice::McuDevice()
|
|||
mThreadRuning = false;
|
||||
mUartDevice = nullptr;
|
||||
}
|
||||
McuDevice::~McuDevice() {}
|
||||
McuDevice::~McuDevice()
|
||||
{
|
||||
}
|
||||
const StatusCode McuDevice::Init(void)
|
||||
{
|
||||
UartInfo uartDevice = {
|
||||
|
@ -50,9 +52,13 @@ const StatusCode McuDevice::Init(void)
|
|||
return code;
|
||||
}
|
||||
std::shared_ptr<McuDevice> device = std::dynamic_pointer_cast<McuDevice>(SharedFromThis());
|
||||
auto recvThread = [](std::shared_ptr<McuDevice> device) { device->DeviceRecvThread(); };
|
||||
auto recvThread = [](std::shared_ptr<McuDevice> device) {
|
||||
device->DeviceRecvThread();
|
||||
};
|
||||
mUartRecvThread = std::thread(recvThread, device);
|
||||
auto mcuAskHandle = [](std::shared_ptr<McuDevice> device) { device->McuAskHandleThread(); };
|
||||
auto mcuAskHandle = [](std::shared_ptr<McuDevice> device) {
|
||||
device->McuAskHandleThread();
|
||||
};
|
||||
mMcuAskHandleThread = std::thread(mcuAskHandle, device);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@
|
|||
#include "McuManagerImpl.h"
|
||||
#include "ILog.h"
|
||||
#include "UartRecvAsk.h"
|
||||
std::shared_ptr<VProtocolBase> McuManagerImpl::SharedFromThis(void) { return shared_from_this(); }
|
||||
std::shared_ptr<VProtocolBase> McuManagerImpl::SharedFromThis(void)
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
const StatusCode McuManagerImpl::Init(void)
|
||||
{
|
||||
McuDevice::Init();
|
||||
|
|
|
@ -36,19 +36,37 @@ enum class SensorTaskType
|
|||
class SensorTaskResponse
|
||||
{
|
||||
public:
|
||||
SensorTaskResponse() {}
|
||||
~SensorTaskResponse() {}
|
||||
SensorTaskResponse()
|
||||
{
|
||||
}
|
||||
~SensorTaskResponse()
|
||||
{
|
||||
}
|
||||
};
|
||||
class VSensorTask
|
||||
{
|
||||
public:
|
||||
VSensorTask() = default;
|
||||
virtual ~VSensorTask() = default;
|
||||
virtual const SensorTaskType GetTaskType(void) { return SensorTaskType::END; }
|
||||
virtual void Response(const std::vector<SensorTaskResponse> &response) {}
|
||||
virtual bool IsTaskFinished(void) { return false; }
|
||||
virtual const signed int GetIsNight(void) { return 0; }
|
||||
virtual const unsigned int GetIsMultShot(void) { return false; }
|
||||
virtual const SensorTaskType GetTaskType(void)
|
||||
{
|
||||
return SensorTaskType::END;
|
||||
}
|
||||
virtual void Response(const std::vector<SensorTaskResponse> &response)
|
||||
{
|
||||
}
|
||||
virtual bool IsTaskFinished(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual const signed int GetIsNight(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual const unsigned int GetIsMultShot(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
class VSensorHandle
|
||||
{
|
||||
|
|
|
@ -36,14 +36,16 @@ public:
|
|||
class State
|
||||
{
|
||||
public:
|
||||
explicit State(const std::string &name) : mStateName(name) {}
|
||||
explicit State(const std::string &name) : mStateName(name)
|
||||
{
|
||||
}
|
||||
virtual ~State() = default;
|
||||
|
||||
public:
|
||||
virtual void GoInState() = 0;
|
||||
virtual void GoOutState() = 0;
|
||||
virtual bool ExecuteStateMsg(VStateMachineData *msg) = 0;
|
||||
std::string GetStateName() { return mStateName; }
|
||||
std::string GetStateName();
|
||||
|
||||
private:
|
||||
std::string mStateName;
|
||||
|
@ -53,20 +55,18 @@ class VStateMachineHandle
|
|||
public:
|
||||
VStateMachineHandle() = default;
|
||||
virtual ~VStateMachineHandle() = default;
|
||||
virtual bool InitialStateMachine() { return false; }
|
||||
virtual void StatePlus(State *state, State *upper) {}
|
||||
virtual void SetCurrentState(State *firstState) {}
|
||||
virtual void StartStateMachine() {}
|
||||
virtual void SendMessage(int msgName) {}
|
||||
virtual void StopHandlerThread() {}
|
||||
virtual void SendMessage(int msgName, const std::shared_ptr<VStateMessage> &messageObj) {}
|
||||
virtual bool InitialStateMachine();
|
||||
virtual void StatePlus(State *state, State *upper);
|
||||
virtual void SetCurrentState(State *firstState);
|
||||
virtual void StartStateMachine();
|
||||
virtual void SendMessage(int msgName);
|
||||
virtual void StopHandlerThread();
|
||||
virtual void SendMessage(int msgName, const std::shared_ptr<VStateMessage> &messageObj);
|
||||
virtual void MessageExecutedLater(int msgName, const std::shared_ptr<VStateMessage> &messageObj,
|
||||
int64_t delayTimeMs)
|
||||
{
|
||||
}
|
||||
virtual void SwitchState(State *targetState) {}
|
||||
virtual void StopTimer(int timerName) {}
|
||||
virtual void DelayMessage(VStateMachineData *msg) {}
|
||||
int64_t delayTimeMs);
|
||||
virtual void SwitchState(State *targetState);
|
||||
virtual void StopTimer(int timerName);
|
||||
virtual void DelayMessage(VStateMachineData *msg);
|
||||
};
|
||||
class IStateMachine
|
||||
{
|
||||
|
|
|
@ -15,6 +15,45 @@
|
|||
#include "IStateMachine.h"
|
||||
#include "ILog.h"
|
||||
#include <thread>
|
||||
std::string State::GetStateName()
|
||||
{
|
||||
return mStateName;
|
||||
}
|
||||
bool VStateMachineHandle::InitialStateMachine()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void VStateMachineHandle::StatePlus(State *state, State *upper)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::SetCurrentState(State *firstState)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::StartStateMachine()
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::SendMessage(int msgName)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::StopHandlerThread()
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::SendMessage(int msgName, const std::shared_ptr<VStateMessage> &messageObj)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::MessageExecutedLater(int msgName, const std::shared_ptr<VStateMessage> &messageObj,
|
||||
int64_t delayTimeMs)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::SwitchState(State *targetState)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::StopTimer(int timerName)
|
||||
{
|
||||
}
|
||||
void VStateMachineHandle::DelayMessage(VStateMachineData *msg)
|
||||
{
|
||||
}
|
||||
std::shared_ptr<IStateMachine> &IStateMachine::GetInstance(std::shared_ptr<IStateMachine> *impl)
|
||||
{
|
||||
static std::shared_ptr<IStateMachine> instance = std::make_shared<IStateMachine>();
|
||||
|
|
|
@ -198,7 +198,10 @@ public:
|
|||
// mMessageObj = T(messageObj);
|
||||
// }
|
||||
|
||||
void SetMessageObj(const std::shared_ptr<VStateMessage> &messageObj) { mMessageObj = messageObj; }
|
||||
void SetMessageObj(const std::shared_ptr<VStateMessage> &messageObj)
|
||||
{
|
||||
mMessageObj = messageObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @DescriptionGet the Message Obj object
|
||||
|
@ -223,7 +226,10 @@ public:
|
|||
// {
|
||||
// return mMessageObj;
|
||||
// }
|
||||
const std::shared_ptr<VStateMessage> &GetMessageObj(void) const override { return mMessageObj; }
|
||||
const std::shared_ptr<VStateMessage> &GetMessageObj(void) const override
|
||||
{
|
||||
return mMessageObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description : Release Message Object.
|
||||
|
|
|
@ -42,14 +42,21 @@ class HunttingCameraTest : public testing::Test,
|
|||
|
||||
{
|
||||
public:
|
||||
HunttingCameraTest() {}
|
||||
virtual ~HunttingCameraTest() {}
|
||||
HunttingCameraTest()
|
||||
{
|
||||
}
|
||||
virtual ~HunttingCameraTest()
|
||||
{
|
||||
}
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
}
|
||||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
ILogUnInit();
|
||||
}
|
||||
virtual void SetUp()
|
||||
{
|
||||
std::shared_ptr<MainThread> mainThread = std::make_shared<MainThreadTest>();
|
||||
|
@ -181,4 +188,92 @@ TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_McuOpenFailed)
|
|||
// MockUploadFiles();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetParamValue
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetParamValue)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetParamValue();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetCapability
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetCapability)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetCapability();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetLockVideoStatus
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetLockVideoStatus)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetLockVideoStatus();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageInfo
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageInfo)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageInfo();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_SetParamValue
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_SetParamValue)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockSetParamValue();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_EnterRecorder
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_EnterRecorder)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockEnterRecorder();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HunttingCameraTest
|
||||
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_AppPlayback
|
||||
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_AppPlayback)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockAppPlayback();
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
} // namespace HunttingCameraTest
|
|
@ -60,7 +60,52 @@ StatusCode TestMissionStateTest::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
|||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::SetDateTime(AppSetDateTime ¶m)
|
||||
StatusCode TestMissionStateTest::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::GetParamValue\n");
|
||||
StatusCode code = GetParamValueTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::GetParamValue(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::GetCapability\n");
|
||||
StatusCode code = GetCapabilityTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::GetCapability(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::GetLockVideoStatus\n");
|
||||
StatusCode code = GetLockVideoStatusTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::GetLockVideoStatus(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::GetStorageInfo\n");
|
||||
StatusCode code = GetStorageInfoTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::GetStorageInfo(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::GetStorageFileList\n");
|
||||
StatusCode code = GetStorageFileListTrace(fileInfo, param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::GetStorageFileList(fileInfo, param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::SetDateTime\n");
|
||||
LogInfo("mYear = %u\n", param.mYear);
|
||||
|
@ -84,6 +129,33 @@ StatusCode TestMissionStateTest::SetTimeZone(const unsigned int &zone)
|
|||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::SetParamValue.\n");
|
||||
StatusCode code = SetParamValueTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::SetParamValue(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::EnterRecorder(void)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::EnterRecorder.\n");
|
||||
StatusCode code = EnterRecorderTrace();
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::EnterRecorder();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::AppPlayback.\n");
|
||||
StatusCode code = AppPlaybackTrace(event);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::AppPlayback(event);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::UploadFile\n");
|
||||
|
|
|
@ -27,19 +27,24 @@ public:
|
|||
StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override;
|
||||
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
||||
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
||||
StatusCode SetDateTime(AppSetDateTime ¶m) override;
|
||||
StatusCode GetParamValue(AppParamValue ¶m) override;
|
||||
StatusCode GetCapability(AppGetCapability ¶m) override;
|
||||
StatusCode GetLockVideoStatus(LockVideoStatus ¶m) override;
|
||||
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> ¶m) override;
|
||||
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m) override;
|
||||
StatusCode SetDateTime(const AppSetDateTime ¶m) override;
|
||||
StatusCode SetTimeZone(const unsigned int &zone) override;
|
||||
StatusCode SetParamValue(const AppSetParamValue ¶m) override;
|
||||
StatusCode EnterRecorder(void) override;
|
||||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||
// const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||
|
||||
protected:
|
||||
// virtual const StatusCode SetAppMonitorTrace(std::shared_ptr<VAppMonitor> &monitor);
|
||||
};
|
||||
class TestMissionStateMock : public AppMonitorMock, public TestMissionStateTest
|
||||
{
|
||||
public:
|
||||
TestMissionStateMock() = default;
|
||||
virtual ~TestMissionStateMock() = default;
|
||||
// MOCK_METHOD1(SetAppMonitorTrace, const StatusCode(std::shared_ptr<VAppMonitor> &));
|
||||
};
|
||||
#endif
|
|
@ -32,7 +32,9 @@ public:
|
|||
const unsigned int &blinkTimeMs);
|
||||
|
||||
protected:
|
||||
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) {}
|
||||
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
void KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs);
|
||||
|
|
|
@ -23,11 +23,17 @@ class KeyControlTest : public KeyControl, public VKeyHal
|
|||
public:
|
||||
KeyControlTest(const std::string &keyName);
|
||||
virtual ~KeyControlTest() = default;
|
||||
unsigned int GetStatusCheckPeriodMs(void) override { return PERIPHERAL_CHECK_PERIOD_MS; }
|
||||
unsigned int GetStatusCheckPeriodMs(void) override
|
||||
{
|
||||
return PERIPHERAL_CHECK_PERIOD_MS;
|
||||
}
|
||||
void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor) override;
|
||||
void CheckKeyStatus(void) override;
|
||||
void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) override;
|
||||
const std::string GetKeyName(void) override { return mKeyName; }
|
||||
const std::string GetKeyName(void) override
|
||||
{
|
||||
return mKeyName;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual StatusCode KeyEventTriggerTrace(const std::string &keyName, const KeyEvent &event,
|
||||
|
|
|
@ -34,7 +34,7 @@ endif()
|
|||
|
||||
set(TARGET_NAME AppManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} AppManagerTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} AppManagerTestTool HalTestTool gtest gmock pthread)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "AppManagerTestTool.h"
|
||||
#include "HalTestTool.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
@ -20,26 +21,37 @@
|
|||
#include <thread>
|
||||
namespace AppManagerTest
|
||||
{
|
||||
class AppManagerTest : public testing::Test, public AppManagerTestTool
|
||||
class AppManagerTest : public testing::Test, public AppManagerTestTool, public HalTestTool
|
||||
{
|
||||
public:
|
||||
AppManagerTest() : mAppParam(APP_MANAGER_HTTP_SERVER_IP, APP_MANAGER_HTTP_SERVER_PORT) {}
|
||||
virtual ~AppManagerTest() {}
|
||||
AppManagerTest() : mAppParam(APP_MANAGER_HTTP_SERVER_IP, APP_MANAGER_HTTP_SERVER_PORT)
|
||||
{
|
||||
}
|
||||
virtual ~AppManagerTest()
|
||||
{
|
||||
}
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
}
|
||||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
ILogUnInit();
|
||||
}
|
||||
virtual void SetUp()
|
||||
{
|
||||
HalTestTool::Init();
|
||||
AppManagerTestTool::Init();
|
||||
CreateHalCppModule();
|
||||
CreateAppManagerModule();
|
||||
}
|
||||
virtual void TearDown()
|
||||
{
|
||||
AppManagerTestTool::UnInit();
|
||||
HalTestTool::UnInit();
|
||||
DestroyAppManagerModule();
|
||||
DestroyHalCppModule();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -48,9 +60,11 @@ protected:
|
|||
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo0
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo0)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo
|
||||
|
@ -145,4 +159,100 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetTimeZone)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamValue
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamValue)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetParamValue();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetCapability
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetCapability)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetCapability();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetLockVideoStatus
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetLockVideoStatus)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetLockVideoStatus();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetStorageInfo
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetStorageInfo)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetStorageFileList
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetStorageFileList)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_SetParamValue
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetParamValue)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockSetParamValue();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_EnterRecorder
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_EnterRecorder)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockEnterRecorder();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/AppManagerTest
|
||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_AppPlayback
|
||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_AppPlayback)
|
||||
{
|
||||
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockAppPlayback();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
} // namespace AppManagerTest
|
|
@ -34,9 +34,19 @@ protected:
|
|||
void MockSetDateTime(void);
|
||||
void MockSetTimeZone(void);
|
||||
void MockUploadFiles(void);
|
||||
void MockGetParamValue(void);
|
||||
void MockGetCapability(void);
|
||||
void MockGetLockVideoStatus(void);
|
||||
void MockGetStorageInfo(void);
|
||||
void MockGetStorageFileList(void);
|
||||
void MockSetParamValue(void);
|
||||
void MockEnterRecorder(void);
|
||||
void MockAppPlayback(void);
|
||||
void MockMonitorSetFileList(std::vector<AppGetFileList> &files);
|
||||
|
||||
private:
|
||||
void AppManagerMockInit(std::shared_ptr<IAppManager> &vMock);
|
||||
void AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock);
|
||||
|
||||
private:
|
||||
std::shared_ptr<IAppManager> mAppManagerMock;
|
||||
|
@ -44,6 +54,5 @@ private:
|
|||
|
||||
public:
|
||||
static std::shared_ptr<VAppMonitor> MakeMonitorMock(void);
|
||||
void AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock);
|
||||
};
|
||||
#endif
|
|
@ -114,6 +114,97 @@ void AppManagerTestTool::MockUploadFiles(void)
|
|||
}
|
||||
ServersMock::GetInstance()->MockUploadFiles();
|
||||
}
|
||||
void AppManagerTestTool::MockGetParamValue(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), GetParamValueTrace(_))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockGetParamValue();
|
||||
}
|
||||
void AppManagerTestTool::MockGetCapability(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), GetCapabilityTrace(_))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockGetCapability();
|
||||
}
|
||||
void AppManagerTestTool::MockGetLockVideoStatus(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), GetLockVideoStatusTrace(_))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockGetLockVideoStatus();
|
||||
}
|
||||
void AppManagerTestTool::MockGetStorageInfo(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), GetStorageInfoTrace(_))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockGetStorageInfo();
|
||||
}
|
||||
void AppManagerTestTool::MockGetStorageFileList(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), GetStorageFileListTrace(_, _))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockGetStorageFileList();
|
||||
}
|
||||
void AppManagerTestTool::MockSetParamValue(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), SetParamValueTrace(_))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockSetParamValue();
|
||||
}
|
||||
void AppManagerTestTool::MockEnterRecorder(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), EnterRecorderTrace())
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockEnterRecorder();
|
||||
}
|
||||
void AppManagerTestTool::MockAppPlayback(void)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), AppPlaybackTrace(_))
|
||||
.Times(ONLY_BE_CALLED_ONCE)
|
||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockAppPlayback();
|
||||
}
|
||||
void AppManagerTestTool::MockMonitorSetFileList(std::vector<AppGetFileList> &files)
|
||||
{
|
||||
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||
if (mock) {
|
||||
EXPECT_CALL(*mock.get(), GetStorageFileListTrace(_, _))
|
||||
.WillRepeatedly(DoAll(SetArgReferee<1>(files), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||
}
|
||||
else {
|
||||
LogError("MockMonitorSetFileList failed, mAppMonitorMock isn't mock object.\n");
|
||||
}
|
||||
}
|
||||
void AppManagerTestTool::AppManagerMockInit(std::shared_ptr<IAppManager> &vMock)
|
||||
{
|
||||
std::shared_ptr<AppManagerMock> mock = std::dynamic_pointer_cast<AppManagerMock>(vMock);
|
||||
|
@ -123,7 +214,6 @@ void AppManagerTestTool::AppManagerMockInit(std::shared_ptr<IAppManager> &vMock)
|
|||
}
|
||||
auto getAppMonitor = [=](std::shared_ptr<VAppMonitor> &monitor) {
|
||||
LogInfo("mAppMonitorMock get.\n");
|
||||
// mAppMonitorMock = std::dynamic_pointer_cast<AppMonitorMock>(monitor);
|
||||
mAppMonitorMock = monitor;
|
||||
AppManagerTestTool::AppMonitorInit(mAppMonitorMock);
|
||||
};
|
||||
|
@ -140,7 +230,6 @@ std::shared_ptr<VAppMonitor> AppManagerTestTool::MakeMonitorMock(void)
|
|||
virtual ~Monitor() = default;
|
||||
};
|
||||
std::shared_ptr<VAppMonitor> monitor = std::make_shared<Monitor>();
|
||||
// auto result = std::dynamic_pointer_cast<VAppMonitor>(monitor);
|
||||
return monitor;
|
||||
}
|
||||
void AppManagerTestTool::AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock)
|
||||
|
@ -155,10 +244,28 @@ void AppManagerTestTool::AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock)
|
|||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetSdCardInfoTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetParamValueTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetCapabilityTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetLockVideoStatusTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetStorageInfoTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetStorageFileListTrace(_, _))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), GetBatteryInfoTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), SetDateTimeTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), SetTimeZoneTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), SetParamValueTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), EnterRecorderTrace())
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), AppPlaybackTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
EXPECT_CALL(*mock.get(), UploadFileTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
|
|
|
@ -84,7 +84,77 @@ StatusCode AppMonitorTrace::GetBatteryInfoTrace(AppGetBatteryInfo ¶m)
|
|||
LogInfo("AppMonitorTrace::GetBatteryInfoTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m)
|
||||
StatusCode AppMonitorTest::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::GetParamValue\n");
|
||||
StatusCode code = GetParamValueTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::GetParamValue(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::GetParamValueTrace(AppParamValue ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::GetParamValueTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::GetCapability\n");
|
||||
StatusCode code = GetCapabilityTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::GetCapability(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::GetCapabilityTrace(AppGetCapability ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::GetCapabilityTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::GetLockVideoStatus\n");
|
||||
StatusCode code = GetLockVideoStatusTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::GetLockVideoStatus(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::GetLockVideoStatusTrace(LockVideoStatus ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::GetLockVideoStatusTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::GetStorageInfo\n");
|
||||
StatusCode code = GetStorageInfoTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::GetStorageInfo(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::GetStorageInfoTrace(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::GetStorageInfoTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::GetStorageFileList\n");
|
||||
StatusCode code = GetStorageFileListTrace(fileInfo, param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::GetStorageFileList(fileInfo, param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::GetStorageFileListTrace(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::GetStorageFileListTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::SetDateTime\n");
|
||||
LogInfo("mYear = %u\n", param.mYear);
|
||||
|
@ -99,7 +169,7 @@ StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m)
|
|||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::SetDateTimeTrace(AppSetDateTime ¶m)
|
||||
StatusCode AppMonitorTrace::SetDateTimeTrace(const AppSetDateTime ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::SetDateTimeTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
@ -118,6 +188,48 @@ StatusCode AppMonitorTrace::SetTimeZoneTrace(const unsigned int &zone)
|
|||
LogInfo("AppMonitorTrace::SetTimeZoneTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::SetParamValue\n");
|
||||
StatusCode code = SetParamValueTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::SetParamValue(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::SetParamValueTrace(const AppSetParamValue ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::SetParamValueTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::EnterRecorder(void)
|
||||
{
|
||||
LogInfo("AppMonitorTest::EnterRecorder\n");
|
||||
StatusCode code = EnterRecorderTrace();
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::EnterRecorder();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::EnterRecorderTrace(void)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::EnterRecorderTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
LogInfo("AppMonitorTest::AppPlayback\n");
|
||||
StatusCode code = AppPlaybackTrace(event);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::AppPlayback(event);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode AppMonitorTrace::AppPlaybackTrace(const PlayBackEvent &event)
|
||||
{
|
||||
LogInfo("AppMonitorTrace::AppPlaybackTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::UploadFile\n");
|
||||
|
|
|
@ -28,8 +28,16 @@ protected:
|
|||
virtual StatusCode GetMediaInfoTrace(AppGetMeidaInfo ¶m);
|
||||
virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m);
|
||||
virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo ¶m);
|
||||
virtual StatusCode SetDateTimeTrace(AppSetDateTime ¶m);
|
||||
virtual StatusCode GetParamValueTrace(AppParamValue ¶m);
|
||||
virtual StatusCode GetCapabilityTrace(AppGetCapability ¶m);
|
||||
virtual StatusCode GetLockVideoStatusTrace(LockVideoStatus ¶m);
|
||||
virtual StatusCode GetStorageInfoTrace(std::vector<AppGetStorageInfo> ¶m);
|
||||
virtual StatusCode GetStorageFileListTrace(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m);
|
||||
virtual StatusCode SetDateTimeTrace(const AppSetDateTime ¶m);
|
||||
virtual StatusCode SetTimeZoneTrace(const unsigned int &zone);
|
||||
virtual StatusCode SetParamValueTrace(const AppSetParamValue ¶m);
|
||||
virtual StatusCode EnterRecorderTrace(void);
|
||||
virtual StatusCode AppPlaybackTrace(const PlayBackEvent &event);
|
||||
virtual StatusCode UploadFileTrace(AppUploadFile ¶m);
|
||||
};
|
||||
class AppMonitorTest : public VAppMonitor, virtual public AppMonitorTrace
|
||||
|
@ -42,8 +50,16 @@ public:
|
|||
StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override;
|
||||
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
||||
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
||||
StatusCode SetDateTime(AppSetDateTime ¶m) override;
|
||||
StatusCode GetParamValue(AppParamValue ¶m) override;
|
||||
StatusCode GetCapability(AppGetCapability ¶m) override;
|
||||
StatusCode GetLockVideoStatus(LockVideoStatus ¶m) override;
|
||||
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> ¶m) override;
|
||||
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m) override;
|
||||
StatusCode SetDateTime(const AppSetDateTime ¶m) override;
|
||||
StatusCode SetTimeZone(const unsigned int &zone) override;
|
||||
StatusCode SetParamValue(const AppSetParamValue ¶m) override;
|
||||
StatusCode EnterRecorder(void) override;
|
||||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||
};
|
||||
class AppMonitorMock : virtual public AppMonitorTrace
|
||||
|
@ -56,8 +72,16 @@ public:
|
|||
MOCK_METHOD1(GetMediaInfoTrace, StatusCode(AppGetMeidaInfo &));
|
||||
MOCK_METHOD1(GetSdCardInfoTrace, StatusCode(AppGetSdCardInfo &));
|
||||
MOCK_METHOD1(GetBatteryInfoTrace, StatusCode(AppGetBatteryInfo &));
|
||||
MOCK_METHOD1(SetDateTimeTrace, StatusCode(AppSetDateTime &));
|
||||
MOCK_METHOD1(GetParamValueTrace, StatusCode(AppParamValue &));
|
||||
MOCK_METHOD1(GetCapabilityTrace, StatusCode(AppGetCapability &));
|
||||
MOCK_METHOD1(GetLockVideoStatusTrace, StatusCode(LockVideoStatus &));
|
||||
MOCK_METHOD1(GetStorageInfoTrace, StatusCode(std::vector<AppGetStorageInfo> &));
|
||||
MOCK_METHOD2(GetStorageFileListTrace, StatusCode(const AppGetFileInfo &, std::vector<AppGetFileList> &));
|
||||
MOCK_METHOD1(SetDateTimeTrace, StatusCode(const AppSetDateTime &));
|
||||
MOCK_METHOD1(SetTimeZoneTrace, StatusCode(const unsigned int &));
|
||||
MOCK_METHOD1(SetParamValueTrace, StatusCode(const AppSetParamValue &));
|
||||
MOCK_METHOD0(EnterRecorderTrace, StatusCode(void));
|
||||
MOCK_METHOD1(AppPlaybackTrace, StatusCode(const PlayBackEvent &));
|
||||
MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &));
|
||||
};
|
||||
#endif
|
|
@ -21,8 +21,16 @@ extern const char *APP_GET_DEVICE_ATTR;
|
|||
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_GET_PARAM_VALUE;
|
||||
extern const char *APP_GET_CAPABILITY;
|
||||
extern const char *APP_GET_LOCK_VIDEO_STATUS;
|
||||
extern const char *APP_GET_STORAGE_INFO;
|
||||
extern const char *APP_GET_FILE_LIST;
|
||||
extern const char *APP_SET_DATE_TIME;
|
||||
extern const char *APP_SET_TIME_ZONE;
|
||||
extern const char *APP_SET_PARAM_VALUE;
|
||||
extern const char *APP_ENTER_RECORDER;
|
||||
extern const char *APP_PLAYBACK;
|
||||
extern const char *APP_UPLOAD_FILE;
|
||||
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
||||
{
|
||||
|
@ -140,9 +148,94 @@ void ServersMock::MockGetBatteryInfo(void)
|
|||
DeleteServersHttp(http);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockGetParamValue(void)
|
||||
{
|
||||
LogInfo("APP_GET_PARAM_VALUE test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_GET_PARAM_VALUE;
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockGetCapability(void)
|
||||
{
|
||||
LogInfo("APP_GET_CAPABILITY test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_GET_CAPABILITY;
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockGetLockVideoStatus(void)
|
||||
{
|
||||
LogInfo("APP_GET_LOCK_VIDEO_STATUS test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_GET_LOCK_VIDEO_STATUS;
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockGetStorageInfo(void)
|
||||
{
|
||||
LogInfo("APP_GET_STORAGE_INFO test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_GET_STORAGE_INFO;
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockGetStorageFileList(void)
|
||||
{
|
||||
LogInfo("APP_GET_FILE_LIST test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_GET_FILE_LIST + "?folder=loop&start=0&end=99";
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockSetDateTime(void)
|
||||
{
|
||||
LogInfo("APP_GET_BATTERY_INFO test start.\n");
|
||||
LogInfo("APP_SET_DATE_TIME test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_SET_DATE_TIME + "?date=20240101010101";
|
||||
ServerHttp *http = NewServersHttp(mockRequest.c_str());
|
||||
if (http) {
|
||||
|
@ -174,6 +267,57 @@ void ServersMock::MockSetTimeZone(void)
|
|||
DeleteServersHttp(http);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockSetParamValue(void)
|
||||
{
|
||||
LogInfo("APP_SET_PARAM_VALUE test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_SET_PARAM_VALUE + "?param=switchcam&value=1";
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockEnterRecorder(void)
|
||||
{
|
||||
LogInfo("APP_ENTER_RECORDER test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_ENTER_RECORDER + "?timezone=8"; // TODO:
|
||||
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);
|
||||
}
|
||||
}
|
||||
void ServersMock::MockAppPlayback(void)
|
||||
{
|
||||
LogInfo("APP_PLAYBACK test start.\n");
|
||||
std::string mockRequest = mServerUrl + APP_PLAYBACK + "?param=enter";
|
||||
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
|
||||
|
|
|
@ -28,8 +28,16 @@ public:
|
|||
virtual void MockGetMediaInfo(void);
|
||||
virtual void MockGetSdCardInfo(void);
|
||||
virtual void MockGetBatteryInfo(void);
|
||||
virtual void MockGetParamValue(void);
|
||||
virtual void MockGetCapability(void);
|
||||
virtual void MockGetLockVideoStatus(void);
|
||||
virtual void MockGetStorageInfo(void);
|
||||
virtual void MockGetStorageFileList(void);
|
||||
virtual void MockSetDateTime(void);
|
||||
virtual void MockSetTimeZone(void);
|
||||
virtual void MockSetParamValue(void);
|
||||
virtual void MockEnterRecorder(void);
|
||||
virtual void MockAppPlayback(void);
|
||||
virtual void MockUploadFiles(void);
|
||||
|
||||
private:
|
||||
|
|
|
@ -26,14 +26,21 @@ const char *LED_TEST = "LED_TEST";
|
|||
class DeviceManagerTest : public testing::Test, virtual public HalTestTool, public DeviceManagerTestTool
|
||||
{
|
||||
public:
|
||||
DeviceManagerTest() {}
|
||||
virtual ~DeviceManagerTest() {}
|
||||
DeviceManagerTest()
|
||||
{
|
||||
}
|
||||
virtual ~DeviceManagerTest()
|
||||
{
|
||||
}
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
}
|
||||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
ILogUnInit();
|
||||
}
|
||||
virtual void SetUp()
|
||||
{
|
||||
CreateAllKeysMcok();
|
||||
|
|
|
@ -22,8 +22,14 @@ public:
|
|||
SingleControlTool(const LedState &state, const unsigned int aliveTimeMs, const unsigned int &blinkTimeMs);
|
||||
virtual ~SingleControlTool() = default;
|
||||
virtual StatusCode GetLedState(LedState &state);
|
||||
virtual unsigned int GetKeepAliveTimeMs(void) { return mAliveTimeMs; }
|
||||
virtual unsigned int GetBlinkTimeMs(void) { return mBlinkTimeMs; }
|
||||
virtual unsigned int GetKeepAliveTimeMs(void)
|
||||
{
|
||||
return mAliveTimeMs;
|
||||
}
|
||||
virtual unsigned int GetBlinkTimeMs(void)
|
||||
{
|
||||
return mBlinkTimeMs;
|
||||
}
|
||||
|
||||
private:
|
||||
const LedState mState;
|
||||
|
|
|
@ -18,10 +18,6 @@ link_directories(
|
|||
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
aux_source_directory(. SRC_FILES_MAIN)
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
|
|
|
@ -32,10 +32,18 @@ public:
|
|||
bool IfTimeout(const unsigned int &integrationTimeMs) override;
|
||||
|
||||
protected:
|
||||
virtual void BlockingTrace(void) {}
|
||||
virtual void NeedReplyTrace(void) {}
|
||||
virtual void ReplyFinishedTrace(const bool result) {}
|
||||
virtual void IfTimeoutTrace(const unsigned int &integrationTimeMs) {}
|
||||
virtual void BlockingTrace(void)
|
||||
{
|
||||
}
|
||||
virtual void NeedReplyTrace(void)
|
||||
{
|
||||
}
|
||||
virtual void ReplyFinishedTrace(const bool result)
|
||||
{
|
||||
}
|
||||
virtual void IfTimeoutTrace(const unsigned int &integrationTimeMs)
|
||||
{
|
||||
}
|
||||
};
|
||||
class McuAskBaseTestTool : public McuAskBaseTest
|
||||
{
|
||||
|
|
|
@ -12,14 +12,21 @@ namespace McuManagerMockTest
|
|||
class McuManagerMockTest : public testing::Test, public McuManagerTestTool
|
||||
{
|
||||
public:
|
||||
McuManagerMockTest() {}
|
||||
virtual ~McuManagerMockTest() {}
|
||||
McuManagerMockTest()
|
||||
{
|
||||
}
|
||||
virtual ~McuManagerMockTest()
|
||||
{
|
||||
}
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
}
|
||||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
ILogUnInit();
|
||||
}
|
||||
virtual void SetUp()
|
||||
{
|
||||
mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||
|
@ -58,7 +65,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission)
|
|||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -96,7 +105,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission2)
|
|||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::NOT_BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -156,8 +167,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply)
|
|||
class McuAskTest : public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest()
|
||||
: McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY) {} // using McuAskReply::NEED_NOT_REPLY
|
||||
McuAskTest() : McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY)
|
||||
{
|
||||
} // using McuAskReply::NEED_NOT_REPLY
|
||||
virtual ~McuAskTest() = default;
|
||||
};
|
||||
IMcuManager::GetInstance()->Init();
|
||||
|
@ -176,8 +188,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_FeedWatchDog)
|
|||
class McuAskTest : public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest()
|
||||
: McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY) {} // using McuAskReply::NEED_NOT_REPLY
|
||||
McuAskTest() : McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY)
|
||||
{
|
||||
} // using McuAskReply::NEED_NOT_REPLY
|
||||
virtual ~McuAskTest() = default;
|
||||
};
|
||||
IMcuManager::GetInstance()->Init();
|
||||
|
@ -196,7 +209,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatc
|
|||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -230,7 +245,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetDateTime)
|
|||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::NOT_BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -262,7 +279,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity)
|
|||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::NOT_BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -293,7 +312,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight)
|
|||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::NOT_BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -324,7 +345,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityVal
|
|||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK
|
||||
McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::NOT_BLOCK
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -351,7 +374,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission)
|
|||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {}
|
||||
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
}
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -381,7 +406,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2)
|
|||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBaseTestTool(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {}
|
||||
McuAskTest() : McuAskBaseTestTool(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
}
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -573,8 +600,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite)
|
|||
class McuAskTest2 : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
||||
{
|
||||
public:
|
||||
McuAskTest2()
|
||||
: McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK
|
||||
McuAskTest2() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
} // using McuAskBlock::NOT_BLOCK
|
||||
virtual ~McuAskTest2() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
@ -763,7 +791,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMissionFailed)
|
|||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
||||
{
|
||||
public:
|
||||
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {}
|
||||
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
}
|
||||
virtual ~McuAskTest() = default;
|
||||
void ReplyFinished(const bool result) override
|
||||
{
|
||||
|
|
|
@ -60,8 +60,12 @@ public:
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
virtual void Init() {}
|
||||
virtual void UnInit() {}
|
||||
virtual void Init()
|
||||
{
|
||||
}
|
||||
virtual void UnInit()
|
||||
{
|
||||
}
|
||||
virtual int fx_open(const char *pathname, int flags);
|
||||
virtual int fx_tcgetattr(int fd, struct termios *termios_p);
|
||||
virtual int fx_tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
|
||||
|
@ -103,7 +107,10 @@ public:
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
virtual int GetHandleForMock(void) { return INVALID_HANDLE; }
|
||||
virtual int GetHandleForMock(void)
|
||||
{
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
public:
|
||||
static std::shared_ptr<LinuxTest> CreateLinuxTest(void);
|
||||
|
|
|
@ -13,7 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "HandleManager.h"
|
||||
HandleManager::HandleManager() { mFdMax = 1000; }
|
||||
HandleManager::HandleManager()
|
||||
{
|
||||
mFdMax = 1000;
|
||||
}
|
||||
int HandleManager::GetHandleForMock(void)
|
||||
{
|
||||
int value = mFdMax;
|
||||
|
|
|
@ -92,7 +92,9 @@ void LinuxTestImpl::ApiInit(std::shared_ptr<LinuxTest> &mock)
|
|||
Invoke((std::dynamic_pointer_cast<LinuxTestImpl>(mock)).get(), &LinuxTestImpl::ApiUnlockThread),
|
||||
ReturnPointee(&selectResult)));
|
||||
}
|
||||
void LinuxTestImpl::Init() {}
|
||||
void LinuxTestImpl::Init()
|
||||
{
|
||||
}
|
||||
void LinuxTestImpl::UnInit()
|
||||
{
|
||||
if (mApiThread.joinable()) {
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int __wrap_fx_open(const char *pathname, int flags) { return LinuxApiMock::GetInstance()->fx_open(pathname, flags); }
|
||||
int __wrap_fx_open(const char *pathname, int flags)
|
||||
{
|
||||
return LinuxApiMock::GetInstance()->fx_open(pathname, flags);
|
||||
}
|
||||
int __wrap_fx_tcgetattr(int fd, struct termios *termios_p)
|
||||
{
|
||||
return LinuxApiMock::GetInstance()->fx_tcgetattr(fd, termios_p);
|
||||
|
@ -30,7 +33,10 @@ ssize_t __wrap_fx_write(int fd, const void *buf, size_t count)
|
|||
{
|
||||
return LinuxApiMock::GetInstance()->fx_write(fd, buf, count);
|
||||
}
|
||||
ssize_t __wrap_fx_read(int fd, void *buf, size_t count) { return LinuxApiMock::GetInstance()->fx_read(fd, buf, count); }
|
||||
ssize_t __wrap_fx_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
return LinuxApiMock::GetInstance()->fx_read(fd, buf, count);
|
||||
}
|
||||
int __wrap_fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
|
||||
{
|
||||
return LinuxApiMock::GetInstance()->fx_select(nfds, readfds, writefds, exceptfds, timeout);
|
||||
|
|
|
@ -601,7 +601,9 @@ void McuProtocolTestTool::GetPhotosensitivityValueInit(std::shared_ptr<LinuxTest
|
|||
}
|
||||
void McuProtocolTestTool::UnlockProtocolHandle(void)
|
||||
{
|
||||
auto unlockThread = [=](McuProtocolTestTool *testTool) { testTool->UnlockThread(); };
|
||||
auto unlockThread = [=](McuProtocolTestTool *testTool) {
|
||||
testTool->UnlockThread();
|
||||
};
|
||||
if (mUnLockThread.joinable()) {
|
||||
mUnLockThread.join();
|
||||
}
|
||||
|
|
|
@ -33,14 +33,21 @@ static UartInfo gUartDevice = {
|
|||
class UartDeviceMockTest : public testing::Test, public UartDeviceTestTool
|
||||
{
|
||||
public:
|
||||
UartDeviceMockTest() {}
|
||||
virtual ~UartDeviceMockTest() {}
|
||||
UartDeviceMockTest()
|
||||
{
|
||||
}
|
||||
virtual ~UartDeviceMockTest()
|
||||
{
|
||||
}
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
}
|
||||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
ILogUnInit();
|
||||
}
|
||||
virtual void SetUp()
|
||||
{
|
||||
mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||
|
|
|
@ -99,7 +99,9 @@ void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const
|
|||
EXPECT_CALL(*mock.get(), fx_select(uartFd + 1, _, _, _, _))
|
||||
.WillOnce(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(selectSucceed)), Return(SELECT_READABLE)))
|
||||
.WillRepeatedly(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(selectTimeOut)), Return(MOCK_SELECT_TIME_OUT)));
|
||||
auto readBuf = [=, &mock](int fd, void *buf, size_t count) { memcpy(buf, recvBuff, length); };
|
||||
auto readBuf = [=, &mock](int fd, void *buf, size_t count) {
|
||||
memcpy(buf, recvBuff, length);
|
||||
};
|
||||
EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _))
|
||||
.WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(readBuf)), Return(length)))
|
||||
.WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING)));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
# cmake_minimum_required(VERSION 2.8.0)
|
||||
add_subdirectory(Config)
|
||||
add_subdirectory(ConfigBase)
|
||||
add_subdirectory(StatusCode)
|
||||
add_subdirectory(Log)
|
||||
add_subdirectory(SharedData)
|
||||
|
|
|
@ -14,8 +14,6 @@ include_directories(
|
|||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME ConfigBase)
|
||||
|
|
|
@ -16,9 +16,18 @@
|
|||
#include "ConfigImpl.h"
|
||||
#include "ILog.h"
|
||||
#include <stddef.h>
|
||||
const StatusCode ConfigInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
const StatusCode ConfigUnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
VConfig *OpenConfigFile(const char *fileName) { return (VConfig *)NewConfig(fileName); }
|
||||
const StatusCode ConfigInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode ConfigUnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
VConfig *OpenConfigFile(const char *fileName)
|
||||
{
|
||||
return (VConfig *)NewConfig(fileName);
|
||||
}
|
||||
const StatusCode ConfigSaveFile(VConfig *cfg)
|
||||
{
|
||||
if (NULL == cfg) {
|
||||
|
|
79
utils/ConfigBase/CMakeLists.txt
Normal file
79
utils/ConfigBase/CMakeLists.txt
Normal file
|
@ -0,0 +1,79 @@
|
|||
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
include(build/config_base.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
|
||||
${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib
|
||||
)
|
||||
# link_directories(
|
||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME ConfigBase)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} StatusCode Log libconfig.a)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
ConfigBase_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/ConfigBase
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ConfigBase_code_check
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
ConfigBase_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/ConfigBase
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ConfigBase_code_check
|
||||
COMMAND make ConfigBase_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
# build libconfig before make libConfigBase.a
|
||||
add_custom_command(
|
||||
# OUTPUT ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a
|
||||
OUTPUT ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
COMMAND echo "Build libconfig-1.7.3. COMPILE_HOST = ${COMPILE_HOST}"
|
||||
# COMMAND tar zxvf libconfig-1.7.3.tar.gz
|
||||
COMMAND sh build_libconfig.sh ${TARGET_PLATFORM} ${COMPILE_HOST}
|
||||
COMMAND mv ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/libconfig/
|
||||
)
|
||||
add_custom_target(
|
||||
libconfig.a
|
||||
# DEPENDS ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a
|
||||
DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
)
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
||||
config_owner(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
12
utils/ConfigBase/build/config_base.cmake
Normal file
12
utils/ConfigBase/build/config_base.cmake
Normal file
|
@ -0,0 +1,12 @@
|
|||
function(config_owner target)
|
||||
get_target_property(source_files "${target}" SOURCES)
|
||||
foreach(source_file ${source_files})
|
||||
get_property(defs SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS)
|
||||
get_filename_component(file_name "${source_file}" NAME)
|
||||
list(APPEND defs "CONFIG_OWNER")
|
||||
set_property(
|
||||
SOURCE "${source_file}"
|
||||
PROPERTY COMPILE_DEFINITIONS ${defs})
|
||||
endforeach()
|
||||
endfunction()
|
52
utils/ConfigBase/include/ConfigBase.h
Normal file
52
utils/ConfigBase/include/ConfigBase.h
Normal 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.
|
||||
*/
|
||||
#ifndef CONFIG_BASE_H
|
||||
#define CONFIG_BASE_H
|
||||
#include "StatusCode.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
enum CONFIG_CODE
|
||||
{
|
||||
CONFIG_CODE_PARAM_NOT_EXIST = STATUS_CODE_END,
|
||||
CONFIG_CODE_END
|
||||
};
|
||||
// StatusCode ConfigInit(void);
|
||||
// StatusCode ConfigUnInit(void);
|
||||
void *OpenConfigFile(const char *fileName);
|
||||
StatusCode ConfigSaveFile(void *object);
|
||||
void CloseConfigFile(void *object);
|
||||
StatusCode ConfigGetInt(void *object, const char *name, int *value);
|
||||
StatusCode ConfigSetInt(void *object, const char *name, const int value);
|
||||
StatusCode ConfigGetShort(void *object, const char *name, short *value);
|
||||
StatusCode ConfigSetShort(void *object, const char *name, const short value);
|
||||
StatusCode ConfigGetLong(void *object, const char *name, long *value);
|
||||
StatusCode ConfigSetLong(void *object, const char *name, const long value);
|
||||
StatusCode ConfigGetLLong(void *object, const char *name, long long *value);
|
||||
StatusCode ConfigSetLLong(void *object, const char *name, const long long value);
|
||||
StatusCode ConfigGetChar(void *object, const char *name, char *value);
|
||||
StatusCode ConfigSetChar(void *object, const char *name, const char value);
|
||||
StatusCode ConfigGetBool(void *object, const char *name, bool *value);
|
||||
StatusCode ConfigSetBool(void *object, const char *name, const bool value);
|
||||
StatusCode ConfigGetFloat(void *object, const char *name, float *value);
|
||||
StatusCode ConfigSetFloat(void *object, const char *name, const float value);
|
||||
StatusCode ConfigGetDouble(void *object, const char *name, double *value);
|
||||
StatusCode ConfigSetDouble(void *object, const char *name, const double value);
|
||||
StatusCode ConfigGetString(void *object, const char *name, const char **value);
|
||||
StatusCode ConfigSetString(void *object, const char *name, const char *value);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
178
utils/ConfigBase/src/ConfigBase.cpp
Normal file
178
utils/ConfigBase/src/ConfigBase.cpp
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* 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 "ConfigBase.h"
|
||||
#include "IConfigBase.h"
|
||||
#include "ILog.h"
|
||||
static bool ObjectCheck(void *object)
|
||||
{
|
||||
if (nullptr == object) {
|
||||
LogError("nullptr object!\n");
|
||||
return false;
|
||||
}
|
||||
if (*((const char **)(((char *)object) - sizeof(IConfigBase))) != GetConfigBaseModuleName()) {
|
||||
LogError("Illegal object!\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void *OpenConfigFile(const char *fileName)
|
||||
{
|
||||
std::shared_ptr<IConfigBase> *configObject = NewConfigBase(fileName);
|
||||
if (nullptr != configObject) {
|
||||
(*configObject)->OpenConfigFile();
|
||||
}
|
||||
return configObject;
|
||||
}
|
||||
StatusCode ConfigSaveFile(void *object)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSaveFile();
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
void CloseConfigFile(void *object)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
(*(std::shared_ptr<IConfigBase> *)object)->CloseConfigFile();
|
||||
(*(std::shared_ptr<IConfigBase> *)object).reset();
|
||||
free(((char *)object) - sizeof(IConfigBase)); // TODO: bug?
|
||||
}
|
||||
}
|
||||
StatusCode ConfigGetInt(void *object, const char *name, int *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetInt(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetInt(void *object, const char *name, const int value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetInt(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetShort(void *object, const char *name, short *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetShort(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetShort(void *object, const char *name, const short value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetShort(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetLong(void *object, const char *name, long *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetLong(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetLong(void *object, const char *name, const long value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetLong(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetLLong(void *object, const char *name, long long *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetLLong(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetLLong(void *object, const char *name, const long long value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetLLong(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetChar(void *object, const char *name, char *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetChar(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetChar(void *object, const char *name, const char value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetChar(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetBool(void *object, const char *name, bool *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetBool(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetBool(void *object, const char *name, const bool value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetBool(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetFloat(void *object, const char *name, float *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetFloat(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetFloat(void *object, const char *name, const float value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetFloat(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetDouble(void *object, const char *name, double *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetDouble(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetDouble(void *object, const char *name, const double value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetDouble(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigGetString(void *object, const char *name, const char **value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigGetString(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
StatusCode ConfigSetString(void *object, const char *name, const char *value)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
return (*(std::shared_ptr<IConfigBase> *)object)->ConfigSetString(name, value);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
53
utils/ConfigBase/src/ConfigBaseCode.c
Normal file
53
utils/ConfigBase/src/ConfigBaseCode.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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 "ConfigBaseCode.h"
|
||||
#include "ILog.h"
|
||||
#include <string.h>
|
||||
static const char *ConfigCodeString[CONFIG_CODE_END - STATUS_CODE_END + 1] = {"CONFIG_CODE_PARAM_NOT_EXIST",
|
||||
"CONFIG_CODE_END"};
|
||||
static const char *PrintStringConfigCode(const StatusCode this)
|
||||
{
|
||||
const int CODE_INDEX = this.mStatusCode - STATUS_CODE_END;
|
||||
if (STATUS_CODE_END <= this.mStatusCode && this.mStatusCode <= CONFIG_CODE_END) {
|
||||
LogInfo("Config code = [ %s ]\n", ConfigCodeString[CODE_INDEX]);
|
||||
return ConfigCodeString[CODE_INDEX];
|
||||
}
|
||||
LogError("Config code undefine.\n");
|
||||
return "Config code undefine.\n";
|
||||
}
|
||||
static const bool CodeEqual(const StatusCode code, const char *value)
|
||||
{
|
||||
if (memcmp(value, ConfigCodeString[code.mStatusCode - STATUS_CODE_END], strlen(value)) == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static StatusCode NewConfigCode(const long int code)
|
||||
{
|
||||
StatusCode result = {PrintStringConfigCode, CodeEqual, code};
|
||||
return result;
|
||||
}
|
||||
const StatusCode CreateConfigCode(const long int code)
|
||||
{
|
||||
// if (STATUS_CODE_OK <= code && code < STATUS_CODE_END)
|
||||
// {
|
||||
// return CreateStatusCode(code);
|
||||
// }
|
||||
if (STATUS_CODE_END <= code && code < CONFIG_CODE_END) {
|
||||
return NewConfigCode(code);
|
||||
}
|
||||
LogError("undefined code.\n");
|
||||
return CreateStatusCode(STATUS_CODE_END);
|
||||
}
|
29
utils/ConfigBase/src/ConfigBaseCode.h
Normal file
29
utils/ConfigBase/src/ConfigBaseCode.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 CONFIG_BASE_CODE_H
|
||||
#define CONFIG_BASE_CODE_H
|
||||
#include "ConfigBase.h"
|
||||
#include "StatusCode.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifndef CONFIG_OWNER
|
||||
#error This is internal file, never include it.
|
||||
#endif
|
||||
const StatusCode CreateConfigCode(const long int code);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
339
utils/ConfigBase/src/ConfigBaseImpl.cpp
Normal file
339
utils/ConfigBase/src/ConfigBaseImpl.cpp
Normal file
|
@ -0,0 +1,339 @@
|
|||
/*
|
||||
* 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 "ConfigBaseImpl.h"
|
||||
#include "ConfigBaseCode.h"
|
||||
#include "ILog.h"
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
constexpr int INVALID_RESULT = -1;
|
||||
#define CHECK_SHORT_LIMIT(value) (value > SHRT_MAX ? false : (value < SHRT_MIN ? false : true))
|
||||
#define CHECK_LONG_LIMIT(value) (value > LONG_MAX ? false : (value < LONG_MIN ? false : true))
|
||||
#define CHECK_CHAR_LIMIT(value) (value > CHAR_MAX ? false : (value < CHAR_MIN ? false : true))
|
||||
#define CHECK_FLOAT_LIMIT(value) (fabs(value - ((float)value)) < 0.000001 ? false : true)
|
||||
|
||||
ConfigBaseImpl::ConfigBaseImpl(const std::string &fileName) : mFileName(fileName)
|
||||
{
|
||||
}
|
||||
void ConfigBaseImpl::OpenConfigFile(void)
|
||||
{
|
||||
config_init(&cfg);
|
||||
config_set_options(&cfg,
|
||||
(CONFIG_OPTION_FSYNC | CONFIG_OPTION_SEMICOLON_SEPARATORS |
|
||||
CONFIG_OPTION_COLON_ASSIGNMENT_FOR_GROUPS | CONFIG_OPTION_OPEN_BRACE_ON_SEPARATE_LINE));
|
||||
constexpr int FIEL_EXIST = 0;
|
||||
if (FIEL_EXIST == access(mFileName.c_str(), F_OK)) {
|
||||
if (!config_read_file(&cfg, mFileName.c_str())) {
|
||||
LogError("Read file failed[%s].\n", mFileName.c_str());
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
LogInfo("Config file doesn't exist.\n");
|
||||
/* Write out the new configuration. */
|
||||
if (!config_write_file(&cfg, mFileName.c_str())) {
|
||||
fprintf(stderr, "Error while writing file.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ConfigBaseImpl::CloseConfigFile(void)
|
||||
{
|
||||
config_destroy(&cfg);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSaveFile(void)
|
||||
{
|
||||
LogInfo("Save file[%s].\n", mFileName.c_str());
|
||||
if (!config_write_file(&cfg, mFileName.c_str())) {
|
||||
LogError("Save config failed.\n");
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetInt(const char *name, int *value)
|
||||
{
|
||||
int result = INVALID_RESULT;
|
||||
result = config_lookup_int(&cfg, name, value);
|
||||
if (CONFIG_FALSE == result) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetInt(const char *name, const int value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
config_setting_set_int(setting, value);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetShort(const char *name, short *value)
|
||||
{
|
||||
int intValue = 0;
|
||||
int result = 0;
|
||||
result = config_lookup_int(&cfg, name, &intValue);
|
||||
if (CONFIG_FALSE == result || CHECK_SHORT_LIMIT(intValue)) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
*value = (short)intValue;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetShort(const char *name, const short value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
int intValue = value;
|
||||
config_setting_set_int(setting, intValue);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetLong(const char *name, long *value)
|
||||
{
|
||||
long long llongValue = 0;
|
||||
int result = 0;
|
||||
result = config_lookup_int64(&cfg, name, &llongValue);
|
||||
if (CONFIG_FALSE == result || CHECK_LONG_LIMIT(llongValue)) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
*value = (long)llongValue;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetLong(const char *name, const long value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT64);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
long long llongValue = value;
|
||||
config_setting_set_int64(setting, llongValue);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetLLong(const char *name, long long *value)
|
||||
{
|
||||
int result = 0;
|
||||
result = config_lookup_int64(&cfg, name, value);
|
||||
if (CONFIG_FALSE == result) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetLLong(const char *name, const long long value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT64);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
config_setting_set_int64(setting, value);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetChar(const char *name, char *value)
|
||||
{
|
||||
int charValue = 0;
|
||||
int result = 0;
|
||||
result = config_lookup_int(&cfg, name, &charValue);
|
||||
if (CONFIG_FALSE == result && CHECK_CHAR_LIMIT(charValue)) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
*value = (char)charValue;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetChar(const char *name, const char value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
int charValue = (int)value;
|
||||
config_setting_set_int(setting, charValue);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetBool(const char *name, bool *value)
|
||||
{
|
||||
int result = 0;
|
||||
result = config_lookup_bool(&cfg, name, (int *)value);
|
||||
if (CONFIG_FALSE == result) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetBool(const char *name, const bool value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_BOOL);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
config_setting_set_bool(setting, (int)value);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetFloat(const char *name, float *value)
|
||||
{
|
||||
double dValue = 0;
|
||||
int result = 0;
|
||||
result = config_lookup_float(&cfg, name, &dValue);
|
||||
if (CONFIG_FALSE == result || CHECK_FLOAT_LIMIT(dValue)) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
*value = (float)dValue;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetFloat(const char *name, const float value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_FLOAT);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
double dValue = value;
|
||||
config_setting_set_float(setting, dValue);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetDouble(const char *name, double *value)
|
||||
{
|
||||
int result = 0;
|
||||
result = config_lookup_float(&cfg, name, value);
|
||||
if (CONFIG_FALSE == result) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetDouble(const char *name, const double value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (nullptr == setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_FLOAT);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
config_setting_set_float(setting, value);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigGetString(const char *name, const char **value)
|
||||
{
|
||||
int result = 0;
|
||||
result = config_lookup_string(&cfg, name, value);
|
||||
if (CONFIG_FALSE == result) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode ConfigBaseImpl::ConfigSetString(const char *name, const char *value)
|
||||
{
|
||||
config_setting_t *root = nullptr;
|
||||
config_setting_t *setting = nullptr;
|
||||
root = config_root_setting(&cfg);
|
||||
if (nullptr == root) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (!setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_STRING);
|
||||
}
|
||||
if (nullptr == setting) {
|
||||
LogError("Config function failed.\n");
|
||||
return CreateConfigCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
config_setting_set_string(setting, value);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
50
utils/ConfigBase/src/ConfigBaseImpl.h
Normal file
50
utils/ConfigBase/src/ConfigBaseImpl.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 CONFIG_BASE_IMPL_H
|
||||
#define CONFIG_BASE_IMPL_H
|
||||
#include "IConfigBase.h"
|
||||
#include <libconfig.h>
|
||||
class ConfigBaseImpl : public IConfigBase
|
||||
{
|
||||
public:
|
||||
ConfigBaseImpl(const std::string &fileName);
|
||||
virtual ~ConfigBaseImpl() = default;
|
||||
void OpenConfigFile(void) override;
|
||||
void CloseConfigFile(void) override;
|
||||
StatusCode ConfigSaveFile(void) override;
|
||||
StatusCode ConfigGetInt(const char *name, int *value) override;
|
||||
StatusCode ConfigSetInt(const char *name, const int value) override;
|
||||
StatusCode ConfigGetShort(const char *name, short *value) override;
|
||||
StatusCode ConfigSetShort(const char *name, const short value) override;
|
||||
StatusCode ConfigGetLong(const char *name, long *value) override;
|
||||
StatusCode ConfigSetLong(const char *name, const long value) override;
|
||||
StatusCode ConfigGetLLong(const char *name, long long *value) override;
|
||||
StatusCode ConfigSetLLong(const char *name, const long long value) override;
|
||||
StatusCode ConfigGetChar(const char *name, char *value) override;
|
||||
StatusCode ConfigSetChar(const char *name, const char value) override;
|
||||
StatusCode ConfigGetBool(const char *name, bool *value) override;
|
||||
StatusCode ConfigSetBool(const char *name, const bool value) override;
|
||||
StatusCode ConfigGetFloat(const char *name, float *value) override;
|
||||
StatusCode ConfigSetFloat(const char *name, const float value) override;
|
||||
StatusCode ConfigGetDouble(const char *name, double *value) override;
|
||||
StatusCode ConfigSetDouble(const char *name, const double value) override;
|
||||
StatusCode ConfigGetString(const char *name, const char **value) override;
|
||||
StatusCode ConfigSetString(const char *name, const char *value) override;
|
||||
|
||||
private:
|
||||
const std::string mFileName;
|
||||
config_t cfg;
|
||||
};
|
||||
#endif
|
119
utils/ConfigBase/src/IConfigBase.cpp
Normal file
119
utils/ConfigBase/src/IConfigBase.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* 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 "IConfigBase.h"
|
||||
#include "ConfigBaseImpl.h"
|
||||
#include "ILog.h"
|
||||
#include <cstring>
|
||||
void IConfigBase::OpenConfigFile(void)
|
||||
{
|
||||
}
|
||||
void IConfigBase::CloseConfigFile(void)
|
||||
{
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSaveFile(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetInt(const char *name, int *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetInt(const char *name, const int value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetShort(const char *name, short *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetShort(const char *name, const short value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetLong(const char *name, long *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetLong(const char *name, const long value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetLLong(const char *name, long long *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetLLong(const char *name, const long long value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetChar(const char *name, char *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetChar(const char *name, const char value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetBool(const char *name, bool *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetBool(const char *name, const bool value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetFloat(const char *name, float *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetFloat(const char *name, const float value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetDouble(const char *name, double *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetDouble(const char *name, const double value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigGetString(const char *name, const char **value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IConfigBase::ConfigSetString(const char *name, const char *value)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
static const char *CONFIG_BASE_NAME = "config_base";
|
||||
const char *GetConfigBaseModuleName(void)
|
||||
{
|
||||
return CONFIG_BASE_NAME;
|
||||
}
|
||||
std::shared_ptr<IConfigBase> *NewConfigBase(const char *fileName)
|
||||
{
|
||||
LogInfo("Create the uart device object.\n");
|
||||
ConfigBase *impl = (ConfigBase *)malloc(sizeof(ConfigBase));
|
||||
if (nullptr == impl) {
|
||||
LogError("NewConfigBase::malloc failed.\n");
|
||||
return nullptr;
|
||||
}
|
||||
ConfigBase tmp;
|
||||
memcpy((void *)impl, (void *)&tmp, sizeof(ConfigBase));
|
||||
impl->mHeader.mCheckName = CONFIG_BASE_NAME;
|
||||
impl->mIConfigBase = std::make_shared<ConfigBaseImpl>(fileName);
|
||||
return (std::shared_ptr<IConfigBase> *)(((char *)impl) + sizeof(IConfigBaseHeader));
|
||||
}
|
57
utils/ConfigBase/src/IConfigBase.h
Normal file
57
utils/ConfigBase/src/IConfigBase.h
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.
|
||||
*/
|
||||
#ifndef I_CONFIG_BASE_H
|
||||
#define I_CONFIG_BASE_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class IConfigBase
|
||||
{
|
||||
public:
|
||||
IConfigBase() = default;
|
||||
virtual ~IConfigBase() = default;
|
||||
virtual void OpenConfigFile(void);
|
||||
virtual void CloseConfigFile(void);
|
||||
virtual StatusCode ConfigSaveFile(void);
|
||||
virtual StatusCode ConfigGetInt(const char *name, int *value);
|
||||
virtual StatusCode ConfigSetInt(const char *name, const int value);
|
||||
virtual StatusCode ConfigGetShort(const char *name, short *value);
|
||||
virtual StatusCode ConfigSetShort(const char *name, const short value);
|
||||
virtual StatusCode ConfigGetLong(const char *name, long *value);
|
||||
virtual StatusCode ConfigSetLong(const char *name, const long value);
|
||||
virtual StatusCode ConfigGetLLong(const char *name, long long *value);
|
||||
virtual StatusCode ConfigSetLLong(const char *name, const long long value);
|
||||
virtual StatusCode ConfigGetChar(const char *name, char *value);
|
||||
virtual StatusCode ConfigSetChar(const char *name, const char value);
|
||||
virtual StatusCode ConfigGetBool(const char *name, bool *value);
|
||||
virtual StatusCode ConfigSetBool(const char *name, const bool value);
|
||||
virtual StatusCode ConfigGetFloat(const char *name, float *value);
|
||||
virtual StatusCode ConfigSetFloat(const char *name, const float value);
|
||||
virtual StatusCode ConfigGetDouble(const char *name, double *value);
|
||||
virtual StatusCode ConfigSetDouble(const char *name, const double value);
|
||||
virtual StatusCode ConfigGetString(const char *name, const char **value);
|
||||
virtual StatusCode ConfigSetString(const char *name, const char *value);
|
||||
};
|
||||
typedef struct i_config_base_header
|
||||
{
|
||||
const char *mCheckName;
|
||||
} IConfigBaseHeader;
|
||||
typedef struct config_base
|
||||
{
|
||||
IConfigBaseHeader mHeader;
|
||||
std::shared_ptr<IConfigBase> mIConfigBase;
|
||||
} ConfigBase;
|
||||
const char *GetConfigBaseModuleName(void);
|
||||
std::shared_ptr<IConfigBase> *NewConfigBase(const char *fileName);
|
||||
#endif
|
|
@ -38,9 +38,17 @@ class VKeyControl
|
|||
public:
|
||||
VKeyControl() = default;
|
||||
virtual ~VKeyControl() = default;
|
||||
virtual const std::string GetKeyName(void) { return "undefine"; }
|
||||
virtual unsigned int GetStatusCheckPeriodMs(void) { return 0; }
|
||||
virtual void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) {}
|
||||
virtual const std::string GetKeyName(void)
|
||||
{
|
||||
return "undefine";
|
||||
}
|
||||
virtual unsigned int GetStatusCheckPeriodMs(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs)
|
||||
{
|
||||
}
|
||||
};
|
||||
class KeyControl : public VKeyControl, public std::enable_shared_from_this<KeyControl>
|
||||
{
|
||||
|
|
|
@ -21,9 +21,16 @@ KeyControl::KeyControl()
|
|||
mPressingTime = KEY_NOT_PRESSING;
|
||||
mLongClickTime = 0;
|
||||
}
|
||||
KeyControl::~KeyControl() {}
|
||||
bool KeyControl::IsKeyPressing(void) { return mPressingTime >= KEY_PRESSING ? true : false; }
|
||||
void KeyControl::UnInit(void) {}
|
||||
KeyControl::~KeyControl()
|
||||
{
|
||||
}
|
||||
bool KeyControl::IsKeyPressing(void)
|
||||
{
|
||||
return mPressingTime >= KEY_PRESSING ? true : false;
|
||||
}
|
||||
void KeyControl::UnInit(void)
|
||||
{
|
||||
}
|
||||
void KeyControl::KeyHalEventHandle(const std::string &key, const KeyHalEvent &keyEvent)
|
||||
{
|
||||
if (KEY_PRESSING <= mPressingTime) {
|
||||
|
|
|
@ -44,20 +44,39 @@ class VSingleControl
|
|||
public:
|
||||
VSingleControl() = default;
|
||||
virtual ~VSingleControl() = default;
|
||||
virtual StatusCode GetLedState(LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
virtual unsigned int GetKeepAliveTimeMs(void) { return KEEP_ALIVE_FOREVER; }
|
||||
virtual unsigned int GetBlinkTimeMs(void) { return LED_NOT_BLINK; }
|
||||
virtual StatusCode GetLedState(LedState &state)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
virtual unsigned int GetKeepAliveTimeMs(void)
|
||||
{
|
||||
return KEEP_ALIVE_FOREVER;
|
||||
}
|
||||
virtual unsigned int GetBlinkTimeMs(void)
|
||||
{
|
||||
return LED_NOT_BLINK;
|
||||
}
|
||||
};
|
||||
class VLedControl
|
||||
{
|
||||
public:
|
||||
VLedControl() = default;
|
||||
virtual ~VLedControl() = default;
|
||||
virtual StatusCode SetLedState(const LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
virtual void AddLedState(std::shared_ptr<VSingleControl> &control) {}
|
||||
virtual void CheckState(const unsigned int &period) {}
|
||||
virtual StatusCode SetLedState(const LedState &state)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
virtual void AddLedState(std::shared_ptr<VSingleControl> &control)
|
||||
{
|
||||
}
|
||||
virtual void CheckState(const unsigned int &period)
|
||||
{
|
||||
}
|
||||
// virtual void SetHalLedState(const VirtualLedState &state) {}
|
||||
virtual std::string GetLedName(void) { return "undefine"; }
|
||||
virtual std::string GetLedName(void)
|
||||
{
|
||||
return "undefine";
|
||||
}
|
||||
};
|
||||
class LedControl : virtual public VLedControl
|
||||
{
|
||||
|
|
|
@ -22,15 +22,30 @@
|
|||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int fx_system(const char *command) { return system(command); }
|
||||
int fx_open(const char *pathname, int flags) { return open(pathname, flags); }
|
||||
int fx_tcgetattr(int fd, struct termios *termios_p) { return tcgetattr(fd, termios_p); }
|
||||
int fx_system(const char *command)
|
||||
{
|
||||
return system(command);
|
||||
}
|
||||
int fx_open(const char *pathname, int flags)
|
||||
{
|
||||
return open(pathname, flags);
|
||||
}
|
||||
int fx_tcgetattr(int fd, struct termios *termios_p)
|
||||
{
|
||||
return tcgetattr(fd, termios_p);
|
||||
}
|
||||
int fx_tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
|
||||
{
|
||||
return tcsetattr(fd, optional_actions, termios_p);
|
||||
}
|
||||
ssize_t fx_write(int fd, const void *buf, size_t count) { return write(fd, buf, count); }
|
||||
ssize_t fx_read(int fd, void *buf, size_t count) { return read(fd, buf, count); }
|
||||
ssize_t fx_write(int fd, const void *buf, size_t count)
|
||||
{
|
||||
return write(fd, buf, count);
|
||||
}
|
||||
ssize_t fx_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
return read(fd, buf, count);
|
||||
}
|
||||
int fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
|
||||
{
|
||||
return select(nfds, readfds, writefds, exceptfds, timeout);
|
||||
|
|
|
@ -39,7 +39,9 @@ class ProtocolContext : public VProtocolContext
|
|||
{
|
||||
|
||||
public:
|
||||
ProtocolContext(T &value) : mData(value) {}
|
||||
ProtocolContext(T &value) : mData(value)
|
||||
{
|
||||
}
|
||||
virtual ~ProtocolContext() = default;
|
||||
|
||||
public:
|
||||
|
@ -48,7 +50,9 @@ public:
|
|||
class SingleMcuPacket
|
||||
{
|
||||
public:
|
||||
SingleMcuPacket(const void *buf, const size_t &length) : mBuf(buf), mLength(length) {}
|
||||
SingleMcuPacket(const void *buf, const size_t &length) : mBuf(buf), mLength(length)
|
||||
{
|
||||
}
|
||||
~SingleMcuPacket() = default;
|
||||
const void *mBuf;
|
||||
const size_t mLength;
|
||||
|
@ -60,7 +64,10 @@ public:
|
|||
virtual ~VProtocolBase() = default;
|
||||
|
||||
protected:
|
||||
virtual std::shared_ptr<VProtocolBase> SharedFromThis(void) { return std::make_shared<VProtocolBase>(); }
|
||||
virtual std::shared_ptr<VProtocolBase> SharedFromThis(void)
|
||||
{
|
||||
return std::make_shared<VProtocolBase>();
|
||||
}
|
||||
virtual size_t WriteData(const void *buff, const size_t buffLength, std::shared_ptr<VProtocolContext> &context,
|
||||
const unsigned int &serialNumber)
|
||||
{
|
||||
|
@ -68,12 +75,17 @@ protected:
|
|||
}
|
||||
|
||||
protected:
|
||||
virtual size_t GetKeyHeadLength(void) { return 0; }
|
||||
virtual size_t GetKeyHeadLength(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual StatusCode GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
virtual void PushMcuData(const void *buf, const size_t &length) {}
|
||||
virtual void PushMcuData(const void *buf, const size_t &length)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
};
|
||||
|
@ -88,15 +100,21 @@ class OtherSideReply
|
|||
public:
|
||||
OtherSideReply() = default;
|
||||
virtual ~OtherSideReply() = default;
|
||||
virtual void GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission) {}
|
||||
virtual void OnlyResultReply(const unsigned int &serialNumber, const ReplyResult &result) {}
|
||||
virtual void GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission)
|
||||
{
|
||||
}
|
||||
virtual void OnlyResultReply(const unsigned int &serialNumber, const ReplyResult &result)
|
||||
{
|
||||
}
|
||||
};
|
||||
class OtherSideAsk
|
||||
{
|
||||
public:
|
||||
OtherSideAsk() = default;
|
||||
virtual ~OtherSideAsk() = default;
|
||||
virtual void OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission) {}
|
||||
virtual void OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission)
|
||||
{
|
||||
}
|
||||
};
|
||||
class VProtocolRecv : public OtherSideReply, public OtherSideAsk
|
||||
{
|
||||
|
|
|
@ -33,7 +33,10 @@ void LittleEndianHandle::BigEndianConversion(ProtocolPacket &packet)
|
|||
packet.mCheckCode = htons(packet.mCheckCode);
|
||||
packet.mSerialNumber = htonl(packet.mSerialNumber);
|
||||
}
|
||||
short LittleEndianHandle::BigEndianConversion(const short &number) { return htons(number); }
|
||||
short LittleEndianHandle::BigEndianConversion(const short &number)
|
||||
{
|
||||
return htons(number);
|
||||
}
|
||||
void LittleEndianHandle::HostByteOrderConversion(ProtocolPacket &packet)
|
||||
{
|
||||
packet.mHead = ntohs(packet.mHead);
|
||||
|
|
|
@ -30,7 +30,9 @@ const StatusCode McuProtocol::Init(void)
|
|||
constexpr int THREAD_SHARING = 0;
|
||||
constexpr int INITIAL_VALUE_OF_SEMAPHORE = 0;
|
||||
sem_init(&mSem, THREAD_SHARING, INITIAL_VALUE_OF_SEMAPHORE);
|
||||
auto dataHandleThread = [](std::shared_ptr<McuProtocol> handle) { handle->DataHandleThread(); };
|
||||
auto dataHandleThread = [](std::shared_ptr<McuProtocol> handle) {
|
||||
handle->DataHandleThread();
|
||||
};
|
||||
std::shared_ptr<McuProtocol> handle = std::dynamic_pointer_cast<McuProtocol>(SharedFromThis());
|
||||
mDataHandleThread = std::thread(dataHandleThread, handle);
|
||||
std::shared_ptr<VProtocolRecv> reply = std::dynamic_pointer_cast<VProtocolRecv>(SharedFromThis());
|
||||
|
@ -153,7 +155,10 @@ void McuProtocol::ReplyOtherSideSendIpcMission(const ReplyResult &result, const
|
|||
WriteProtocolData(
|
||||
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
|
||||
}
|
||||
size_t McuProtocol::GetKeyHeadLength(void) { return ProtocolHandle::GetKeyHeadLength(); }
|
||||
size_t McuProtocol::GetKeyHeadLength(void)
|
||||
{
|
||||
return ProtocolHandle::GetKeyHeadLength();
|
||||
}
|
||||
StatusCode McuProtocol::GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength)
|
||||
{
|
||||
return ProtocolHandle::GetDataLength(keyHead, headLength, dataLength);
|
||||
|
|
|
@ -30,7 +30,10 @@ std::shared_ptr<McuProtocolMakePtr> &McuProtocolMakePtr::GetInstance(std::shared
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
McuProtocolMakePtr::McuProtocolMakePtr() { mByteOrder = 0x00; }
|
||||
McuProtocolMakePtr::McuProtocolMakePtr()
|
||||
{
|
||||
mByteOrder = 0x00;
|
||||
}
|
||||
const StatusCode McuProtocolMakePtr::CreateProtocolHandle(std::shared_ptr<ProtocolHandle> &impl,
|
||||
const std::shared_ptr<VProtocolParam> ¶m)
|
||||
{
|
||||
|
|
|
@ -265,7 +265,10 @@ void ProtocolHandle::ProtocolAnalysis(const void *data, const size_t &length)
|
|||
handle->AnalyzeProtocolPacket();
|
||||
}
|
||||
}
|
||||
size_t ProtocolHandle::GetKeyHeadLength(void) { return KEY_HEAD_LENGTH; }
|
||||
size_t ProtocolHandle::GetKeyHeadLength(void)
|
||||
{
|
||||
return KEY_HEAD_LENGTH;
|
||||
}
|
||||
StatusCode ProtocolHandle::GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength)
|
||||
{
|
||||
if (KEY_HEAD_LENGTH != headLength) {
|
||||
|
|
|
@ -104,7 +104,9 @@ class ProtocolParam : public VProtocolParam
|
|||
{
|
||||
|
||||
public:
|
||||
ProtocolParam(const PROTOCOL_COMMAND &command, T &value) : VProtocolParam(command), mData(value) {}
|
||||
ProtocolParam(const PROTOCOL_COMMAND &command, T &value) : VProtocolParam(command), mData(value)
|
||||
{
|
||||
}
|
||||
virtual ~ProtocolParam() = default;
|
||||
|
||||
public:
|
||||
|
@ -126,9 +128,18 @@ public:
|
|||
ProtocolHandle(const std::shared_ptr<VProtocolParam> ¶m);
|
||||
ProtocolHandle(const void *data, const size_t &length);
|
||||
virtual ~ProtocolHandle();
|
||||
void *GetProtocolDataBuff(void) { return mProtocolData; }
|
||||
size_t GetProtocolDataLength(void) { return mProtocolDataLength; }
|
||||
unsigned int GetSerialNumber(void) { return mProtocolSerialNumber; }
|
||||
void *GetProtocolDataBuff(void)
|
||||
{
|
||||
return mProtocolData;
|
||||
}
|
||||
size_t GetProtocolDataLength(void)
|
||||
{
|
||||
return mProtocolDataLength;
|
||||
}
|
||||
unsigned int GetSerialNumber(void)
|
||||
{
|
||||
return mProtocolSerialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief These functions assemble scattered data into continuous memory protocol packets and complete the sending
|
||||
|
@ -172,9 +183,16 @@ private:
|
|||
void AnalyzeOtherSideSendIpcMissionPacket(const ProtocolPacket &packet);
|
||||
|
||||
private:
|
||||
virtual void BigEndianConversion(ProtocolPacket &packet) {}
|
||||
virtual short BigEndianConversion(const short &number) { return number; }
|
||||
virtual void HostByteOrderConversion(ProtocolPacket &packet) {}
|
||||
virtual void BigEndianConversion(ProtocolPacket &packet)
|
||||
{
|
||||
}
|
||||
virtual short BigEndianConversion(const short &number)
|
||||
{
|
||||
return number;
|
||||
}
|
||||
virtual void HostByteOrderConversion(ProtocolPacket &packet)
|
||||
{
|
||||
}
|
||||
virtual bool CheckoutTheCheckCode(const ProtocolPacket &packet);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
#include "ILog.h"
|
||||
#include <string.h>
|
||||
static const char *MEDIA_ADAPTER_NAME = "media_adapter";
|
||||
const char inline *GetMediaAdapterModuleName(void) { return MEDIA_ADAPTER_NAME; }
|
||||
const char inline *GetMediaAdapterModuleName(void)
|
||||
{
|
||||
return MEDIA_ADAPTER_NAME;
|
||||
}
|
||||
std::shared_ptr<IMediaAdapter> *NewIMediaAdapter(const SENSOR_NUM &num)
|
||||
{
|
||||
LogInfo("Create the uart device object.\n");
|
||||
|
|
|
@ -21,7 +21,9 @@ class IMediaAdapter
|
|||
public:
|
||||
IMediaAdapter() = default;
|
||||
virtual ~IMediaAdapter() = default;
|
||||
virtual void TestApi(void) {}
|
||||
virtual void TestApi(void)
|
||||
{
|
||||
}
|
||||
};
|
||||
typedef struct media_adapter_header
|
||||
{
|
||||
|
|
|
@ -15,7 +15,10 @@
|
|||
#include "MediaAdapter.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaAdapter.h"
|
||||
void *CreateMediaAdapter(const SENSOR_NUM num) { return NewIMediaAdapter(num); }
|
||||
void *CreateMediaAdapter(const SENSOR_NUM num)
|
||||
{
|
||||
return NewIMediaAdapter(num);
|
||||
}
|
||||
static bool ObjectCheck(void *object)
|
||||
{
|
||||
if (nullptr == object) {
|
||||
|
|
|
@ -14,8 +14,14 @@
|
|||
*/
|
||||
#include "curl_serve.h"
|
||||
static ServerParam gCurlServe;
|
||||
void SetVerboseLog(LogFlag flag) { gCurlServe.logFlag = flag; }
|
||||
void SetSslVerify(SslFlag flag) { gCurlServe.sslVerifyFlag = flag; }
|
||||
void SetVerboseLog(LogFlag flag)
|
||||
{
|
||||
gCurlServe.logFlag = flag;
|
||||
}
|
||||
void SetSslVerify(SslFlag flag)
|
||||
{
|
||||
gCurlServe.sslVerifyFlag = flag;
|
||||
}
|
||||
CURL *CurlEasyMake(void)
|
||||
{
|
||||
CURL *curl;
|
||||
|
|
|
@ -26,7 +26,9 @@ void ServersInit(ServerParam init)
|
|||
SetVerboseLog(init.logFlag);
|
||||
SetSslVerify(init.sslVerifyFlag);
|
||||
}
|
||||
void ServersUnInit(void) {}
|
||||
void ServersUnInit(void)
|
||||
{
|
||||
}
|
||||
void HttpGet(ServerHttp *param)
|
||||
{
|
||||
LogInfo("HttpGet\n");
|
||||
|
@ -105,7 +107,10 @@ void DeleteServersFtp(ServerFtp *ptr)
|
|||
free(ptr);
|
||||
}
|
||||
}
|
||||
void FtpServersCheck(ServerFtp *param) { FtpServersCheckConnect(param); }
|
||||
void FtpServersCheck(ServerFtp *param)
|
||||
{
|
||||
FtpServersCheckConnect(param);
|
||||
}
|
||||
void FtpDownload(ServerFtp *param)
|
||||
{
|
||||
LogInfo("FtpDownload\n");
|
||||
|
|
|
@ -45,7 +45,10 @@ static inline const StatusCode IMakeSharedData(SharedData *object, const unsigne
|
|||
{
|
||||
return object->mMakeSharedData(object, readableSize, writableSize);
|
||||
}
|
||||
static inline const StatusCode ICleanSharedData(SharedData *object) { return object->mCleanSharedData(object); }
|
||||
static inline const StatusCode ICleanSharedData(SharedData *object)
|
||||
{
|
||||
return object->mCleanSharedData(object);
|
||||
}
|
||||
static inline const StatusCode IGetReadableData(SharedData *object, void *buf, const unsigned int bufLength)
|
||||
{
|
||||
return object->mGetReadableData(object, buf, bufLength);
|
||||
|
@ -54,7 +57,10 @@ static inline void ISetWritableData(SharedData *object, void *buf, const unsigne
|
|||
{
|
||||
object->mSetWritableData(object, buf, bufLength);
|
||||
}
|
||||
static inline void IShareDataFree(SharedData *object) { object->mFree(object); }
|
||||
static inline void IShareDataFree(SharedData *object)
|
||||
{
|
||||
object->mFree(object);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user