[Convergence] Added checking if service is started. submit/tizen/20170105.131619
authorTomasz Marciniak <t.marciniak@samsung.com>
Thu, 5 Jan 2017 07:59:08 +0000 (08:59 +0100)
committerjk.pu <jk.pu@samsung.com>
Thu, 5 Jan 2017 13:00:52 +0000 (22:00 +0900)
[Verification] Code compiles. Function successfully
tested in chrome console.

Change-Id: Ic1ee1b6cd182d4aa09d924d96435f07d71c3fe11
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/convergence/convergence_remote_app_control_service.cc

index 89b1201..23bb6b6 100644 (file)
@@ -34,6 +34,7 @@ static const char* kAppControl = "app_control";
 static const char* kReply = "reply";
 static const char* kCbResult = "callback_result";
 static const char* kRemoteFunc = "remote_function";
+static const char* kJSCurrentListenerId = "curListenerId";
 
 static const std::string kLaunch = "launch";
 static const std::string kLaunchAppControl = "launchAppControl";
@@ -161,15 +162,34 @@ TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const in
     return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
   }
 
-  if (reply) {
-    UpdateListener(cur_listener_id);
-  }
+  bool is_started = false;
+  //regarding to native team returned value should not be checked
+  //as CONV_ERROR_NONE means service is started, otherwise not started
+  //check only passed bool variable
+  conv_service_is_started(service, nullptr, &is_started);
 
-  const int error = conv_service_start(service, nullptr, nullptr);
-  if (CONV_ERROR_NONE != error) {
-    return LogAndCreateTizenError(AbortError, "conv_service_start error");
+  if (is_started) {
+    //just call success callback
+    picojson::object param;
+    param[kServiceResultType] = picojson::value("onStart");
+    param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk);
+    param[kJSCurrentListenerId] = picojson::value(static_cast<double>(cur_listener_id));
+
+    convergence_plugin_->ReplyAsync(kRemoteAppControlListenerCallback,
+      cur_listener_id,
+      true,
+      param);
   } else {
-    LoggerI("RemoteAppControlService started");
+    if (reply) {
+      UpdateListener(cur_listener_id);
+    }
+
+    const int error = conv_service_start(service, nullptr, nullptr);
+    if (CONV_ERROR_NONE != error) {
+      return LogAndCreateTizenError(AbortError, "conv_service_start error");
+    } else {
+      LoggerI("RemoteAppControlService started");
+    }
   }
 
   return TizenSuccess();