diff --git a/bundle.json b/bundle.json index e53251ae431437ec73e1c63a8fb2e4d89b04ae08..3dcbde773a41e93d1cab2dee9427a5c3faa3112c 100644 --- a/bundle.json +++ b/bundle.json @@ -51,6 +51,7 @@ "third_party": [ "ffmpeg", "jsoncpp", + "cJSON", "libyuv" ] }, diff --git a/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp b/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp index d44d7c50358d6639d3ad3f0cf9469f299e3abd56..049556563bd1b557435742da43b7349bb21d0e37 100644 --- a/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp @@ -15,7 +15,8 @@ #include "dcamera_channel_info_cmd.h" -#include "json/json.h" +// #include "json/json.h" +#include "cJSON.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -25,83 +26,84 @@ namespace OHOS { namespace DistributedHardware { int32_t DCameraChannelInfoCmd::Marshal(std::string& jsonStr) { - Json::Value rootValue; - rootValue["Type"] = Json::Value(type_); - rootValue["dhId"] = Json::Value(dhId_); - rootValue["Command"] = Json::Value(command_); + cJSON *rootValue = cJSON_CreateObject(); + cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); + cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); + cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); - Json::Value channelInfo; - channelInfo["SourceDevId"] = Json::Value(value_->sourceDevId_); - Json::Value details; + cJSON *details = cJSON_CreateArray(); for (auto iter = value_->detail_.begin(); iter != value_->detail_.end(); iter++) { - Json::Value detail; - detail["DataSessionFlag"] = Json::Value(iter->dataSessionFlag_); - detail["StreamType"] = Json::Value(iter->streamType_); - details.append(detail); + cJSON *detail = cJSON_CreateObject(); + cJSON_AddStringToObject(detail, "DataSessionFlag", iter->dataSessionFlag_.c_str()); + cJSON_AddNumberToObject(detail, "StreamType", iter->streamType_); + cJSON_AddItemToArray(details, detail); } - channelInfo["Detail"] = details; - rootValue["Value"] = channelInfo; - - jsonStr = rootValue.toStyledString(); + cJSON *channelInfo = cJSON_CreateObject(); + cJSON_AddStringToObject(channelInfo, "SourceDevId", value_->sourceDevId_.c_str()); + cJSON_AddItemToObject(channelInfo, "Detail", details); + cJSON_AddItemToObject(rootValue, "Value", channelInfo); + jsonStr = cJSON_Print(rootValue); + cJSON_Delete(rootValue); return DCAMERA_OK; } int32_t DCameraChannelInfoCmd::Unmarshal(const std::string& jsonStr) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == NULL) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - if (!rootValue.isMember("Type") || !rootValue["Type"].isString()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); + if (!cJSON_IsString(type)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - type_ = rootValue["Type"].asString(); - - if (!rootValue.isMember("dhId") || !rootValue["dhId"].isString()) { + type_ = type->valuestring; + cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); + if (!cJSON_IsString(dhId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - dhId_ = rootValue["dhId"].asString(); - - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + dhId_ = dhId->valuestring; + cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (!cJSON_IsString(command)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - command_ = rootValue["Command"].asString(); - - if (!rootValue.isMember("Value") || !rootValue["Value"].isObject()) { + command_ = command->valuestring; + cJSON *valueJson = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); + if (!cJSON_IsObject(valueJson)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - Json::Value valueJson = rootValue["Value"]; - - if (!valueJson.isMember("SourceDevId") || !valueJson["SourceDevId"].isString()) { + cJSON *sourceDevId = cJSON_GetObjectItemCaseSensitive(valueJson, "SourceDevId"); + if (!cJSON_IsString(sourceDevId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } std::shared_ptr channelInfo = std::make_shared(); - channelInfo->sourceDevId_ = valueJson["SourceDevId"].asString(); - - if (!valueJson.isMember("Detail") || !valueJson["Detail"].isArray()) { + channelInfo->sourceDevId_ = sourceDevId->valuestring; + cJSON *details = cJSON_GetObjectItemCaseSensitive(valueJson, "Detail"); + if (!cJSON_IsArray(details)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - for (Json::ArrayIndex i = 0; i < valueJson["Detail"].size(); i++) { - Json::Value detailJson = valueJson["Detail"][i]; - DCameraChannelDetail channelDetail; - if (!detailJson.isMember("DataSessionFlag") || !detailJson["DataSessionFlag"].isString()) { + cJSON *detail = NULL; + cJSON_ArrayForEach(detail, details) { + cJSON *dataSessionFlag = cJSON_GetObjectItemCaseSensitive(detail, "DataSessionFlag"); + cJSON *streamType = cJSON_GetObjectItemCaseSensitive(detail, "StreamType"); + if (!cJSON_IsString(dataSessionFlag) || !cJSON_IsNumber(streamType)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - if (!detailJson.isMember("StreamType") || !detailJson["StreamType"].isInt()) { - return DCAMERA_BAD_VALUE; - } - channelDetail.dataSessionFlag_ = detailJson["DataSessionFlag"].asString(); - channelDetail.streamType_ = static_cast(detailJson["StreamType"].asInt()); + DCameraChannelDetail channelDetail; + channelDetail.dataSessionFlag_ = dataSessionFlag->valuestring; + channelDetail.streamType_ = static_cast(streamType->valueint); channelInfo->detail_.push_back(channelDetail); } value_ = channelInfo; + cJSON_Delete(rootValue); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/base/src/dcamera_event_cmd.cpp b/services/cameraservice/base/src/dcamera_event_cmd.cpp index 74bc41ad7caca2fd877f13f380d4d4872b1568b2..57c34d6a3ee501e9f09dbded66685b1f951edcf0 100644 --- a/services/cameraservice/base/src/dcamera_event_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_event_cmd.cpp @@ -15,7 +15,8 @@ #include "dcamera_event_cmd.h" -#include "json/json.h" +// #include "json/json.h" +#include "cJSON.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -25,70 +26,73 @@ namespace OHOS { namespace DistributedHardware { int32_t DCameraEventCmd::Marshal(std::string& jsonStr) { - Json::Value rootValue; - rootValue["Type"] = Json::Value(type_); - rootValue["dhId"] = Json::Value(dhId_); - rootValue["Command"] = Json::Value(command_); - - Json::Value event; - event["EventType"] = Json::Value(value_->eventType_); - event["EventResult"] = Json::Value(value_->eventResult_); - event["EventContent"] = Json::Value(value_->eventContent_); - rootValue["Value"] = event; - - jsonStr = rootValue.toStyledString(); + cJSON *rootValue = cJSON_CreateObject(); + cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); + cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); + cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); + + cJSON *event = cJSON_CreateObject(); + cJSON_AddNumberToObject(event, "EventType", value_->eventType_); + cJSON_AddNumberToObject(event, "EventResult", value_->eventResult_); + cJSON_AddStringToObject(event, "EventContent", value_->eventContent_.c_str()); + cJSON_AddItemToObject(rootValue, "Value", event); + jsonStr = cJSON_Print(rootValue); + cJSON_Delete(rootValue); return DCAMERA_OK; } int32_t DCameraEventCmd::Unmarshal(const std::string& jsonStr) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == NULL) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - if (!rootValue.isMember("Type") || !rootValue["Type"].isString()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); + if (!cJSON_IsString(type)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - type_ = rootValue["Type"].asString(); - - if (!rootValue.isMember("dhId") || !rootValue["dhId"].isString()) { + type_ = type->valuestring; + cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); + if (!cJSON_IsString(dhId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - dhId_ = rootValue["dhId"].asString(); - - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + dhId_ = dhId->valuestring; + cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (!cJSON_IsString(command)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - command_ = rootValue["Command"].asString(); - - if (!rootValue.isMember("Value") || !rootValue["Value"].isObject()) { + command_ = command->valuestring; + cJSON *valueJson = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); + if (!cJSON_IsObject(valueJson)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - Json::Value valueJson = rootValue["Value"]; - - if (!valueJson.isMember("EventType") || !valueJson["EventType"].isInt()) { + cJSON *eventType = cJSON_GetObjectItemCaseSensitive(valueJson, "EventType"); + if (!cJSON_IsNumber(eventType)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } std::shared_ptr event = std::make_shared(); - event->eventType_ = valueJson["EventType"].asInt(); - - if (!valueJson.isMember("EventResult") || !valueJson["EventResult"].isInt()) { + event->eventType_ = eventType->valueint; + cJSON *eventResult = cJSON_GetObjectItemCaseSensitive(valueJson, "EventResult"); + if (!cJSON_IsNumber(eventResult)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - event->eventResult_ = valueJson["EventResult"].asInt(); - - if (!valueJson.isMember("EventContent") || !valueJson["EventContent"].isString()) { + event->eventResult_ = eventResult->valueint; + cJSON *eventContent = cJSON_GetObjectItemCaseSensitive(valueJson, "EventContent"); + if (!cJSON_IsString(eventContent)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - event->eventContent_ = valueJson["EventContent"].asString(); + event->eventContent_ = eventContent->valuestring; value_ = event; + cJSON_Delete(rootValue); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/base/src/dcamera_info_cmd.cpp b/services/cameraservice/base/src/dcamera_info_cmd.cpp index c785b323995268505dc96985c69699d320a1a972..4e61371c1ba9419f0ce2ecf42fbfd3654e062e56 100644 --- a/services/cameraservice/base/src/dcamera_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_info_cmd.cpp @@ -15,7 +15,8 @@ #include "dcamera_info_cmd.h" -#include "json/json.h" +// #include "json/json.h" +#include "cJSON.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -25,58 +26,59 @@ namespace OHOS { namespace DistributedHardware { int32_t DCameraInfoCmd::Marshal(std::string& jsonStr) { - Json::Value rootValue; - rootValue["Type"] = Json::Value(type_); - rootValue["dhId"] = Json::Value(dhId_); - rootValue["Command"] = Json::Value(command_); + cJSON *rootValue = cJSON_CreateObject(); + cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); + cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); + cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); - Json::Value info; - info["State"] = Json::Value(value_->state_); - rootValue["Value"] = info; - - jsonStr = rootValue.toStyledString(); + cJSON *info = cJSON_CreateObject(); + cJSON_AddNumberToObject(info, "State", value_->state_); + cJSON_AddItemToObject(rootValue, "Value", info); + jsonStr = cJSON_Print(rootValue); + cJSON_Delete(rootValue); return DCAMERA_OK; } int32_t DCameraInfoCmd::Unmarshal(const std::string& jsonStr) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == NULL) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - if (!rootValue.isMember("Type") || !rootValue["Type"].isString()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); + if (!cJSON_IsString(type)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - type_ = rootValue["Type"].asString(); - - if (!rootValue.isMember("dhId") || !rootValue["dhId"].isString()) { + type_ = type->valuestring; + cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); + if (!cJSON_IsString(dhId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - dhId_ = rootValue["dhId"].asString(); - - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + dhId_ = dhId->valuestring; + cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (!cJSON_IsString(command)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - command_ = rootValue["Command"].asString(); - - if (!rootValue.isMember("Value") || !rootValue["Value"].isObject()) { + command_ = command->valuestring; + cJSON *valueJson = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); + if (!cJSON_IsObject(valueJson)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - Json::Value valueJson = rootValue["Value"]; - - if (!valueJson.isMember("State") || !valueJson["State"].isInt()) { + cJSON *state = cJSON_GetObjectItemCaseSensitive(valueJson, "State"); + if (!cJSON_IsNumber(state)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } std::shared_ptr info = std::make_shared(); - info->state_ = valueJson["State"].asInt(); + info->state_ = state->valueint; value_ = info; + cJSON_Delete(rootValue); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp b/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp index 2599cd8dd14ed557f4b629f5df5e279ff75284e0..d1b69ab1f1b36edd88254eeb2419ba19c13a7c71 100644 --- a/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp @@ -15,7 +15,8 @@ #include "dcamera_metadata_setting_cmd.h" -#include "json/json.h" +// #include "json/json.h" +#include "cJSON.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -25,68 +26,68 @@ namespace OHOS { namespace DistributedHardware { int32_t DCameraMetadataSettingCmd::Marshal(std::string& jsonStr) { - Json::Value rootValue; - rootValue["Type"] = Json::Value(type_); - rootValue["dhId"] = Json::Value(dhId_); - rootValue["Command"] = Json::Value(command_); + cJSON *rootValue = cJSON_CreateObject(); + cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); + cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); + cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); - Json::Value settings; + cJSON *settings = cJSON_CreateArray(); for (auto iter = value_.begin(); iter != value_.end(); iter++) { - Json::Value setting; - setting["SettingType"] = (*iter)->type_; - setting["SettingValue"] = (*iter)->value_; - settings.append(setting); + cJSON *setting = cJSON_CreateObject(); + cJSON_AddNumberToObject(setting, "SettingType", (*iter)->type_); + cJSON_AddStringToObject(setting, "SettingValue", (*iter)->value_.c_str()); + cJSON_AddItemToArray(settings, setting); } - - rootValue["Value"] = settings; - jsonStr = rootValue.toStyledString(); + cJSON_AddItemToObject(rootValue, "Value", settings); + jsonStr = cJSON_Print(rootValue); + cJSON_Delete(rootValue); return DCAMERA_OK; } int32_t DCameraMetadataSettingCmd::Unmarshal(const std::string& jsonStr) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == NULL) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - if (!rootValue.isMember("Type") || !rootValue["Type"].isString()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); + if (!cJSON_IsString(type)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - type_ = rootValue["Type"].asString(); - - if (!rootValue.isMember("dhId") || !rootValue["dhId"].isString()) { + type_ = type->valuestring; + cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); + if (!cJSON_IsString(dhId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - dhId_ = rootValue["dhId"].asString(); - - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + dhId_ = dhId->valuestring; + cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (!cJSON_IsString(command)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - command_ = rootValue["Command"].asString(); - - if (!rootValue.isMember("Value") || !rootValue["Value"].isArray()) { + command_ = command->valuestring; + cJSON *settings = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); + if (!cJSON_IsArray(settings)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - for (Json::ArrayIndex i = 0; i < rootValue["Value"].size(); i++) { - Json::Value valueJsonEle = rootValue["Value"][i]; - if (!valueJsonEle.isMember("SettingType") || !valueJsonEle["SettingType"].isInt()) { - return DCAMERA_BAD_VALUE; - } - if (!valueJsonEle.isMember("SettingValue") || !valueJsonEle["SettingValue"].isString()) { + cJSON *subSetting = NULL; + cJSON_ArrayForEach(subSetting, settings) { + cJSON *settingType = cJSON_GetObjectItemCaseSensitive(subSetting, "SettingType"); + cJSON *settingValue = cJSON_GetObjectItemCaseSensitive(subSetting, "SettingValue"); + if (!cJSON_IsNumber(settingType) || !cJSON_IsString(settingValue)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } std::shared_ptr setting = std::make_shared(); - setting->type_ = (DCSettingsType)valueJsonEle["SettingType"].asInt(); - setting->value_ = valueJsonEle["SettingValue"].asString(); + setting->type_ = (DCSettingsType)settingValue->valueint; + setting->value_ = settingValue->valuestring; value_.push_back(setting); } + cJSON_Delete(rootValue); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp index ce88c25f7b027e5e4d005fe067be8d8da3ef7f2d..c56f67d85323e26d0a7195327c4357dd4e396784 100644 --- a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp @@ -15,7 +15,8 @@ #include "dcamera_open_info_cmd.h" -#include "json/json.h" +// #include "json/json.h" +#include "cJSON.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -25,57 +26,58 @@ namespace OHOS { namespace DistributedHardware { int32_t DCameraOpenInfoCmd::Marshal(std::string& jsonStr) { - Json::Value rootValue; - rootValue["Type"] = Json::Value(type_); - rootValue["dhId"] = Json::Value(dhId_); - rootValue["Command"] = Json::Value(command_); + cJSON *rootValue = cJSON_CreateObject(); + cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); + cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); + cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); - Json::Value openInfo; - openInfo["SourceDevId"] = Json::Value(value_->sourceDevId_); - rootValue["Value"] = openInfo; - - jsonStr = rootValue.toStyledString(); + cJSON *openInfo = cJSON_CreateObject(); + cJSON_AddStringToObject(openInfo, "SourceDevId", value_->sourceDevId_.c_str()); + cJSON_AddItemToObject(rootValue, "Value", openInfo); + jsonStr = cJSON_Print(rootValue); + cJSON_Delete(rootValue); return DCAMERA_OK; } int32_t DCameraOpenInfoCmd::Unmarshal(const std::string& jsonStr) { - JSONCPP_STRING errs; - Json::CharReaderBuilder readerBuilder; - Json::Value rootValue; - - std::unique_ptr const jsonReader(readerBuilder.newCharReader()); - if (!jsonReader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.length(), &rootValue, &errs) || - !rootValue.isObject()) { + cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); + if (rootValue == NULL) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - - if (!rootValue.isMember("Type") || !rootValue["Type"].isString()) { + cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); + if (!cJSON_IsString(type)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - type_ = rootValue["Type"].asString(); - - if (!rootValue.isMember("dhId") || !rootValue["dhId"].isString()) { + type_ = type->valuestring; + cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); + if (!cJSON_IsString(dhId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - dhId_ = rootValue["dhId"].asString(); - - if (!rootValue.isMember("Command") || !rootValue["Command"].isString()) { + dhId_ = dhId->valuestring; + cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); + if (!cJSON_IsString(command)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - command_ = rootValue["Command"].asString(); - - if (!rootValue.isMember("Value") || !rootValue["Value"].isObject()) { + command_ = command->valuestring; + cJSON *valueJson = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); + if (!cJSON_IsObject(valueJson)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } - Json::Value valueJson = rootValue["Value"]; - - if (!valueJson.isMember("SourceDevId") || !valueJson["SourceDevId"].isString()) { + cJSON *sourceDevId = cJSON_GetObjectItemCaseSensitive(valueJson, "SourceDevId"); + if (!cJSON_IsString(sourceDevId)) { + cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } std::shared_ptr openInfo = std::make_shared(); - openInfo->sourceDevId_ = valueJson["SourceDevId"].asString(); + openInfo->sourceDevId_ = sourceDevId->valuestring; value_ = openInfo; + cJSON_Delete(rootValue); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index 9b4feabe382ee666a68c79832d99a89c6ade7b0c..758d5a0c39ea265cf3c24bdeb8371857e9fc7e80 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -96,6 +96,7 @@ ohos_shared_library("distributed_camera_sink") { "${services_path}/cameraservice/cameraoperator/handler:distributed_camera_handler", "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", + "//third_party/cJSON:cjson", "//third_party/jsoncpp:jsoncpp", ] diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index e31473f71f8830ba1c677619327ebdfe9e09375c..80d5784f4e90093d61594cc0488bb1484c848d0b 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -35,7 +35,7 @@ #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" #include "idistributed_camera_source.h" -#include "json/json.h" +// #include "json/json.h" #include "dcamera_low_latency.h" #include diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 5ecc69efd22cf19b62193621239fb74d1c2afe73..2003aecf403807e971325fba250e707a249864b8 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -97,6 +97,7 @@ ohos_shared_library("distributed_camera_source") { "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", "//third_party/jsoncpp:jsoncpp", + "//third_party/cJSON:cjson", ] defines = [ diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 432d8d33d23eec491dfbf606029aba2662a3e962..8cf4869ae9552fbac524028332ce791b1a778b2f 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -16,7 +16,7 @@ #include "dcamera_source_controller.h" #include -#include "json/json.h" +// #include "json/json.h" #include "dcamera_capture_info_cmd.h" #include "dcamera_channel_source_impl.h" diff --git a/services/channel/test/unittest/common/channel/BUILD.gn b/services/channel/test/unittest/common/channel/BUILD.gn index 3fc507667723af86b125ddd5a28a4d4511ea247a..90aff08fe35e86f2faee0acb1a3e32438ce9fa04 100644 --- a/services/channel/test/unittest/common/channel/BUILD.gn +++ b/services/channel/test/unittest/common/channel/BUILD.gn @@ -49,6 +49,7 @@ config("module_private_config") { "${innerkits_path}/native_cpp/camera_source/include/callback", "${graphicstandard_path}/frameworks/surface/include", "//third_party/jsoncpp/include", + "//third_party/cJSON", "${feeding_smoother_path}/base", ] }