//Pipeline::getSwitch() end
//Pipeline::getValve() begin
+function Valve(name, pipeline_id) {
+ Object.defineProperties(this, {
+ name: {
+ enumerable: true,
+ value: name
+ },
+ _pipeline_id: {
+ value: pipeline_id
+ }
+ });
+}
+var ValidPipelineGetValveExceptions = [
+ 'InvalidValuesError',
+ 'NotFoundError',
+ 'NotSupportedError',
+ 'AbortError'
+];
+Pipeline.prototype.getValve = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'name',
+ type: validator_.Types.STRING
+ }
+ ]);
+
+ var nativeArgs = {
+ name: args.name,
+ id: this._id
+ };
+
+ var result = native_.callSync('MLPipelineGetValve', nativeArgs);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidPipelineGetValveExceptions,
+ AbortError
+ );
+ }
+
+ return new Valve(nativeArgs.name, this._id);
+};
//Pipeline::getValve() end
//Pipeline::registerSinkCallback() begin
'ml_pipeline_switch.cc',
'ml_pipeline_switch.h',
#TODO pipeline Source
- #TODO pipeline Valve
+ 'ml_pipeline_valve.h',
+ 'ml_pipeline_valve.cc',
'ml_tensors_info_manager.cc',
'ml_tensors_info_manager.h',
#TODO single SingleShotManager
REGISTER_METHOD(MLPipelineGetSwitch);
REGISTER_METHOD(MLPipelineSwitchGetPadList);
REGISTER_METHOD(MLPipelineSwitchSelect);
+ REGISTER_METHOD(MLPipelineGetValve);
// Pipeline API end
#undef REGISTER_METHOD
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
+void MlInstance::MLPipelineGetValve(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+
+ CHECK_ARGS(args, kId, double, out);
+ CHECK_ARGS(args, kName, std::string, out);
+
+ auto name = args.get(kName).get<std::string>();
+ auto pipeline_id = args.get(kId).get<double>();
+ auto ret = pipeline_manager_.GetValve(name, pipeline_id);
+ if (!ret) {
+ LogAndReportError(ret, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
// Pipeline::getValve() end
// Pipeline::registerSinkCallback() begin
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
-
+ void MLPipelineGetValve(const picojson::value& args, picojson::object& out);
// Pipeline::getValve() end
// Pipeline::registerSinkCallback() begin
node_info_.clear();
+ valves_.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::getSwitch() end
// Pipeline::getValve() begin
+PlatformResult Pipeline::GetValve(const std::string& name) {
+ ScopeLogger("id: [%d], name: [%s]", id_, name.c_str());
+
+ auto valve_it = valves_.find(name);
+ if (valves_.end() != valve_it) {
+ LoggerD("Valve [%s] found", name.c_str());
+ return PlatformResult{};
+ }
+ LoggerD("Creating [%s] Valve", name.c_str());
+ std::unique_ptr<Valve> valve_ptr;
+ auto ret = Valve::CreateValve(name, pipeline_, &valve_ptr);
+ if (ret) {
+ valves_.insert({name, std::move(valve_ptr)});
+ }
+ return ret;
+}
// Pipeline::getValve() end
// Pipeline::registerSinkCallback() begin
#include "common/platform_result.h"
#include "ml_pipeline_nodeinfo.h"
#include "ml_pipeline_switch.h"
+#include "ml_pipeline_valve.h"
using common::PlatformResult;
using namespace extension::ml::pipeline;
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
-
+ PlatformResult GetValve(const std::string& name);
// Pipeline::getValve() end
// Pipeline::registerSinkCallback() begin
*/
/*
- * As switch controls the flow of the data in the pipeline
- * and users could potentially want to access it
- * often, we use unordered_map instead of a map for quick
+ * As switch/valve control the flow of the data in the pipeline
+ * and users could potentially want to access them
+ * often, we use unordered_maps instead of a maps for quick
* retrieval.
*/
std::unordered_map<std::string, std::unique_ptr<Switch>> switches_;
std::map<std::string, std::unique_ptr<NodeInfo>> node_info_;
+ std::unordered_map<std::string, std::unique_ptr<Valve>> valves_;
static void PipelineStateChangeListener(ml_pipeline_state_e state, void* user_data);
};
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
+PlatformResult PipelineManager::GetValve(const std::string& name, int pipeline_id) {
+ ScopeLogger("name: [%s], pipeline_id: [%d]", name.c_str(), pipeline_id);
+
+ auto pipeline_it = pipelines_.find(pipeline_id);
+ if (pipelines_.end() == pipeline_it) {
+ LoggerD("Pipeline not found: [%d]", pipeline_id);
+ return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"};
+ }
+ return pipeline_it->second->GetValve(name);
+}
// Pipeline::getValve() end
// Pipeline::registerSinkCallback() begin
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
-
+ PlatformResult GetValve(const std::string& name, int pipeline_id);
// Pipeline::getValve() end
// Pipeline::registerSinkCallback() begin
--- /dev/null
+/*
+ * Copyright (c) 2021 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 "ml_pipeline_valve.h"
+#include "ml_utils.h"
+
+using common::PlatformResult;
+using common::ErrorCode;
+
+namespace extension {
+namespace ml {
+namespace pipeline {
+
+PlatformResult Valve::CreateValve(const std::string& name, ml_pipeline_h pipeline,
+ std::unique_ptr<Valve>* out) {
+ ScopeLogger("name: [%s], pipeline: [%p]", name.c_str(), pipeline);
+
+ ml_pipeline_valve_h valve_handle = nullptr;
+ auto ret = ml_pipeline_valve_get_handle(pipeline, name.c_str(), &valve_handle);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_valve_get_handle() failed: [%d] (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Could not get valve");
+ }
+ LoggerD("ml_pipeline_valve_get_handle() succeeded");
+
+ out->reset(new (std::nothrow) Valve{name, valve_handle});
+ if (!out) {
+ ret = ml_pipeline_valve_release_handle(valve_handle);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_valve_release_handle() failed: [%d] (%s)", ret, get_error_message(ret));
+ } else {
+ LoggerD("ml_pipeline_valve_release_handle() succeeded");
+ }
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Could not get the valve",
+ ("Could not allocate memory"));
+ }
+
+ return PlatformResult{};
+}
+
+Valve::Valve(const std::string& name, ml_pipeline_valve_h valve_handle)
+ : name_{name}, valve_{valve_handle} {
+ ScopeLogger("name: [%s], handle: [%p]", name.c_str(), valve_handle);
+}
+
+Valve::~Valve() {
+ ScopeLogger("name: [%s], handle: [%p]", name_.c_str(), valve_);
+
+ auto ret = ml_pipeline_valve_release_handle(valve_);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_valve_release_handle() failed: [%d] (%s)", ret, get_error_message(ret));
+ } else {
+ LoggerD("ml_pipeline_valve_release_handle() succeeded");
+ }
+}
+
+} // namespace pipeline
+} // namespace ml
+} // namespace extension
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2021 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_VALVE_H_
+#define ML_ML_PIPELINE_VALVE_H_
+
+#include <memory>
+#include <string>
+
+#include <nnstreamer/nnstreamer.h>
+
+#include "common/platform_result.h"
+
+using common::PlatformResult;
+
+namespace extension {
+namespace ml {
+namespace pipeline {
+
+class Valve {
+ public:
+ static PlatformResult CreateValve(const std::string& name, ml_pipeline_h pipeline,
+ std::unique_ptr<Valve>* out);
+
+ ~Valve();
+
+ Valve(const Valve&) = delete;
+ Valve& operator=(const Valve&) = delete;
+
+ private:
+ Valve(const std::string& name, ml_pipeline_valve_h valve_handle);
+ const std::string name_;
+ const ml_pipeline_valve_h valve_;
+};
+
+} // namespace pipeline
+} // namespace ml
+} // namespace extension
+
+#endif // ML_ML_PIPELINE_VALVE_H_
\ No newline at end of file