Improve:SixFrame protocol.
This commit is contained in:
parent
7d706cc822
commit
936fc127da
|
@ -88,13 +88,22 @@ StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||||
}
|
}
|
||||||
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||||
{
|
{
|
||||||
|
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
||||||
AppGetFileList file;
|
AppGetFileList file;
|
||||||
file.mCreateTime_s = 123456789;
|
file.mCreateTime_s = 123456789;
|
||||||
file.mDuration = 15;
|
file.mDuration = 15;
|
||||||
file.mName = "/DCIM/2024/01/15/20240115135444-20240115135504.mp4";
|
file.mName = "/DCIM/2024/01/15/20240115135521-20240115135540.mp4";
|
||||||
file.mSize = 1024;
|
file.mSize = 1024;
|
||||||
file.mType = StorageFileType::VIDEO;
|
file.mType = StorageFileType::VIDEO;
|
||||||
param.push_back(file);
|
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);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||||
|
@ -115,3 +124,8 @@ StatusCode AppMonitor::UploadFile(AppUploadFile ¶m)
|
||||||
//
|
//
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||||
|
{
|
||||||
|
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
|
@ -36,5 +36,6 @@ public:
|
||||||
StatusCode EnterRecorder(void) override;
|
StatusCode EnterRecorder(void) override;
|
||||||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||||
|
StatusCode GetThumbnail(AppGetThumbnail ¶m) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -79,6 +79,9 @@ enum class StorageFileEvent
|
||||||
LOOP = 0,
|
LOOP = 0,
|
||||||
PIR,
|
PIR,
|
||||||
CRASH,
|
CRASH,
|
||||||
|
EMR,
|
||||||
|
EVENT,
|
||||||
|
PARK,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
enum class MicStatus
|
enum class MicStatus
|
||||||
|
@ -301,6 +304,12 @@ 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:
|
||||||
|
@ -322,6 +331,7 @@ public:
|
||||||
virtual StatusCode EnterRecorder(void);
|
virtual StatusCode EnterRecorder(void);
|
||||||
virtual StatusCode AppPlayback(const PlayBackEvent &event);
|
virtual StatusCode AppPlayback(const PlayBackEvent &event);
|
||||||
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
||||||
|
virtual StatusCode GetThumbnail(AppGetThumbnail ¶m);
|
||||||
};
|
};
|
||||||
typedef struct app_param
|
typedef struct app_param
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,6 +66,7 @@ StatusCode VAppMonitor::AppPlayback(const PlayBackEvent &event)
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
StatusCode VAppMonitor::UploadFile(AppUploadFile ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
StatusCode VAppMonitor::UploadFile(AppUploadFile ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
StatusCode VAppMonitor::GetThumbnail(AppGetThumbnail ¶m) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
std::shared_ptr<IAppManager> &IAppManager::GetInstance(std::shared_ptr<IAppManager> *impl)
|
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>();
|
||||||
|
|
|
@ -39,6 +39,7 @@ 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";
|
||||||
|
const char *APP_GET_THUMBNAIL = "/app/getthumbnail";
|
||||||
// /app/getparamvalue?param=rec
|
// /app/getparamvalue?param=rec
|
||||||
// /app/exitrecorder
|
// /app/exitrecorder
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
@ -63,6 +64,7 @@ SixFrameHandle::SixFrameHandle()
|
||||||
mResquesHandleFunc[APP_ENTER_RECORDER] = std::bind(&SixFrameHandle::RequestEnterRecorder, 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_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,
|
||||||
|
@ -377,13 +379,13 @@ AppGetFileInfo inline SixFrameHandle::RequestGetFileListParse(const std::string
|
||||||
parseyImpl->mData.mEvent = StorageFileEvent::LOOP;
|
parseyImpl->mData.mEvent = StorageFileEvent::LOOP;
|
||||||
}
|
}
|
||||||
if ("emr" == value) {
|
if ("emr" == value) {
|
||||||
parseyImpl->mData.mEvent = StorageFileEvent::END;
|
parseyImpl->mData.mEvent = StorageFileEvent::EMR;
|
||||||
}
|
}
|
||||||
if ("event" == value) {
|
if ("event" == value) {
|
||||||
parseyImpl->mData.mEvent = StorageFileEvent::END;
|
parseyImpl->mData.mEvent = StorageFileEvent::EVENT;
|
||||||
}
|
}
|
||||||
if ("park" == value) {
|
if ("park" == value) {
|
||||||
parseyImpl->mData.mEvent = StorageFileEvent::END;
|
parseyImpl->mData.mEvent = StorageFileEvent::PARK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ("start" == key) {
|
if ("start" == key) {
|
||||||
|
@ -636,6 +638,28 @@ void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle respon
|
||||||
ResponseJsonString(result, responseHandle, context);
|
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>> parseyImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||||
|
if ("file" == key) {
|
||||||
|
parseyImpl->mData = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
|
||||||
|
std::shared_ptr<ParseUrl<std::string>> parseyImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||||
|
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||||
|
return parseyImpl->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";
|
||||||
|
|
|
@ -89,6 +89,8 @@ private:
|
||||||
void RequestPlayback(const std::string &url, ResponseHandle responseHandle, void *context);
|
void RequestPlayback(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||||
void RequestEnterRecorder(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);
|
||||||
|
|
|
@ -57,7 +57,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_Demo0)
|
||||||
IAppManager::GetInstance()->Init(mAppParam);
|
IAppManager::GetInstance()->Init(mAppParam);
|
||||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
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(20000));
|
||||||
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
|
||||||
|
|
|
@ -85,6 +85,43 @@ static void response_handle(const char *responseStr, void *context)
|
||||||
websWrite(wp, "%s", responseStr);
|
websWrite(wp, "%s", responseStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void get_thumbnail_handle(const char *thumbnailUrl, void *context)
|
||||||
|
{
|
||||||
|
struct Webs *wp = (struct Webs *)context;
|
||||||
|
if (nullptr == thumbnailUrl) {
|
||||||
|
LogError("thumbnailUrl is nullptr.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FILE *file = nullptr;
|
||||||
|
unsigned char *buffer = nullptr;
|
||||||
|
size_t bytesRead = 0;
|
||||||
|
long int fsize = 0;
|
||||||
|
file = fopen(thumbnailUrl, "rb");
|
||||||
|
if (file == nullptr) {
|
||||||
|
LogError("Open picture failed[%s].\n", thumbnailUrl);
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
fseek(file, 0, SEEK_END);
|
||||||
|
fsize = ftell(file);
|
||||||
|
rewind(file);
|
||||||
|
buffer = (unsigned char *)malloc(fsize);
|
||||||
|
if (!buffer) {
|
||||||
|
LogError("malloc failed.\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||||
|
websWriteBlock(wp, (cchar *)buffer, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
END:
|
||||||
|
if (buffer) {
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
if (file) {
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
static bool AppRequestHandle(Webs *wp)
|
static bool AppRequestHandle(Webs *wp)
|
||||||
{
|
{
|
||||||
websSetStatus(wp, 200);
|
websSetStatus(wp, 200);
|
||||||
|
@ -129,53 +166,12 @@ static bool AppUploadHandle(Webs *wp)
|
||||||
}
|
}
|
||||||
static bool AppGetThumbnail(Webs *wp)
|
static bool AppGetThumbnail(Webs *wp)
|
||||||
{
|
{
|
||||||
LogInfo("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n");
|
LogInfo("AppGetThumbnail url = %s\n", wp->url);
|
||||||
websSetStatus(wp, 200);
|
websSetStatus(wp, 200);
|
||||||
websWriteHeaders(wp, UNKNOWN_LENGTH, 0);
|
websWriteHeaders(wp, UNKNOWN_LENGTH, 0);
|
||||||
websWriteHeader(wp, "Content-Type", "image/jpeg");
|
websWriteHeader(wp, "Content-Type", "image/jpeg");
|
||||||
websWriteEndHeaders(wp);
|
websWriteEndHeaders(wp);
|
||||||
// gHttpHandle(wp->url, 0, response_handle, wp);
|
gHttpHandle(wp->url, 0, get_thumbnail_handle, wp);
|
||||||
// websWrite(wp, "ssssssssssssssssssssssssss");
|
|
||||||
|
|
||||||
char imagePath[] = "./34a396526922a33e97906920dbfef2a5.jpg";
|
|
||||||
FILE *file = nullptr;
|
|
||||||
unsigned char *buffer = nullptr;
|
|
||||||
size_t bytesRead = 0;
|
|
||||||
long int fsize = 0;
|
|
||||||
/* 打开图片文件 */
|
|
||||||
file = fopen(imagePath, "rb");
|
|
||||||
if (file == nullptr) {
|
|
||||||
/* 文件打开失败,返回 404 错误 */
|
|
||||||
LogError("Open picture failed.\n");
|
|
||||||
goto END;
|
|
||||||
}
|
|
||||||
// 获取文件大小
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
fsize = ftell(file);
|
|
||||||
rewind(file);
|
|
||||||
// 分配足够大的缓冲区来存储文件内容
|
|
||||||
buffer = (unsigned char *)malloc(fsize + 1);
|
|
||||||
if (!buffer) {
|
|
||||||
LogError("malloc failed.\n");
|
|
||||||
fclose(file);
|
|
||||||
goto END;
|
|
||||||
}
|
|
||||||
memset(buffer, 0, fsize + 1);
|
|
||||||
// 读取文件内容到缓冲区
|
|
||||||
bytesRead = fread(buffer, 1, fsize, file);
|
|
||||||
if (bytesRead != fsize) {
|
|
||||||
LogError("fread picture failed.\n");
|
|
||||||
free(buffer);
|
|
||||||
fclose(file);
|
|
||||||
goto END;
|
|
||||||
}
|
|
||||||
// websWrite(wp, "%s", buffer);
|
|
||||||
websWriteBlock(wp, (cchar *)buffer, fsize);
|
|
||||||
|
|
||||||
END:
|
|
||||||
if (buffer) {
|
|
||||||
free(buffer);
|
|
||||||
}
|
|
||||||
websDone(wp);
|
websDone(wp);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -209,13 +205,11 @@ StatusCode WebServerInit(const WebServerParam webParam)
|
||||||
gHttpHandle = webParam.mHttpRequestHandle;
|
gHttpHandle = webParam.mHttpRequestHandle;
|
||||||
websDefineHandler("appRequestHandle", 0, AppRequestHandle, 0, 0);
|
websDefineHandler("appRequestHandle", 0, AppRequestHandle, 0, 0);
|
||||||
websAddRoute("/app", "appRequestHandle", 0);
|
websAddRoute("/app", "appRequestHandle", 0);
|
||||||
}
|
|
||||||
if (nullptr != webParam.mHttpRequestHandle) {
|
|
||||||
websDefineHandler("AppUploadHandle", 0, AppUploadHandle, 0, 0);
|
websDefineHandler("AppUploadHandle", 0, AppUploadHandle, 0, 0);
|
||||||
websAddRoute("/upload", "AppUploadHandle", 0);
|
websAddRoute("/upload", "AppUploadHandle", 0);
|
||||||
}
|
|
||||||
websDefineHandler("AppGetThumbnail", 0, AppGetThumbnail, 0, 0);
|
websDefineHandler("AppGetThumbnail", 0, AppGetThumbnail, 0, 0);
|
||||||
websAddRoute("/app/getthumbnail", "AppGetThumbnail", 0);
|
websAddRoute("/app/getthumbnail", "AppGetThumbnail", 0);
|
||||||
|
}
|
||||||
websServiceEvents(&finished);
|
websServiceEvents(&finished);
|
||||||
logmsg(1, "Instructed to exit\n");
|
logmsg(1, "Instructed to exit\n");
|
||||||
websClose();
|
websClose();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user