Improve:SixFrame protocol.

This commit is contained in:
Fancy code 2024-03-25 14:46:29 +08:00
parent 9a10d9e16a
commit 4780a46e8a
4 changed files with 73 additions and 13 deletions

View File

@ -91,7 +91,7 @@ StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::v
AppGetFileList file; AppGetFileList file;
file.mCreateTime_s = 123456789; file.mCreateTime_s = 123456789;
file.mDuration = 15; file.mDuration = 15;
file.mName = "/video/test.mp4"; file.mName = "/DCIM/2024/01/15/20240115135444-20240115135504.mp4";
file.mSize = 1024; file.mSize = 1024;
file.mType = StorageFileType::VIDEO; file.mType = StorageFileType::VIDEO;
param.push_back(file); param.push_back(file);

View File

@ -22,6 +22,7 @@ using std::placeholders::_3;
// using std::placeholders::_4; // using std::placeholders::_4;
// clang-format off // clang-format off
const char *CJSON_INFO_STRING = "info"; const char *CJSON_INFO_STRING = "info";
const char *CJSON_FILES_STRING = "files";
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo"; const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr"; const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr";
const char *APP_GET_MEDIA_INFO = "/app/getmediainfo"; const char *APP_GET_MEDIA_INFO = "/app/getmediainfo";
@ -38,6 +39,8 @@ const char *APP_SET_PARAM_VALUE = "/app/setparamvalue";
const char *APP_ENTER_RECORDER = "/app/enterrecorder"; const char *APP_ENTER_RECORDER = "/app/enterrecorder";
const char *APP_PLAYBACK = "/app/playback"; const char *APP_PLAYBACK = "/app/playback";
const char *APP_UPLOAD_FILE = "/upload"; const char *APP_UPLOAD_FILE = "/upload";
// /app/getparamvalue?param=rec
// /app/exitrecorder
// clang-format on // clang-format on
constexpr bool SET_REQUEST_RESPONSE = true; constexpr bool SET_REQUEST_RESPONSE = true;
SixFrameHandle::SixFrameHandle() SixFrameHandle::SixFrameHandle()
@ -371,7 +374,7 @@ AppGetFileInfo inline SixFrameHandle::RequestGetFileListParse(const std::string
std::dynamic_pointer_cast<ParseUrl<AppGetFileInfo>>(parse); std::dynamic_pointer_cast<ParseUrl<AppGetFileInfo>>(parse);
if ("folder" == key) { if ("folder" == key) {
if ("loop" == value) { if ("loop" == value) {
parseyImpl->mData.mEvent = StorageFileEvent::END; parseyImpl->mData.mEvent = StorageFileEvent::LOOP;
} }
if ("emr" == value) { if ("emr" == value) {
parseyImpl->mData.mEvent = StorageFileEvent::END; parseyImpl->mData.mEvent = StorageFileEvent::END;
@ -407,30 +410,57 @@ void SixFrameHandle::RequestGetFileList(const std::string &url, ResponseHandle r
responseHandle("Device run out of memory.", context); responseHandle("Device run out of memory.", context);
return; return;
} }
ResponseGetFileList(result, param); ResponseGetFileList(result, param, info);
ResponseJsonString(result, responseHandle, context); ResponseJsonString(result, responseHandle, context);
cJSON_Delete(result); cJSON_Delete(result);
} }
void inline SixFrameHandle::ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> &param) /**
* @brief
{
"result": 0,
"info": [{
"folder": "loop",
"count": 1,
"files": [{
"name": "/DCIM/2024/01/15/20240115135444-20240115135504.mp4",
"duration": 15,
"size": 1024,
"createtime": 123456789,
"type": 0
}]
}]
}
* @param result
* @param param
* @param fileInfo
*/
void inline SixFrameHandle::ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> &param,
const AppGetFileInfo &fileInfo)
{ {
cJSON *info = cJSON_CreateArray(); cJSON *info = cJSON_CreateArray();
if (nullptr == info) { cJSON *folder = cJSON_CreateObject();
cJSON *files = cJSON_CreateArray();
if (nullptr == info || nullptr == folder || nullptr == files) {
LogError("cJSON_CreateArray failed.\n"); LogError("cJSON_CreateArray failed.\n");
return; return;
} }
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info); cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
for (const auto &fileInfo : param) { cJSON_AddItemToArray(info, folder);
for (const auto &fileList : param) {
cJSON_AddStringToObject(folder, "folder", PrintfFileEvent(fileInfo));
cJSON_AddNumberToObject(folder, "count", param.size());
cJSON *file = nullptr; cJSON *file = nullptr;
file = cJSON_CreateObject(); file = cJSON_CreateObject();
if (nullptr != file) { if (nullptr != file) {
cJSON_AddItemToArray(info, file); cJSON_AddItemToArray(files, file);
cJSON_AddStringToObject(file, "name", fileInfo.mName.c_str()); cJSON_AddStringToObject(file, "name", fileList.mName.c_str());
cJSON_AddNumberToObject(file, "duration", fileInfo.mDuration); cJSON_AddNumberToObject(file, "duration", fileList.mDuration);
cJSON_AddNumberToObject(file, "size", fileInfo.mSize); cJSON_AddNumberToObject(file, "size", fileList.mSize);
cJSON_AddNumberToObject(file, "createtime", fileInfo.mCreateTime_s); cJSON_AddNumberToObject(file, "createtime", fileList.mCreateTime_s);
cJSON_AddNumberToObject(file, "type", static_cast<int>(fileInfo.mType)); 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)
{ {
@ -640,6 +670,21 @@ void SixFrameHandle::ResponseJsonString(cJSON *json, ResponseHandle responseHand
responseHandle("Device run out of memory.", context); 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

@ -78,7 +78,7 @@ private:
void ResponseGetStorageInfo(cJSON *result, const std::vector<AppGetStorageInfo> &param); void ResponseGetStorageInfo(cJSON *result, const std::vector<AppGetStorageInfo> &param);
AppGetFileInfo RequestGetFileListParse(const std::string &url); AppGetFileInfo RequestGetFileListParse(const std::string &url);
void RequestGetFileList(const std::string &url, ResponseHandle responseHandle, void *context); void RequestGetFileList(const std::string &url, ResponseHandle responseHandle, void *context);
void ResponseGetFileList(cJSON *result, const std::vector<AppGetFileList> &param); 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);
@ -93,6 +93,7 @@ private:
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); 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"