Improve:App protocol.
This commit is contained in:
parent
9ccc38c9e7
commit
a9f698bf8b
|
@ -19,7 +19,7 @@
|
|||
|
||||
```code
|
||||
# 项目根目录执行:
|
||||
$ make install-cmake
|
||||
$ make install_cmake
|
||||
```
|
||||
|
||||
### 1.2.2. llvm工具安装
|
||||
|
|
|
@ -101,26 +101,41 @@ StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
|||
}
|
||||
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
std::vector<FileCreateType> types;
|
||||
std::vector<SyncFileInfo> info;
|
||||
types.push_back(FileCreateType::PIR);
|
||||
IFilesManager::GetInstance()->GetAllFiles(info);
|
||||
LogInfo("GetStorageFileList: file size = %d.\n", info.size());
|
||||
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
||||
if (StorageFileEvent::ALL == fileInfo.mEvent) {
|
||||
IFilesManager::GetInstance()->GetAllFiles(info);
|
||||
}
|
||||
else {
|
||||
std::vector<FileCreateType> types;
|
||||
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
||||
types.push_back(FileCreateType::TIMED);
|
||||
types.push_back(FileCreateType::MANUAL_TEST);
|
||||
types.push_back(FileCreateType::MANUAL_PHONE);
|
||||
types.push_back(FileCreateType::TIMED);
|
||||
}
|
||||
if (StorageFileEvent::EMR == fileInfo.mEvent) {
|
||||
types.push_back(FileCreateType::PIR);
|
||||
}
|
||||
if (StorageFileEvent::EVENT == fileInfo.mEvent) {
|
||||
types.push_back(FileCreateType::MANUAL_TEST);
|
||||
types.push_back(FileCreateType::MANUAL_PHONE);
|
||||
}
|
||||
if (StorageFileEvent::PARK == fileInfo.mEvent) {
|
||||
types.push_back(FileCreateType::TIMED);
|
||||
}
|
||||
IFilesManager::GetInstance()->GetFiles(types, info);
|
||||
}
|
||||
LogInfo("GetStorageFileList: file size = %d, event = %s.\n",
|
||||
info.size(),
|
||||
IAppManager::GetInstance()->StorageFileEventToString(fileInfo.mEvent));
|
||||
for (auto &oneFileInfo : info) {
|
||||
AppGetFileList file;
|
||||
file.mCreateTime_s = 123456789;
|
||||
file.mDuration = 182;
|
||||
file.mName = "/DCIM/2024/01/15/20240115140207-20240115140509.mp4";
|
||||
file.mSize = 1024 * 182;
|
||||
file.mCreateTime_s = oneFileInfo.mCreateTime_s;
|
||||
file.mDuration = oneFileInfo.mFileDuration;
|
||||
file.mName = oneFileInfo.mFileName;
|
||||
file.mSize = oneFileInfo.mFileSize;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <sys/stat.h>
|
||||
#include <vector>
|
||||
MediaHandleState::MediaHandleState() : State("MediaHandleState")
|
||||
{
|
||||
|
@ -66,11 +67,12 @@ bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
|||
LogInfo("response files = %d.\n", data->mData.mResponse.size());
|
||||
std::vector<SyncFileInfo> files;
|
||||
for (auto &response : data->mData.mResponse) {
|
||||
auto fileSize = GetFileSize_KB(response.mFileName.c_str());
|
||||
SyncFileInfo file(data->mData.mSerialNumber,
|
||||
response.mFileName,
|
||||
0,
|
||||
fileSize,
|
||||
response.mDuration_ms,
|
||||
0,
|
||||
data->mData.mCreateTime_s,
|
||||
FileCreateType::MANUAL_TEST,
|
||||
FileStatus::FINISHED_RECORD);
|
||||
files.push_back(file);
|
||||
|
@ -78,3 +80,12 @@ bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
|||
IFilesManager::GetInstance()->SaveFiles(files);
|
||||
return EXECUTED;
|
||||
}
|
||||
int MediaHandleState::GetFileSize_KB(const char *filePath)
|
||||
{
|
||||
struct stat fileInfo;
|
||||
if (stat(filePath, &fileInfo) != 0) {
|
||||
LogError("stat failed.\n");
|
||||
return FILE_SIZE_ERROR;
|
||||
}
|
||||
return static_cast<double>(fileInfo.st_size) / 1024.0;
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "MediaTaskHandle.h"
|
||||
constexpr int FILE_SIZE_ERROR = -1;
|
||||
class MediaHandleState : public State,
|
||||
public DataProcessing,
|
||||
public MediaTaskHandle,
|
||||
|
@ -34,5 +35,8 @@ private:
|
|||
void TaskResponse(const MediaTaskInfo &taskinfo) override;
|
||||
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||
bool MediaTaskFinishedHandle(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
static int GetFileSize_KB(const char *filePath);
|
||||
};
|
||||
#endif
|
|
@ -29,7 +29,8 @@
|
|||
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||
const std::weak_ptr<VMediaTaskIniator> &iniator, const unsigned long &serialNumber,
|
||||
const std::string &savePath)
|
||||
: mType(type), mBindEvent(bindEvent), mIniator(iniator), mSerialNumber(serialNumber), mSavePath(savePath)
|
||||
: mType(type), mBindEvent(bindEvent), mIniator(iniator), mSerialNumber(serialNumber), mSavePath(savePath),
|
||||
mCreateTime_s(0)
|
||||
{
|
||||
mResponseData.reset();
|
||||
mTargetName.clear();
|
||||
|
@ -47,6 +48,7 @@ std::string MediaTask::GetTargetNameForSaving(void)
|
|||
time_t t_now = std::chrono::system_clock::to_time_t(now);
|
||||
struct tm tm_now = *std::localtime(&t_now);
|
||||
|
||||
mCreateTime_s = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
|
||||
int hour = tm_now.tm_hour;
|
||||
int minute = tm_now.tm_min;
|
||||
int second = tm_now.tm_sec;
|
||||
|
@ -69,6 +71,7 @@ void MediaTask::Response(const std::vector<MediaTaskResponse> &response)
|
|||
MediaTaskInfo info = {
|
||||
.mResponse = response,
|
||||
.mSerialNumber = mSerialNumber,
|
||||
.mCreateTime_s = mCreateTime_s,
|
||||
};
|
||||
iniator->TaskResponse(info);
|
||||
}
|
|
@ -22,6 +22,7 @@ typedef struct media_task_info
|
|||
{
|
||||
const std::vector<MediaTaskResponse> mResponse;
|
||||
const unsigned long mSerialNumber;
|
||||
const long long mCreateTime_s;
|
||||
} MediaTaskInfo;
|
||||
class VMediaTaskIniator
|
||||
{
|
||||
|
@ -50,5 +51,6 @@ private:
|
|||
bool mFinished = false;
|
||||
std::shared_ptr<MediaTaskResponse> mResponseData;
|
||||
std::string mTargetName;
|
||||
long long mCreateTime_s;
|
||||
};
|
||||
#endif
|
|
@ -76,6 +76,9 @@ enum class StorageFileType
|
|||
};
|
||||
/**
|
||||
* @brief A file classification list mapped to hunting camera scenes based on the dash cam protocol.
|
||||
* NOTE: ALL is the process of getting all files in the protocol, while LOOP is the "all" files mapped to the hunting
|
||||
* camera scene according to the protocol. ALL includes LOOP and other types outside LOOP, and LOOP returns the "all"
|
||||
* file list in the hunting camera scene.
|
||||
*/
|
||||
enum class StorageFileEvent
|
||||
{
|
||||
|
@ -340,5 +343,6 @@ public:
|
|||
virtual const StatusCode UnInit(void);
|
||||
virtual const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor);
|
||||
virtual StatusCode SetSdCardStatus(const SdCardStatus &status);
|
||||
virtual const char *StorageFileEventToString(const StorageFileEvent &event);
|
||||
};
|
||||
#endif
|
|
@ -75,6 +75,27 @@ StatusCode AppManager::SetSdCardStatus(const SdCardStatus &status)
|
|||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const char *AppManager::StorageFileEventToString(const StorageFileEvent &event)
|
||||
{
|
||||
switch (event) {
|
||||
case StorageFileEvent::LOOP:
|
||||
return "LOOP";
|
||||
case StorageFileEvent::EMR:
|
||||
return "EMR";
|
||||
case StorageFileEvent::EVENT:
|
||||
return "EVENT";
|
||||
case StorageFileEvent::PARK:
|
||||
return "PARK";
|
||||
case StorageFileEvent::ALL:
|
||||
return "ALL";
|
||||
case StorageFileEvent::END:
|
||||
return "END";
|
||||
|
||||
default:
|
||||
return "UNDEFINE";
|
||||
break;
|
||||
}
|
||||
}
|
||||
void AppManager::AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||
void *context)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
const StatusCode UnInit(void) override;
|
||||
const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||
StatusCode SetSdCardStatus(const SdCardStatus &status) override;
|
||||
const char *StorageFileEventToString(const StorageFileEvent &event) override;
|
||||
void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context);
|
||||
void AppRequestHandleTcp(const char *data, const unsigned int dataLength, ResponseHandle responseHandle,
|
||||
void *context);
|
||||
|
|
|
@ -100,92 +100,116 @@ app_param::app_param(const char *ip, const int &httpPort, const int &tcpPort)
|
|||
}
|
||||
void VAppClient::SetRecordingStatus(const RecordingStatus &status)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
}
|
||||
void VAppClient::SetMicrophoneStatus(const MicrophoneStatus &status)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
}
|
||||
void VAppClient::SetBatteryStatus(const BatteryStatus &status, const int &batteryCapacity)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
}
|
||||
void VAppClient::SetSdCardStatus(const SdCardStatus &status)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
}
|
||||
void VAppClient::DeletedFileMessage(const std::string &file, const StorageFileType &type)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
}
|
||||
void VAppClient::CreatedFileMessage(const std::string &file, const StorageFileType &type)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
}
|
||||
StatusCode VAppMonitor::GetProductInfo(AppGetProductInfo ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetMediaInfo(AppGetMediaInfo ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetTimeZone(const unsigned int &zone)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::EnterRecorder(void)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VAppMonitor::AppClientConnected(std::shared_ptr<VAppClient> &client)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl)
|
||||
|
@ -204,17 +228,25 @@ std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManag
|
|||
}
|
||||
const StatusCode IAppManager::Init(const AppParam ¶m)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IAppManager::UnInit(void)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IAppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IAppManager::SetSdCardStatus(const SdCardStatus &status)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const char *IAppManager::StorageFileEventToString(const StorageFileEvent &event)
|
||||
{
|
||||
return "STATUS_CODE_VIRTUAL_FUNCTION";
|
||||
}
|
|
@ -597,41 +597,68 @@ AppGetFileInfo inline SixFrameHandle::RequestGetFileListParse(const std::string
|
|||
};
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<AppGetFileInfo>>();
|
||||
std::shared_ptr<ParseUrl<AppGetFileInfo>> parseImpl = std::dynamic_pointer_cast<ParseUrl<AppGetFileInfo>>(parse);
|
||||
/**
|
||||
* @brief If there is no "folder" field, it means to obtain all types of files (including: LOOP, EMR, EVENT, PARK).
|
||||
* Example: http://192.168.1.100/app/getfilelist ==> no "folder" field
|
||||
*/
|
||||
parseImpl->mData.mEvent = StorageFileEvent::ALL;
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
return parseImpl->mData;
|
||||
}
|
||||
/**
|
||||
* @brief The code discussion at this stage is a bit confusing, because it is based on the projection of the file types
|
||||
* that mobile apps use to hunt for opponents. If you still have doubts, please refer to the README document.
|
||||
*/
|
||||
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) {
|
||||
cJSON *infoJson = cJSON_CreateArray();
|
||||
if (nullptr == result || nullptr == infoJson) {
|
||||
LogError("MakeResponseResult failed.\n");
|
||||
responseHandle("Device run out of memory.", context);
|
||||
return;
|
||||
}
|
||||
ResponseGetFileList(result, files, info);
|
||||
LogInfo("info.mEvent: %s\n", IAppManager::GetInstance()->StorageFileEventToString(info.mEvent));
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, infoJson);
|
||||
if (StorageFileEvent::ALL == info.mEvent) { // "ALL" means that all types of files are retrieved once.
|
||||
for (int i = 0; i < static_cast<int>(StorageFileEvent::ALL); i++) {
|
||||
files.clear();
|
||||
info.mEvent = static_cast<StorageFileEvent>(i);
|
||||
LogInfo("GetStorageFileList: %s\n", IAppManager::GetInstance()->StorageFileEventToString(info.mEvent));
|
||||
mAppMonitor->GetStorageFileList(info, files);
|
||||
ResponseGetFileList(infoJson, files, info);
|
||||
}
|
||||
}
|
||||
else if (StorageFileEvent::LOOP == info.mEvent) { // "LOOP" means to get all files at once.
|
||||
info.mEvent = StorageFileEvent::ALL;
|
||||
mAppMonitor->GetStorageFileList(info, files);
|
||||
ResponseGetFileList(infoJson, files, info);
|
||||
}
|
||||
else {
|
||||
mAppMonitor->GetStorageFileList(info, files);
|
||||
ResponseGetFileList(infoJson, files, info);
|
||||
}
|
||||
ResponseJsonString(result, responseHandle, context);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void inline SixFrameHandle::ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> ¶m,
|
||||
void inline SixFrameHandle::ResponseGetFileList(cJSON *resultInfo, const std::vector<AppGetFileList> ¶m,
|
||||
const AppGetFileInfo &fileInfo)
|
||||
{
|
||||
cJSON *info = cJSON_CreateArray();
|
||||
// cJSON *info = cJSON_CreateArray();
|
||||
cJSON *folder = cJSON_CreateObject();
|
||||
cJSON *files = cJSON_CreateArray();
|
||||
if (nullptr == info || nullptr == folder || nullptr == files) {
|
||||
if (nullptr == resultInfo || nullptr == folder || nullptr == files) {
|
||||
LogError("cJSON_CreateArray failed.\n");
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
|
||||
cJSON_AddItemToArray(info, folder);
|
||||
// cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
|
||||
cJSON_AddItemToArray(resultInfo, folder);
|
||||
cJSON_AddStringToObject(folder, "folder", PrintfFileEvent(fileInfo));
|
||||
cJSON_AddNumberToObject(folder, "count", param.size());
|
||||
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) {
|
||||
|
@ -983,9 +1010,18 @@ void SixFrameHandle::ResponseJsonString(cJSON *json, ResponseHandle responseHand
|
|||
const char *SixFrameHandle::PrintfFileEvent(const AppGetFileInfo &fileInfo)
|
||||
{
|
||||
switch (fileInfo.mEvent) {
|
||||
case StorageFileEvent::ALL:
|
||||
case StorageFileEvent::LOOP: {
|
||||
return "loop";
|
||||
break;
|
||||
}
|
||||
case StorageFileEvent::EMR: {
|
||||
return "emr";
|
||||
}
|
||||
case StorageFileEvent::EVENT: {
|
||||
return "event";
|
||||
}
|
||||
case StorageFileEvent::PARK: {
|
||||
return "park";
|
||||
}
|
||||
|
||||
default: {
|
||||
|
|
|
@ -143,18 +143,19 @@ bool SqliteHandle::SyncFile(const SyncFileInfo &info)
|
|||
bool SqliteHandle::SearchFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info)
|
||||
{
|
||||
std::string sqlAnd = " ";
|
||||
if (types.size() > 1) {
|
||||
sqlAnd = " AND ";
|
||||
}
|
||||
// if (types.size() > 1) {
|
||||
// sqlAnd = " AND ";
|
||||
// }
|
||||
constexpr FileCreateType END_MEANS_SEARCHING_ALL_FILES = FileCreateType::END;
|
||||
std::stringstream sqlStream;
|
||||
if (types.size() == 1 && types[0] == END_MEANS_SEARCHING_ALL_FILES) {
|
||||
sqlStream << "SELECT * from " FILES_TABLE << ";";
|
||||
}
|
||||
else {
|
||||
sqlStream << "SELECT * from " FILES_TABLE;
|
||||
sqlStream << "SELECT * from " FILES_TABLE " WHERE ";
|
||||
for (auto &type : types) {
|
||||
sqlStream << sqlAnd << "WHERE " FILE_TYPE " = '" << ConvertFileTypeToString(type) << "'";
|
||||
sqlStream << sqlAnd << FILE_TYPE " = '" << ConvertFileTypeToString(type) << "'";
|
||||
sqlAnd = " OR ";
|
||||
}
|
||||
sqlStream << ";";
|
||||
}
|
||||
|
@ -312,8 +313,9 @@ bool SqliteHandle::SearchFiles(sqlite3 *db, const std::string &sql, std::vector<
|
|||
* TEXT, size INTEGER, status TEXT, duration INTEGER);
|
||||
* 4 5 6
|
||||
*/
|
||||
if (6 != argc) {
|
||||
LogError("Something wrong happened.\n");
|
||||
constexpr int TABLE_MEMBER_NUM = 7;
|
||||
if (TABLE_MEMBER_NUM != argc) {
|
||||
LogError("Something wrong happened, argc = %d.\n", argc);
|
||||
return 0;
|
||||
}
|
||||
std::vector<SyncFileInfo> *info = (std::vector<SyncFileInfo> *)data;
|
||||
|
|
|
@ -160,8 +160,8 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageInfo)
|
|||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList)
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_ALL
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_ALL)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
|
@ -171,6 +171,50 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList)
|
|||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_LOOP
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_LOOP)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList(StorageFileEvent::LOOP);
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_EMR
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_EMR)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList(StorageFileEvent::EMR);
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_EVENT
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_EVENT)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList(StorageFileEvent::EVENT);
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_PARK
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_GetStorageFileList_PARK)
|
||||
{
|
||||
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList(StorageFileEvent::PARK);
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_AUTO_SetParamValue
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_SetParamValue)
|
||||
{
|
||||
|
|
|
@ -185,8 +185,8 @@ void AppManagerTestTool::MockGetStorageFileList(const StorageFileEvent &event)
|
|||
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))));
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
ServersMock::GetInstance()->MockGetStorageFileList(event);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user