From 3ff361e26e286119dc48448e02710ffad2e859d2 Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Wed, 20 Jan 2021 13:48:43 +0100 Subject: [PATCH] [ML][Pipeline] Implementation setProperty and getProperty ACR: TWDAPI-274 [Verification] Code compiles without error. Tested in chrome console. // test code var pipeline = tizen.ml.pipeline.createPipeline("videotestsrc name=vsrc is-live=true ! videoconvert ! videoscale name=vscale ! video/x-raw,format=RGBx,width=224,height=224,framerate=60/1 ! tensor_converter ! valve name=valvex ! input-selector name=is01 ! tensor_sink name=sinkx") //BOOLEAN var nodeinfo_bool = pipeline.getNodeInfo("is01") nodeinfo_bool.setProperty("sync-streams", "BOOLEAN", true) nodeinfo_bool.getProperty("sync-streams", "BOOLEAN") nodeinfo_bool.setProperty("sync-streams", "BOOLEAN", false) nodeinfo_bool.getProperty("sync-streams", "BOOLEAN") //DOUBLE var nodeinfo_double = pipeline.getNodeInfo("vscale") nodeinfo_double.setProperty("sharpness", "DOUBLE", 0.72) nodeinfo_double.getProperty("sharpness", "DOUBLE") //INT32 var nodeinfo_int32 = pipeline.getNodeInfo("vsrc") nodeinfo_int32.setProperty("kx", "INT32", 10) nodeinfo_int32.getProperty("kx", "INT32") //UINT32 var nodeinfo_uint32 = pipeline.getNodeInfo("vsrc") nodeinfo_uint32.setProperty("foreground-color", "UINT32", 123456) nodeinfo_uint32.getProperty("foreground-color", "UINT32") //INT64 var nodeinfo_int64 = pipeline.getNodeInfo("vsrc") nodeinfo_int64.setProperty("timestamp-offset", "INT64", 10) nodeinfo_int64.getProperty("timestamp-offset", "INT64") //UINT64 var pipeline_uint64 = tizen.ml.pipeline.createPipeline("udpsrc name=usrc port=5555 caps=application/x-rtp ! queue ! fakesink") var nodeinfo_uint64 = pipeline_uint64.getNodeInfo("usrc") nodeinfo_uint64.setProperty("timeout", "UINT64", 166513216516510) nodeinfo_uint64.getProperty("timeout", "UINT64") //STRING var pipeline_string = tizen.ml.pipeline.createPipeline("videotestsrc ! video/x-raw,format=RGB,width=640,height=480 ! videorate max-rate=1 ! tensor_converter ! tensor_mux ! tensor_demux name=demux ! tensor_sink") var nodeinfo_string = pipeline_string.getNodeInfo("demux") nodeinfo_string.setProperty("tensorpick", "STRING", "1,2") nodeinfo_string.getProperty("tensorpick", "STRING") // ENUM var vscale_enum = { GST_VIDEO_SCALE_NEAREST:0, GST_VIDEO_SCALE_BILINEAR:1, GST_VIDEO_SCALE_4TAP:2, GST_VIDEO_SCALE_LANCZOS:3 } var pipeline_enum = tizen.ml.pipeline.createPipeline("videotestsrc name=vsrc is-live=true ! videoconvert ! videoscale name=vscale ! video/x-raw,format=RGBx,width=224,height=224,framerate=60/1 ! tensor_converter ! valve name=valvex ! input-selector name=is01 ! tensor_sink name=sinkx") var nodeinfo_enum = pipeline_enum.getNodeInfo("vscale") nodeinfo_enum.setProperty("method", "ENUM", vscale_enum.GST_VIDEO_SCALE_4TAP) nodeinfo_enum.getProperty("method", "ENUM") Change-Id: I90f9a3986beeb6a071ce4b265965eec399679c55 Signed-off-by: Lukasz Bardeli --- src/ml/js/ml_pipeline.js | 87 ++++++++++++++++ src/ml/ml_instance.cc | 85 +++++++++++---- src/ml/ml_instance.h | 4 +- src/ml/ml_pipeline.cc | 29 +++++- src/ml/ml_pipeline.h | 6 +- src/ml/ml_pipeline_manager.cc | 26 +++++ src/ml/ml_pipeline_manager.h | 6 +- src/ml/ml_pipeline_nodeinfo.cc | 184 ++++++++++++++++++++++++++++++++- src/ml/ml_pipeline_nodeinfo.h | 7 +- 9 files changed, 401 insertions(+), 33 deletions(-) diff --git a/src/ml/js/ml_pipeline.js b/src/ml/js/ml_pipeline.js index ad745f18..425e34c0 100755 --- a/src/ml/js/ml_pipeline.js +++ b/src/ml/js/ml_pipeline.js @@ -321,12 +321,99 @@ Pipeline.prototype.getValve = function() { //Pipeline::unregisterCustomFilter() end +var PropertyType = { + BOOLEAN: 'BOOLEAN', + DOUBLE: 'DOUBLE', + ENUM: 'ENUM', + INT32: 'INT32', + INT64: 'INT64', + UINT32: 'UINT32', + UINT64: 'UINT64', + STRING: 'STRING' +}; //NodeInfo::getProperty() begin +var ValidNodeInfoGetPropertyExceptions = [ + 'InvalidValuesError', + 'NotFoundError', + 'NotSupportedError', + 'TypeMismatchError', + 'AbortError' +]; +NodeInfo.prototype.getProperty = function() { + var args = validator_.validateArgs(arguments, [ + { + name: 'name', + type: validator_.Types.STRING + }, + { + name: 'propertyType', + type: types_.ENUM, + values: Object.keys(PropertyType) + } + ]); + + var nativeArgs = { + id: this._pipeline_id, + nodeName: this.name, + name: args.name, + type: args.propertyType + }; + + var result = native_.callSync('MLPipelineNodeInfoGetProperty', nativeArgs); + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidNodeInfoGetPropertyExceptions, + AbortError + ); + } + return result.property; +}; //NodeInfo::getProperty() end //NodeInfo::setProperty() begin +var ValidNodeInfoSetPropertyExceptions = [ + 'InvalidValuesError', + 'NotFoundError', + 'NotSupportedError', + 'TypeMismatchError', + 'AbortError' +]; +NodeInfo.prototype.setProperty = function() { + var args = validator_.validateArgs(arguments, [ + { + name: 'name', + type: validator_.Types.STRING + }, + { + name: 'propertyType', + type: types_.ENUM, + values: Object.keys(PropertyType) + }, + { + name: 'property', + type: types_.SIMPLE_TYPE + } + ]); + + var nativeArgs = { + id: this._pipeline_id, + nodeName: this.name, + name: args.name, + type: args.propertyType, + property: args.property + }; + var result = native_.callSync('MLPipelineNodeInfoSetProperty', nativeArgs); + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidNodeInfoSetPropertyExceptions, + AbortError + ); + } +}; //NodeInfo::setProperty() end //Source::inputTensorsInfo begin diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 9fe01114..50d04e6f 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -39,6 +39,10 @@ const std::string kDefinition = "definition"; const std::string kPipelineStateChangeListenerName = "listenerName"; const std::string kOtherId = "otherId"; const std::string kPadName = "padName"; +const std::string kNodeName = "nodeName"; +const std::string kProperty = "property"; +const std::string kBOOLEAN = "BOOLEAN"; +const std::string kSTRING = "STRING"; } // namespace using namespace common; @@ -115,6 +119,8 @@ MlInstance::MlInstance() : single_manager_{&tensors_info_manager_}, pipeline_man REGISTER_METHOD(MLPipelineSwitchGetPadList); REGISTER_METHOD(MLPipelineSwitchSelect); REGISTER_METHOD(MLPipelineGetValve); + REGISTER_METHOD(MLPipelineNodeInfoGetProperty); + REGISTER_METHOD(MLPipelineNodeInfoSetProperty); // Pipeline API end #undef REGISTER_METHOD @@ -608,7 +614,7 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: int res_id = -1; result = single_manager_.OpenModel(model_path, in_tensors_info, out_tensors_info, nnfw_e, hw_e, - is_dynamic_mode, &res_id); + is_dynamic_mode, &res_id); if (!result) { ReportError(result, &out); return; @@ -727,11 +733,8 @@ void MlInstance::MLPipelineGetState(const picojson::value& args, picojson::objec void MlInstance::MLPipelineStart(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); - if (!args.get(kId).is()) { - LoggerD("id is not a number"); - ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out); - return; - } + CHECK_ARGS(args, kId, double, out); + auto id = static_cast(args.get(kId).get()); PlatformResult result = pipeline_manager_.Start(id); @@ -749,11 +752,8 @@ void MlInstance::MLPipelineStart(const picojson::value& args, picojson::object& void MlInstance::MLPipelineStop(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); - if (!args.get(kId).is()) { - LoggerD("id is not a number"); - ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out); - return; - } + CHECK_ARGS(args, kId, double, out); + auto id = static_cast(args.get(kId).get()); PlatformResult result = pipeline_manager_.Stop(id); @@ -793,17 +793,8 @@ void MlInstance::MLPipelineDispose(const picojson::value& args, picojson::object void MlInstance::MLPipelineGetNodeInfo(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); - if (!args.get(kId).is()) { - LoggerD("id is not a number"); - ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out); - return; - } - - if (!args.get(kName).is()) { - LoggerD("name is not a string"); - ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid name"}, &out); - return; - } + CHECK_ARGS(args, kId, double, out); + CHECK_ARGS(args, kName, std::string, out); auto name = args.get(kName).get(); auto id = static_cast(args.get(kId).get()); @@ -891,11 +882,61 @@ void MlInstance::MLPipelineGetValve(const picojson::value& args, picojson::objec // Pipeline::unregisterCustomFilter() end // NodeInfo::getProperty() begin +void MlInstance::MLPipelineNodeInfoGetProperty(const picojson::value& args, picojson::object& out) { + ScopeLogger("args: %s", args.serialize().c_str()); + + CHECK_ARGS(args, kId, double, out); + CHECK_ARGS(args, kNodeName, std::string, out); + CHECK_ARGS(args, kName, std::string, out); + CHECK_ARGS(args, kType, std::string, out); + + auto id = static_cast(args.get(kId).get()); + const auto& name = args.get(kName).get(); + const auto& node_name = args.get(kNodeName).get(); + const auto& type = args.get(kType).get(); + + PlatformResult result = pipeline_manager_.getProperty(id, node_name, name, type, &out); + if (!result) { + LogAndReportError(result, &out); + return; + } + + ReportSuccess(out); +} // NodeInfo::getProperty() end // NodeInfo::setProperty() begin +void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, picojson::object& out) { + ScopeLogger("args: %s", args.serialize().c_str()); + CHECK_ARGS(args, kId, double, out); + CHECK_ARGS(args, kNodeName, std::string, out); + CHECK_ARGS(args, kName, std::string, out); + CHECK_ARGS(args, kType, std::string, out); + + auto id = static_cast(args.get(kId).get()); + const auto& name = args.get(kName).get(); + const auto& node_name = args.get(kNodeName).get(); + const auto& type = args.get(kType).get(); + + if (kBOOLEAN == type) { + CHECK_ARGS(args, kProperty, bool, out); + } else if (kSTRING == type) { + CHECK_ARGS(args, kProperty, std::string, out); + } else { + CHECK_ARGS(args, kProperty, double, out); + } + const picojson::value& property = args.get(kProperty); + + PlatformResult result = pipeline_manager_.setProperty(id, node_name, name, type, property); + if (!result) { + LogAndReportError(result, &out); + return; + } + + ReportSuccess(out); +} // NodeInfo::setProperty() end // Source::inputTensorsInfo begin diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 9619647b..cb05d46c 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -124,11 +124,11 @@ class MlInstance : public common::ParsedInstance { // Pipeline::unregisterCustomFilter() end // NodeInfo::getProperty() begin - + void MLPipelineNodeInfoGetProperty(const picojson::value& args, picojson::object& out); // NodeInfo::getProperty() end // NodeInfo::setProperty() begin - + void MLPipelineNodeInfoSetProperty(const picojson::value& args, picojson::object& out); // NodeInfo::setProperty() end // Source::inputTensorsInfo begin diff --git a/src/ml/ml_pipeline.cc b/src/ml/ml_pipeline.cc index 11ec31a3..fe359489 100644 --- a/src/ml/ml_pipeline.cc +++ b/src/ml/ml_pipeline.cc @@ -71,7 +71,7 @@ Pipeline::Pipeline(int id, const std::string& state_change_listener_name, ScopeLogger("id: [%d], state_change_listener_name: [%s]", id, state_change_listener_name.c_str()); } -// PipelineManager::createPipeline() begin +// Pipeline::createPipeline() begin PlatformResult Pipeline::CreatePipeline(int id, const std::string& definition, const std::string& state_change_listener_name, common::Instance* instance_ptr, @@ -107,7 +107,7 @@ PlatformResult Pipeline::CreatePipeline(int id, const std::string& definition, *out = std::move(pipeline_ptr); return PlatformResult{}; } -// PipelineManager::createPipeline() end +// Pipeline::createPipeline() end Pipeline::~Pipeline() { ScopeLogger("Destroying pipeline: [%d]", id_); @@ -295,11 +295,36 @@ PlatformResult Pipeline::GetValve(const std::string& name) { // Pipeline::unregisterCustomFilter() end // NodeInfo::getProperty() begin +PlatformResult Pipeline::getProperty(const std::string& node_name, const std::string& name, + const std::string& type, picojson::object* property) { + ScopeLogger("id_: [%d], name: [%s], type: [%s]", id_, name.c_str(), type.c_str()); + + auto nodeinfo_it = node_info_.find(node_name); + if (node_info_.end() == nodeinfo_it) { + LoggerD("NodeInfo [%s] not found", node_name.c_str()); + return PlatformResult{ErrorCode::NOT_FOUND_ERR, "NodeInfo not found"}; + } + + auto ret = nodeinfo_it->second->getProperty(name, type, property); + return ret; +} // NodeInfo::getProperty() end // NodeInfo::setProperty() begin +PlatformResult Pipeline::setProperty(const std::string& node_name, const std::string& name, + const std::string& type, const picojson::value& property) { + ScopeLogger("id_: [%d], name: [%s], type: [%s]", id_, name.c_str(), type.c_str()); + + auto nodeinfo_it = node_info_.find(node_name); + if (node_info_.end() == nodeinfo_it) { + LoggerD("NodeInfo [%s] not found", node_name.c_str()); + return PlatformResult{ErrorCode::NOT_FOUND_ERR, "NodeInfo not found"}; + } + auto ret = nodeinfo_it->second->setProperty(name, type, property); + return ret; +} // NodeInfo::setProperty() end // Source::inputTensorsInfo begin diff --git a/src/ml/ml_pipeline.h b/src/ml/ml_pipeline.h index 110cec90..afe3fee4 100644 --- a/src/ml/ml_pipeline.h +++ b/src/ml/ml_pipeline.h @@ -104,11 +104,13 @@ class Pipeline { // Pipeline::unregisterCustomFilter() end // NodeInfo::getProperty() begin - + PlatformResult getProperty(const std::string& node_name, const std::string& name, + const std::string& type, picojson::object* property); // NodeInfo::getProperty() end // NodeInfo::setProperty() begin - + PlatformResult setProperty(const std::string& node_name, const std::string& name, + const std::string& type, const picojson::value& property); // NodeInfo::setProperty() end // Source::inputTensorsInfo begin diff --git a/src/ml/ml_pipeline_manager.cc b/src/ml/ml_pipeline_manager.cc index a4032005..3e1cc413 100644 --- a/src/ml/ml_pipeline_manager.cc +++ b/src/ml/ml_pipeline_manager.cc @@ -193,11 +193,37 @@ PlatformResult PipelineManager::GetValve(const std::string& name, int pipeline_i // Pipeline::unregisterCustomFilter() end // NodeInfo::getProperty() begin +PlatformResult PipelineManager::getProperty(int id, const std::string& node_name, + const std::string& name, const std::string& type, + picojson::object* property) { + ScopeLogger("id: [%d], name [%s], nodeName [%s], type [%s] ", id, name.c_str(), node_name.c_str(), + type.c_str()); + auto pipeline_it = pipelines_.find(id); + if (pipelines_.end() == pipeline_it) { + LoggerD("Pipeline not found: [%d]", id); + return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"}; + } + + return pipeline_it->second->getProperty(node_name, name, type, property); +} // NodeInfo::getProperty() end // NodeInfo::setProperty() begin +PlatformResult PipelineManager::setProperty(int id, const std::string& node_name, + const std::string& name, const std::string& type, + const picojson::value& property) { + ScopeLogger("id: [%d], name [%s], nodeName [%s], type [%s] ", id, name.c_str(), node_name.c_str(), + type.c_str()); + auto pipeline_it = pipelines_.find(id); + if (pipelines_.end() == pipeline_it) { + LoggerD("Pipeline not found: [%d]", id); + return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"}; + } + + return pipeline_it->second->setProperty(node_name, name, type, property); +} // NodeInfo::setProperty() end // Source::inputTensorsInfo begin diff --git a/src/ml/ml_pipeline_manager.h b/src/ml/ml_pipeline_manager.h index 666887f0..f9866248 100644 --- a/src/ml/ml_pipeline_manager.h +++ b/src/ml/ml_pipeline_manager.h @@ -92,11 +92,13 @@ class PipelineManager { // Pipeline::unregisterCustomFilter() end // NodeInfo::getProperty() begin - + PlatformResult getProperty(int id, const std::string& node_name, const std::string& name, + const std::string& type, picojson::object* property); // NodeInfo::getProperty() end // NodeInfo::setProperty() begin - + PlatformResult setProperty(int id, const std::string& node_name, const std::string& name, + const std::string& type, const picojson::value& property); // NodeInfo::setProperty() end // Source::inputTensorsInfo begin diff --git a/src/ml/ml_pipeline_nodeinfo.cc b/src/ml/ml_pipeline_nodeinfo.cc index 91fe836a..c6ebfbfa 100644 --- a/src/ml/ml_pipeline_nodeinfo.cc +++ b/src/ml/ml_pipeline_nodeinfo.cc @@ -23,6 +23,18 @@ using common::PlatformResult; using common::ErrorCode; +namespace { +const std::string kProperty = "property"; +const std::string kBOOLEAN = "BOOLEAN"; +const std::string kDOUBLE = "DOUBLE"; +const std::string kENUM = "ENUM"; +const std::string kINT32 = "INT32"; +const std::string kUINT32 = "UINT32"; +const std::string kINT64 = "INT64"; +const std::string kUINT64 = "UINT64"; +const std::string kSTRING = "STRING"; +} // namespace + namespace extension { namespace ml { namespace pipeline { @@ -45,7 +57,7 @@ PlatformResult NodeInfo::CreateNodeInfo(ml_pipeline_h pipeline, const std::strin } NodeInfo::NodeInfo(const std::string& name) : name_{name} { - ScopeLogger("name: [%s], ", name.c_str()); + ScopeLogger("name: [%s] ", name.c_str()); } NodeInfo::~NodeInfo() { @@ -59,6 +71,174 @@ NodeInfo::~NodeInfo() { } } +PlatformResult NodeInfo::getProperty(const std::string& name, const std::string& type, + picojson::object* property) { + ScopeLogger("name: [%s], type: [%s]", name.c_str(), type.c_str()); + if (kBOOLEAN == type) { + int32_t val; + int ret = ml_pipeline_element_get_property_bool(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_bool() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty Bool %d", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kDOUBLE == type) { + double val; + int ret = ml_pipeline_element_get_property_double(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_double() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty Double %f", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kENUM == type) { + uint32_t val; + int ret = ml_pipeline_element_get_property_enum(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_enum() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty Enum %u", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kINT32 == type) { + int32_t val; + int ret = ml_pipeline_element_get_property_int32(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_int32() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty Int32 %d", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kINT64 == type) { + int64_t val; + int ret = ml_pipeline_element_get_property_int64(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_int64() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty Int64 %lld", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kUINT32 == type) { + uint32_t val; + int ret = ml_pipeline_element_get_property_uint32(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_uint32() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty UInt32 %u", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kUINT64 == type) { + uint64_t val; + int ret = ml_pipeline_element_get_property_uint64(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_uint64() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty UInt64 %llu", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else if (kSTRING == type) { + char* val; + int ret = ml_pipeline_element_get_property_string(node_info_, name.c_str(), &val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_get_property_string() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not get property of NodeInfo"); + } + LoggerD("getProperty UString %s", val); + property->insert(std::make_pair(kProperty, picojson::value(static_cast(val)))); + } else { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid PropertyType", + ("Unknown property type")); + } + + return PlatformResult{}; +} + +PlatformResult NodeInfo::setProperty(const std::string& name, const std::string& type, + const picojson::value& property) { + ScopeLogger("name: [%s], type: [%s]", name.c_str(), type.c_str()); + + if (kBOOLEAN == type) { + bool bval = property.get(); + int32_t val = bval ? 1 : 0; + int ret = ml_pipeline_element_set_property_bool(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_bool() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kDOUBLE == type) { + double val = property.get(); + int ret = ml_pipeline_element_set_property_double(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_double() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kENUM == type) { + uint32_t val = static_cast(property.get()); + int ret = ml_pipeline_element_set_property_enum(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_enum() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kINT32 == type) { + int32_t val = static_cast(property.get()); + int ret = ml_pipeline_element_set_property_int32(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_int32() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kINT64 == type) { + int64_t val = static_cast(property.get()); + int ret = ml_pipeline_element_set_property_int64(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_int64() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kUINT32 == type) { + uint32_t val = static_cast(property.get()); + int ret = ml_pipeline_element_set_property_uint32(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_uint32() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kUINT64 == type) { + uint64_t val = static_cast(property.get()); + int ret = ml_pipeline_element_set_property_uint64(node_info_, name.c_str(), val); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_uint64() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else if (kSTRING == type) { + const std::string& val = property.get(); + int ret = ml_pipeline_element_set_property_string(node_info_, name.c_str(), val.c_str()); + if (ML_ERROR_NONE != ret) { + LoggerE("ml_pipeline_element_set_property_string() failed: [%d] (%s)", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Could not set property of NodeInfo"); + } + } else { + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid PropertyType", + ("Unknown property type")); + } + + return PlatformResult{}; +} + } // namespace pipeline } // namespace ml -} // namespace extension \ No newline at end of file +} // namespace extension diff --git a/src/ml/ml_pipeline_nodeinfo.h b/src/ml/ml_pipeline_nodeinfo.h index 4140025e..dcc22ac1 100644 --- a/src/ml/ml_pipeline_nodeinfo.h +++ b/src/ml/ml_pipeline_nodeinfo.h @@ -40,6 +40,11 @@ class NodeInfo { ~NodeInfo(); + PlatformResult getProperty(const std::string& name, const std::string& type, + picojson::object* property); + PlatformResult setProperty(const std::string& name, const std::string& type, + const picojson::value& property); + private: NodeInfo(const std::string& name); const std::string name_; @@ -50,4 +55,4 @@ class NodeInfo { } // namespace ml } // namespace extension -#endif // ML_ML_PIPELINE_NODEINFO_H_ \ No newline at end of file +#endif // ML_ML_PIPELINE_NODEINFO_H_ -- 2.34.1