Add:SixFrame protocol code.
This commit is contained in:
parent
7b3691bd36
commit
ffce54a373
|
@ -61,8 +61,15 @@ typedef struct app_get_media_info
|
||||||
} AppGetMeidaInfo;
|
} AppGetMeidaInfo;
|
||||||
enum class SdCardStatus
|
enum class SdCardStatus
|
||||||
{
|
{
|
||||||
UNMOUNT = 0,
|
NORMAL = 0,
|
||||||
END
|
UNFORMATTED = 1,
|
||||||
|
NOT_INSERTED = 2,
|
||||||
|
CARD_DAMAGED = 3,
|
||||||
|
CARD_LOCKED = 10,
|
||||||
|
SLOW_CARD = 11,
|
||||||
|
FORMAT_REQUIRED = 12,
|
||||||
|
FORMATTING = 13,
|
||||||
|
END = 99
|
||||||
};
|
};
|
||||||
typedef struct app_get_sd_card_info
|
typedef struct app_get_sd_card_info
|
||||||
{
|
{
|
||||||
|
@ -76,6 +83,36 @@ 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
|
||||||
|
{
|
||||||
|
app_get_battery_info()
|
||||||
|
{
|
||||||
|
mCapacity = 0;
|
||||||
|
mChargeStatus = ChargeStatus::END;
|
||||||
|
}
|
||||||
|
int mCapacity;
|
||||||
|
ChargeStatus mChargeStatus;
|
||||||
|
} AppGetBatteryInfo;
|
||||||
|
typedef struct app_set_date_time
|
||||||
|
{
|
||||||
|
app_set_date_time(const unsigned int year, const unsigned int month, const unsigned int day,
|
||||||
|
const unsigned int hour, const unsigned int minute, const unsigned int second)
|
||||||
|
: mYear(year), mMonth(month), mDay(day), mHour(hour), mMinute(minute), mSecond(second)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
const unsigned int mYear;
|
||||||
|
const unsigned int mMonth;
|
||||||
|
const unsigned int mDay;
|
||||||
|
const unsigned int mHour;
|
||||||
|
const unsigned int mMinute;
|
||||||
|
const unsigned int mSecond;
|
||||||
|
} AppSetDateTime;
|
||||||
typedef struct app_upload_file
|
typedef struct app_upload_file
|
||||||
{
|
{
|
||||||
app_upload_file(const std::string filePath, const UploadCommand command) : mFilePath(filePath), mCommand(command)
|
app_upload_file(const std::string filePath, const UploadCommand command) : mFilePath(filePath), mCommand(command)
|
||||||
|
@ -95,6 +132,8 @@ public:
|
||||||
virtual StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m);
|
virtual StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m);
|
||||||
virtual StatusCode GetMediaInfo(AppGetMeidaInfo ¶m);
|
virtual StatusCode GetMediaInfo(AppGetMeidaInfo ¶m);
|
||||||
virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m);
|
virtual StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m);
|
||||||
|
virtual StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m);
|
||||||
|
virtual StatusCode SetDateTime(AppSetDateTime ¶m);
|
||||||
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
virtual StatusCode UploadFile(AppUploadFile ¶m);
|
||||||
};
|
};
|
||||||
typedef struct app_param
|
typedef struct app_param
|
||||||
|
|
|
@ -30,6 +30,14 @@ StatusCode inline VAppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
|
StatusCode inline VAppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
StatusCode inline VAppMonitor::SetDateTime(AppSetDateTime ¶m)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
StatusCode inline VAppMonitor::UploadFile(AppUploadFile ¶m)
|
StatusCode inline VAppMonitor::UploadFile(AppUploadFile ¶m)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
|
|
@ -19,22 +19,26 @@
|
||||||
using std::placeholders::_1;
|
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";
|
const char *CJSON_INFO_STRING = "info";
|
||||||
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";
|
||||||
const char *APP_GET_SD_CARD_INFO = "/app/getsdinfo";
|
const char *APP_GET_SD_CARD_INFO = "/app/getsdinfo";
|
||||||
|
const char *APP_GET_BATTERY_INFO = "/app/getbatteryinfo";
|
||||||
|
const char *APP_SET_DATE_TIME = "/app/setsystime";
|
||||||
const char *APP_UPLOAD_FILE = "/upload";
|
const char *APP_UPLOAD_FILE = "/upload";
|
||||||
SixFrameHandle::SixFrameHandle()
|
SixFrameHandle::SixFrameHandle()
|
||||||
{
|
{
|
||||||
mAppMonitor = std::make_shared<VAppMonitor>();
|
mAppMonitor = std::make_shared<VAppMonitor>();
|
||||||
mResquesHandleFunc[APP_GET_PRODUCT_INFO] = std::bind(&SixFrameHandle::RequestGetProductInfo, this, _1, _2, _3);
|
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);
|
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);
|
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);
|
mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3, _4);
|
||||||
mResquesHandleFunc[APP_UPLOAD_FILE] = std::bind(&SixFrameHandle::RequestUpload, this, _1, _2, _3);
|
mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3, _4);
|
||||||
// mResquesHandleFunc["favicon.ico"] = std::bind(&SixFrameHandle::DoNothing, this, _1, _2, _3);
|
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);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||||
void *context)
|
void *context)
|
||||||
|
@ -51,10 +55,11 @@ void SixFrameHandle::RequestHandle(const char *url, const unsigned int urlLength
|
||||||
command = urlStr2.substr(0, urlStr2.length());
|
command = urlStr2.substr(0, urlStr2.length());
|
||||||
}
|
}
|
||||||
LogInfo("command = %s\n", command.c_str());
|
LogInfo("command = %s\n", command.c_str());
|
||||||
ExtractParamsFromUrl(urlStr2, paramsMap);
|
// ExtractParamsFromUrl(urlStr2, paramsMap);
|
||||||
RequestHandle2(command, paramsMap, responseHandle, context);
|
RequestHandle2(command, paramsMap, urlStr2, responseHandle, context);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap<std::string, std::string> ¶msMap)
|
void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap<std::string, std::string> ¶msMap,
|
||||||
|
ParseUrlResultFunc resultHandle, std::shared_ptr<VParseUrl> &context)
|
||||||
{
|
{
|
||||||
size_t queryStartPos = url.find('?');
|
size_t queryStartPos = url.find('?');
|
||||||
if (queryStartPos != std::string::npos && queryStartPos + 1 < url.length()) {
|
if (queryStartPos != std::string::npos && queryStartPos + 1 < url.length()) {
|
||||||
|
@ -68,30 +73,31 @@ void SixFrameHandle::ExtractParamsFromUrl(const std::string &url, std::multimap<
|
||||||
std::string key = token.substr(0, equalSignPos);
|
std::string key = token.substr(0, equalSignPos);
|
||||||
std::string value = token.substr(equalSignPos + 1);
|
std::string value = token.substr(equalSignPos + 1);
|
||||||
LogInfo("url get [%s] = %s\n", key.c_str(), value.c_str());
|
LogInfo("url get [%s] = %s\n", key.c_str(), value.c_str());
|
||||||
paramsMap.insert({key, value});
|
resultHandle(key, value, context);
|
||||||
|
// paramsMap.insert({key, value});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestHandle2(const std::string command, std::multimap<std::string, std::string> ¶msMap,
|
void SixFrameHandle::RequestHandle2(const std::string command, std::multimap<std::string, std::string> ¶msMap,
|
||||||
ResponseHandle responseHandle, void *context)
|
const std::string &url, ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
auto result = mResquesHandleFunc.find(command);
|
auto result = mResquesHandleFunc.find(command);
|
||||||
if (result != mResquesHandleFunc.end()) {
|
if (result != mResquesHandleFunc.end()) {
|
||||||
(*result).second(paramsMap, responseHandle, context);
|
(*result).second(paramsMap, url, responseHandle, context);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("Unknown command.\n");
|
LogError("Unknown command.\n");
|
||||||
DoNothing(paramsMap, responseHandle, context);
|
DoNothing(paramsMap, url, responseHandle, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void SixFrameHandle::DoNothing(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
void SixFrameHandle::DoNothing(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
responseHandle("Unknown command.", context);
|
responseHandle("Unknown command.", context);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap,
|
void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
ResponseHandle responseHandle, void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
LogInfo("RequestGetProductInfo.\n");
|
LogInfo("RequestGetProductInfo.\n");
|
||||||
|
@ -104,7 +110,7 @@ void SixFrameHandle::RequestGetProductInfo(std::multimap<std::string, std::strin
|
||||||
free(resultStr);
|
free(resultStr);
|
||||||
cJSON_Delete(result);
|
cJSON_Delete(result);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestGetDeviceAttr(std::multimap<std::string, std::string> ¶msMap,
|
void SixFrameHandle::RequestGetDeviceAttr(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
ResponseHandle responseHandle, void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
LogInfo("RequestGetDeviceAttr.\n");
|
LogInfo("RequestGetDeviceAttr.\n");
|
||||||
|
@ -132,7 +138,7 @@ void inline SixFrameHandle::ResponseGetDeviceAttr(cJSON *result, const AppGetDev
|
||||||
cJSON_AddStringToObject(info, "curcamid", param.mCurrentCameraID.c_str());
|
cJSON_AddStringToObject(info, "curcamid", param.mCurrentCameraID.c_str());
|
||||||
cJSON_AddStringToObject(info, "wifireboot", param.mWifiReboot.c_str());
|
cJSON_AddStringToObject(info, "wifireboot", param.mWifiReboot.c_str());
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestGetMediaInfo(std::multimap<std::string, std::string> ¶msMap,
|
void SixFrameHandle::RequestGetMediaInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
ResponseHandle responseHandle, void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
LogInfo("RequestGetDeviceAttr.\n");
|
LogInfo("RequestGetDeviceAttr.\n");
|
||||||
|
@ -154,7 +160,7 @@ void inline SixFrameHandle::ResponseGetMediaInfo(cJSON *result, const AppGetMeid
|
||||||
cJSON_AddStringToObject(info, "softver", param.mTransport.c_str());
|
cJSON_AddStringToObject(info, "softver", param.mTransport.c_str());
|
||||||
cJSON_AddNumberToObject(info, "otaver", param.mPort);
|
cJSON_AddNumberToObject(info, "otaver", param.mPort);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestGetSdCardInfo(std::multimap<std::string, std::string> ¶msMap,
|
void SixFrameHandle::RequestGetSdCardInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
ResponseHandle responseHandle, void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
LogInfo("RequestGetDeviceAttr.\n");
|
LogInfo("RequestGetDeviceAttr.\n");
|
||||||
|
@ -176,8 +182,73 @@ void inline SixFrameHandle::ResponseGetSdCardInfo(cJSON *result, const AppGetSdC
|
||||||
cJSON_AddNumberToObject(info, "free", param.mFree);
|
cJSON_AddNumberToObject(info, "free", param.mFree);
|
||||||
cJSON_AddNumberToObject(info, "total", param.mTotal);
|
cJSON_AddNumberToObject(info, "total", param.mTotal);
|
||||||
}
|
}
|
||||||
void SixFrameHandle::RequestUpload(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
void SixFrameHandle::RequestGetBatteryInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void *context)
|
ResponseHandle responseHandle, void *context)
|
||||||
|
{
|
||||||
|
LogInfo("RequestGetDeviceAttr.\n");
|
||||||
|
char *resultStr = nullptr;
|
||||||
|
AppGetBatteryInfo param;
|
||||||
|
mAppMonitor->GetBatteryInfo(param);
|
||||||
|
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||||
|
ResponseGetBatteryInfo(result, param);
|
||||||
|
resultStr = cJSON_Print(result);
|
||||||
|
responseHandle(resultStr, context);
|
||||||
|
free(resultStr);
|
||||||
|
cJSON_Delete(result);
|
||||||
|
}
|
||||||
|
void inline SixFrameHandle::ResponseGetBatteryInfo(cJSON *result, const AppGetBatteryInfo ¶m)
|
||||||
|
{
|
||||||
|
cJSON *info = nullptr;
|
||||||
|
cJSON_AddItemToObject(result, CJSON_INFO_STRING, info = cJSON_CreateObject());
|
||||||
|
cJSON_AddNumberToObject(info, "charge", static_cast<int>(param.mChargeStatus));
|
||||||
|
cJSON_AddNumberToObject(info, "capacity", param.mCapacity);
|
||||||
|
}
|
||||||
|
AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(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 ("date" == key) {
|
||||||
|
parseyImpl->mData = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::string>>();
|
||||||
|
std::multimap<std::string, std::string> paramsMap;
|
||||||
|
ExtractParamsFromUrl(url, paramsMap, 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");
|
||||||
|
return AppSetDateTime(0, 0, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
std::string yearStr = parseyImpl->mData.substr(0, 4);
|
||||||
|
std::string monthStr = parseyImpl->mData.substr(4, 2);
|
||||||
|
std::string dayStr = parseyImpl->mData.substr(6, 2);
|
||||||
|
std::string hourStr = parseyImpl->mData.substr(8, 2);
|
||||||
|
std::string minuteStr = parseyImpl->mData.substr(10, 2);
|
||||||
|
std::string secondStr = parseyImpl->mData.substr(12, 2);
|
||||||
|
unsigned int year = std::stoi(yearStr);
|
||||||
|
unsigned int month = std::stoi(monthStr);
|
||||||
|
unsigned int day = std::stoi(dayStr);
|
||||||
|
unsigned int hour = std::stoi(hourStr);
|
||||||
|
unsigned int minute = std::stoi(minuteStr);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
LogInfo("RequestGetDeviceAttr.\n");
|
||||||
|
char *resultStr = nullptr;
|
||||||
|
AppSetDateTime param = RequestSetDateTimeParse(url);
|
||||||
|
mAppMonitor->SetDateTime(param);
|
||||||
|
cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
|
||||||
|
// ResponseGetBatteryInfo(result, param);
|
||||||
|
resultStr = cJSON_Print(result);
|
||||||
|
responseHandle(resultStr, context);
|
||||||
|
free(resultStr);
|
||||||
|
cJSON_Delete(result);
|
||||||
|
}
|
||||||
|
void SixFrameHandle::RequestUpload(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
|
ResponseHandle responseHandle, void *context)
|
||||||
{
|
{
|
||||||
LogInfo("RequestUpload.\n");
|
LogInfo("RequestUpload.\n");
|
||||||
char *resultStr = nullptr;
|
char *resultStr = nullptr;
|
||||||
|
|
|
@ -23,7 +23,26 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using ResquesHandleFunc = std::function<void(std::multimap<std::string, std::string> &, ResponseHandle, void *)>;
|
using ResquesHandleFunc =
|
||||||
|
std::function<void(std::multimap<std::string, std::string> &, const std::string &, ResponseHandle, void *)>;
|
||||||
|
class VParseUrl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VParseUrl() = default;
|
||||||
|
virtual ~VParseUrl() = default;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class ParseUrl : public VParseUrl
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
ParseUrl() {}
|
||||||
|
virtual ~ParseUrl() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
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:
|
||||||
|
@ -35,23 +54,31 @@ public:
|
||||||
void *context) override;
|
void *context) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ExtractParamsFromUrl(const std::string &url, std::multimap<std::string, std::string> ¶msMap);
|
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,
|
void RequestHandle2(const std::string command, std::multimap<std::string, std::string> ¶msMap,
|
||||||
ResponseHandle responseHandle, void *context);
|
const std::string &url, ResponseHandle responseHandle, void *context);
|
||||||
void DoNothing(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle, void *context);
|
void DoNothing(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
ResponseHandle responseHandle, void *context);
|
||||||
void *context);
|
void RequestGetProductInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void RequestGetDeviceAttr(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
ResponseHandle responseHandle, void *context);
|
||||||
void *context);
|
void RequestGetDeviceAttr(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
|
ResponseHandle responseHandle, void *context);
|
||||||
void ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr ¶m);
|
void ResponseGetDeviceAttr(cJSON *result, const AppGetDeviceAttr ¶m);
|
||||||
void RequestGetMediaInfo(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
void RequestGetMediaInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void *context);
|
ResponseHandle responseHandle, void *context);
|
||||||
void ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo ¶m);
|
void ResponseGetMediaInfo(cJSON *result, const AppGetMeidaInfo ¶m);
|
||||||
void RequestGetSdCardInfo(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
void RequestGetSdCardInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void *context);
|
ResponseHandle responseHandle, void *context);
|
||||||
void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo ¶m);
|
void ResponseGetSdCardInfo(cJSON *result, const AppGetSdCardInfo ¶m);
|
||||||
void RequestUpload(std::multimap<std::string, std::string> ¶msMap, ResponseHandle responseHandle,
|
void RequestGetBatteryInfo(std::multimap<std::string, std::string> ¶msMap, const std::string &url,
|
||||||
void *context);
|
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);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cJSON *MakeResponseResult(const ResposeResult result);
|
cJSON *MakeResponseResult(const ResposeResult result);
|
||||||
|
|
|
@ -109,4 +109,28 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetSdCardInfo)
|
||||||
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_GetBatteryInfo
|
||||||
|
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetBatteryInfo)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||||
|
IAppManager::GetInstance()->Init(mAppParam);
|
||||||
|
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
MockGetBatteryInfo();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
IAppManager::GetInstance()->UnInit();
|
||||||
|
}
|
||||||
|
// ../output_files/test/bin/AppManagerTest
|
||||||
|
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_SetDateTime
|
||||||
|
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetDateTime)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||||
|
IAppManager::GetInstance()->Init(mAppParam);
|
||||||
|
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
MockSetDateTime();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
IAppManager::GetInstance()->UnInit();
|
||||||
|
}
|
||||||
} // namespace AppManagerTest
|
} // namespace AppManagerTest
|
|
@ -30,6 +30,8 @@ protected:
|
||||||
void MockGetDeviceAttr(void);
|
void MockGetDeviceAttr(void);
|
||||||
void MockGetMediaInfo(void);
|
void MockGetMediaInfo(void);
|
||||||
void MockGetSdCardInfo(void);
|
void MockGetSdCardInfo(void);
|
||||||
|
void MockGetBatteryInfo(void);
|
||||||
|
void MockSetDateTime(void);
|
||||||
void MockUploadFiles(void);
|
void MockUploadFiles(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -75,6 +75,30 @@ void AppManagerTestTool::MockGetSdCardInfo(void)
|
||||||
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
ServersMock::GetInstance()->MockGetSdCardInfo();
|
ServersMock::GetInstance()->MockGetSdCardInfo();
|
||||||
}
|
}
|
||||||
|
void AppManagerTestTool::MockGetBatteryInfo(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||||
|
if (!mock) {
|
||||||
|
LogError("vMock error.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EXPECT_CALL(*mock.get(), GetBatteryInfoTrace(_))
|
||||||
|
.Times(ONLY_BE_CALLED_ONCE)
|
||||||
|
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
ServersMock::GetInstance()->MockGetBatteryInfo();
|
||||||
|
}
|
||||||
|
void AppManagerTestTool::MockSetDateTime(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
|
||||||
|
if (!mock) {
|
||||||
|
LogError("vMock error.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EXPECT_CALL(*mock.get(), SetDateTimeTrace(_))
|
||||||
|
.Times(ONLY_BE_CALLED_ONCE)
|
||||||
|
.WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
ServersMock::GetInstance()->MockSetDateTime();
|
||||||
|
}
|
||||||
void AppManagerTestTool::MockUploadFiles(void)
|
void AppManagerTestTool::MockUploadFiles(void)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
@ -107,6 +131,10 @@ std::shared_ptr<VAppMonitor> AppManagerTestTool::MakeMonitorMock(void)
|
||||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
EXPECT_CALL(*monitor.get(), GetSdCardInfoTrace(_))
|
EXPECT_CALL(*monitor.get(), GetSdCardInfoTrace(_))
|
||||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
EXPECT_CALL(*monitor.get(), GetBatteryInfoTrace(_))
|
||||||
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
EXPECT_CALL(*monitor.get(), SetDateTimeTrace(_))
|
||||||
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
EXPECT_CALL(*monitor.get(), UploadFileTrace(_))
|
EXPECT_CALL(*monitor.get(), UploadFileTrace(_))
|
||||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
return monitor;
|
return monitor;
|
||||||
|
|
|
@ -70,6 +70,34 @@ StatusCode AppMonitorTest::GetSdCardInfoTrace(AppGetSdCardInfo ¶m)
|
||||||
LogInfo("AppMonitorTest::GetSdCardInfoTrace\n");
|
LogInfo("AppMonitorTest::GetSdCardInfoTrace\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
|
StatusCode AppMonitorTest::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||||
|
{
|
||||||
|
LogInfo("AppMonitorTest::GetBatteryInfo\n");
|
||||||
|
StatusCode code = GetBatteryInfoTrace(param);
|
||||||
|
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||||
|
return VAppMonitor::GetBatteryInfo(param);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
StatusCode AppMonitorTest::GetBatteryInfoTrace(AppGetBatteryInfo ¶m)
|
||||||
|
{
|
||||||
|
LogInfo("AppMonitorTest::GetBatteryInfoTrace\n");
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
StatusCode AppMonitorTest::SetDateTime(AppSetDateTime ¶m)
|
||||||
|
{
|
||||||
|
LogInfo("AppMonitorTest::SetDateTime\n");
|
||||||
|
StatusCode code = SetDateTimeTrace(param);
|
||||||
|
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||||
|
return VAppMonitor::SetDateTime(param);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
StatusCode AppMonitorTest::SetDateTimeTrace(AppSetDateTime ¶m)
|
||||||
|
{
|
||||||
|
LogInfo("AppMonitorTest::SetDateTimeTrace\n");
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m)
|
StatusCode AppMonitorTest::UploadFile(AppUploadFile ¶m)
|
||||||
{
|
{
|
||||||
LogInfo("AppMonitorTest::UploadFile\n");
|
LogInfo("AppMonitorTest::UploadFile\n");
|
||||||
|
|
|
@ -25,6 +25,8 @@ public:
|
||||||
StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override;
|
StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override;
|
||||||
StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override;
|
StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override;
|
||||||
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override;
|
||||||
|
StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override;
|
||||||
|
StatusCode SetDateTime(AppSetDateTime ¶m) override;
|
||||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -32,6 +34,8 @@ protected:
|
||||||
virtual StatusCode GetDeviceAttrTrace(AppGetDeviceAttr ¶m);
|
virtual StatusCode GetDeviceAttrTrace(AppGetDeviceAttr ¶m);
|
||||||
virtual StatusCode GetMediaInfoTrace(AppGetMeidaInfo ¶m);
|
virtual StatusCode GetMediaInfoTrace(AppGetMeidaInfo ¶m);
|
||||||
virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m);
|
virtual StatusCode GetSdCardInfoTrace(AppGetSdCardInfo ¶m);
|
||||||
|
virtual StatusCode GetBatteryInfoTrace(AppGetBatteryInfo ¶m);
|
||||||
|
virtual StatusCode SetDateTimeTrace(AppSetDateTime ¶m);
|
||||||
virtual StatusCode UploadFileTrace(AppUploadFile ¶m);
|
virtual StatusCode UploadFileTrace(AppUploadFile ¶m);
|
||||||
};
|
};
|
||||||
class AppMonitorMock : public AppMonitorTest
|
class AppMonitorMock : public AppMonitorTest
|
||||||
|
@ -43,6 +47,8 @@ public:
|
||||||
MOCK_METHOD1(GetDeviceAttrTrace, StatusCode(AppGetDeviceAttr &));
|
MOCK_METHOD1(GetDeviceAttrTrace, StatusCode(AppGetDeviceAttr &));
|
||||||
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(SetDateTimeTrace, StatusCode(AppSetDateTime &));
|
||||||
MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &));
|
MOCK_METHOD1(UploadFileTrace, StatusCode(AppUploadFile &));
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -21,6 +21,8 @@ extern const char *APP_GET_DEVICE_ATTR;
|
||||||
extern const char *APP_UPLOAD_FILE;
|
extern const char *APP_UPLOAD_FILE;
|
||||||
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_SET_DATE_TIME;
|
||||||
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
std::shared_ptr<ServersMock> &ServersMock::GetInstance(std::shared_ptr<ServersMock> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<ServersMock>();
|
static auto instance = std::make_shared<ServersMock>();
|
||||||
|
@ -120,6 +122,40 @@ void ServersMock::MockGetSdCardInfo(void)
|
||||||
DeleteServersHttp(http);
|
DeleteServersHttp(http);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void ServersMock::MockGetBatteryInfo(void)
|
||||||
|
{
|
||||||
|
LogInfo("APP_GET_BATTERY_INFO test start.\n");
|
||||||
|
std::string mockRequest = mServerUrl + APP_GET_BATTERY_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::MockSetDateTime(void)
|
||||||
|
{
|
||||||
|
LogInfo("APP_GET_BATTERY_INFO test start.\n");
|
||||||
|
std::string mockRequest = mServerUrl + APP_SET_DATE_TIME + "?date=20240101010101";
|
||||||
|
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
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
virtual void MockGetDeviceAttr(void);
|
virtual void MockGetDeviceAttr(void);
|
||||||
virtual void MockGetMediaInfo(void);
|
virtual void MockGetMediaInfo(void);
|
||||||
virtual void MockGetSdCardInfo(void);
|
virtual void MockGetSdCardInfo(void);
|
||||||
|
virtual void MockGetBatteryInfo(void);
|
||||||
|
virtual void MockSetDateTime(void);
|
||||||
virtual void MockUploadFiles(void);
|
virtual void MockUploadFiles(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user