Formatters::CFormatterJsonSDLRPCv2::tMetaFormatterErrorCode Formatters::CFormatterJsonSDLRPCv2::MetaFormatToString( const NsSmartDeviceLink::NsSmartObjects::SmartObject& object, const NsSmartDeviceLink::NsSmartObjects::CSmartSchema& schema, std::string& outStr) { meta_formatter_error_code::tMetaFormatterErrorCode result_code = meta_formatter_error_code::kErrorOk; NsSmartDeviceLink::NsSmartObjects::SmartObject tmp_object; if (false == CMetaFormatter::CreateObjectByPattern(object, schema, tmp_object)) { result_code |= meta_formatter_error_code::kErrorFailedCreateObjectBySchema; return result_code; } // determine whether smart objects are functions // (in terms of SDLRPC communication) bool is_root_object_created_by_schema = ( (tmp_object.getType() == smart_objects_ns::SmartType_Map) && tmp_object.keyExists(jsonhandler_ns::strings::S_PARAMS) && tmp_object.keyExists(jsonhandler_ns::strings::S_MSG_PARAMS)); bool is_root_object = ( (object.getType() == smart_objects_ns::SmartType_Map) && object.keyExists(jsonhandler_ns::strings::S_PARAMS) && object.keyExists(jsonhandler_ns::strings::S_MSG_PARAMS)); if (false == is_root_object) { result_code |= meta_formatter_error_code::kErrorObjectIsNotFunction; } if (false == is_root_object_created_by_schema) { result_code |= meta_formatter_error_code::kErrorSchemaIsNotFunction; } CFormatterJsonSDLRPCv2::toString(tmp_object, outStr); return result_code; }
bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject &object) { if(false == object.keyExists(strings::S_PARAMS)) return false; if(false == object[strings::S_PARAMS].keyExists(strings::S_MESSAGE_TYPE)) return false; if(false == object[strings::S_PARAMS].keyExists(strings::S_FUNCTION_ID)) return false; MessageTypeEnum msgtype((MessageTypeEnum)(int)object[strings::S_PARAMS][strings::S_MESSAGE_TYPE]); FunctionIdEnum fid((FunctionIdEnum)(int)object[strings::S_PARAMS][strings::S_FUNCTION_ID]); SmartSchemaKey<FunctionIdEnum, MessageTypeEnum> key(fid, msgtype); typename FuncionsSchemesMap::iterator schemaIterator = functions_schemes_.find(key); if(schemaIterator == functions_schemes_.end()) { // Schema was not found return false; } object.setSchema(schemaIterator->second); schemaIterator->second.applySchema(object); return true; }