Merge branch 'master-develop' of gitee.com:shenzhen-jiuyilian/ipc into master-develop

This commit is contained in:
xiaojiazhu 2024-04-07 08:01:00 -07:00
commit a2f8103fa5
106 changed files with 3416 additions and 376 deletions

View File

@ -14,8 +14,8 @@ AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All AllowShortFunctionsOnASingleLine: false
AllowShortLambdasOnASingleLine: All AllowShortLambdasOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterDefinitionReturnType: None

View File

@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 3.5.1) 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) include(build/global_config.cmake)
project(fancycode) project(fancycode)
@ -60,6 +63,8 @@ if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
--header-filter=.* --header-filter=.*
--system-headers=false --system-headers=false
${ALL_MODEFIED_FILES} ${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 -p ${PLATFORM_PATH}/cmake-shell
WORKING_DIRECTORY ${PLATFORM_PATH} WORKING_DIRECTORY ${PLATFORM_PATH}
) )

View File

@ -33,7 +33,10 @@ void InitSignalHandle(void)
signal(SIGKILL, sigHandler); signal(SIGKILL, sigHandler);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
} }
MainThread::MainThread() { mMainThreadRuning = false; } MainThread::MainThread()
{
mMainThreadRuning = false;
}
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl) std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
{ {
static auto instance = std::make_shared<MainThread>(); static auto instance = std::make_shared<MainThread>();
@ -87,7 +90,9 @@ void MainThread::DestoryAllModules(void)
DestroyMcuManager(); DestroyMcuManager();
DestroyHalCppModule(); DestroyHalCppModule();
} }
void MainThread::ResetAllPtrMaker(void) {} void MainThread::ResetAllPtrMaker(void)
{
}
void MainThread::Runing(void) void MainThread::Runing(void)
{ {
while (mMainThreadRuning) { while (mMainThreadRuning) {

View File

@ -25,7 +25,10 @@ public:
virtual StatusCode Init(void); virtual StatusCode Init(void);
virtual StatusCode UnInit(void); virtual StatusCode UnInit(void);
void Runing(void); void Runing(void);
void Exit(void) { mMainThreadRuning = false; } void Exit(void)
{
mMainThreadRuning = false;
}
virtual void CustomizationInit(void); virtual void CustomizationInit(void);
private: private:

View File

@ -43,7 +43,9 @@ class VMissionDataV2 : public VMissionData
{ {
public: public:
VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value) {} VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value)
{
}
virtual ~VMissionDataV2() = default; virtual ~VMissionDataV2() = default;
public: public:

View File

@ -40,17 +40,17 @@ StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr &param)
StatusCode AppMonitor::GetMediaInfo(AppGetMeidaInfo &param) StatusCode AppMonitor::GetMediaInfo(AppGetMeidaInfo &param)
{ {
LogInfo("AppMonitor::GetMediaInfo.\n"); 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.mTransport = "tcp";
param.mPort = 6035; param.mPort = 554;
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }
StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo &param) StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo &param)
{ {
LogInfo("AppMonitor::GetSdCardInfo.\n"); LogInfo("AppMonitor::GetSdCardInfo.\n");
param.mStatus = SdCardStatus::CARD_DAMAGED; param.mStatus = SdCardStatus::NORMAL;
param.mFree = 0; param.mFree = 1024 * 32;
param.mTotal = 0; param.mTotal = 1024 * 32;
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }
StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo &param) StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo &param)
@ -60,7 +60,54 @@ StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo &param)
param.mChargeStatus = ChargeStatus::CHARGING; param.mChargeStatus = ChargeStatus::CHARGING;
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }
StatusCode AppMonitor::SetDateTime(AppSetDateTime &param) StatusCode AppMonitor::GetParamValue(AppParamValue &param)
{
param.mMicStatus = SwitchStatus::ON;
param.mRec = SwitchStatus::OFF;
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode AppMonitor::GetCapability(AppGetCapability &param)
{
param.mPlaybackType = PlaybackType::DOWNLOAD_PLAYBACK;
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode AppMonitor::GetLockVideoStatus(LockVideoStatus &param)
{
param = LockVideoStatus::LOCK;
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> &param)
{
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> &param)
{
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 &param)
{ {
// //
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
@ -70,8 +117,25 @@ StatusCode AppMonitor::SetTimeZone(const unsigned int &zone)
// //
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }
StatusCode AppMonitor::SetParamValue(const AppSetParamValue &param)
{
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 &param) StatusCode AppMonitor::UploadFile(AppUploadFile &param)
{ {
// //
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail &param)
{
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
return CreateStatusCode(STATUS_CODE_OK);
}

View File

@ -25,8 +25,17 @@ public:
StatusCode GetMediaInfo(AppGetMeidaInfo &param) override; StatusCode GetMediaInfo(AppGetMeidaInfo &param) override;
StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override; StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override;
StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override; StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override;
StatusCode SetDateTime(AppSetDateTime &param) override; StatusCode GetParamValue(AppParamValue &param) override;
StatusCode GetCapability(AppGetCapability &param) override;
StatusCode GetLockVideoStatus(LockVideoStatus &param) override;
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> &param) override;
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param) override;
StatusCode SetDateTime(const AppSetDateTime &param) override;
StatusCode SetTimeZone(const unsigned int &zone) override; StatusCode SetTimeZone(const unsigned int &zone) override;
StatusCode SetParamValue(const AppSetParamValue &param) override;
StatusCode EnterRecorder(void) override;
StatusCode AppPlayback(const PlayBackEvent &event) override;
StatusCode UploadFile(AppUploadFile &param) override; StatusCode UploadFile(AppUploadFile &param) override;
StatusCode GetThumbnail(AppGetThumbnail &param) override;
}; };
#endif #endif

View File

@ -27,7 +27,9 @@ enum class InternalStateEvent
class MissionData : public VStateMachineData class MissionData : public VStateMachineData
{ {
public: public:
MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data) {} MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
{
}
virtual ~MissionData() = default; virtual ~MissionData() = default;
const std::shared_ptr<VMissionData> mMissionData; const std::shared_ptr<VMissionData> mMissionData;
}; };

View File

@ -28,5 +28,11 @@ std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<I
} }
return instance; return instance;
} }
const StatusCode IMissionManager::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } const StatusCode IMissionManager::Init(void)
const StatusCode IMissionManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
const StatusCode IMissionManager::UnInit(void)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}

View File

@ -15,7 +15,9 @@
#include "MissionState.h" #include "MissionState.h"
#include "IAppManager.h" #include "IAppManager.h"
#include "ILog.h" #include "ILog.h"
MissionState::MissionState(const std::string &name) : State(name) {} MissionState::MissionState(const std::string &name) : State(name)
{
}
void MissionState::GoInState() void MissionState::GoInState()
{ {
// //
@ -26,4 +28,7 @@ void MissionState::GoOutState()
// //
LogInfo(" ========== MissionState::GoOutState.\n"); LogInfo(" ========== MissionState::GoOutState.\n");
} }
bool MissionState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); } bool MissionState::ExecuteStateMsg(VStateMachineData *msg)
{
return DataProcessing::EventHandle(msg);
}

View File

@ -63,7 +63,10 @@ IpcMission MissionStateMachine::GetStartMission(void)
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
{ {
public: public:
McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) { mDataReply = IpcMission::END; } McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
{
mDataReply = IpcMission::END;
}
virtual ~McuAskIpcMission() = default; virtual ~McuAskIpcMission() = default;
}; };
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>(); std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>();

View File

@ -15,7 +15,9 @@
#include "TestMissionState.h" #include "TestMissionState.h"
#include "IAppManager.h" #include "IAppManager.h"
#include "ILog.h" #include "ILog.h"
TestMissionState::TestMissionState() : MissionState("TestMissionState") {} TestMissionState::TestMissionState() : MissionState("TestMissionState")
{
}
void TestMissionState::GoInState() void TestMissionState::GoInState()
{ {
MissionState::GoInState(); MissionState::GoInState();
@ -31,4 +33,7 @@ void TestMissionState::GoOutState()
MissionState::GoOutState(); MissionState::GoOutState();
LogInfo(" ========== TestMissionState::GoOutState.\n"); LogInfo(" ========== TestMissionState::GoOutState.\n");
} }
bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg) { return MissionState::EventHandle(msg); } bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg)
{
return MissionState::EventHandle(msg);
}

View File

@ -15,7 +15,9 @@
#include "TopState.h" #include "TopState.h"
#include "ILog.h" #include "ILog.h"
#include "MissionStateMachine.h" #include "MissionStateMachine.h"
TopState::TopState() : State("TopState") {} TopState::TopState() : State("TopState")
{
}
void TopState::GoInState() void TopState::GoInState()
{ {
// //
@ -27,4 +29,7 @@ void TopState::GoOutState()
// //
LogInfo(" ========== opState::GoOutState.\n"); LogInfo(" ========== opState::GoOutState.\n");
} }
bool TopState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); } bool TopState::ExecuteStateMsg(VStateMachineData *msg)
{
return DataProcessing::EventHandle(msg);
}

View File

@ -16,7 +16,10 @@
#include "IHalCpp.h" #include "IHalCpp.h"
#include "ILog.h" #include "ILog.h"
#include <thread> #include <thread>
MainThread::MainThread() { mMainThreadRuning = false; } MainThread::MainThread()
{
mMainThreadRuning = false;
}
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl) std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
{ {
static auto instance = std::make_shared<MainThread>(); static auto instance = std::make_shared<MainThread>();
@ -56,8 +59,12 @@ StatusCode MainThread::CreateAllModules(void)
CreateHalCppModule(); CreateHalCppModule();
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }
void MainThread::DestoryAllModules(void) {} void MainThread::DestoryAllModules(void)
void MainThread::ResetAllPtrMaker(void) {} {
}
void MainThread::ResetAllPtrMaker(void)
{
}
void MainThread::Runing(void) void MainThread::Runing(void)
{ {
while (mMainThreadRuning) { while (mMainThreadRuning) {

View File

@ -25,8 +25,13 @@ public:
virtual StatusCode Init(void); virtual StatusCode Init(void);
virtual StatusCode UnInit(void); virtual StatusCode UnInit(void);
void Runing(void); void Runing(void);
void Exit(void) { mMainThreadRuning = false; } void Exit(void)
virtual void CustomizationInit(void) {} {
mMainThreadRuning = false;
}
virtual void CustomizationInit(void)
{
}
private: private:
StatusCode CreateAllModules(void); StatusCode CreateAllModules(void);

View File

@ -68,6 +68,7 @@ set(CURL_SHARED_LIBS_PATH "/mnt/mmc")
# ------------ build curl + openssl ------------ end # ------------ build curl + openssl ------------ end
# ------------ build AppManager ------------ # # ------------ 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") set(APP_MANAGER_HTTP_SERVER_PORT "8080")
# ------------ build AppManager end ------------ # # ------------ build AppManager end ------------ #

View File

@ -1,6 +1,6 @@
set(DEFINE_LINUX "linux") set(DEFINE_LINUX "linux")
set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_SOURCE_DIR}") # 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_IPCSDK}${SUBMODULE_PATH_OF_IPC_SDK}")
set(EXEC_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/bin") set(EXEC_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/bin")
set(LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs") set(LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs")
set(EXTERNAL_LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/external") set(EXTERNAL_LIBS_OUTPUT_PATH "${PLATFORM_PATH}/${PROJECT_OUTPUT_FOLDER}/libs/external")

View File

@ -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) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

View 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和tcphttp协议框架开发完成rtsp推流到手机APP完成
2. 存在问题rtsp推流存在卡顿问题待优化
3. 更换SC230AI调试快启快启报错需要提问题单找原厂协助

View File

@ -67,7 +67,7 @@ if(EPOLL)
target_compile_definitions(httpsrv PRIVATE EPOLL) target_compile_definitions(httpsrv PRIVATE EPOLL)
endif() 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( add_custom_command(
TARGET httpsrv TARGET httpsrv
POST_BUILD POST_BUILD

View File

@ -17,16 +17,27 @@
#include "StatusCode.h" #include "StatusCode.h"
// #include <stddef.h> // #include <stddef.h>
#include <string.h> #include <string.h>
static StatusCode IHalInit(IHal *object) { return IHalCpp::GetInstance()->Init(); } static StatusCode IHalInit(IHal *object)
static void IHalFree(void *object) {} {
static StatusCode IHalUnInit(IHal *object) { return IHalCpp::GetInstance()->UnInit(); } return IHalCpp::GetInstance()->Init();
}
static void IHalFree(void *object)
{
}
static StatusCode IHalUnInit(IHal *object)
{
return IHalCpp::GetInstance()->UnInit();
}
static IHal default_hal = { static IHal default_hal = {
.init = IHalInit, .init = IHalInit,
.un_init = IHalUnInit, .un_init = IHalUnInit,
.free = IHalFree, .free = IHalFree,
}; };
static IHal *hal_instance = &default_hal; static IHal *hal_instance = &default_hal;
IHal *GetHalIntance(void) { return hal_instance; } IHal *GetHalIntance(void)
{
return hal_instance;
}
StatusCode NewIHal(IHal **object) StatusCode NewIHal(IHal **object)
{ {
if (!object || !(*object)) { if (!object || !(*object)) {

View File

@ -29,8 +29,14 @@ std::shared_ptr<IHalCpp> &IHalCpp::GetInstance(std::shared_ptr<IHalCpp> *impl)
} }
return instance; return instance;
} }
StatusCode IHalCpp::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode IHalCpp::Init(void)
StatusCode IHalCpp::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
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) StatusCode IHalCpp::GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);

View File

@ -48,8 +48,14 @@ typedef struct i_hal
IHal *GetHalIntance(void); IHal *GetHalIntance(void);
StatusCode NewIHal(IHal **object); StatusCode NewIHal(IHal **object);
void ResetHalImpl(IHal *impl); void ResetHalImpl(IHal *impl);
static inline StatusCode IHalInit(void) { return GetHalIntance()->init(GetHalIntance()); } static inline StatusCode IHalInit(void)
static inline StatusCode IHalUnInit(void) { return GetHalIntance()->un_init(GetHalIntance()); } {
return GetHalIntance()->init(GetHalIntance());
}
static inline StatusCode IHalUnInit(void)
{
return GetHalIntance()->un_init(GetHalIntance());
}
StatusCode CreateHalModule(void); StatusCode CreateHalModule(void);
StatusCode DestroyHalModule(void); StatusCode DestroyHalModule(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -40,9 +40,15 @@ class VKeyHal
public: public:
VKeyHal() = default; VKeyHal() = default;
virtual ~VKeyHal() = default; virtual ~VKeyHal() = default;
virtual void CheckKeyStatus(void) {} virtual void CheckKeyStatus(void)
virtual void GetHoldPressingTimeMs(long int &holdTimeMs, VirtualKeyEvent &event) {} {
virtual void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor) {} }
virtual void GetHoldPressingTimeMs(long int &holdTimeMs, VirtualKeyEvent &event)
{
}
virtual void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor)
{
}
}; };
class VLedHal class VLedHal
{ {
@ -55,7 +61,10 @@ class VWifiHal
public: public:
VWifiHal() = default; VWifiHal() = default;
virtual ~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 class IHalCpp
{ {

View File

@ -24,8 +24,14 @@ public:
HalMakePtr() = default; HalMakePtr() = default;
virtual ~HalMakePtr() = default; virtual ~HalMakePtr() = default;
static std::shared_ptr<HalMakePtr> &GetInstance(std::shared_ptr<HalMakePtr> *impl = nullptr); static std::shared_ptr<HalMakePtr> &GetInstance(std::shared_ptr<HalMakePtr> *impl = nullptr);
virtual StatusCode Init() { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } virtual StatusCode Init()
virtual StatusCode UnInit() { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
virtual StatusCode UnInit()
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
virtual StatusCode CreateHalPtr(IHal **hal); virtual StatusCode CreateHalPtr(IHal **hal);
virtual StatusCode CreateHalSharePtr(std::shared_ptr<IHalCpp> &impl); virtual StatusCode CreateHalSharePtr(std::shared_ptr<IHalCpp> &impl);
virtual StatusCode CreateWifiHal(std::shared_ptr<VWifiHal> &impl); virtual StatusCode CreateWifiHal(std::shared_ptr<VWifiHal> &impl);

View File

@ -31,34 +31,12 @@ enum class UploadCommand
UPGRADE_CPU = 0, UPGRADE_CPU = 0,
END END
}; };
typedef struct app_get_product_info enum class ChargeStatus
{ {
app_get_product_info() {} UNCHARGED = 0,
std::string mModel; CHARGING,
std::string mCompany; END
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;
enum class SdCardStatus enum class SdCardStatus
{ {
NORMAL = 0, NORMAL = 0,
@ -71,6 +49,143 @@ enum class SdCardStatus
FORMATTING = 13, FORMATTING = 13,
END = 99 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 typedef struct app_get_sd_card_info
{ {
app_get_sd_card_info() app_get_sd_card_info()
@ -83,12 +198,6 @@ typedef struct app_get_sd_card_info
int mFree; int mFree;
int mTotal; int mTotal;
} AppGetSdCardInfo; } AppGetSdCardInfo;
enum class ChargeStatus
{
UNCHARGED = 0,
CHARGING,
END
};
typedef struct app_get_battery_info typedef struct app_get_battery_info
{ {
app_get_battery_info() app_get_battery_info()
@ -99,6 +208,93 @@ typedef struct app_get_battery_info
int mCapacity; int mCapacity;
ChargeStatus mChargeStatus; ChargeStatus mChargeStatus;
} AppGetBatteryInfo; } 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 typedef struct app_set_date_time
{ {
app_set_date_time(const unsigned int year, const unsigned int month, const unsigned int day, 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; const UploadCommand mCommand;
ResposeResult mResult; ResposeResult mResult;
} AppUploadFile; } 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 class VAppMonitor
{ {
public: public:
@ -133,13 +337,24 @@ public:
virtual StatusCode GetMediaInfo(AppGetMeidaInfo &param); virtual StatusCode GetMediaInfo(AppGetMeidaInfo &param);
virtual StatusCode GetSdCardInfo(AppGetSdCardInfo &param); virtual StatusCode GetSdCardInfo(AppGetSdCardInfo &param);
virtual StatusCode GetBatteryInfo(AppGetBatteryInfo &param); virtual StatusCode GetBatteryInfo(AppGetBatteryInfo &param);
virtual StatusCode SetDateTime(AppSetDateTime &param); virtual StatusCode GetParamValue(AppParamValue &param);
virtual StatusCode GetCapability(AppGetCapability &param);
virtual StatusCode GetLockVideoStatus(LockVideoStatus &param);
virtual StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> &param);
virtual StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param);
virtual StatusCode SetDateTime(const AppSetDateTime &param);
virtual StatusCode SetTimeZone(const unsigned int &zone); virtual StatusCode SetTimeZone(const unsigned int &zone);
virtual StatusCode SetParamValue(const AppSetParamValue &param);
virtual StatusCode EnterRecorder(void);
virtual StatusCode AppPlayback(const PlayBackEvent &event);
virtual StatusCode UploadFile(AppUploadFile &param); virtual StatusCode UploadFile(AppUploadFile &param);
virtual StatusCode GetThumbnail(AppGetThumbnail &param);
}; };
typedef struct app_param 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 char *mIP;
const int mPort; const int mPort;
} AppParam; } AppParam;

View File

@ -22,7 +22,10 @@ StatusCode VAppMonitor::GetDeviceAttr(AppGetDeviceAttr &param)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
} }
StatusCode VAppMonitor::GetMediaInfo(AppGetMeidaInfo &param) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode VAppMonitor::GetMediaInfo(AppGetMeidaInfo &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::GetSdCardInfo(AppGetSdCardInfo &param) StatusCode VAppMonitor::GetSdCardInfo(AppGetSdCardInfo &param)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
@ -31,9 +34,54 @@ StatusCode VAppMonitor::GetBatteryInfo(AppGetBatteryInfo &param)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
} }
StatusCode VAppMonitor::SetDateTime(AppSetDateTime &param) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode VAppMonitor::GetParamValue(AppParamValue &param)
StatusCode VAppMonitor::SetTimeZone(const unsigned int &zone) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
StatusCode VAppMonitor::UploadFile(AppUploadFile &param) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::GetCapability(AppGetCapability &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::GetLockVideoStatus(LockVideoStatus &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::SetDateTime(const AppSetDateTime &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::SetTimeZone(const unsigned int &zone)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::SetParamValue(const AppSetParamValue &param)
{
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 &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode VAppMonitor::GetThumbnail(AppGetThumbnail &param)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl) std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl)
{ {
static auto instance = std::make_shared<IAppManager>(); static auto instance = std::make_shared<IAppManager>();
@ -48,8 +96,14 @@ std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManag
} }
return instance; return instance;
} }
const StatusCode IAppManager::Init(const AppParam &param) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } const StatusCode IAppManager::Init(const AppParam &param)
const StatusCode IAppManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
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) const StatusCode IAppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);

View File

@ -30,12 +30,18 @@ class IAppProtocolHandle
public: public:
IAppProtocolHandle() = default; IAppProtocolHandle() = default;
virtual ~IAppProtocolHandle() = default; virtual ~IAppProtocolHandle() = default;
virtual void Init(void) {} virtual void Init(void)
virtual void UnInit(void) {} {
}
virtual void UnInit(void)
{
}
virtual void RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, virtual void RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
void *context) void *context)
{ {
} }
virtual void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) {} virtual void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
{
}
}; };
#endif #endif

View File

@ -20,15 +20,29 @@ using std::placeholders::_1;
using std::placeholders::_2; using std::placeholders::_2;
using std::placeholders::_3; using std::placeholders::_3;
// using std::placeholders::_4; // using std::placeholders::_4;
const char *CJSON_INFO_STRING = "info"; // clang-format off
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo"; const char *CJSON_INFO_STRING = "info";
const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr"; const char *CJSON_FILES_STRING = "files";
const char *APP_GET_MEDIA_INFO = "/app/getmediainfo"; const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
const char *APP_GET_SD_CARD_INFO = "/app/getsdinfo"; const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr";
const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo"; const char *APP_GET_MEDIA_INFO = "/app/getmediainfo";
const char *APP_SET_DATE_TIME = "/app/setsystime"; const char *APP_GET_SD_CARD_INFO = "/app/getsdinfo";
const char *APP_SET_TIME_ZONE = "/app/settimezone"; const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo";
const char *APP_UPLOAD_FILE = "/upload"; 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; constexpr bool SET_REQUEST_RESPONSE = true;
SixFrameHandle::SixFrameHandle() SixFrameHandle::SixFrameHandle()
{ {
@ -38,9 +52,19 @@ SixFrameHandle::SixFrameHandle()
mResquesHandleFunc[APP_GET_MEDIA_INFO] = std::bind(&SixFrameHandle::RequestGetMediaInfo, this, _1, _2, _3); 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_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3);
mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3); mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3);
mResquesHandleFunc[APP_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_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_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_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, _); // mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _);
} }
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, 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) void SixFrameHandle::DoNothing(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
// responseHandle("Unknown command.", context);
char *resultStr = nullptr;
cJSON *result = MakeResponseResult(ResposeResult::FAILED); cJSON *result = MakeResponseResult(ResposeResult::FAILED);
resultStr = cJSON_Print(result); if (nullptr == result) {
responseHandle(resultStr, context); LogError("MakeResponseResult failed.\n");
free(resultStr); responseHandle("Device run out of memory.", context);
return;
}
ResponseJsonString(result, responseHandle, context);
cJSON_Delete(result); cJSON_Delete(result);
} }
void SixFrameHandle::RequestGetProductInfo(const std::string &url, ResponseHandle responseHandle, void *context) void SixFrameHandle::RequestGetProductInfo(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetProductInfo.\n"); LogInfo("RequestGetProductInfo.\n");
char *resultStr = nullptr;
AppGetProductInfo param; AppGetProductInfo param;
mAppMonitor->GetProductInfo(param); mAppMonitor->GetProductInfo(param);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
if (nullptr == result) {
LogError("MakeResponseResult failed.\n");
responseHandle("Device run out of memory.", context);
return;
}
ResponseGetProductInfo(result, param); ResponseGetProductInfo(result, param);
resultStr = cJSON_Print(result); ResponseJsonString(result, responseHandle, context);
responseHandle(resultStr, context);
free(resultStr);
cJSON_Delete(result); cJSON_Delete(result);
} }
void inline SixFrameHandle::ResponseGetProductInfo(cJSON *result, const AppGetProductInfo &param) void inline SixFrameHandle::ResponseGetProductInfo(cJSON *result, const AppGetProductInfo &param)
@ -128,14 +155,16 @@ void inline SixFrameHandle::ResponseGetProductInfo(cJSON *result, const AppGetPr
void SixFrameHandle::RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context) void SixFrameHandle::RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetDeviceAttr.\n"); LogInfo("RequestGetDeviceAttr.\n");
char *resultStr = nullptr;
AppGetDeviceAttr param; AppGetDeviceAttr param;
mAppMonitor->GetDeviceAttr(param); mAppMonitor->GetDeviceAttr(param);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
if (nullptr == result) {
LogError("MakeResponseResult failed.\n");
responseHandle("Device run out of memory.", context);
return;
}
ResponseGetDeviceAttr(result, param); ResponseGetDeviceAttr(result, param);
resultStr = cJSON_Print(result); ResponseJsonString(result, responseHandle, context);
responseHandle(resultStr, context);
free(resultStr);
cJSON_Delete(result); cJSON_Delete(result);
} }
void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr &param) void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr &param)
@ -155,15 +184,16 @@ void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDev
void SixFrameHandle::RequestGetMediaInfo(const std::string &url, ResponseHandle responseHandle, void *context) void SixFrameHandle::RequestGetMediaInfo(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetMediaInfo.\n"); LogInfo("RequestGetMediaInfo.\n");
char *resultStr = nullptr;
AppGetMeidaInfo param; AppGetMeidaInfo param;
mAppMonitor->GetMediaInfo(param); mAppMonitor->GetMediaInfo(param);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
if (nullptr == result) {
LogError("MakeResponseResult failed.\n");
responseHandle("Device run out of memory.", context);
return;
}
ResponseGetMediaInfo(result, param); ResponseGetMediaInfo(result, param);
resultStr = cJSON_Print(result); ResponseJsonString(result, responseHandle, context);
responseHandle(resultStr, context);
LogInfo("resultStr = \n%s\n", resultStr);
free(resultStr);
cJSON_Delete(result); cJSON_Delete(result);
} }
void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo &param) void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo &param)
@ -173,18 +203,21 @@ void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeid
cJSON_AddStringToObject(info, "rtsp", param.mRtspUrl.c_str()); cJSON_AddStringToObject(info, "rtsp", param.mRtspUrl.c_str());
cJSON_AddStringToObject(info, "transport", param.mTransport.c_str()); cJSON_AddStringToObject(info, "transport", param.mTransport.c_str());
cJSON_AddNumberToObject(info, "port", param.mPort); 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) void SixFrameHandle::RequestGetSdCardInfo(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetDeviceAttr.\n"); LogInfo("RequestGetDeviceAttr.\n");
char *resultStr = nullptr;
AppGetSdCardInfo param; AppGetSdCardInfo param;
mAppMonitor->GetSdCardInfo(param); mAppMonitor->GetSdCardInfo(param);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
if (nullptr == result) {
LogError("MakeResponseResult failed.\n");
responseHandle("Device run out of memory.", context);
return;
}
ResponseGetSdCardInfo(result, param); ResponseGetSdCardInfo(result, param);
resultStr = cJSON_Print(result); ResponseJsonString(result, responseHandle, context);
responseHandle(resultStr, context);
free(resultStr);
cJSON_Delete(result); cJSON_Delete(result);
} }
void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo &param) void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo &param)
@ -198,14 +231,16 @@ void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdC
void SixFrameHandle::RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context) void SixFrameHandle::RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetDeviceAttr.\n"); LogInfo("RequestGetDeviceAttr.\n");
char *resultStr = nullptr;
AppGetBatteryInfo param; AppGetBatteryInfo param;
mAppMonitor->GetBatteryInfo(param); mAppMonitor->GetBatteryInfo(param);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
if (nullptr == result) {
LogError("MakeResponseResult failed.\n");
responseHandle("Device run out of memory.", context);
return;
}
ResponseGetBatteryInfo(result, param); ResponseGetBatteryInfo(result, param);
resultStr = cJSON_Print(result); ResponseJsonString(result, responseHandle, context);
responseHandle(resultStr, context);
free(resultStr);
cJSON_Delete(result); cJSON_Delete(result);
} }
void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo &param) void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo &param)
@ -215,27 +250,243 @@ void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBa
cJSON_AddNumberToObject(info, "charge", static_cast<int>(param.mChargeStatus)); cJSON_AddNumberToObject(info, "charge", static_cast<int>(param.mChargeStatus));
cJSON_AddNumberToObject(info, "capacity", param.mCapacity); 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 &param)
{
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 &param)
{
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 &param)
{
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> &param)
{
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> &param,
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) AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(const std::string &url)
{ {
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) { 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) { if ("date" == key) {
parseyImpl->mData = value; parseImpl->mData = value;
} }
}; };
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>(); std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
ExtractParamsFromUrl(url, parseFunc, parse); ExtractParamsFromUrl(url, parseFunc, 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 (14 != parseyImpl->mData.length()) { if (14 != parseImpl->mData.length()) {
LogError("date parse failed.\n"); LogError("date parse failed.\n");
return AppSetDateTime(0, 0, 0, 0, 0, 0); return AppSetDateTime(0, 0, 0, 0, 0, 0);
} }
std::string yearStr = parseyImpl->mData.substr(0, 4); std::string yearStr = parseImpl->mData.substr(0, 4);
std::string monthStr = parseyImpl->mData.substr(4, 2); std::string monthStr = parseImpl->mData.substr(4, 2);
std::string dayStr = parseyImpl->mData.substr(6, 2); std::string dayStr = parseImpl->mData.substr(6, 2);
std::string hourStr = parseyImpl->mData.substr(8, 2); std::string hourStr = parseImpl->mData.substr(8, 2);
std::string minuteStr = parseyImpl->mData.substr(10, 2); std::string minuteStr = parseImpl->mData.substr(10, 2);
std::string secondStr = parseyImpl->mData.substr(12, 2); std::string secondStr = parseImpl->mData.substr(12, 2);
unsigned int year = std::stoi(yearStr); unsigned int year = std::stoi(yearStr);
unsigned int month = std::stoi(monthStr); unsigned int month = std::stoi(monthStr);
unsigned int day = std::stoi(dayStr); 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) void SixFrameHandle::RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetDeviceAttr.\n"); LogInfo("RequestGetDeviceAttr.\n");
char *resultStr = nullptr;
AppSetDateTime param = RequestSetDateTimeParse(url); AppSetDateTime param = RequestSetDateTimeParse(url);
mAppMonitor->SetDateTime(param); mAppMonitor->SetDateTime(param);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE);
// ResponseGetBatteryInfo(result, param); if (nullptr == result) {
resultStr = cJSON_Print(result); LogError("MakeResponseResult failed.\n");
responseHandle(resultStr, context); responseHandle("Device run out of memory.", context);
free(resultStr); return;
}
ResponseJsonString(result, responseHandle, context);
cJSON_Delete(result); cJSON_Delete(result);
} }
int inline SixFrameHandle::RequestSetTimeZoneParse(const std::string &url) int inline SixFrameHandle::RequestSetTimeZoneParse(const std::string &url)
{ {
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) { 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) { if ("timezone" == key) {
parseyImpl->mData = value; parseImpl->mData = value;
} }
}; };
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>(); std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
ExtractParamsFromUrl(url, parseFunc, parse); ExtractParamsFromUrl(url, parseFunc, 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 (2 <= parseyImpl->mData.length()) { if (2 <= parseImpl->mData.length()) {
LogError("date parse failed.\n"); LogError("date parse failed.\n");
return 0; return 0;
} }
int zone = std::stoi(parseyImpl->mData); int zone = std::stoi(parseImpl->mData);
return zone; return zone;
} }
void SixFrameHandle::RequestSetTimeZone(const std::string &url, ResponseHandle responseHandle, void *context) void SixFrameHandle::RequestSetTimeZone(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestGetDeviceAttr.\n"); LogInfo("RequestSetTimeZone.\n");
char *resultStr = nullptr;
int zone = RequestSetTimeZoneParse(url); int zone = RequestSetTimeZoneParse(url);
mAppMonitor->SetTimeZone(zone); mAppMonitor->SetTimeZone(zone);
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE); cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL, SET_REQUEST_RESPONSE);
// ResponseGetBatteryInfo(result, param); if (nullptr == result) {
resultStr = cJSON_Print(result); LogError("MakeResponseResult failed.\n");
responseHandle(resultStr, context); responseHandle("Device run out of memory.", context);
free(resultStr); 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); cJSON_Delete(result);
} }
void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context) void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context)
{ {
LogInfo("RequestUpload.\n"); LogInfo("RequestUpload.\n");
char *resultStr = nullptr;
AppUploadFile info("path", UploadCommand::UPGRADE_CPU); AppUploadFile info("path", UploadCommand::UPGRADE_CPU);
mAppMonitor->UploadFile(info); mAppMonitor->UploadFile(info);
cJSON *result = MakeResponseResult(info.mResult); cJSON *result = MakeResponseResult(info.mResult);
resultStr = cJSON_Print(result); if (nullptr == result) {
responseHandle(resultStr, context); LogError("MakeResponseResult failed.\n");
free(resultStr); responseHandle("Device run out of memory.", context);
return;
}
ResponseJsonString(result, responseHandle, context);
cJSON_Delete(result); 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) cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result, const bool requestSet)
{ {
const char *RESPONSE_RESULT = "result"; const char *RESPONSE_RESULT = "result";
cJSON *resultCJSON = cJSON_CreateObject(); cJSON *resultCJSON = cJSON_CreateObject();
if (nullptr == resultCJSON) {
LogError("cJSON_CreateObject failed.\n");
goto END;
}
cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(result)); cJSON_AddNumberToObject(resultCJSON, RESPONSE_RESULT, static_cast<int>(result));
if (false == requestSet) { if (false == requestSet) {
return resultCJSON; goto END;
} }
if (ResposeResult::SUCCESSFUL == result) { if (ResposeResult::SUCCESSFUL == result) {
cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set success."); cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set success.");
@ -314,8 +680,37 @@ cJSON *SixFrameHandle::MakeResponseResult(const ResposeResult result, const bool
else { else {
cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set failed."); // TODO: what the failed string is? cJSON_AddStringToObject(resultCJSON, CJSON_INFO_STRING, "set failed."); // TODO: what the failed string is?
} }
END:
return resultCJSON; 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) void SixFrameHandle::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
{ {
if (monitor) { if (monitor) {

View File

@ -30,18 +30,20 @@ public:
VParseUrl() = default; VParseUrl() = default;
virtual ~VParseUrl() = default; virtual ~VParseUrl() = default;
}; };
using ParseUrlResultFunc = void(const std::string &, const std::string &, std::shared_ptr<VParseUrl> &);
template <typename T> template <typename T>
class ParseUrl : public VParseUrl class ParseUrl : public VParseUrl
{ {
public: public:
ParseUrl() {} ParseUrl()
{
}
virtual ~ParseUrl() = default; virtual ~ParseUrl() = default;
public: public:
T mData; T mData;
}; };
using ParseUrlResultFunc = void(const std::string &, const std::string &, std::shared_ptr<VParseUrl> &);
class SixFrameHandle : public IAppProtocolHandle class SixFrameHandle : public IAppProtocolHandle
{ {
public: public:
@ -68,14 +70,35 @@ private:
void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo &param); void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo &param);
void RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context); void RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo &param); void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo &param);
AppParamValue RequestParamValueParse(const std::string &url);
void RequestGetParamValue(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetParamValue(cJSON *result, const AppParamValue &param);
void RequestGetCapability(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetCapability(cJSON *result, const AppGetCapability &param);
void RequestGetLockVideoStatus(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetLockVideoStatus(cJSON *result, const LockVideoStatus &param);
void RequestGetStorageInfo(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetStorageInfo(cJSON *result, const std::vector<AppGetStorageInfo> &param);
AppGetFileInfo RequestGetFileListParse(const std::string &url);
void RequestGetFileList(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> &param, const AppGetFileInfo &fileInfo);
AppSetDateTime RequestSetDateTimeParse(const std::string &url); AppSetDateTime RequestSetDateTimeParse(const std::string &url);
void RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context); void RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context);
int RequestSetTimeZoneParse(const std::string &url); int RequestSetTimeZoneParse(const std::string &url);
void RequestSetTimeZone(const std::string &url, ResponseHandle responseHandle, void *context); 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); 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: private:
cJSON *MakeResponseResult(const ResposeResult result, const bool requestSet = false); cJSON *MakeResponseResult(const ResposeResult result, const bool requestSet = false);
void ResponseJsonString(cJSON *json, ResponseHandle responseHandle, void *context);
const char *PrintfFileEvent(const AppGetFileInfo &fileInfo);
protected: protected:
void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override; void SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;

View File

@ -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 "SixFrameMakePtr.h"
#include "ILog.h" #include "ILog.h"
#include "SixFrameHandle.h" #include "SixFrameHandle.h"

View File

@ -36,7 +36,9 @@ class VKeyMonitor
public: public:
VKeyMonitor() = default; VKeyMonitor() = default;
virtual ~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 class VirtualLedControl
{ {

View File

@ -28,8 +28,14 @@ std::shared_ptr<IDeviceManager> &IDeviceManager::GetInstance(std::shared_ptr<IDe
} }
return instance; return instance;
} }
const StatusCode IDeviceManager::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } const StatusCode IDeviceManager::Init(void)
const StatusCode IDeviceManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
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) const StatusCode IDeviceManager::ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);

View File

@ -8,7 +8,7 @@ include_directories(
./include ./include
${UTILS_SOURCE_PATH}/StatusCode/include ${UTILS_SOURCE_PATH}/StatusCode/include
${UTILS_SOURCE_PATH}/Log/include ${UTILS_SOURCE_PATH}/Log/include
${UTILS_SOURCE_PATH}/Config/include ${UTILS_SOURCE_PATH}/ConfigBase/include
) )
#do not rely on any other library #do not rely on any other library
#link_directories( #link_directories(

View File

@ -96,30 +96,30 @@ class IIpcConfig
public: public:
IIpcConfig() = default; IIpcConfig() = default;
virtual ~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); 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 ConfigFileSave(void);
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const StatusCode Init(void);
virtual const int GetInt(const IpcConfigKey &key) { return -1; } virtual const StatusCode UnInit(void);
virtual void SetInt(const IpcConfigKey &key, const int &value) {} virtual const int GetInt(const IpcConfigKey &key);
virtual const short GetShort(const IpcConfigKey &key) { return -1; } virtual void SetInt(const IpcConfigKey &key, const int &value);
virtual void SetShort(const IpcConfigKey &key, const short &value) {} virtual const short GetShort(const IpcConfigKey &key);
virtual const long GetLong(const IpcConfigKey &key) { return -1; } virtual void SetShort(const IpcConfigKey &key, const short &value);
virtual void SetLong(const IpcConfigKey &key, const long &value) {} virtual const long GetLong(const IpcConfigKey &key);
virtual const long long GetLLong(const IpcConfigKey &key) { return -1; } virtual void SetLong(const IpcConfigKey &key, const long &value);
virtual void SetLLong(const IpcConfigKey &key, const long long &value) {} virtual const long long GetLLong(const IpcConfigKey &key);
virtual const char GetChar(const IpcConfigKey &key) { return '\0'; } virtual void SetLLong(const IpcConfigKey &key, const long long &value);
virtual void SetChar(const IpcConfigKey &key, const char &value) {} virtual const char GetChar(const IpcConfigKey &key);
virtual const float GetFloat(const IpcConfigKey &key) { return -1.0; } virtual void SetChar(const IpcConfigKey &key, const char &value);
virtual void SetFloat(const IpcConfigKey &key, const float &value) {} virtual const float GetFloat(const IpcConfigKey &key);
virtual const double GetDouble(const IpcConfigKey &key) { return -1.0; } virtual void SetFloat(const IpcConfigKey &key, const float &value);
virtual void SetDouble(const IpcConfigKey &key, const double &value) {} virtual const double GetDouble(const IpcConfigKey &key);
virtual const long double GetLongDouble(const IpcConfigKey &key) { return -1.0; } virtual void SetDouble(const IpcConfigKey &key, const double &value);
virtual void SetLongDouble(const IpcConfigKey &key, const long double &value) {} virtual const long double GetLongDouble(const IpcConfigKey &key);
virtual const bool GetBool(const IpcConfigKey &key) { return true; } virtual void SetLongDouble(const IpcConfigKey &key, const long double &value);
virtual void SetBool(const IpcConfigKey &key, const bool &value) {} virtual const bool GetBool(const IpcConfigKey &key);
virtual const std::string GetString(const IpcConfigKey &key) { return "undefine"; } virtual void SetBool(const IpcConfigKey &key, const bool &value);
virtual void SetString(const IpcConfigKey &key, const std::string string) {} virtual const std::string GetString(const IpcConfigKey &key);
virtual void SetString(const IpcConfigKey &key, const std::string string);
}; };
bool CreateIpcConfig(void); bool CreateIpcConfig(void);
#endif #endif

View File

@ -28,3 +28,85 @@ std::shared_ptr<IIpcConfig> &IIpcConfig::GetInstance(std::shared_ptr<IIpcConfig>
} }
return instance; 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)
{
}

View File

@ -121,7 +121,10 @@ const StatusCode IpcConfig::UnInit(void)
CloseConfigFile(mCfg); CloseConfigFile(mCfg);
return CreateStatusCode(STATUS_CODE_OK); 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) const int IpcConfig::GetInt(const IpcConfigKey &key)
{ {
@ -140,7 +143,7 @@ void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
iter = mCfgMapInt.find(key); iter = mCfgMapInt.find(key);
if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetInt(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -165,7 +168,7 @@ void IpcConfig::SetShort(const IpcConfigKey &key, const short &value)
iter = mCfgMapShort.find(key); iter = mCfgMapShort.find(key);
if (iter != mCfgMapShort.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapShort.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetShort(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -190,7 +193,7 @@ void IpcConfig::SetLong(const IpcConfigKey &key, const long &value)
iter = mCfgMapLong.find(key); iter = mCfgMapLong.find(key);
if (iter != mCfgMapLong.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapLong.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetLong(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -215,7 +218,7 @@ void IpcConfig::SetLLong(const IpcConfigKey &key, const long long &value)
iter = mCfgMapLLong.find(key); iter = mCfgMapLLong.find(key);
if (iter != mCfgMapLLong.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapLLong.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetLLong(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -240,7 +243,7 @@ void IpcConfig::SetChar(const IpcConfigKey &key, const char &character)
iter = mCfgMapChar.find(key); iter = mCfgMapChar.find(key);
if (iter != mCfgMapChar.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapChar.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = character; 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); ConfigSetChar(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -265,7 +268,7 @@ void IpcConfig::SetFloat(const IpcConfigKey &key, const float &value)
iter = mCfgMapFloat.find(key); iter = mCfgMapFloat.find(key);
if (iter != mCfgMapFloat.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapFloat.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetFloat(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -290,7 +293,7 @@ void IpcConfig::SetDouble(const IpcConfigKey &key, const double &value)
iter = mCfgMapDouble.find(key); iter = mCfgMapDouble.find(key);
if (iter != mCfgMapDouble.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapDouble.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetDouble(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -338,7 +341,7 @@ void IpcConfig::SetBool(const IpcConfigKey &key, const bool &value)
iter = mCfgMapBool.find(key); iter = mCfgMapBool.find(key);
if (iter != mCfgMapBool.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapBool.end() && CHECK_MAP(iter->second)) {
iter->second.begin()->second.get() = value; 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); ConfigSetBool(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -364,7 +367,7 @@ void IpcConfig::SetString(const IpcConfigKey &key, const std::string string)
iter = mCfgMapString.find(key); iter = mCfgMapString.find(key);
if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) { if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) {
strncpy(iter->second.begin()->second, string.c_str(), sizeof(CHAR_STRING)); // const std::strinbg --> char[] 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); ConfigSetString(mCfg, name, iter->second.begin()->second);
mCfgChanged = CONFIG_HAS_CHANGED; mCfgChanged = CONFIG_HAS_CHANGED;
} }
@ -399,7 +402,7 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetInt(mCfg, "burst_photo_interval", mAllData.burstPhotoInterval); ConfigSetInt(mCfg, "burst_photo_interval", mAllData.burstPhotoInterval);
} }
const char *imageSizeString = NULL; const char *imageSizeString = nullptr;
StatusCode imageSizeCode = ConfigGetString(mCfg, "image_size", &(imageSizeString)); StatusCode imageSizeCode = ConfigGetString(mCfg, "image_size", &(imageSizeString));
if (StatusCodeEqual(imageSizeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) { if (StatusCodeEqual(imageSizeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("image_size doesn't exist, will make it as default.\n"); 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); ConfigSetString(mCfg, "image_size", mAllData.imageSize);
} }
else { 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)); StatusCode videoSizeCode = ConfigGetInt(mCfg, "video_size", &(mAllData.videoSize));
@ -471,7 +479,7 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetBool(mCfg, "formatting_SD_card", mAllData.formattingSDCard); ConfigSetBool(mCfg, "formatting_SD_card", mAllData.formattingSDCard);
} }
const char *darkModeString = NULL; const char *darkModeString = nullptr;
StatusCode darkModeCode = ConfigGetString(mCfg, "dark_mode", &(darkModeString)); StatusCode darkModeCode = ConfigGetString(mCfg, "dark_mode", &(darkModeString));
if (StatusCodeEqual(darkModeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) { if (StatusCodeEqual(darkModeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("dark_mode doesn't exist, will make it as default.\n"); 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); ConfigSetString(mCfg, "dark_mode", mAllData.darkMode);
} }
else { 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)); StatusCode workIntervalCode = ConfigGetString(mCfg, "work_interval", &(workIntervalString));
if (StatusCodeEqual(workIntervalCode, "CONFIG_CODE_PARAM_NOT_EXIST")) { if (StatusCodeEqual(workIntervalCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("work_interval doesn't exist, will make it as default.\n"); 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); ConfigSetString(mCfg, "work_interval", mAllData.workingInterval);
} }
else { 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)); StatusCode shortCode = ConfigGetShort(mCfg, "test_short", &(mAllData.testShort));

View File

@ -14,7 +14,7 @@
*/ */
#ifndef IPCCONFIG_H #ifndef IPCCONFIG_H
#define IPCCONFIG_H #define IPCCONFIG_H
#include "Config.h" #include "ConfigBase.h"
#include "IIpcConfig.h" #include "IIpcConfig.h"
#include "StatusCode.h" #include "StatusCode.h"
#include <map> #include <map>
@ -84,7 +84,7 @@ private:
private: private:
bool mCfgChanged; bool mCfgChanged;
VConfig *mCfg; void *mCfg;
Config_s mAllData; 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<int>>> mCfgMapInt;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<short>>> mCfgMapShort; std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<short>>> mCfgMapShort;

View File

@ -57,12 +57,26 @@ typedef struct mcu_ask_date_time
class VMcuAsk class VMcuAsk
{ {
public: public:
VMcuAsk() { mSerialNumber = 0; } VMcuAsk()
{
mSerialNumber = 0;
}
virtual ~VMcuAsk() = default; virtual ~VMcuAsk() = default;
virtual ASK_RESULT Blocking(void) { return ASK_RESULT::END; } virtual ASK_RESULT Blocking(void)
virtual bool NeedReply(void) { return false; } {
virtual void ReplyFinished(const bool result) {} return ASK_RESULT::END;
virtual bool IfTimeout(const unsigned int &integrationTimeMs) { return false; } }
virtual bool NeedReply(void)
{
return false;
}
virtual void ReplyFinished(const bool result)
{
}
virtual bool IfTimeout(const unsigned int &integrationTimeMs)
{
return false;
}
public: public:
/** /**
@ -87,7 +101,9 @@ class VMcuMonitor
public: public:
VMcuMonitor() = default; VMcuMonitor() = default;
virtual ~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 class IMcuManager
{ {

View File

@ -28,8 +28,14 @@ std::shared_ptr<IMcuManager> &IMcuManager::GetInstance(std::shared_ptr<IMcuManag
} }
return instance; return instance;
} }
const StatusCode IMcuManager::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } const StatusCode IMcuManager::Init(void)
const StatusCode IMcuManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } {
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) const StatusCode IMcuManager::SetMcuMonitor(std::shared_ptr<VMcuMonitor> &monitor)
{ {
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);

View File

@ -28,7 +28,9 @@ McuDevice::McuDevice()
mThreadRuning = false; mThreadRuning = false;
mUartDevice = nullptr; mUartDevice = nullptr;
} }
McuDevice::~McuDevice() {} McuDevice::~McuDevice()
{
}
const StatusCode McuDevice::Init(void) const StatusCode McuDevice::Init(void)
{ {
UartInfo uartDevice = { UartInfo uartDevice = {
@ -50,9 +52,13 @@ const StatusCode McuDevice::Init(void)
return code; return code;
} }
std::shared_ptr<McuDevice> device = std::dynamic_pointer_cast<McuDevice>(SharedFromThis()); 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); 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); mMcuAskHandleThread = std::thread(mcuAskHandle, device);
return CreateStatusCode(STATUS_CODE_OK); return CreateStatusCode(STATUS_CODE_OK);
} }

View File

@ -15,7 +15,10 @@
#include "McuManagerImpl.h" #include "McuManagerImpl.h"
#include "ILog.h" #include "ILog.h"
#include "UartRecvAsk.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) const StatusCode McuManagerImpl::Init(void)
{ {
McuDevice::Init(); McuDevice::Init();

View File

@ -36,19 +36,37 @@ enum class SensorTaskType
class SensorTaskResponse class SensorTaskResponse
{ {
public: public:
SensorTaskResponse() {} SensorTaskResponse()
~SensorTaskResponse() {} {
}
~SensorTaskResponse()
{
}
}; };
class VSensorTask class VSensorTask
{ {
public: public:
VSensorTask() = default; VSensorTask() = default;
virtual ~VSensorTask() = default; virtual ~VSensorTask() = default;
virtual const SensorTaskType GetTaskType(void) { return SensorTaskType::END; } virtual const SensorTaskType GetTaskType(void)
virtual void Response(const std::vector<SensorTaskResponse> &response) {} {
virtual bool IsTaskFinished(void) { return false; } return SensorTaskType::END;
virtual const signed int GetIsNight(void) { return 0; } }
virtual const unsigned int GetIsMultShot(void) { return false; } 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 class VSensorHandle
{ {

View File

@ -36,14 +36,16 @@ public:
class State class State
{ {
public: public:
explicit State(const std::string &name) : mStateName(name) {} explicit State(const std::string &name) : mStateName(name)
{
}
virtual ~State() = default; virtual ~State() = default;
public: public:
virtual void GoInState() = 0; virtual void GoInState() = 0;
virtual void GoOutState() = 0; virtual void GoOutState() = 0;
virtual bool ExecuteStateMsg(VStateMachineData *msg) = 0; virtual bool ExecuteStateMsg(VStateMachineData *msg) = 0;
std::string GetStateName() { return mStateName; } std::string GetStateName();
private: private:
std::string mStateName; std::string mStateName;
@ -53,20 +55,18 @@ class VStateMachineHandle
public: public:
VStateMachineHandle() = default; VStateMachineHandle() = default;
virtual ~VStateMachineHandle() = default; virtual ~VStateMachineHandle() = default;
virtual bool InitialStateMachine() { return false; } virtual bool InitialStateMachine();
virtual void StatePlus(State *state, State *upper) {} virtual void StatePlus(State *state, State *upper);
virtual void SetCurrentState(State *firstState) {} virtual void SetCurrentState(State *firstState);
virtual void StartStateMachine() {} virtual void StartStateMachine();
virtual void SendMessage(int msgName) {} virtual void SendMessage(int msgName);
virtual void StopHandlerThread() {} virtual void StopHandlerThread();
virtual void SendMessage(int msgName, const std::shared_ptr<VStateMessage> &messageObj) {} virtual void SendMessage(int msgName, const std::shared_ptr<VStateMessage> &messageObj);
virtual void MessageExecutedLater(int msgName, const std::shared_ptr<VStateMessage> &messageObj, virtual void MessageExecutedLater(int msgName, const std::shared_ptr<VStateMessage> &messageObj,
int64_t delayTimeMs) int64_t delayTimeMs);
{ virtual void SwitchState(State *targetState);
} virtual void StopTimer(int timerName);
virtual void SwitchState(State *targetState) {} virtual void DelayMessage(VStateMachineData *msg);
virtual void StopTimer(int timerName) {}
virtual void DelayMessage(VStateMachineData *msg) {}
}; };
class IStateMachine class IStateMachine
{ {

View File

@ -15,6 +15,45 @@
#include "IStateMachine.h" #include "IStateMachine.h"
#include "ILog.h" #include "ILog.h"
#include <thread> #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) std::shared_ptr<IStateMachine> &IStateMachine::GetInstance(std::shared_ptr<IStateMachine> *impl)
{ {
static std::shared_ptr<IStateMachine> instance = std::make_shared<IStateMachine>(); static std::shared_ptr<IStateMachine> instance = std::make_shared<IStateMachine>();

View File

@ -198,7 +198,10 @@ public:
// mMessageObj = T(messageObj); // 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 * @DescriptionGet the Message Obj object
@ -223,7 +226,10 @@ public:
// { // {
// return mMessageObj; // 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. * @Description : Release Message Object.

View File

@ -42,14 +42,21 @@ class HunttingCameraTest : public testing::Test,
{ {
public: public:
HunttingCameraTest() {} HunttingCameraTest()
virtual ~HunttingCameraTest() {} {
}
virtual ~HunttingCameraTest()
{
}
static void SetUpTestCase() static void SetUpTestCase()
{ {
CreateLogModule(); CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END); ILogInit(LOG_INSTANCE_TYPE_END);
} }
static void TearDownTestCase() { ILogUnInit(); } static void TearDownTestCase()
{
ILogUnInit();
}
virtual void SetUp() virtual void SetUp()
{ {
std::shared_ptr<MainThread> mainThread = std::make_shared<MainThreadTest>(); std::shared_ptr<MainThread> mainThread = std::make_shared<MainThreadTest>();
@ -181,4 +188,92 @@ TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_McuOpenFailed)
// MockUploadFiles(); // MockUploadFiles();
MainThread::GetInstance()->Runing(); 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 } // namespace HunttingCameraTest

View File

@ -60,7 +60,52 @@ StatusCode TestMissionStateTest::GetBatteryInfo(AppGetBatteryInfo &param)
} }
return code; return code;
} }
StatusCode TestMissionStateTest::SetDateTime(AppSetDateTime &param) StatusCode TestMissionStateTest::GetParamValue(AppParamValue &param)
{
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 &param)
{
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 &param)
{
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> &param)
{
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> &param)
{
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 &param)
{ {
LogInfo("TestMissionStateTest::SetDateTime\n"); LogInfo("TestMissionStateTest::SetDateTime\n");
LogInfo("mYear = %u\n", param.mYear); LogInfo("mYear = %u\n", param.mYear);
@ -84,6 +129,33 @@ StatusCode TestMissionStateTest::SetTimeZone(const unsigned int &zone)
} }
return code; return code;
} }
StatusCode TestMissionStateTest::SetParamValue(const AppSetParamValue &param)
{
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 &param) StatusCode TestMissionStateTest::UploadFile(AppUploadFile &param)
{ {
LogInfo("TestMissionStateTest::UploadFile\n"); LogInfo("TestMissionStateTest::UploadFile\n");

View File

@ -27,19 +27,24 @@ public:
StatusCode GetMediaInfo(AppGetMeidaInfo &param) override; StatusCode GetMediaInfo(AppGetMeidaInfo &param) override;
StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override; StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override;
StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override; StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override;
StatusCode SetDateTime(AppSetDateTime &param) override; StatusCode GetParamValue(AppParamValue &param) override;
StatusCode GetCapability(AppGetCapability &param) override;
StatusCode GetLockVideoStatus(LockVideoStatus &param) override;
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> &param) override;
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param) override;
StatusCode SetDateTime(const AppSetDateTime &param) override;
StatusCode SetTimeZone(const unsigned int &zone) override; StatusCode SetTimeZone(const unsigned int &zone) override;
StatusCode SetParamValue(const AppSetParamValue &param) override;
StatusCode EnterRecorder(void) override;
StatusCode AppPlayback(const PlayBackEvent &event) override;
StatusCode UploadFile(AppUploadFile &param) override; StatusCode UploadFile(AppUploadFile &param) override;
// const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
protected: protected:
// virtual const StatusCode SetAppMonitorTrace(std::shared_ptr<VAppMonitor> &monitor);
}; };
class TestMissionStateMock : public AppMonitorMock, public TestMissionStateTest class TestMissionStateMock : public AppMonitorMock, public TestMissionStateTest
{ {
public: public:
TestMissionStateMock() = default; TestMissionStateMock() = default;
virtual ~TestMissionStateMock() = default; virtual ~TestMissionStateMock() = default;
// MOCK_METHOD1(SetAppMonitorTrace, const StatusCode(std::shared_ptr<VAppMonitor> &));
}; };
#endif #endif

View File

@ -32,7 +32,9 @@ public:
const unsigned int &blinkTimeMs); const unsigned int &blinkTimeMs);
protected: protected:
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) {} virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
{
}
private: private:
void KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs); void KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs);

View File

@ -23,11 +23,17 @@ class KeyControlTest : public KeyControl, public VKeyHal
public: public:
KeyControlTest(const std::string &keyName); KeyControlTest(const std::string &keyName);
virtual ~KeyControlTest() = default; 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 SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor) override;
void CheckKeyStatus(void) override; void CheckKeyStatus(void) override;
void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) 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: private:
virtual StatusCode KeyEventTriggerTrace(const std::string &keyName, const KeyEvent &event, virtual StatusCode KeyEventTriggerTrace(const std::string &keyName, const KeyEvent &event,

View File

@ -34,7 +34,7 @@ endif()
set(TARGET_NAME AppManagerTest) set(TARGET_NAME AppManagerTest)
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) 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") if(${TEST_COVERAGE} MATCHES "true")
target_link_libraries(${TARGET_NAME} gcov) target_link_libraries(${TARGET_NAME} gcov)
endif() endif()

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "AppManagerTestTool.h" #include "AppManagerTestTool.h"
#include "HalTestTool.h"
#include "IAppManager.h" #include "IAppManager.h"
#include "ILog.h" #include "ILog.h"
#include <gmock/gmock.h> #include <gmock/gmock.h>
@ -20,26 +21,37 @@
#include <thread> #include <thread>
namespace AppManagerTest namespace AppManagerTest
{ {
class AppManagerTest : public testing::Test, public AppManagerTestTool class AppManagerTest : public testing::Test, public AppManagerTestTool, public HalTestTool
{ {
public: public:
AppManagerTest() : mAppParam(APP_MANAGER_HTTP_SERVER_IP, APP_MANAGER_HTTP_SERVER_PORT) {} AppManagerTest() : mAppParam(APP_MANAGER_HTTP_SERVER_IP, APP_MANAGER_HTTP_SERVER_PORT)
virtual ~AppManagerTest() {} {
}
virtual ~AppManagerTest()
{
}
static void SetUpTestCase() static void SetUpTestCase()
{ {
CreateLogModule(); CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END); ILogInit(LOG_INSTANCE_TYPE_END);
} }
static void TearDownTestCase() { ILogUnInit(); } static void TearDownTestCase()
{
ILogUnInit();
}
virtual void SetUp() virtual void SetUp()
{ {
HalTestTool::Init();
AppManagerTestTool::Init(); AppManagerTestTool::Init();
CreateHalCppModule();
CreateAppManagerModule(); CreateAppManagerModule();
} }
virtual void TearDown() virtual void TearDown()
{ {
AppManagerTestTool::UnInit(); AppManagerTestTool::UnInit();
HalTestTool::UnInit();
DestroyAppManagerModule(); DestroyAppManagerModule();
DestroyHalCppModule();
} }
protected: protected:
@ -48,9 +60,11 @@ protected:
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo0 // ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo0
TEST_F(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()->Init(mAppParam);
IAppManager::GetInstance()->SetAppMonitor(monitor);
std::this_thread::sleep_for(std::chrono::milliseconds(100)); 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(); IAppManager::GetInstance()->UnInit();
} }
// ../output_files/test/bin/AppManagerTest --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_Demo // ../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)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
IAppManager::GetInstance()->UnInit(); IAppManager::GetInstance()->UnInit();
} }
// ../output_files/test/bin/AppManagerTest
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_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 } // namespace AppManagerTest

View File

@ -34,9 +34,19 @@ protected:
void MockSetDateTime(void); void MockSetDateTime(void);
void MockSetTimeZone(void); void MockSetTimeZone(void);
void MockUploadFiles(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: private:
void AppManagerMockInit(std::shared_ptr<IAppManager> &vMock); void AppManagerMockInit(std::shared_ptr<IAppManager> &vMock);
void AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock);
private: private:
std::shared_ptr<IAppManager> mAppManagerMock; std::shared_ptr<IAppManager> mAppManagerMock;
@ -44,6 +54,5 @@ private:
public: public:
static std::shared_ptr<VAppMonitor> MakeMonitorMock(void); static std::shared_ptr<VAppMonitor> MakeMonitorMock(void);
void AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock);
}; };
#endif #endif

View File

@ -114,6 +114,97 @@ void AppManagerTestTool::MockUploadFiles(void)
} }
ServersMock::GetInstance()->MockUploadFiles(); 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) void AppManagerTestTool::AppManagerMockInit(std::shared_ptr<IAppManager> &vMock)
{ {
std::shared_ptr<AppManagerMock> mock = std::dynamic_pointer_cast<AppManagerMock>(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) { auto getAppMonitor = [=](std::shared_ptr<VAppMonitor> &monitor) {
LogInfo("mAppMonitorMock get.\n"); LogInfo("mAppMonitorMock get.\n");
// mAppMonitorMock = std::dynamic_pointer_cast<AppMonitorMock>(monitor);
mAppMonitorMock = monitor; mAppMonitorMock = monitor;
AppManagerTestTool::AppMonitorInit(mAppMonitorMock); AppManagerTestTool::AppMonitorInit(mAppMonitorMock);
}; };
@ -140,7 +230,6 @@ std::shared_ptr<VAppMonitor> AppManagerTestTool::MakeMonitorMock(void)
virtual ~Monitor() = default; virtual ~Monitor() = default;
}; };
std::shared_ptr<VAppMonitor> monitor = std::make_shared<Monitor>(); std::shared_ptr<VAppMonitor> monitor = std::make_shared<Monitor>();
// auto result = std::dynamic_pointer_cast<VAppMonitor>(monitor);
return monitor; return monitor;
} }
void AppManagerTestTool::AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock) 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)))); .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
EXPECT_CALL(*mock.get(), GetSdCardInfoTrace(_)) EXPECT_CALL(*mock.get(), GetSdCardInfoTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); .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(_)) EXPECT_CALL(*mock.get(), GetBatteryInfoTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
EXPECT_CALL(*mock.get(), SetDateTimeTrace(_)) EXPECT_CALL(*mock.get(), SetDateTimeTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); .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(_)) EXPECT_CALL(*mock.get(), UploadFileTrace(_))
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
} }

View File

@ -84,7 +84,77 @@ StatusCode AppMonitorTrace::GetBatteryInfoTrace(AppGetBatteryInfo &param)
LogInfo("AppMonitorTrace::GetBatteryInfoTrace\n"); LogInfo("AppMonitorTrace::GetBatteryInfoTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
} }
StatusCode AppMonitorTest::SetDateTime(AppSetDateTime &param) StatusCode AppMonitorTest::GetParamValue(AppParamValue &param)
{
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 &param)
{
LogInfo("AppMonitorTrace::GetParamValueTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode AppMonitorTest::GetCapability(AppGetCapability &param)
{
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 &param)
{
LogInfo("AppMonitorTrace::GetCapabilityTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode AppMonitorTest::GetLockVideoStatus(LockVideoStatus &param)
{
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 &param)
{
LogInfo("AppMonitorTrace::GetLockVideoStatusTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode AppMonitorTest::GetStorageInfo(std::vector<AppGetStorageInfo> &param)
{
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> &param)
{
LogInfo("AppMonitorTrace::GetStorageInfoTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode AppMonitorTest::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param)
{
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> &param)
{
LogInfo("AppMonitorTrace::GetStorageFileListTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode AppMonitorTest::SetDateTime(const AppSetDateTime &param)
{ {
LogInfo("AppMonitorTest::SetDateTime\n"); LogInfo("AppMonitorTest::SetDateTime\n");
LogInfo("mYear = %u\n", param.mYear); LogInfo("mYear = %u\n", param.mYear);
@ -99,7 +169,7 @@ StatusCode AppMonitorTest::SetDateTime(AppSetDateTime &param)
} }
return code; return code;
} }
StatusCode AppMonitorTrace::SetDateTimeTrace(AppSetDateTime &param) StatusCode AppMonitorTrace::SetDateTimeTrace(const AppSetDateTime &param)
{ {
LogInfo("AppMonitorTrace::SetDateTimeTrace\n"); LogInfo("AppMonitorTrace::SetDateTimeTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
@ -118,6 +188,48 @@ StatusCode AppMonitorTrace::SetTimeZoneTrace(const unsigned int &zone)
LogInfo("AppMonitorTrace::SetTimeZoneTrace\n"); LogInfo("AppMonitorTrace::SetTimeZoneTrace\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
} }
StatusCode AppMonitorTest::SetParamValue(const AppSetParamValue &param)
{
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 &param)
{
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 &param) StatusCode AppMonitorTest::UploadFile(AppUploadFile &param)
{ {
LogInfo("AppMonitorTest::UploadFile\n"); LogInfo("AppMonitorTest::UploadFile\n");

View File

@ -28,8 +28,16 @@ protected:
virtual StatusCode GetMediaInfoTrace(AppGetMeidaInfo &param); virtual StatusCode GetMediaInfoTrace(AppGetMeidaInfo &param);
virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo &param); virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo &param);
virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo &param); virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo &param);
virtual StatusCode SetDateTimeTrace(AppSetDateTime &param); virtual StatusCode GetParamValueTrace(AppParamValue &param);
virtual StatusCode GetCapabilityTrace(AppGetCapability &param);
virtual StatusCode GetLockVideoStatusTrace(LockVideoStatus &param);
virtual StatusCode GetStorageInfoTrace(std::vector<AppGetStorageInfo> &param);
virtual StatusCode GetStorageFileListTrace(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param);
virtual StatusCode SetDateTimeTrace(const AppSetDateTime &param);
virtual StatusCode SetTimeZoneTrace(const unsigned int &zone); virtual StatusCode SetTimeZoneTrace(const unsigned int &zone);
virtual StatusCode SetParamValueTrace(const AppSetParamValue &param);
virtual StatusCode EnterRecorderTrace(void);
virtual StatusCode AppPlaybackTrace(const PlayBackEvent &event);
virtual StatusCode UploadFileTrace(AppUploadFile &param); virtual StatusCode UploadFileTrace(AppUploadFile &param);
}; };
class AppMonitorTest : public VAppMonitor, virtual public AppMonitorTrace class AppMonitorTest : public VAppMonitor, virtual public AppMonitorTrace
@ -42,8 +50,16 @@ public:
StatusCode GetMediaInfo(AppGetMeidaInfo &param) override; StatusCode GetMediaInfo(AppGetMeidaInfo &param) override;
StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override; StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override;
StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override; StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override;
StatusCode SetDateTime(AppSetDateTime &param) override; StatusCode GetParamValue(AppParamValue &param) override;
StatusCode GetCapability(AppGetCapability &param) override;
StatusCode GetLockVideoStatus(LockVideoStatus &param) override;
StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> &param) override;
StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param) override;
StatusCode SetDateTime(const AppSetDateTime &param) override;
StatusCode SetTimeZone(const unsigned int &zone) override; StatusCode SetTimeZone(const unsigned int &zone) override;
StatusCode SetParamValue(const AppSetParamValue &param) override;
StatusCode EnterRecorder(void) override;
StatusCode AppPlayback(const PlayBackEvent &event) override;
StatusCode UploadFile(AppUploadFile &param) override; StatusCode UploadFile(AppUploadFile &param) override;
}; };
class AppMonitorMock : virtual public AppMonitorTrace class AppMonitorMock : virtual public AppMonitorTrace
@ -56,8 +72,16 @@ public:
MOCK_METHOD1(GetMediaInfoTrace, StatusCode(AppGetMeidaInfo &)); MOCK_METHOD1(GetMediaInfoTrace, StatusCode(AppGetMeidaInfo &));
MOCK_METHOD1(GetSdCardInfoTrace, StatusCode(AppGetSdCardInfo &)); MOCK_METHOD1(GetSdCardInfoTrace, StatusCode(AppGetSdCardInfo &));
MOCK_METHOD1(GetBatteryInfoTrace, StatusCode(AppGetBatteryInfo &)); 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(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 &)); MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &));
}; };
#endif #endif

View File

@ -21,8 +21,16 @@ extern const char *APP_GET_DEVICE_ATTR;
extern const char *APP_GET_MEDIA_INFO; extern const char *APP_GET_MEDIA_INFO;
extern const char *APP_GET_SD_CARD_INFO; extern const char *APP_GET_SD_CARD_INFO;
extern const char *APP_GET_BATTERY_INFO; extern const char *APP_GET_BATTERY_INFO;
extern const char *APP_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_DATE_TIME;
extern const char *APP_SET_TIME_ZONE; 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; extern const char *APP_UPLOAD_FILE;
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl) std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
{ {
@ -140,9 +148,94 @@ void ServersMock::MockGetBatteryInfo(void)
DeleteServersHttp(http); 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) 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"; std::string mockRequest = mServerUrl + APP_SET_DATE_TIME + "?date=20240101010101";
ServerHttp *http = NewServersHttp(mockRequest.c_str()); ServerHttp *http = NewServersHttp(mockRequest.c_str());
if (http) { if (http) {
@ -174,6 +267,57 @@ void ServersMock::MockSetTimeZone(void)
DeleteServersHttp(http); 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 #ifndef PLATFORM_PATH
#error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}") #error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}")
#endif #endif

View File

@ -28,8 +28,16 @@ public:
virtual void MockGetMediaInfo(void); virtual void MockGetMediaInfo(void);
virtual void MockGetSdCardInfo(void); virtual void MockGetSdCardInfo(void);
virtual void MockGetBatteryInfo(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 MockSetDateTime(void);
virtual void MockSetTimeZone(void); virtual void MockSetTimeZone(void);
virtual void MockSetParamValue(void);
virtual void MockEnterRecorder(void);
virtual void MockAppPlayback(void);
virtual void MockUploadFiles(void); virtual void MockUploadFiles(void);
private: private:

View File

@ -26,14 +26,21 @@ const char *LED_TEST = "LED_TEST";
class DeviceManagerTest : public testing::Test, virtual public HalTestTool, public DeviceManagerTestTool class DeviceManagerTest : public testing::Test, virtual public HalTestTool, public DeviceManagerTestTool
{ {
public: public:
DeviceManagerTest() {} DeviceManagerTest()
virtual ~DeviceManagerTest() {} {
}
virtual ~DeviceManagerTest()
{
}
static void SetUpTestCase() static void SetUpTestCase()
{ {
CreateLogModule(); CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END); ILogInit(LOG_INSTANCE_TYPE_END);
} }
static void TearDownTestCase() { ILogUnInit(); } static void TearDownTestCase()
{
ILogUnInit();
}
virtual void SetUp() virtual void SetUp()
{ {
CreateAllKeysMcok(); CreateAllKeysMcok();

View File

@ -22,8 +22,14 @@ public:
SingleControlTool(const LedState &state, const unsigned int aliveTimeMs, const unsigned int &blinkTimeMs); SingleControlTool(const LedState &state, const unsigned int aliveTimeMs, const unsigned int &blinkTimeMs);
virtual ~SingleControlTool() = default; virtual ~SingleControlTool() = default;
virtual StatusCode GetLedState(LedState &state); virtual StatusCode GetLedState(LedState &state);
virtual unsigned int GetKeepAliveTimeMs(void) { return mAliveTimeMs; } virtual unsigned int GetKeepAliveTimeMs(void)
virtual unsigned int GetBlinkTimeMs(void) { return mBlinkTimeMs; } {
return mAliveTimeMs;
}
virtual unsigned int GetBlinkTimeMs(void)
{
return mBlinkTimeMs;
}
private: private:
const LedState mState; const LedState mState;

View File

@ -18,10 +18,6 @@ link_directories(
${EXTERNAL_LIBS_OUTPUT_PATH} ${EXTERNAL_LIBS_OUTPUT_PATH}
) )
aux_source_directory(. SRC_FILES_MAIN) aux_source_directory(. SRC_FILES_MAIN)
aux_source_directory(./src SRC_FILES) aux_source_directory(./src SRC_FILES)

View File

@ -32,10 +32,18 @@ public:
bool IfTimeout(const unsigned int &integrationTimeMs) override; bool IfTimeout(const unsigned int &integrationTimeMs) override;
protected: protected:
virtual void BlockingTrace(void) {} virtual void BlockingTrace(void)
virtual void NeedReplyTrace(void) {} {
virtual void ReplyFinishedTrace(const bool result) {} }
virtual void IfTimeoutTrace(const unsigned int &integrationTimeMs) {} virtual void NeedReplyTrace(void)
{
}
virtual void ReplyFinishedTrace(const bool result)
{
}
virtual void IfTimeoutTrace(const unsigned int &integrationTimeMs)
{
}
}; };
class McuAskBaseTestTool : public McuAskBaseTest class McuAskBaseTestTool : public McuAskBaseTest
{ {

View File

@ -12,14 +12,21 @@ namespace McuManagerMockTest
class McuManagerMockTest : public testing::Test, public McuManagerTestTool class McuManagerMockTest : public testing::Test, public McuManagerTestTool
{ {
public: public:
McuManagerMockTest() {} McuManagerMockTest()
virtual ~McuManagerMockTest() {} {
}
virtual ~McuManagerMockTest()
{
}
static void SetUpTestCase() static void SetUpTestCase()
{ {
CreateLogModule(); CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END); ILogInit(LOG_INSTANCE_TYPE_END);
} }
static void TearDownTestCase() { ILogUnInit(); } static void TearDownTestCase()
{
ILogUnInit();
}
virtual void SetUp() virtual void SetUp()
{ {
mLinuxTest = LinuxTest::CreateLinuxTest(); mLinuxTest = LinuxTest::CreateLinuxTest();
@ -58,7 +65,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission)
class McuAskTest : public McuAsk<IpcMission>, public McuAskBase class McuAskTest : public McuAsk<IpcMission>, public McuAskBase
{ {
public: public:
McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::BLOCK McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
{
} // using McuAskBlock::BLOCK
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override void ReplyFinished(const bool result) override
{ {
@ -96,7 +105,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission2)
class McuAskTest : public McuAsk<IpcMission>, public McuAskBase class McuAskTest : public McuAsk<IpcMission>, public McuAskBase
{ {
public: 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; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override void ReplyFinished(const bool result) override
{ {
@ -156,8 +167,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply)
class McuAskTest : public McuAskBase class McuAskTest : public McuAskBase
{ {
public: public:
McuAskTest() McuAskTest() : McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY)
: McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY) {} // using McuAskReply::NEED_NOT_REPLY {
} // using McuAskReply::NEED_NOT_REPLY
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
}; };
IMcuManager::GetInstance()->Init(); IMcuManager::GetInstance()->Init();
@ -176,8 +188,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_FeedWatchDog)
class McuAskTest : public McuAskBase class McuAskTest : public McuAskBase
{ {
public: public:
McuAskTest() McuAskTest() : McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY)
: McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY) {} // using McuAskReply::NEED_NOT_REPLY {
} // using McuAskReply::NEED_NOT_REPLY
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
}; };
IMcuManager::GetInstance()->Init(); IMcuManager::GetInstance()->Init();
@ -196,7 +209,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatc
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
{ {
public: public:
McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::BLOCK McuAskTest() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
{
} // using McuAskBlock::BLOCK
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override 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 class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
{ {
public: 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; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override 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 class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
{ {
public: 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; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override 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 class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
{ {
public: 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; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override 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 class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
{ {
public: 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; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override void ReplyFinished(const bool result) override
{ {
@ -351,7 +374,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission)
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
{ {
public: public:
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
{
}
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override void ReplyFinished(const bool result) override
{ {
@ -381,7 +406,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2)
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
{ {
public: public:
McuAskTest() : McuAskBaseTestTool(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} McuAskTest() : McuAskBaseTestTool(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
{
}
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override 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 class McuAskTest2 : public McuAsk<IpcMission>, public McuAskBaseTestTool
{ {
public: public:
McuAskTest2() McuAskTest2() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
: McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK {
} // using McuAskBlock::NOT_BLOCK
virtual ~McuAskTest2() = default; virtual ~McuAskTest2() = default;
void ReplyFinished(const bool result) override void ReplyFinished(const bool result) override
{ {
@ -763,7 +791,9 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMissionFailed)
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
{ {
public: public:
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {} McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
{
}
virtual ~McuAskTest() = default; virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override void ReplyFinished(const bool result) override
{ {

View File

@ -60,8 +60,12 @@ public:
} }
return instance; return instance;
} }
virtual void Init() {} virtual void Init()
virtual void UnInit() {} {
}
virtual void UnInit()
{
}
virtual int fx_open(const char *pathname, int flags); virtual int fx_open(const char *pathname, int flags);
virtual int fx_tcgetattr(int fd, struct termios *termios_p); virtual int fx_tcgetattr(int fd, struct termios *termios_p);
virtual int fx_tcsetattr(int fd, int optional_actions, const 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 * @return int
*/ */
virtual int GetHandleForMock(void) { return INVALID_HANDLE; } virtual int GetHandleForMock(void)
{
return INVALID_HANDLE;
}
public: public:
static std::shared_ptr<LinuxTest> CreateLinuxTest(void); static std::shared_ptr<LinuxTest> CreateLinuxTest(void);

View File

@ -13,7 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
#include "HandleManager.h" #include "HandleManager.h"
HandleManager::HandleManager() { mFdMax = 1000; } HandleManager::HandleManager()
{
mFdMax = 1000;
}
int HandleManager::GetHandleForMock(void) int HandleManager::GetHandleForMock(void)
{ {
int value = mFdMax; int value = mFdMax;

View File

@ -92,7 +92,9 @@ void LinuxTestImpl::ApiInit(std::shared_ptr<LinuxTest> &mock)
Invoke((std::dynamic_pointer_cast<LinuxTestImpl>(mock)).get(), &LinuxTestImpl::ApiUnlockThread), Invoke((std::dynamic_pointer_cast<LinuxTestImpl>(mock)).get(), &LinuxTestImpl::ApiUnlockThread),
ReturnPointee(&selectResult))); ReturnPointee(&selectResult)));
} }
void LinuxTestImpl::Init() {} void LinuxTestImpl::Init()
{
}
void LinuxTestImpl::UnInit() void LinuxTestImpl::UnInit()
{ {
if (mApiThread.joinable()) { if (mApiThread.joinable()) {

View File

@ -17,7 +17,10 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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) int __wrap_fx_tcgetattr(int fd, struct termios *termios_p)
{ {
return LinuxApiMock::GetInstance()->fx_tcgetattr(fd, 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); 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) 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); return LinuxApiMock::GetInstance()->fx_select(nfds, readfds, writefds, exceptfds, timeout);

View File

@ -601,7 +601,9 @@ void McuProtocolTestTool::GetPhotosensitivityValueInit(std::shared_ptr<LinuxTest
} }
void McuProtocolTestTool::UnlockProtocolHandle(void) void McuProtocolTestTool::UnlockProtocolHandle(void)
{ {
auto unlockThread = [=](McuProtocolTestTool *testTool) { testTool->UnlockThread(); }; auto unlockThread = [=](McuProtocolTestTool *testTool) {
testTool->UnlockThread();
};
if (mUnLockThread.joinable()) { if (mUnLockThread.joinable()) {
mUnLockThread.join(); mUnLockThread.join();
} }

View File

@ -33,14 +33,21 @@ static UartInfo gUartDevice = {
class UartDeviceMockTest : public testing::Test, public UartDeviceTestTool class UartDeviceMockTest : public testing::Test, public UartDeviceTestTool
{ {
public: public:
UartDeviceMockTest() {} UartDeviceMockTest()
virtual ~UartDeviceMockTest() {} {
}
virtual ~UartDeviceMockTest()
{
}
static void SetUpTestCase() static void SetUpTestCase()
{ {
CreateLogModule(); CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END); ILogInit(LOG_INSTANCE_TYPE_END);
} }
static void TearDownTestCase() { ILogUnInit(); } static void TearDownTestCase()
{
ILogUnInit();
}
virtual void SetUp() virtual void SetUp()
{ {
mLinuxTest = LinuxTest::CreateLinuxTest(); mLinuxTest = LinuxTest::CreateLinuxTest();

View File

@ -99,7 +99,9 @@ void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const
EXPECT_CALL(*mock.get(), fx_select(uartFd + 1, _, _, _, _)) EXPECT_CALL(*mock.get(), fx_select(uartFd + 1, _, _, _, _))
.WillOnce(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(selectSucceed)), Return(SELECT_READABLE))) .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))); .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, _, _)) EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _))
.WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(readBuf)), Return(length))) .WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(readBuf)), Return(length)))
.WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING))); .WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING)));

View File

@ -1,6 +1,6 @@
# cmake_minimum_required(VERSION 2.8.0) # cmake_minimum_required(VERSION 2.8.0)
add_subdirectory(Config) add_subdirectory(ConfigBase)
add_subdirectory(StatusCode) add_subdirectory(StatusCode)
add_subdirectory(Log) add_subdirectory(Log)
add_subdirectory(SharedData) add_subdirectory(SharedData)

View File

@ -14,8 +14,6 @@ include_directories(
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
# ) # )
aux_source_directory(./src SRC_FILES) aux_source_directory(./src SRC_FILES)
set(TARGET_NAME ConfigBase) set(TARGET_NAME ConfigBase)

View File

@ -16,9 +16,18 @@
#include "ConfigImpl.h" #include "ConfigImpl.h"
#include "ILog.h" #include "ILog.h"
#include <stddef.h> #include <stddef.h>
const StatusCode ConfigInit(void) { return CreateStatusCode(STATUS_CODE_OK); } const StatusCode ConfigInit(void)
const StatusCode ConfigUnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } {
VConfig *OpenConfigFile(const char *fileName) { return (VConfig *)NewConfig(fileName); } 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) const StatusCode ConfigSaveFile(VConfig *cfg)
{ {
if (NULL == cfg) { if (NULL == cfg) {

View 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)

View 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()

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#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

View 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);
}

View 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);
}

View 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

View 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);
}

View 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

View 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));
}

View 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

View File

@ -38,9 +38,17 @@ class VKeyControl
public: public:
VKeyControl() = default; VKeyControl() = default;
virtual ~VKeyControl() = default; virtual ~VKeyControl() = default;
virtual const std::string GetKeyName(void) { return "undefine"; } virtual const std::string GetKeyName(void)
virtual unsigned int GetStatusCheckPeriodMs(void) { return 0; } {
virtual void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) {} 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> class KeyControl : public VKeyControl, public std::enable_shared_from_this<KeyControl>
{ {

View File

@ -21,9 +21,16 @@ KeyControl::KeyControl()
mPressingTime = KEY_NOT_PRESSING; mPressingTime = KEY_NOT_PRESSING;
mLongClickTime = 0; mLongClickTime = 0;
} }
KeyControl::~KeyControl() {} KeyControl::~KeyControl()
bool KeyControl::IsKeyPressing(void) { return mPressingTime >= KEY_PRESSING ? true : false; } {
void KeyControl::UnInit(void) {} }
bool KeyControl::IsKeyPressing(void)
{
return mPressingTime >= KEY_PRESSING ? true : false;
}
void KeyControl::UnInit(void)
{
}
void KeyControl::KeyHalEventHandle(const std::string &key, const KeyHalEvent &keyEvent) void KeyControl::KeyHalEventHandle(const std::string &key, const KeyHalEvent &keyEvent)
{ {
if (KEY_PRESSING <= mPressingTime) { if (KEY_PRESSING <= mPressingTime) {

View File

@ -44,20 +44,39 @@ class VSingleControl
public: public:
VSingleControl() = default; VSingleControl() = default;
virtual ~VSingleControl() = default; virtual ~VSingleControl() = default;
virtual StatusCode GetLedState(LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } virtual StatusCode GetLedState(LedState &state)
virtual unsigned int GetKeepAliveTimeMs(void) { return KEEP_ALIVE_FOREVER; } {
virtual unsigned int GetBlinkTimeMs(void) { return LED_NOT_BLINK; } 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 class VLedControl
{ {
public: public:
VLedControl() = default; VLedControl() = default;
virtual ~VLedControl() = default; virtual ~VLedControl() = default;
virtual StatusCode SetLedState(const LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } virtual StatusCode SetLedState(const LedState &state)
virtual void AddLedState(std::shared_ptr<VSingleControl> &control) {} {
virtual void CheckState(const unsigned int &period) {} 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 void SetHalLedState(const VirtualLedState &state) {}
virtual std::string GetLedName(void) { return "undefine"; } virtual std::string GetLedName(void)
{
return "undefine";
}
}; };
class LedControl : virtual public VLedControl class LedControl : virtual public VLedControl
{ {

View File

@ -22,15 +22,30 @@
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
int fx_system(const char *command) { return system(command); } int fx_system(const char *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); } 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) int fx_tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
{ {
return tcsetattr(fd, optional_actions, 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_write(int fd, const void *buf, size_t count)
ssize_t fx_read(int fd, void *buf, size_t count) { return read(fd, buf, 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) int fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{ {
return select(nfds, readfds, writefds, exceptfds, timeout); return select(nfds, readfds, writefds, exceptfds, timeout);

View File

@ -39,7 +39,9 @@ class ProtocolContext : public VProtocolContext
{ {
public: public:
ProtocolContext(T &value) : mData(value) {} ProtocolContext(T &value) : mData(value)
{
}
virtual ~ProtocolContext() = default; virtual ~ProtocolContext() = default;
public: public:
@ -48,7 +50,9 @@ public:
class SingleMcuPacket class SingleMcuPacket
{ {
public: 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; ~SingleMcuPacket() = default;
const void *mBuf; const void *mBuf;
const size_t mLength; const size_t mLength;
@ -60,7 +64,10 @@ public:
virtual ~VProtocolBase() = default; virtual ~VProtocolBase() = default;
protected: 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, virtual size_t WriteData(const void *buff, const size_t buffLength, std::shared_ptr<VProtocolContext> &context,
const unsigned int &serialNumber) const unsigned int &serialNumber)
{ {
@ -68,12 +75,17 @@ protected:
} }
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) virtual StatusCode GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength)
{ {
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); 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: public:
}; };
@ -88,15 +100,21 @@ class OtherSideReply
public: public:
OtherSideReply() = default; OtherSideReply() = default;
virtual ~OtherSideReply() = default; virtual ~OtherSideReply() = default;
virtual void GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission) {} virtual void GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission)
virtual void OnlyResultReply(const unsigned int &serialNumber, const ReplyResult &result) {} {
}
virtual void OnlyResultReply(const unsigned int &serialNumber, const ReplyResult &result)
{
}
}; };
class OtherSideAsk class OtherSideAsk
{ {
public: public:
OtherSideAsk() = default; OtherSideAsk() = default;
virtual ~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 class VProtocolRecv : public OtherSideReply, public OtherSideAsk
{ {

View File

@ -33,7 +33,10 @@ void LittleEndianHandle::BigEndianConversion(ProtocolPacket &packet)
packet.mCheckCode = htons(packet.mCheckCode); packet.mCheckCode = htons(packet.mCheckCode);
packet.mSerialNumber = htonl(packet.mSerialNumber); 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) void LittleEndianHandle::HostByteOrderConversion(ProtocolPacket &packet)
{ {
packet.mHead = ntohs(packet.mHead); packet.mHead = ntohs(packet.mHead);

View File

@ -30,7 +30,9 @@ const StatusCode McuProtocol::Init(void)
constexpr int THREAD_SHARING = 0; constexpr int THREAD_SHARING = 0;
constexpr int INITIAL_VALUE_OF_SEMAPHORE = 0; constexpr int INITIAL_VALUE_OF_SEMAPHORE = 0;
sem_init(&mSem, THREAD_SHARING, INITIAL_VALUE_OF_SEMAPHORE); 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()); std::shared_ptr<McuProtocol> handle = std::dynamic_pointer_cast<McuProtocol>(SharedFromThis());
mDataHandleThread = std::thread(dataHandleThread, handle); mDataHandleThread = std::thread(dataHandleThread, handle);
std::shared_ptr<VProtocolRecv> reply = std::dynamic_pointer_cast<VProtocolRecv>(SharedFromThis()); std::shared_ptr<VProtocolRecv> reply = std::dynamic_pointer_cast<VProtocolRecv>(SharedFromThis());
@ -153,7 +155,10 @@ void McuProtocol::ReplyOtherSideSendIpcMission(const ReplyResult &result, const
WriteProtocolData( WriteProtocolData(
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber()); 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) StatusCode McuProtocol::GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength)
{ {
return ProtocolHandle::GetDataLength(keyHead, headLength, dataLength); return ProtocolHandle::GetDataLength(keyHead, headLength, dataLength);

View File

@ -30,7 +30,10 @@ std::shared_ptr<McuProtocolMakePtr> &McuProtocolMakePtr::GetInstance(std::shared
} }
return instance; return instance;
} }
McuProtocolMakePtr::McuProtocolMakePtr() { mByteOrder = 0x00; } McuProtocolMakePtr::McuProtocolMakePtr()
{
mByteOrder = 0x00;
}
const StatusCode McuProtocolMakePtr::CreateProtocolHandle(std::shared_ptr<ProtocolHandle> &impl, const StatusCode McuProtocolMakePtr::CreateProtocolHandle(std::shared_ptr<ProtocolHandle> &impl,
const std::shared_ptr<VProtocolParam> &param) const std::shared_ptr<VProtocolParam> &param)
{ {

View File

@ -265,7 +265,10 @@ void ProtocolHandle::ProtocolAnalysis(const void *data, const size_t &length)
handle->AnalyzeProtocolPacket(); 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) StatusCode ProtocolHandle::GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength)
{ {
if (KEY_HEAD_LENGTH != headLength) { if (KEY_HEAD_LENGTH != headLength) {

View File

@ -104,7 +104,9 @@ class ProtocolParam : public VProtocolParam
{ {
public: 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; virtual ~ProtocolParam() = default;
public: public:
@ -126,9 +128,18 @@ public:
ProtocolHandle(const std::shared_ptr<VProtocolParam> &param); ProtocolHandle(const std::shared_ptr<VProtocolParam> &param);
ProtocolHandle(const void *data, const size_t &length); ProtocolHandle(const void *data, const size_t &length);
virtual ~ProtocolHandle(); virtual ~ProtocolHandle();
void *GetProtocolDataBuff(void) { return mProtocolData; } void *GetProtocolDataBuff(void)
size_t GetProtocolDataLength(void) { return mProtocolDataLength; } {
unsigned int GetSerialNumber(void) { return mProtocolSerialNumber; } 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 * @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); void AnalyzeOtherSideSendIpcMissionPacket(const ProtocolPacket &packet);
private: private:
virtual void BigEndianConversion(ProtocolPacket &packet) {} virtual void BigEndianConversion(ProtocolPacket &packet)
virtual short BigEndianConversion(const short &number) { return number; } {
virtual void HostByteOrderConversion(ProtocolPacket &packet) {} }
virtual short BigEndianConversion(const short &number)
{
return number;
}
virtual void HostByteOrderConversion(ProtocolPacket &packet)
{
}
virtual bool CheckoutTheCheckCode(const ProtocolPacket &packet); virtual bool CheckoutTheCheckCode(const ProtocolPacket &packet);
protected: protected:

View File

@ -16,7 +16,10 @@
#include "ILog.h" #include "ILog.h"
#include <string.h> #include <string.h>
static const char *MEDIA_ADAPTER_NAME = "media_adapter"; 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) std::shared_ptr<IMediaAdapter> *NewIMediaAdapter(const SENSOR_NUM &num)
{ {
LogInfo("Create the uart device object.\n"); LogInfo("Create the uart device object.\n");

View File

@ -21,7 +21,9 @@ class IMediaAdapter
public: public:
IMediaAdapter() = default; IMediaAdapter() = default;
virtual ~IMediaAdapter() = default; virtual ~IMediaAdapter() = default;
virtual void TestApi(void) {} virtual void TestApi(void)
{
}
}; };
typedef struct media_adapter_header typedef struct media_adapter_header
{ {

View File

@ -15,7 +15,10 @@
#include "MediaAdapter.h" #include "MediaAdapter.h"
#include "ILog.h" #include "ILog.h"
#include "IMediaAdapter.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) static bool ObjectCheck(void *object)
{ {
if (nullptr == object) { if (nullptr == object) {

View File

@ -14,8 +14,14 @@
*/ */
#include "curl_serve.h" #include "curl_serve.h"
static ServerParam gCurlServe; static ServerParam gCurlServe;
void SetVerboseLog(LogFlag flag) { gCurlServe.logFlag = flag; } void SetVerboseLog(LogFlag flag)
void SetSslVerify(SslFlag flag) { gCurlServe.sslVerifyFlag = flag; } {
gCurlServe.logFlag = flag;
}
void SetSslVerify(SslFlag flag)
{
gCurlServe.sslVerifyFlag = flag;
}
CURL *CurlEasyMake(void) CURL *CurlEasyMake(void)
{ {
CURL *curl; CURL *curl;

View File

@ -26,7 +26,9 @@ void ServersInit(ServerParam init)
SetVerboseLog(init.logFlag); SetVerboseLog(init.logFlag);
SetSslVerify(init.sslVerifyFlag); SetSslVerify(init.sslVerifyFlag);
} }
void ServersUnInit(void) {} void ServersUnInit(void)
{
}
void HttpGet(ServerHttp *param) void HttpGet(ServerHttp *param)
{ {
LogInfo("HttpGet\n"); LogInfo("HttpGet\n");
@ -105,7 +107,10 @@ void DeleteServersFtp(ServerFtp *ptr)
free(ptr); free(ptr);
} }
} }
void FtpServersCheck(ServerFtp *param) { FtpServersCheckConnect(param); } void FtpServersCheck(ServerFtp *param)
{
FtpServersCheckConnect(param);
}
void FtpDownload(ServerFtp *param) void FtpDownload(ServerFtp *param)
{ {
LogInfo("FtpDownload\n"); LogInfo("FtpDownload\n");

View File

@ -45,7 +45,10 @@ static inline const StatusCode IMakeSharedData(SharedData *object, const unsigne
{ {
return object->mMakeSharedData(object, readableSize, writableSize); 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) static inline const StatusCode IGetReadableData(SharedData *object, void *buf, const unsigned int bufLength)
{ {
return object->mGetReadableData(object, buf, 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); 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 #ifdef __cplusplus
} }
#endif #endif

Some files were not shown because too many files have changed in this diff Show More