//Pipeline::state end
//Pipeline::start() begin
-var ValidPipelineStartStopExceptions = ['NotFoundError', 'NotSupportedError', 'AbortError'];
+var ValidPipelineStartStopExceptions = [
+ 'NotFoundError',
+ 'NotSupportedError',
+ 'AbortError'
+];
Pipeline.prototype.start = function() {
var nativeArgs = {
id: this._id
//Pipeline::dispose() end
//Pipeline::getNodeInfo() begin
+var NodeInfo = function(name, pipeline_id) {
+ Object.defineProperties(this, {
+ name: { enumerable: true, writable: false, value: name },
+ _pipeline_id: { value: pipeline_id }
+ });
+};
+
+var ValidPipelineGetNodeInfoExceptions = [
+ 'InvalidValuesError',
+ 'NotFoundError',
+ 'NotSupportedError',
+ 'AbortError'
+];
+
+Pipeline.prototype.getNodeInfo = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'name',
+ type: validator_.Types.STRING
+ }
+ ]);
+
+ var nativeArgs = {
+ id: this._id,
+ name: args.name
+ };
+
+ var result = native_.callSync('MLPipelineGetNodeInfo', nativeArgs);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidPipelineGetNodeInfoExceptions,
+ AbortError
+ );
+ }
+ return new NodeInfo(args.name, this._id);
+};
//Pipeline::getNodeInfo() end
//Pipeline::getSource() begin
'ml_pipeline.h',
'ml_pipeline_manager.cc',
'ml_pipeline_manager.h',
+ 'ml_pipeline_nodeinfo.cc',
+ 'ml_pipeline_nodeinfo.h',
'ml_utils.cc',
'ml_utils.h',
],
REGISTER_METHOD(MLPipelineDispose);
REGISTER_METHOD(MLPipelineStart);
REGISTER_METHOD(MLPipelineStop);
+ REGISTER_METHOD(MLPipelineGetNodeInfo);
// Pipeline API end
#undef REGISTER_METHOD
namespace {
const std::string kId = "id";
+const std::string kName = "name";
const std::string kDefinition = "definition";
const std::string kPipelineStateChangeListenerName = "listenerName";
// Pipeline::dispose() end
// Pipeline::getNodeInfo() begin
+void MlInstance::MLPipelineGetNodeInfo(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+
+ if (!args.get(kId).is<double>()) {
+ LoggerD("id is not a number");
+ ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out);
+ return;
+ }
+
+ if (!args.get(kName).is<std::string>()) {
+ LoggerD("name is not a string");
+ ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid name"}, &out);
+ return;
+ }
+ auto name = args.get(kName).get<std::string>();
+ auto id = static_cast<int>(args.get(kId).get<double>());
+
+ PlatformResult result = pipeline_manager_.GetNodeInfo(id, name);
+
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
// Pipeline::getNodeInfo() end
// Pipeline::getSource() begin
// Pipeline::dispose() end
// Pipeline::getNodeInfo() begin
-
+ void MLPipelineGetNodeInfo(const picojson::value& args, picojson::object& out);
// Pipeline::getNodeInfo() end
// Pipeline::getSource() begin
* If they're released after pipeline_, the app may crash.
*/
+ node_info_.clear();
+
auto ret = ml_pipeline_destroy(pipeline_);
if (ML_ERROR_NONE != ret) {
LoggerE("ml_pipeline_destroy() failed: [%d] (%s)", ret, get_error_message(ret));
// Pipeline::dispose() end
// Pipeline::getNodeInfo() begin
+PlatformResult Pipeline::GetNodeInfo(std::string& name) {
+ ScopeLogger("id_: [%d], name: [%s]", id_, name.c_str());
+
+ auto nodeinfo_it = node_info_.find(name);
+ if (node_info_.end() != nodeinfo_it) {
+ LoggerD("NodeInfo [%s] found", name.c_str());
+ return PlatformResult{};
+ }
+ std::unique_ptr<NodeInfo> node_info_ptr;
+ auto ret = NodeInfo::CreateNodeInfo(pipeline_, name, &node_info_ptr);
+
+ if (!ret) {
+ return ret;
+ }
+
+ node_info_.insert({name, std::move(node_info_ptr)});
+
+ return PlatformResult{};
+}
// Pipeline::getNodeInfo() end
// Pipeline::getSource() begin
#include "common/extension.h"
#include "common/picojson.h"
#include "common/platform_result.h"
+#include "ml_pipeline_nodeinfo.h"
using common::PlatformResult;
+using extension::ml::pipeline::NodeInfo;
namespace extension {
namespace ml {
// Pipeline::dispose() end
// Pipeline::getNodeInfo() begin
-
+ PlatformResult GetNodeInfo(std::string& name);
// Pipeline::getNodeInfo() end
// Pipeline::getSource() begin
const std::string state_change_listener_name_;
common::Instance* instance_ptr_;
+ std::map<std::string, std::unique_ptr<NodeInfo>> node_info_;
+
static void PipelineStateChangeListener(ml_pipeline_state_e state, void* user_data);
};
// Pipeline::dispose() end
// Pipeline::getNodeInfo() begin
+PlatformResult PipelineManager::GetNodeInfo(int id, std::string& name) {
+ ScopeLogger("id: [%d], name [%s]", id, name.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"};
+ }
+
+ auto ret = pipeline_it->second->GetNodeInfo(name);
+ return ret;
+}
// Pipeline::getNodeInfo() end
// Pipeline::getSource() begin
// Pipeline::dispose() end
// Pipeline::getNodeInfo() begin
-
+ PlatformResult GetNodeInfo(int id, std::string& name);
// Pipeline::getNodeInfo() end
// Pipeline::getSource() begin
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <tizen.h>
+
+#include "common/logger.h"
+#include "ml_pipeline_nodeinfo.h"
+#include "ml_utils.h"
+
+using common::PlatformResult;
+using common::ErrorCode;
+
+namespace extension {
+namespace ml {
+namespace pipeline {
+
+PlatformResult NodeInfo::CreateNodeInfo(ml_pipeline_h pipeline, const std::string& name,
+ std::unique_ptr<NodeInfo>* out) {
+ std::unique_ptr<NodeInfo> nodeinfo_ptr{new (std::nothrow) NodeInfo{name}};
+ if (!nodeinfo_ptr) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "An unknown occurred.",
+ ("Could not allocate memory for NodeInfo"));
+ }
+ auto ret = ml_pipeline_element_get_handle(pipeline, name.c_str(), &nodeinfo_ptr->node_info_);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_element_get_handle() failed: [%d] (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Could not get NodeInfo");
+ }
+
+ *out = std::move(nodeinfo_ptr);
+ return PlatformResult{};
+}
+
+NodeInfo::NodeInfo(const std::string& name) : name_{name} {
+ ScopeLogger("name: [%s], ", name.c_str());
+}
+
+NodeInfo::~NodeInfo() {
+ ScopeLogger("name: [%s], handle: [%p]", name_.c_str(), node_info_);
+
+ auto ret = ml_pipeline_element_release_handle(node_info_);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_element_release_handle() failed: [%d] (%s)", ret, get_error_message(ret));
+ } else {
+ LoggerD("ml_pipeline_element_release_handle() succeeded");
+ }
+}
+
+} // namespace pipeline
+} // namespace ml
+} // namespace extension
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ML_ML_PIPELINE_NODEINFO_H_
+#define ML_ML_PIPELINE_NODEINFO_H_
+
+#include <memory>
+#include <string>
+
+#include <nnstreamer/nnstreamer.h>
+
+#include "common/platform_result.h"
+
+using common::PlatformResult;
+
+namespace extension {
+namespace ml {
+namespace pipeline {
+
+class NodeInfo {
+ public:
+ NodeInfo() = delete;
+ NodeInfo(const NodeInfo&) = delete;
+ NodeInfo& operator=(const NodeInfo&) = delete;
+ static PlatformResult CreateNodeInfo(ml_pipeline_h pipeline, const std::string& name,
+ std::unique_ptr<NodeInfo>* out);
+
+ ~NodeInfo();
+
+ private:
+ NodeInfo(const std::string& name);
+ const std::string name_;
+ ml_pipeline_element_h node_info_;
+};
+
+} // namespace pipeline
+} // namespace ml
+} // namespace extension
+
+#endif // ML_ML_PIPELINE_NODEINFO_H_
\ No newline at end of file