[ML][pipeline] Implement Pipeline::state getter 75/250775/12
authorPawel Wasowski <p.wasowski2@samsung.com>
Mon, 4 Jan 2021 09:59:39 +0000 (10:59 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Mon, 18 Jan 2021 09:04:04 +0000 (09:04 +0000)
ACR: TWDAPI-274

[Verification] Tested in Chrome DevTools with the snippets below. Works fine

 var pipeline = tizen.ml.pipeline.createPipeline('videotestsrc ! tizenwlsink',
                  function(state) {console.log(state);})

<wait a few seconds>

pipeline.state

Change-Id: Iae5e70c63d5c9fd98877defe0949024516c8c41d
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/ml/js/ml_pipeline.js
src/ml/ml_instance.cc
src/ml/ml_instance.h
src/ml/ml_pipeline.cc
src/ml/ml_pipeline.h
src/ml/ml_pipeline_manager.cc
src/ml/ml_pipeline_manager.h

index f50b97ab11f600f186254c0c4bc52d8368dbe75d..3472be1fe5cc80e138c9aa8113fc4e2a40484d37 100755 (executable)
@@ -101,7 +101,7 @@ var Pipeline = function(id) {
                     );
                 }
 
-                return result.state;
+                return result.result;
             }
         },
         _id: {
index 5d2f242d0ed6e298aa75959f9eaa7826c8b0a340..0576dac0cd235adddd71d50931cc4d72df43c831 100644 (file)
@@ -40,6 +40,7 @@ MlInstance::MlInstance() : pipeline_manager_{this} {
 
   // Pipeline API begin
   REGISTER_METHOD(MLPipelineManagerCreatePipeline);
+  REGISTER_METHOD(MLPipelineGetState);
 
 // Pipeline API end
 
@@ -113,7 +114,26 @@ void MlInstance::MLPipelineManagerCreatePipeline(const picojson::value& args,
 // PipelineManager::createPipeline() end
 
 // Pipeline::state begin
+void MlInstance::MLPipelineGetState(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;
+  }
+  auto id = static_cast<int>(args.get(kId).get<double>());
 
+  picojson::value state_value{std::string{}};
+  std::string* state_ptr = &state_value.get<std::string>();
+  auto ret = pipeline_manager_.GetPipelineState(id, state_ptr);
+  if (!ret) {
+    ReportError(ret, &out);
+    return;
+  }
+
+  ReportSuccess(state_value, out);
+}
 // Pipeline::state end
 
 // Pipeline::start() begin
index 622bcc8a515aa71c43f740ae92f785f61b7f9379..7bb28f444cf41082bfc68c02e47918e95fe7ea63 100644 (file)
@@ -48,7 +48,7 @@ class MlInstance : public common::ParsedInstance {
   // PipelineManager::createPipeline() end
 
   // Pipeline::state begin
-
+  void MLPipelineGetState(const picojson::value& args, picojson::object& out);
   // Pipeline::state end
 
   // Pipeline::start() begin
index caa63a50b3c5b885d816fce094f7e999c6067387..6faec4473a5aa898b8437d3b71174cfb7eda211f 100644 (file)
@@ -133,7 +133,20 @@ void Pipeline::PipelineStateChangeListener(ml_pipeline_state_e state, void* user
 }
 
 // Pipeline::state begin
+PlatformResult Pipeline::GetState(std::string* out) {
+  ScopeLogger("id_: [%d]", id_);
 
+  ml_pipeline_state_e state = ML_PIPELINE_STATE_UNKNOWN;
+  auto ret = ml_pipeline_get_state(pipeline_, &state);
+  if (ML_ERROR_NONE != ret) {
+    LoggerE("ml_pipeline_get_state() failed: [%d] (%s)", ret, get_error_message(ret));
+    return util::ToPlatformResult(ret, "Could not get pipeline state");
+  }
+  LoggerD("ml_pipeline_get_state() succeeded");
+
+  *out = StateToString(state);
+  return PlatformResult{};
+}
 // Pipeline::state end
 
 // Pipeline::start() begin
index b5834f4f7dd5a2158c495d9246feddd7afde82d3..c29f244f0c91b58dbd9d5c0b9a5b0b922afc67ce 100644 (file)
@@ -52,7 +52,7 @@ class Pipeline {
   ~Pipeline();
 
   // Pipeline::state begin
-
+  PlatformResult GetState(std::string* out);
   // Pipeline::state end
 
   // Pipeline::start() begin
index 1a2151625955232e53ce6b6cd12ce5f97e56ba92..2d4781ceedfcf7672b175b31d6f1dcdf4813063e 100644 (file)
@@ -58,7 +58,19 @@ PlatformResult PipelineManager::CreatePipeline(int id, const std::string& defini
 // PipelineManager::createPipeline() end
 
 // Pipeline::state begin
+PlatformResult PipelineManager::GetPipelineState(int id, std::string* out) {
+  ScopeLogger("id: [%d]", id);
+
+  auto pipeline_it = pipelines_.find(id);
+  if (pipelines_.end() == pipeline_it) {
+    LoggerD("Pipeline not found: [%d]", id);
+    *out = "NULL";
+    return PlatformResult{};
+  }
 
+  auto ret = pipeline_it->second->GetState(out);
+  return ret;
+}
 // Pipeline::state end
 
 // Pipeline::start() begin
index 1ecf79af6041ddd5ad033fb15bfd1bee2cce9c60..f3e0293b042f8499151413d06ad4efa4e5ef66e4 100644 (file)
@@ -44,7 +44,7 @@ class PipelineManager {
   // PipelineManager::createPipeline() end
 
   // Pipeline::state begin
-
+  PlatformResult GetPipelineState(int id, std::string* out);
   // Pipeline::state end
 
   // Pipeline::start() begin