修改看板告警

Signed-off-by: li-tiangang4 <litiangang4@huawei.com>
This commit is contained in:
li-tiangang4 2024-11-07 18:48:41 +08:00
parent 21f5e840ac
commit 38427ad3ac
18 changed files with 349 additions and 315 deletions

View File

@ -58,6 +58,7 @@ private:
void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo);
void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo);
void FromJsonContinue(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo);
using MetaCapInfoMap = std::map<std::string, std::shared_ptr<MetaCapabilityInfo>>;
} // namespace DistributedHardware

View File

@ -110,85 +110,108 @@ std::vector<DHType> ComponentLoader::GetAllCompTypes()
int32_t ParseComponent(const cJSON *json, CompConfig &cfg)
{
if (!IsString(json, COMP_NAME)) {
cJSON *nameJson = cJSON_GetObjectItem(json, COMP_NAME.c_str());
if (!IsString(nameJson)) {
DHLOGE("COMP_NAME is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.name = cJSON_GetObjectItem(json, COMP_NAME.c_str())->valuestring;
if (!IsString(json, COMP_TYPE)) {
cfg.name = nameJson->valuestring;
cJSON *typeJson = cJSON_GetObjectItem(json, COMP_TYPE.c_str());
if (!IsString(typeJson)) {
DHLOGE("COMP_TYPE is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.type = g_mapDhTypeName[cJSON_GetObjectItem(json, COMP_TYPE.c_str())->valuestring];
if (!IsString(json, COMP_HANDLER_LOC)) {
cfg.type = g_mapDhTypeName[typeJson->valuestring];
cJSON *handlerLocJson = cJSON_GetObjectItem(json, COMP_HANDLER_LOC.c_str());
if (!IsString(handlerLocJson)) {
DHLOGE("COMP_HANDLER_LOC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compHandlerLoc = cJSON_GetObjectItem(json, COMP_HANDLER_LOC.c_str())->valuestring;
if (!IsString(json, COMP_HANDLER_VERSION)) {
cfg.compHandlerLoc = handlerLocJson->valuestring;
cJSON *handlerVerJson = cJSON_GetObjectItem(json, COMP_HANDLER_VERSION.c_str());
if (!IsString(handlerVerJson)) {
DHLOGE("COMP_HANDLER_VERSION is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compHandlerVersion = cJSON_GetObjectItem(json, COMP_HANDLER_VERSION.c_str())->valuestring;
cfg.compHandlerVersion = handlerVerJson->valuestring;
return DH_FWK_SUCCESS;
}
int32_t ParseSource(const cJSON *json, CompConfig &cfg)
{
if (!IsString(json, COMP_SOURCE_LOC)) {
cJSON *sourceLocJson = cJSON_GetObjectItem(json, COMP_SOURCE_LOC.c_str());
if (!IsString(sourceLocJson)) {
DHLOGE("COMP_SOURCE_LOC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compSourceLoc = cJSON_GetObjectItem(json, COMP_SOURCE_LOC.c_str())->valuestring;
if (!IsString(json, COMP_SOURCE_VERSION)) {
cfg.compSourceLoc = sourceLocJson->valuestring;
cJSON *sourceVerJson = cJSON_GetObjectItem(json, COMP_SOURCE_VERSION.c_str());
if (!IsString(sourceVerJson)) {
DHLOGE("COMP_SOURCE_VERSION is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compSourceVersion = cJSON_GetObjectItem(json, COMP_SOURCE_VERSION.c_str())->valuestring;
if (!IsInt32(json, COMP_SOURCE_SA_ID)) {
cfg.compSourceVersion = sourceVerJson->valuestring;
cJSON *sourceSaIdJson = cJSON_GetObjectItem(json, COMP_SOURCE_SA_ID.c_str());
if (!IsInt32(sourceSaIdJson)) {
DHLOGE("COMP_SOURCE_SA_ID is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compSourceSaId = static_cast<int32_t>(cJSON_GetObjectItem(json, COMP_SOURCE_SA_ID.c_str())->valuedouble);
cfg.compSourceSaId = static_cast<int32_t>(sourceSaIdJson->valueint);
return DH_FWK_SUCCESS;
}
int32_t ParseSink(const cJSON *json, CompConfig &cfg)
{
if (!IsString(json, COMP_SINK_LOC)) {
cJSON *sinkLocJson = cJSON_GetObjectItem(json, COMP_SINK_LOC.c_str());
if (!IsString(sinkLocJson)) {
DHLOGE("COMP_SINK_LOC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compSinkLoc = cJSON_GetObjectItem(json, COMP_SINK_LOC.c_str())->valuestring;
if (!IsString(json, COMP_SINK_VERSION)) {
cfg.compSinkLoc = sinkLocJson->valuestring;
cJSON *sinkVerJson = cJSON_GetObjectItem(json, COMP_SINK_VERSION.c_str());
if (!IsString(sinkVerJson)) {
DHLOGE("COMP_SINK_VERSION is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compSinkVersion = cJSON_GetObjectItem(json, COMP_SINK_VERSION.c_str())->valuestring;
if (!IsInt32(json, COMP_SINK_SA_ID)) {
cfg.compSinkVersion = sinkVerJson->valuestring;
cJSON *sinkSaIdJson = cJSON_GetObjectItem(json, COMP_SINK_SA_ID.c_str());
if (!IsInt32(sinkSaIdJson)) {
DHLOGE("COMP_SINK_SA_ID is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cfg.compSinkSaId = static_cast<int32_t>(cJSON_GetObjectItem(json, COMP_SINK_SA_ID.c_str())->valuedouble);
cfg.compSinkSaId = static_cast<int32_t>(sinkSaIdJson->valueint);
return DH_FWK_SUCCESS;
}
int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg)
{
if (!IsArray(json, COMP_RESOURCE_DESC)) {
cJSON *resouceDescJson = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str());
if (!IsArray(resouceDescJson)) {
DHLOGE("COMP_RESOURCE_DESC is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
cJSON *resourceDescArray = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str());
cJSON *element = nullptr;
cJSON_ArrayForEach(element, resourceDescArray) {
cJSON_ArrayForEach(element, resouceDescJson) {
ResourceDesc desc;
if (!IsString(element, COMP_SUBTYPE)) {
cJSON *subtypeJson = cJSON_GetObjectItem(element, COMP_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("COMP_SUBTYPE is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
desc.subtype = cJSON_GetObjectItem(element, COMP_SUBTYPE.c_str())->valuestring;
desc.subtype = subtypeJson->valuestring;
cJSON *sensitive = cJSON_GetObjectItem(element, COMP_SENSITIVE.c_str());
if (!IsBool(sensitive)) {
DHLOGE("COMP_SENSITIVE is invalid!");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
if (cJSON_IsTrue(sensitive)) {
desc.sensitiveValue = true;
} else {
@ -256,12 +279,12 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::
DHLOGE("jsonStr parse failed");
return ERR_DH_FWK_JSON_PARSE_FAILED;
}
if (!IsArray(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS)) {
cJSON *components = cJSON_GetObjectItem(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS.c_str());
if (!IsArray(components)) {
DHLOGE("distributed_components is not an array");
cJSON_Delete(root);
return ERR_DH_FWK_PARA_INVALID;
}
cJSON *components = cJSON_GetObjectItem(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS.c_str());
size_t compSize = static_cast<size_t>(cJSON_GetArraySize(components));
if (compSize == 0 || compSize > MAX_COMP_SIZE) {
@ -284,40 +307,48 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::
void ComponentLoader::ParseCompConfigFromJson(cJSON *component, CompConfig &config)
{
if (IsString(component, COMP_NAME.c_str())) {
config.name = cJSON_GetObjectItem(component, COMP_NAME.c_str())->valuestring;
cJSON *nameJson = cJSON_GetObjectItem(component, COMP_NAME.c_str());
if (IsString(nameJson)) {
config.name = nameJson->valuestring;
}
if (IsString(component, COMP_TYPE.c_str())) {
config.type = g_mapDhTypeName[cJSON_GetObjectItem(component, COMP_TYPE.c_str())->valuestring];
cJSON *typeJson = cJSON_GetObjectItem(component, COMP_TYPE.c_str());
if (IsString(typeJson)) {
config.type = g_mapDhTypeName[typeJson->valuestring];
}
if (IsString(component, COMP_HANDLER_LOC.c_str())) {
config.compHandlerLoc = cJSON_GetObjectItem(component, COMP_HANDLER_LOC.c_str())->valuestring;
cJSON *handlerLocJson = cJSON_GetObjectItem(component, COMP_HANDLER_LOC.c_str());
if (IsString(handlerLocJson)) {
config.compHandlerLoc = handlerLocJson->valuestring;
}
if (IsString(component, COMP_HANDLER_VERSION.c_str())) {
config.compHandlerVersion = cJSON_GetObjectItem(component, COMP_HANDLER_VERSION.c_str())->valuestring;
cJSON *handlerVerJson = cJSON_GetObjectItem(component, COMP_HANDLER_VERSION.c_str());
if (IsString(handlerVerJson)) {
config.compHandlerVersion = handlerVerJson->valuestring;
}
if (IsString(component, COMP_SOURCE_LOC.c_str())) {
config.compSourceLoc = cJSON_GetObjectItem(component, COMP_SOURCE_LOC.c_str())->valuestring;
cJSON *sourceLocJson = cJSON_GetObjectItem(component, COMP_SOURCE_LOC.c_str());
if (IsString(sourceLocJson)) {
config.compSourceLoc = sourceLocJson->valuestring;
}
if (IsString(component, COMP_SOURCE_VERSION.c_str())) {
config.compSourceVersion = cJSON_GetObjectItem(component, COMP_SOURCE_VERSION.c_str())->valuestring;
cJSON *sourceVerJson = cJSON_GetObjectItem(component, COMP_SOURCE_VERSION.c_str());
if (IsString(sourceVerJson)) {
config.compSourceVersion = sourceVerJson->valuestring;
}
if (IsInt32(component, COMP_SOURCE_SA_ID.c_str())) {
config.compSourceSaId =
static_cast<int32_t>(cJSON_GetObjectItem(component, COMP_SOURCE_SA_ID.c_str())->valuedouble);
cJSON *sourceSaIdJson = cJSON_GetObjectItem(component, COMP_SOURCE_SA_ID.c_str());
if (IsInt32(sourceSaIdJson)) {
config.compSourceSaId = static_cast<int32_t>(sourceSaIdJson->valueint);
}
if (IsString(component, COMP_SINK_LOC.c_str())) {
config.compSinkLoc = cJSON_GetObjectItem(component, COMP_SINK_LOC.c_str())->valuestring;
cJSON *sinkLocJson = cJSON_GetObjectItem(component, COMP_SINK_LOC.c_str());
if (IsString(sinkLocJson)) {
config.compSinkLoc = sinkLocJson->valuestring;
}
if (IsString(component, COMP_SINK_VERSION.c_str())) {
config.compSinkVersion = cJSON_GetObjectItem(component, COMP_SINK_VERSION.c_str())->valuestring;
cJSON *sinkVerJson = cJSON_GetObjectItem(component, COMP_SINK_VERSION.c_str());
if (IsString(sinkVerJson)) {
config.compSinkVersion = sinkVerJson->valuestring;
}
if (IsInt32(component, COMP_SINK_SA_ID.c_str())) {
config.compSinkSaId =
static_cast<int32_t>(cJSON_GetObjectItem(component, COMP_SINK_SA_ID.c_str())->valuedouble);
cJSON *sinkSaIdJson = cJSON_GetObjectItem(component, COMP_SINK_SA_ID.c_str());
if (IsInt32(sinkSaIdJson)) {
config.compSinkSaId = static_cast<int32_t>(sinkSaIdJson->valueint);
}
if (IsArray(component, COMP_RESOURCE_DESC.c_str())) {
cJSON *resourceDescs = cJSON_GetObjectItem(component, COMP_RESOURCE_DESC.c_str());
cJSON *resourceDescs = cJSON_GetObjectItem(component, COMP_RESOURCE_DESC.c_str());
if (IsArray(resourceDescs)) {
ParseResourceDescFromJson(resourceDescs, config);
}
}
@ -328,17 +359,22 @@ void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig
cJSON_ArrayForEach(resourceDesc, resourceDescs) {
bool sensitiveValue;
cJSON *sensitive = cJSON_GetObjectItem(resourceDesc, COMP_SENSITIVE.c_str());
if (!IsBool(sensitive)) {
DHLOGE("COMP_SUBTYPE is invalid!");
return;
}
if (cJSON_IsTrue(sensitive)) {
sensitiveValue = true;
} else {
sensitiveValue = false;
}
ResourceDesc resource;
if (!IsString(resourceDesc, COMP_SUBTYPE)) {
cJSON *subtypeJson = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("COMP_SUBTYPE is invalid!");
return;
}
resource.subtype = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str())->valuestring;
resource.subtype = subtypeJson->valuestring;
resource.sensitiveValue = sensitiveValue;
config.compResourceDesc.push_back(resource);
}

View File

@ -295,47 +295,46 @@ ComponentPrivacy::ComponentEventHandler::~ComponentEventHandler()
void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk::InnerEvent::Pointer &event)
{
DHLOGI("ProcessStartPage enter.");
if (event == nullptr) {
DHLOGE("event is nullptr");
return;
}
std::shared_ptr<cJSON> dataMsg = event->GetSharedObject<cJSON>();
cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0);
if (!IsString(innerMsg, PRIVACY_SUBTYPE)) {
cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("PRIVACY_SUBTYPE is invalid!");
return;
}
std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring;
if (!IsString(innerMsg, PRIVACY_NETWORKID)) {
std::string subtype = subtypeJson->valuestring;
cJSON *networkIdJson = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str());
if (!IsString(networkIdJson)) {
DHLOGE("PRIVACY_NETWORKID is invalid!");
return;
}
std::string networkId = networkIdJson->valuestring;
if (comPrivacyObj_ == nullptr) {
DHLOGE("comPrivacyObj_ is nullptr");
return;
}
std::string networkId = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str())->valuestring;
comPrivacyObj_->StartPrivacePage(subtype, networkId);
}
void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk::InnerEvent::Pointer &event)
{
DHLOGI("ProcessStopPage enter.");
if (event == nullptr) {
DHLOGE("event is nullptr");
return;
}
std::shared_ptr<cJSON> dataMsg = event->GetSharedObject<cJSON>();
cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0);
if (!IsString(innerMsg, PRIVACY_SUBTYPE)) {
if (innerMsg == NULL) {
DHLOGE("innerMsg is nullptr");
return;
}
cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str());
if (!IsString(subtypeJson)) {
DHLOGE("PRIVACY_SUBTYPE is invalid!");
return;
}
std::string subtype = subtypeJson->valuestring;
if (comPrivacyObj_ == nullptr) {
DHLOGE("comPrivacyObj_ is nullptr");
return;
}
std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring;
comPrivacyObj_->StopPrivacePage(subtype);
}
} // namespace DistributedHardware

View File

@ -237,12 +237,13 @@ std::string DistributedHardwareService::QueryDhSysSpec(const std::string &target
DHLOGE("attrs json is invalid, attrs: %{public}s", attrs.c_str());
return "";
}
if (!IsString(attrJson, targetKey)) {
cJSON *targetKeyJson = cJSON_GetObjectItem(attrJson, targetKey.c_str());
if (!IsString(targetKeyJson)) {
DHLOGE("Attrs Json not contains key: %{public}s", targetKey.c_str());
cJSON_Delete(attrJson);
return "";
}
std::string result = cJSON_GetObjectItem(attrJson, targetKey.c_str())->valuestring;
std::string result = targetKeyJson->valuestring;
cJSON_Delete(attrJson);
return result;
}

View File

@ -53,19 +53,21 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa
DHLOGE("jsonStr parse failed");
return;
}
if (!IsUInt32(jsonObj, DH_TYPE)) {
cJSON *dhTypeJson = cJSON_GetObjectItem(jsonObj, DH_TYPE.c_str());
if (!IsUInt32(dhTypeJson)) {
DHLOGE("The DH_TYPE key is invalid!");
cJSON_Delete(jsonObj);
return;
}
if (!IsBool(jsonObj, LOW_LATENCY_ENABLE)) {
cJSON *enableJson = cJSON_GetObjectItem(jsonObj, LOW_LATENCY_ENABLE.c_str());
if (!IsBool(enableJson)) {
DHLOGE("The LOW_LATENCY_ENABLE key is invalid!");
cJSON_Delete(jsonObj);
return;
}
DHType dhType = (DHType)cJSON_GetObjectItem(jsonObj, DH_TYPE.c_str())->valuedouble;
cJSON *isEnable = cJSON_GetObjectItem(jsonObj, LOW_LATENCY_ENABLE.c_str());
if (cJSON_IsTrue(isEnable)) {
DHType dhType = (DHType)dhTypeJson->valueint;
if (cJSON_IsTrue(enableJson)) {
LowLatency::GetInstance().EnableLowLatency(dhType);
} else {
LowLatency::GetInstance().DisableLowLatency(dhType);

View File

@ -207,47 +207,54 @@ void FromJson(const cJSON *jsonObject, CapabilityInfo &capability)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, DH_ID)) {
cJSON *dhIdJson = cJSON_GetObjectItem(jsonObject, DH_ID.c_str());
if (!IsString(dhIdJson)) {
DHLOGE("DH_ID is invalid!");
return;
}
capability.SetDHId(cJSON_GetObjectItem(jsonObject, DH_ID.c_str())->valuestring);
capability.SetDHId(dhIdJson->valuestring);
if (!IsString(jsonObject, DEV_ID)) {
cJSON *devIdJson = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str());
if (!IsString(devIdJson)) {
DHLOGE("DEV_ID is invalid!");
return;
}
capability.SetDeviceId(cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring);
capability.SetDeviceId(devIdJson->valuestring);
if (!IsString(jsonObject, DEV_NAME)) {
cJSON *devNameJson = cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str());
if (!IsString(devNameJson)) {
DHLOGE("DEV_NAME is invalid!");
return;
}
capability.SetDeviceName(cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str())->valuestring);
capability.SetDeviceName(devNameJson->valuestring);
if (!IsUInt16(jsonObject, DEV_TYPE)) {
cJSON *devTypeJson = cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str());
if (!IsUInt16(devTypeJson)) {
DHLOGE("DEV_TYPE is invalid!");
return;
}
capability.SetDeviceType((uint16_t)cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str())->valuedouble);
capability.SetDeviceType(static_cast<uint16_t>(devTypeJson->valueint));
if (!IsUInt32(jsonObject, DH_TYPE)) {
cJSON *dhTypeJson = cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str());
if (!IsUInt32(dhTypeJson)) {
DHLOGE("DH_TYPE is invalid!");
return;
}
capability.SetDHType((DHType)cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str())->valuedouble);
capability.SetDHType((DHType)dhTypeJson->valueint);
if (!IsString(jsonObject, DH_ATTRS)) {
cJSON *dhAttrsJson = cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str());
if (!IsString(dhAttrsJson)) {
DHLOGE("DH_ATTRS is invalid!");
return;
}
capability.SetDHAttrs(cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str())->valuestring);
capability.SetDHAttrs(dhAttrsJson->valuestring);
if (!IsString(jsonObject, DH_SUBTYPE)) {
cJSON *dhSubtypeJson = cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str());
if (!IsString(dhSubtypeJson)) {
DHLOGE("DH_SUBTYPE is invalid!");
return;
}
capability.SetDHSubtype(cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str())->valuestring);
capability.SetDHSubtype(dhSubtypeJson->valuestring);
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -172,8 +172,8 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos()
DHLOGE("Get capability ptr by value failed");
continue;
}
const std::string &deviceId = capabilityInfo->GetDeviceId();
const std::string &localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
const std::string deviceId = capabilityInfo->GetDeviceId();
const std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
if (deviceId.compare(localDeviceId) == 0) {
DHLOGE("local device info not need sync from db");
continue;

View File

@ -163,59 +163,73 @@ void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo)
void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo)
{
if (!IsString(jsonObject, DH_ID)) {
cJSON *dhIdJson = cJSON_GetObjectItem(jsonObject, DH_ID.c_str());
if (!IsString(dhIdJson)) {
DHLOGE("DH_ID is invalid!");
return;
}
metaCapInfo.SetDHId(cJSON_GetObjectItem(jsonObject, DH_ID.c_str())->valuestring);
metaCapInfo.SetDHId(dhIdJson->valuestring);
if (!IsString(jsonObject, DEV_ID)) {
cJSON *devIdJson = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str());
if (!IsString(devIdJson)) {
DHLOGE("DEV_ID is invalid!");
return;
}
metaCapInfo.SetDeviceId(cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring);
metaCapInfo.SetDeviceId(devIdJson->valuestring);
if (!IsString(jsonObject, DEV_NAME)) {
cJSON *devNameJson = cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str());
if (!IsString(devNameJson)) {
DHLOGE("DEV_NAME is invalid!");
return;
}
metaCapInfo.SetDeviceName(cJSON_GetObjectItem(jsonObject, DEV_NAME.c_str())->valuestring);
metaCapInfo.SetDeviceName(devNameJson->valuestring);
if (!IsUInt16(jsonObject, DEV_TYPE)) {
cJSON *devTypeJson = cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str());
if (!IsUInt16(devTypeJson)) {
DHLOGE("DEV_TYPE is invalid!");
return;
}
metaCapInfo.SetDeviceType((uint16_t)cJSON_GetObjectItem(jsonObject, DEV_TYPE.c_str())->valuedouble);
metaCapInfo.SetDeviceType(static_cast<uint16_t>(devTypeJson->valueint));
if (!IsUInt32(jsonObject, DH_TYPE)) {
cJSON *dhTypeJson = cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str());
if (!IsUInt32(dhTypeJson)) {
DHLOGE("DH_TYPE is invalid!");
return;
}
metaCapInfo.SetDHType((DHType)cJSON_GetObjectItem(jsonObject, DH_TYPE.c_str())->valuedouble);
metaCapInfo.SetDHType((DHType)dhTypeJson->valueint);
if (!IsString(jsonObject, DH_ATTRS)) {
cJSON *dhAttrsObj = cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str());
if (!IsString(dhAttrsObj)) {
DHLOGE("DH_ATTRS is invalid!");
return;
}
metaCapInfo.SetDHAttrs(cJSON_GetObjectItem(jsonObject, DH_ATTRS.c_str())->valuestring);
metaCapInfo.SetDHAttrs(dhAttrsObj->valuestring);
if (!IsString(jsonObject, DH_SUBTYPE)) {
FromJsonContinue(jsonObject, metaCapInfo);
}
void FromJsonContinue(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo)
{
cJSON *dhSubtypeJson = cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str());
if (!IsString(dhSubtypeJson)) {
DHLOGE("DH_SUBTYPE is invalid!");
return;
}
metaCapInfo.SetDHSubtype(cJSON_GetObjectItem(jsonObject, DH_SUBTYPE.c_str())->valuestring);
metaCapInfo.SetDHSubtype(dhSubtypeJson->valuestring);
if (!IsString(jsonObject, DEV_UDID_HASH)) {
cJSON *udidHashJson = cJSON_GetObjectItem(jsonObject, DEV_UDID_HASH.c_str());
if (!IsString(udidHashJson)) {
DHLOGE("DEV_UDID_HASH is invalid!");
return;
}
metaCapInfo.SetUdidHash(cJSON_GetObjectItem(jsonObject, DEV_UDID_HASH.c_str())->valuestring);
metaCapInfo.SetUdidHash(udidHashJson->valuestring);
if (!IsString(jsonObject, SINK_VER)) {
cJSON *sinkVerJson = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str());
if (!IsString(sinkVerJson)) {
DHLOGE("SINK_VER is invalid!");
return;
}
metaCapInfo.SetSinkVersion(cJSON_GetObjectItem(jsonObject, SINK_VER.c_str())->valuestring);
metaCapInfo.SetSinkVersion(sinkVerJson->valuestring);
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -208,8 +208,8 @@ int32_t MetaInfoManager::SyncRemoteMetaInfos()
DHLOGE("Get Metainfo ptr by value failed");
continue;
}
const std::string &udidHash = metaCapInfo->GetUdidHash();
const std::string &localUdidHash = DHContext::GetInstance().GetDeviceInfo().udidHash;
const std::string udidHash = metaCapInfo->GetUdidHash();
const std::string localUdidHash = DHContext::GetInstance().GetDeviceInfo().udidHash;
if (udidHash.compare(localUdidHash) == 0) {
DHLOGE("device MetaInfo not need sync from db");
continue;

View File

@ -101,21 +101,25 @@ void FromJson(const cJSON *jsonObject, CompVersion &compVer)
DHLOGE("Json pointer is nullptr!");
return;
}
if (IsString(jsonObject, NAME)) {
compVer.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
cJSON *nameJson = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (IsString(nameJson)) {
compVer.name = nameJson->valuestring;
}
if (IsUInt32(jsonObject, TYPE) &&
(DHType)cJSON_GetObjectItem(jsonObject, TYPE.c_str())->valuedouble <= DHType::MAX_DH) {
compVer.dhType = (DHType)(cJSON_GetObjectItem(jsonObject, TYPE.c_str())->valuedouble);
cJSON *typeJson = cJSON_GetObjectItem(jsonObject, TYPE.c_str());
if (IsUInt32(typeJson) && (DHType)typeJson->valueint <= DHType::MAX_DH) {
compVer.dhType = (DHType)typeJson->valueint;
}
if (IsString(jsonObject, HANDLER)) {
compVer.handlerVersion = cJSON_GetObjectItem(jsonObject, HANDLER.c_str())->valuestring;
cJSON *handlerJson = cJSON_GetObjectItem(jsonObject, HANDLER.c_str());
if (IsString(handlerJson)) {
compVer.handlerVersion = handlerJson->valuestring;
}
if (IsString(jsonObject, SOURCE_VER)) {
compVer.sourceVersion = cJSON_GetObjectItem(jsonObject, SOURCE_VER.c_str())->valuestring;
cJSON *sourceVerJson = cJSON_GetObjectItem(jsonObject, SOURCE_VER.c_str());
if (IsString(sourceVerJson)) {
compVer.sourceVersion = sourceVerJson->valuestring;
}
if (IsString(jsonObject, SINK_VER)) {
compVer.sinkVersion = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str())->valuestring;
cJSON *sinkVerJson = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str());
if (IsString(sinkVerJson)) {
compVer.sinkVersion = sinkVerJson->valuestring;
}
}
@ -125,12 +129,14 @@ void FromJson(const cJSON *jsonObject, VersionInfo &versionInfo)
DHLOGE("Json pointer is nullptr!");
return;
}
if (IsString(jsonObject, DEV_ID)) {
versionInfo.deviceId = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring;
cJSON *devIdJson = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str());
if (IsString(devIdJson)) {
versionInfo.deviceId = devIdJson->valuestring;
}
if (IsString(jsonObject, DH_VER)) {
versionInfo.dhVersion = cJSON_GetObjectItem(jsonObject, DH_VER.c_str())->valuestring;
cJSON *dhVerJson = cJSON_GetObjectItem(jsonObject, DH_VER.c_str());
if (IsString(dhVerJson)) {
versionInfo.dhVersion = dhVerJson->valuestring;
}
const cJSON *compVer = cJSON_GetObjectItem(jsonObject, COMP_VER.c_str());

View File

@ -243,8 +243,8 @@ int32_t VersionInfoManager::SyncRemoteVersionInfos()
if (versionInfo.FromJsonString(data) != DH_FWK_SUCCESS) {
continue;
}
const std::string &deviceId = versionInfo.deviceId;
const std::string &localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
const std::string deviceId = versionInfo.deviceId;
const std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
if (deviceId.compare(localDeviceId) == 0) {
DHLOGE("Local device info not need sync from db");
continue;

View File

@ -51,16 +51,15 @@ void FromJson(const cJSON *jsonObject, FullCapsRsp &capsRsp)
DHLOGE("Json pointer is nullptr!");
return;
}
std::string keyNetworkId(CAPS_RSP_NETWORKID_KEY);
if (IsString(jsonObject, keyNetworkId)) {
capsRsp.networkId = cJSON_GetObjectItem(jsonObject, CAPS_RSP_NETWORKID_KEY)->valuestring;
cJSON *capsRspJson = cJSON_GetObjectItem(jsonObject, CAPS_RSP_NETWORKID_KEY);
if (IsString(capsRspJson)) {
capsRsp.networkId = capsRspJson->valuestring;
}
std::string keyCaps(CAPS_RSP_CAPS_KEY);
if (IsArray(jsonObject, keyCaps)) {
cJSON *capsArr = cJSON_GetObjectItem(jsonObject, CAPS_RSP_CAPS_KEY);
int32_t arrSize = cJSON_GetArraySize(capsArr);
cJSON *capsRspKeyJson = cJSON_GetObjectItem(jsonObject, CAPS_RSP_CAPS_KEY);
if (IsArray(capsRspKeyJson)) {
int32_t arrSize = cJSON_GetArraySize(capsRspKeyJson);
for (int32_t i = 0; i < arrSize; i++) {
cJSON *cap = cJSON_GetArrayItem(capsArr, i);
cJSON *cap = cJSON_GetArrayItem(capsRspKeyJson, i);
std::shared_ptr<CapabilityInfo> capPtr = std::make_shared<CapabilityInfo>();
FromJson(cap, *capPtr);
capsRsp.caps.push_back(capPtr);
@ -85,13 +84,13 @@ void FromJson(const cJSON *jsonObject, CommMsg &commMsg)
DHLOGE("Json pointer is nullptr!");
return;
}
std::string keyCode(COMM_MSG_CODE_KEY);
if (IsInt32(jsonObject, keyCode)) {
commMsg.code = cJSON_GetObjectItem(jsonObject, COMM_MSG_CODE_KEY)->valueint;
cJSON *commMsgCodeJson = cJSON_GetObjectItem(jsonObject, COMM_MSG_CODE_KEY);
if (IsInt32(commMsgCodeJson)) {
commMsg.code = commMsgCodeJson->valueint;
}
std::string keyMsg(COMM_MSG_MSG_KEY);
if (IsString(jsonObject, keyMsg)) {
commMsg.msg = cJSON_GetObjectItem(jsonObject, COMM_MSG_MSG_KEY)->valuestring;
cJSON *commMsgeJson = cJSON_GetObjectItem(jsonObject, COMM_MSG_MSG_KEY);
if (IsString(commMsgeJson)) {
commMsg.msg = commMsgeJson->valuestring;
}
}

View File

@ -324,13 +324,13 @@ void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std
return;
}
cJSON *eventObj = cJSON_GetObjectItemCaseSensitive(messageJson, ISOMERISM_EVENT_KEY.c_str());
if (eventObj == nullptr || !IsString(messageJson, ISOMERISM_EVENT_KEY)) {
if (!IsString(eventObj)) {
cJSON_Delete(messageJson);
DHLOGE("OnMessage event invaild");
return;
}
cJSON *devObj = cJSON_GetObjectItemCaseSensitive(messageJson, DEV_ID.c_str());
if (devObj == nullptr || !IsString(messageJson, DEV_ID)) {
if (!IsString(devObj)) {
cJSON_Delete(messageJson);
DHLOGE("OnMessage deviceId invaild");
return;

View File

@ -931,8 +931,7 @@ HWTEST_F(ComponentLoaderTest, from_json_001, TestSize.Level0)
cJSON_AddStringToObject(Json2, COMP_SOURCE_VERSION.c_str(), "1.0");
cJSON_AddNumberToObject(Json2, COMP_SOURCE_SA_ID.c_str(), 4801);
cJSON_AddNumberToObject(Json2, COMP_SINK_LOC.c_str(), 100);
from_json(Json2, cfg);
EXPECT_EQ(4801, static_cast<int32_t>(cJSON_GetObjectItem(Json2, COMP_SOURCE_SA_ID.c_str())->valuedouble));
EXPECT_NO_FATAL_FAILURE(from_json(Json2, cfg));
cJSON_Delete(Json2);
}

View File

@ -47,19 +47,19 @@ std::string GetDeviceIdByUUID(const std::string &uuid);
std::string Sha256(const std::string& string);
bool IsUInt8(const cJSON* jsonObj, const std::string& key);
bool IsUInt8(const cJSON* jsonObj);
bool IsUInt16(const cJSON* jsonObj, const std::string& key);
bool IsUInt16(const cJSON* jsonObj);
bool IsInt32(const cJSON* jsonObj, const std::string& key);
bool IsInt32(const cJSON* jsonObj);
bool IsUInt32(const cJSON* jsonObj, const std::string& key);
bool IsUInt32(const cJSON* jsonObj);
bool IsBool(const cJSON* jsonObj, const std::string& key);
bool IsBool(const cJSON* jsonObj);
bool IsString(const cJSON* jsonObj, const std::string& key);
bool IsString(const cJSON* jsonObj);
bool IsArray(const cJSON* jsonObj, const std::string& key);
bool IsArray(const cJSON* jsonObj);
std::string Compress(const std::string& data);
std::string Decompress(const std::string& data);

View File

@ -163,64 +163,57 @@ std::string GetLocalNetworkId()
return info.networkId;
}
bool IsUInt8(const cJSON* jsonObj, const std::string& key)
bool IsUInt8(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
if (value == NULL || !cJSON_IsNumber(value)) {
if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
return false;
}
return (value->valuedouble >= 0 && value->valuedouble <= UINT8_MAX);
return (jsonObj->valueint >= 0 && jsonObj->valueint <= UINT8_MAX);
}
bool IsUInt16(const cJSON* jsonObj, const std::string& key)
bool IsUInt16(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
if (value == NULL || !cJSON_IsNumber(value)) {
if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
return false;
}
return (value->valuedouble >= 0 && value->valuedouble <= UINT16_MAX);
return (jsonObj->valueint >= 0 && jsonObj->valueint <= UINT16_MAX);
}
bool IsInt32(const cJSON* jsonObj, const std::string& key)
bool IsInt32(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
if (value == NULL || !cJSON_IsNumber(value)) {
if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
return false;
}
return (value->valuedouble >= INT32_MIN && value->valuedouble <= INT32_MAX);
return (jsonObj->valueint >= INT32_MIN && jsonObj->valueint <= INT32_MAX);
}
bool IsUInt32(const cJSON* jsonObj, const std::string& key)
bool IsUInt32(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
if (value == NULL || !cJSON_IsNumber(value)) {
if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) {
return false;
}
return (value->valuedouble >= 0 && value->valuedouble <= UINT32_MAX);
return (jsonObj->valueint >= 0 && jsonObj->valueint <= UINT32_MAX);
}
bool IsBool(const cJSON* jsonObj, const std::string& key)
bool IsBool(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
return (value != NULL && cJSON_IsBool(value));
return (jsonObj != NULL && cJSON_IsBool(jsonObj));
}
bool IsString(const cJSON* jsonObj, const std::string& key)
bool IsString(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
if (value == NULL || !cJSON_IsString(value)) {
if (jsonObj == NULL || !cJSON_IsString(jsonObj)) {
return false;
}
return (strlen(value->valuestring) > MIN_MESSAGE_LEN && strlen(value->valuestring) <= MAX_MESSAGE_LEN);
return (strlen(jsonObj->valuestring) > MIN_MESSAGE_LEN && strlen(jsonObj->valuestring) <= MAX_MESSAGE_LEN);
}
bool IsArray(const cJSON* jsonObj, const std::string& key)
bool IsArray(const cJSON* jsonObj)
{
const cJSON* value = cJSON_GetObjectItem(jsonObj, key.c_str());
if (value == NULL || !cJSON_IsArray(value)) {
if (jsonObj == NULL || !cJSON_IsArray(jsonObj)) {
return false;
}
return ((uint32_t)cJSON_GetArraySize(value) >= 0 && (uint32_t)cJSON_GetArraySize(value) <= MAX_ARR_SIZE);
return ((uint32_t)cJSON_GetArraySize(jsonObj) >= 0 && (uint32_t)cJSON_GetArraySize(jsonObj) <= MAX_ARR_SIZE);
}
std::string Compress(const std::string& data)

View File

@ -41,18 +41,16 @@ void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
DHLOGE("AudioEncoderIn MIME is invalid!\n");
return;
}
audioEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
if (!IsArray(jsonObject, SAMPLE_RATE)) {
DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n");
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioEncoderIn MIME is invalid!");
return;
}
audioEncoderIn.mime = mimeJsonObj->valuestring;
cJSON *sampleRate = cJSON_GetObjectItem(jsonObject, SAMPLE_RATE.c_str());
if (sampleRate == NULL) {
DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n");
if (!IsArray(sampleRate)) {
DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid!");
return;
}
cJSON *sampleRateItem = nullptr;
@ -69,30 +67,33 @@ void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioEncoderOut MIME is invalid!");
return;
}
audioEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
if (!IsUInt32(jsonObject, AD_MPEG_VER)) {
audioEncoderOut.mime = mimeJsonObj->valuestring;
cJSON *mpegVerJsonObj = cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str());
if (!IsUInt32(mpegVerJsonObj)) {
DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!");
return;
}
audioEncoderOut.ad_mpeg_ver = (uint32_t)cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str())->valuedouble;
audioEncoderOut.ad_mpeg_ver = static_cast<uint32_t>(mpegVerJsonObj->valuedouble);
if (!IsUInt8(jsonObject, AUDIO_AAC_PROFILE)) {
cJSON *aacProfileJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str());
if (!IsUInt8(aacProfileJsonObj)) {
DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!");
return;
}
audioEncoderOut.aac_profile =
(AudioAacProfile)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str())->valuedouble;
audioEncoderOut.aac_profile = (AudioAacProfile)aacProfileJsonObj->valuedouble;
if (!IsUInt8(jsonObject, AUDIO_AAC_STREAM_FORMAT)) {
cJSON *aacStreamFmtJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT.c_str());
if (!IsUInt8(aacStreamFmtJsonObj)) {
DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!");
return;
}
audioEncoderOut.aac_stm_fmt =
(AudioAacStreamFormat)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT.c_str())->valuedouble;
audioEncoderOut.aac_stm_fmt = (AudioAacStreamFormat)aacStreamFmtJsonObj->valuedouble;
}
void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
@ -101,17 +102,18 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, NAME)) {
cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("AudioEncoder NAME is invalid!");
return;
}
audioEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
audioEncoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) {
cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(insJson)) {
DHLOGE("AudioEncoder INS is invalid!");
return;
}
cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, insJson) {
AudioEncoderIn in;
@ -119,11 +121,11 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
audioEncoder.ins.push_back(in);
}
if (!IsArray(jsonObject, OUTS)) {
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(outsJson)) {
DHLOGE("AudioEncoder OUTS is invalid!");
return;
}
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, outsJson) {
AudioEncoderOut out;
@ -138,17 +140,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioDecoderIn MIME is invalid!");
return;
}
audioDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
audioDecoderIn.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, AUDIO_CHANNEL_LAYOUT)) {
cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str());
if (!IsArray(channelLayoutJson)) {
DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!");
return;
}
const cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str());
const cJSON *layout = nullptr;
cJSON_ArrayForEach(layout, channelLayoutJson) {
if (layout && layout->type == cJSON_Number) {
@ -163,16 +166,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("AudioDecoderOut MIME is invalid!");
return;
}
audioDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
if (!IsArray(jsonObject, AUDIO_SAMPLE_FORMAT)) {
audioDecoderOut.mime = mimeJsonObj->valuestring;
cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str());
if (!IsArray(sampleFormatJson)) {
DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!");
return;
}
cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str());
cJSON *format = nullptr;
cJSON_ArrayForEach(format, sampleFormatJson) {
if (format && format->type == cJSON_Number) {
@ -187,28 +192,30 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, NAME)) {
cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("AudioDecoderOut MIME is invalid!");
return;
}
audioDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
audioDecoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) {
DHLOGE("AudioDecoder OUTS is invalid!");
cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(insJson)) {
DHLOGE("AudioDecoder INS is invalid!");
return;
}
const cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, insJson) {
AudioDecoderIn in;
FromJson(inJson, in);
audioDecoder.ins.push_back(in);
}
if (!IsArray(jsonObject, OUTS)) {
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(outsJson)) {
DHLOGE("AudioDecoder OUTS is invalid!");
return;
}
cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, outsJson) {
AudioDecoderOut out;
@ -223,17 +230,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoEncoderIn MIME is invalid!");
return;
}
videoEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
videoEncoderIn.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) {
cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
if (!IsArray(videoPixelFmt)) {
DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!");
return;
}
cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
cJSON *pixelFmt = nullptr;
cJSON_ArrayForEach(pixelFmt, videoPixelFmt) {
if (pixelFmt && pixelFmt->type == cJSON_Number) {
@ -248,11 +256,12 @@ void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
DHLOGE("VideoEncoderIn MIME is invalid!");
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoEncoderOut MIME is invalid!");
return;
}
videoEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
videoEncoderOut.mime = mimeJsonObj->valuestring;
}
void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
@ -261,17 +270,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, NAME)) {
cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("VideoEncoder NAME is invalid!");
return;
}
videoEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
videoEncoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) {
cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(videoEncoderInsJson)) {
DHLOGE("VideoEncoder INS is invalid!");
return;
}
cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, videoEncoderInsJson) {
VideoEncoderIn in;
@ -279,11 +289,11 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
videoEncoder.ins.push_back(in);
}
if (!IsArray(jsonObject, OUTS)) {
cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(videoEncoderOutsJson)) {
DHLOGE("VideoEncoder OUTS is invalid!");
return;
}
cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, videoEncoderOutsJson) {
VideoEncoderOut out;
@ -298,17 +308,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoDecoderIn MIME is invalid!");
return;
}
videoDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
videoDecoderIn.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) {
cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str());
if (!IsArray(videoBitStreamFmtJson)) {
DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!");
return;
}
cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str());
cJSON *fmt = nullptr;
cJSON_ArrayForEach(fmt, videoBitStreamFmtJson) {
if (fmt && fmt->type == cJSON_Number) {
@ -323,17 +334,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, MIME)) {
cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str());
if (!IsString(mimeJsonObj)) {
DHLOGE("VideoDecoderOut MIME is invalid!");
return;
}
videoDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
videoDecoderOut.mime = mimeJsonObj->valuestring;
if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) {
cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
if (!IsArray(videoPixelFmtJson)) {
DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!");
return;
}
cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
cJSON *fmt = nullptr;
cJSON_ArrayForEach(fmt, videoPixelFmtJson) {
if (fmt && fmt->type == cJSON_Number) {
@ -348,17 +360,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder)
DHLOGE("Json pointer is nullptr!");
return;
}
if (!IsString(jsonObject, NAME)) {
cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str());
if (!IsString(nameJsonObj)) {
DHLOGE("VideoDecoder NAME is invalid!");
return;
}
videoDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
videoDecoder.name = nameJsonObj->valuestring;
if (!IsArray(jsonObject, INS)) {
cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
if (!IsArray(videoDecoderInsJson)) {
DHLOGE("VideoDecoder INS is invalid!");
return;
}
cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
cJSON *inJson = nullptr;
cJSON_ArrayForEach(inJson, videoDecoderInsJson) {
VideoDecoderIn in;
@ -366,11 +379,11 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder)
videoDecoder.ins.push_back(in);
}
if (!IsArray(jsonObject, OUTS)) {
cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
if (!IsArray(videoDecoderOutsJson)) {
DHLOGE("VideoDecoder OUTS is invalid!");
return;
}
cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
cJSON *outJson = nullptr;
cJSON_ArrayForEach(outJson, videoDecoderOutsJson) {
VideoDecoderOut out;

View File

@ -149,98 +149,62 @@ HWTEST_F(UtilsToolTest, GetDeviceIdByUUID_002, TestSize.Level0)
HWTEST_F(UtilsToolTest, IsUInt8_001, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "int8_key";
cJSON_AddStringToObject(jsonObj, key.c_str(), "int8_key_test");
std::string inputKey = "key";
auto ret = IsUInt8(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(false, ret);
cJSON* jsonObj1 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj1 != nullptr);
cJSON_AddStringToObject(jsonObj1, key.c_str(), "int8_key_test");
ret = IsUInt8(jsonObj1, key);
cJSON_Delete(jsonObj1);
EXPECT_EQ(false, ret);
}
HWTEST_F(UtilsToolTest, IsUInt8_002, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "int8_key";
const uint8_t keyVaule = 1;
cJSON_AddNumberToObject(jsonObj, key.c_str(), keyVaule);
auto ret = IsUInt8(jsonObj, key);
cJSON_Delete(jsonObj);
cJSON_AddStringToObject(jsonObj1, key.c_str(), "int8_key_test");
cJSON *keyJson1 = cJSON_GetObjectItem(jsonObj1, key.c_str());
auto ret = IsUInt8(keyJson1);
EXPECT_EQ(false, ret);
cJSON_Delete(jsonObj1);
cJSON* jsonObj2 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj2 != nullptr);
cJSON_AddNumberToObject(jsonObj2, key.c_str(), 1);
cJSON *keyJson2 = cJSON_GetObjectItem(jsonObj2, key.c_str());
ret = IsUInt8(keyJson2);
EXPECT_EQ(true, ret);
cJSON_Delete(jsonObj2);
}
HWTEST_F(UtilsToolTest, IsUInt16_001, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint16_key";
cJSON_AddStringToObject(jsonObj, key.c_str(), "uint16_key_test");
std::string inputKey = "key";
auto ret = IsUInt16(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(false, ret);
cJSON* jsonObj1 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj1 != nullptr);
const std::string key = "uint16_key";
cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint16_key_test");
ret = IsUInt16(jsonObj1, key);
cJSON *keyJson1 = cJSON_GetObjectItem(jsonObj1, key.c_str());
auto ret = IsUInt16(keyJson1);
cJSON_Delete(jsonObj1);
EXPECT_EQ(false, ret);
}
HWTEST_F(UtilsToolTest, IsUInt16_002, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint16_key";
const uint16_t keyVaule = 1;
cJSON_AddNumberToObject(jsonObj, key.c_str(), keyVaule);
auto ret = IsUInt16(jsonObj, key);
cJSON_Delete(jsonObj);
cJSON* jsonObj2 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj2 != nullptr);
cJSON_AddNumberToObject(jsonObj2, key.c_str(), 1);
cJSON *keyJson2 = cJSON_GetObjectItem(jsonObj2, key.c_str());
ret = IsUInt16(keyJson2);
EXPECT_EQ(true, ret);
cJSON_Delete(jsonObj2);
}
HWTEST_F(UtilsToolTest, IsUInt32_001, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint32_key";
cJSON_AddStringToObject(jsonObj, key.c_str(), "uint32_key_test");
std::string inputKey = "key";
auto ret = IsUInt32(jsonObj, key);
cJSON_Delete(jsonObj);
EXPECT_EQ(false, ret);
cJSON* jsonObj1 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj1 != nullptr);
cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint32_key_test");
ret = IsUInt32(jsonObj1, key);
cJSON_Delete(jsonObj1);
EXPECT_EQ(false, ret);
}
HWTEST_F(UtilsToolTest, IsUInt32_002, TestSize.Level0)
{
cJSON* jsonObj = cJSON_CreateObject();
ASSERT_TRUE(jsonObj != nullptr);
const std::string key = "uint32_key";
const uint32_t keyVaule = 1;
cJSON_AddNumberToObject(jsonObj, key.c_str(), keyVaule);
auto ret = IsUInt32(jsonObj, key);
cJSON_Delete(jsonObj);
cJSON_AddStringToObject(jsonObj1, key.c_str(), "uint32_key_test");
cJSON *keyJson1 = cJSON_GetObjectItem(jsonObj1, key.c_str());
auto ret = IsUInt32(keyJson1);
EXPECT_EQ(false, ret);
cJSON_Delete(jsonObj1);
cJSON* jsonObj2 = cJSON_CreateObject();
ASSERT_TRUE(jsonObj2 != nullptr);
cJSON_AddNumberToObject(jsonObj2, key.c_str(), 1);
cJSON *keyJson2 = cJSON_GetObjectItem(jsonObj2, key.c_str());
ret = IsUInt32(keyJson2);
EXPECT_EQ(true, ret);
cJSON_Delete(jsonObj2);
}
HWTEST_F(UtilsToolTest, GetSysPara_001, TestSize.Level0)