mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Improve:SixFrame protocol code.
This commit is contained in:
parent
ffce54a373
commit
c01a4f636f
|
@ -19,7 +19,7 @@
|
|||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
using std::placeholders::_3;
|
||||
using std::placeholders::_4;
|
||||
// using std::placeholders::_4;
|
||||
const char *CJSON_INFO_STRING = "info";
|
||||
const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo";
|
||||
const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr";
|
||||
|
@ -31,19 +31,18 @@ const char *APP_UPLOAD_FILE = "/upload";
|
|||
SixFrameHandle::SixFrameHandle()
|
||||
{
|
||||
mAppMonitor = std::make_shared<VAppMonitor>();
|
||||
mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3, _4);
|
||||
mResquesHandleFunc[APP_GET_DEVICE_ATTR] = std::bind(&SixFrameHandle::RequestGetDeviceAttr, this, _1, _2, _3, _4);
|
||||
mResquesHandleFunc[APP_GET_MEDIA_INFO] = std::bind(&SixFrameHandle::RequestGetMediaInfo, this, _1, _2, _3, _4);
|
||||
mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3, _4);
|
||||
mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3, _4);
|
||||
mResquesHandleFunc[APP_SET_DATE_TIME] = std::bind(&SixFrameHandle::RequestSetDateTime, this, _1, _2, _3, _4);
|
||||
mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3, _4);
|
||||
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3,_4);
|
||||
mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_GET_DEVICE_ATTR] = std::bind(&SixFrameHandle::RequestGetDeviceAttr, 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_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_SET_DATE_TIME] = std::bind(&SixFrameHandle::RequestSetDateTime, this, _1, _2, _3);
|
||||
mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3);
|
||||
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _);
|
||||
}
|
||||
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||
void *context)
|
||||
{
|
||||
std::multimap<std::string, std::string> paramsMap;
|
||||
const std::string urlStr2 = url;
|
||||
LogInfo("URL = %s\n", urlStr2.c_str());
|
||||
size_t queryStartPos = urlStr2.find('?');
|
||||
|
@ -56,10 +55,10 @@ void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength
|
|||
}
|
||||
LogInfo("command = %s\n", command.c_str());
|
||||
// ExtractParamsFromUrl(urlStr2, paramsMap);
|
||||
RequestHandle2(command, paramsMap, urlStr2, responseHandle, context);
|
||||
RequestHandle2(command, urlStr2, responseHandle, context);
|
||||
}
|
||||
void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap<std::string, std::string> ¶msMap,
|
||||
ParseUrlResultFunc resultHandle, std::shared_ptr<VParseUrl> &context)
|
||||
void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, ParseUrlResultFunc resultHandle,
|
||||
std::shared_ptr<VParseUrl> &context)
|
||||
{
|
||||
size_t queryStartPos = url.find('?');
|
||||
if (queryStartPos != std::string::npos && queryStartPos + 1 < url.length()) {
|
||||
|
@ -79,26 +78,24 @@ void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap<
|
|||
}
|
||||
}
|
||||
}
|
||||
void SixFrameHandle::RequestHandle2(const std::string command, std::multimap<std::string, std::string> ¶msMap,
|
||||
const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestHandle2(const std::string command, const std::string &url, ResponseHandle responseHandle,
|
||||
void *context)
|
||||
{
|
||||
auto result = mResquesHandleFunc.find(command);
|
||||
if (result != mResquesHandleFunc.end()) {
|
||||
(*result).second(paramsMap, url, responseHandle, context);
|
||||
(*result).second(url, responseHandle, context);
|
||||
}
|
||||
else {
|
||||
LogError("Unknown command.\n");
|
||||
DoNothing(paramsMap, url, responseHandle, context);
|
||||
DoNothing(url, responseHandle, context);
|
||||
}
|
||||
}
|
||||
void SixFrameHandle::DoNothing(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::DoNothing(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
//
|
||||
responseHandle("Unknown command.", context);
|
||||
}
|
||||
void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestGetProductInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetProductInfo.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
@ -110,8 +107,7 @@ void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::strin
|
|||
free(resultStr);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void SixFrameHandle::RequestGetDeviceAttr(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
@ -138,8 +134,7 @@ void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDev
|
|||
cJSON_AddStringToObject(info, "curcamid", param.mCurrentCameraID.c_str());
|
||||
cJSON_AddStringToObject(info, "wifireboot", param.mWifiReboot.c_str());
|
||||
}
|
||||
void SixFrameHandle::RequestGetMediaInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestGetMediaInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
@ -160,8 +155,7 @@ void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeid
|
|||
cJSON_AddStringToObject(info, "softver", param.mTransport.c_str());
|
||||
cJSON_AddNumberToObject(info, "otaver", param.mPort);
|
||||
}
|
||||
void SixFrameHandle::RequestGetSdCardInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestGetSdCardInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
@ -182,8 +176,7 @@ void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdC
|
|||
cJSON_AddNumberToObject(info, "free", param.mFree);
|
||||
cJSON_AddNumberToObject(info, "total", param.mTotal);
|
||||
}
|
||||
void SixFrameHandle::RequestGetBatteryInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
@ -212,8 +205,7 @@ AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(const std::string
|
|||
}
|
||||
};
|
||||
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
|
||||
std::multimap<std::string, std::string> paramsMap;
|
||||
ExtractParamsFromUrl(url, paramsMap, parseFunc, parse);
|
||||
ExtractParamsFromUrl(url, parseFunc, parse);
|
||||
std::shared_ptr<ParseUrl<std::string>> parseyImpl = std::dynamic_pointer_cast<ParseUrl<std::string>>(parse);
|
||||
if (14 != parseyImpl->mData.length()) {
|
||||
LogError("date parse failed.\n");
|
||||
|
@ -233,8 +225,7 @@ AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(const std::string
|
|||
unsigned int second = std::stoi(secondStr);
|
||||
return AppSetDateTime(year, month, day, hour, minute, second);
|
||||
}
|
||||
void SixFrameHandle::RequestSetDateTime(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestGetDeviceAttr.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
@ -247,8 +238,7 @@ void SixFrameHandle::RequestSetDateTime(std::multimap<std::string, std::string>
|
|||
free(resultStr);
|
||||
cJSON_Delete(result);
|
||||
}
|
||||
void SixFrameHandle::RequestUpload(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context)
|
||||
void SixFrameHandle::RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context)
|
||||
{
|
||||
LogInfo("RequestUpload.\n");
|
||||
char *resultStr = nullptr;
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
using ResquesHandleFunc =
|
||||
std::function<void(std::multimap<std::string, std::string> &, const std::string &, ResponseHandle, void *)>;
|
||||
using ResquesHandleFunc = std::function<void(const std::string &, ResponseHandle, void *)>;
|
||||
class VParseUrl
|
||||
{
|
||||
public:
|
||||
|
@ -54,31 +53,23 @@ public:
|
|||
void *context) override;
|
||||
|
||||
private:
|
||||
void ExtractParamsFromUrl(const std::string &url, std::multimap<std::string, std::string> ¶msMap,
|
||||
ParseUrlResultFunc resultHandle, std::shared_ptr<VParseUrl> &context);
|
||||
void RequestHandle2(const std::string command, std::multimap<std::string, std::string> ¶msMap,
|
||||
const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void DoNothing(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestGetDeviceAttr(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void ExtractParamsFromUrl(const std::string &url, ParseUrlResultFunc resultHandle,
|
||||
std::shared_ptr<VParseUrl> &context);
|
||||
void RequestHandle2(const std::string command, const std::string &url, ResponseHandle responseHandle,
|
||||
void *context);
|
||||
void DoNothing(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void RequestGetProductInfo(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void RequestGetDeviceAttr(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr ¶m);
|
||||
void RequestGetMediaInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestGetMediaInfo(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo ¶m);
|
||||
void RequestGetSdCardInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestGetSdCardInfo(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo ¶m);
|
||||
void RequestGetBatteryInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestGetBatteryInfo(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m);
|
||||
AppSetDateTime RequestSetDateTimeParse(const std::string &url);
|
||||
void RequestSetDateTime(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestUpload(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||
ResponseHandle responseHandle, void *context);
|
||||
void RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
void RequestUpload(const std::string &url, ResponseHandle responseHandle, void *context);
|
||||
|
||||
private:
|
||||
cJSON *MakeResponseResult(const ResposeResult result);
|
||||
|
|
|
@ -87,6 +87,12 @@ StatusCode AppMonitorTest::GetBatteryInfoTrace(AppGetBatteryInfo ¶m)
|
|||
StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m)
|
||||
{
|
||||
LogInfo("AppMonitorTest::SetDateTime\n");
|
||||
LogInfo("mYear = %u\n", param.mYear);
|
||||
LogInfo("mMonth = %02u\n", param.mMonth);
|
||||
LogInfo("mDay = %02u\n", param.mDay);
|
||||
LogInfo("mHour = %02u\n", param.mHour);
|
||||
LogInfo("mMinute = %02u\n", param.mMinute);
|
||||
LogInfo("mSecond = %02u\n", param.mSecond);
|
||||
StatusCode code = SetDateTimeTrace(param);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return VAppMonitor::SetDateTime(param);
|
||||
|
|
Loading…
Reference in New Issue
Block a user