[Convergence] - adding conv_service_is_started to AppCommunicationService 97/109197/1
authorAndrzej Popowski <a.popowski@samsung.com>
Mon, 9 Jan 2017 07:31:40 +0000 (08:31 +0100)
committerAndrzej Popowski <a.popowski@samsung.com>
Mon, 9 Jan 2017 07:31:40 +0000 (08:31 +0100)
Change-Id: I7fbf4412805b9e7ecaf0326c84016c8441e3d2c4
Signed-off-by: Andrzej Popowski <a.popowski@samsung.com>
src/convergence/convergence_app_communication_service.cc

index 2b71890b5b86b76918384c2aaf5461815fefdc23..5d40451051ff7347cdbf085492b541e62fb9cf24 100644 (file)
@@ -73,14 +73,32 @@ common::TizenResult ConvergenceAppCommunicationService::Start(
     return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
   }
 
-  UpdateListener(cur_listener_id, REMOTE_SERVICE_START);
+  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_handle, channel->GetHandle(), &is_started);
 
-  const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr);
-  if (CONV_ERROR_NONE != error) {
-    return LogAndCreateTizenError(AbortError, "conv_service_start [fail]");
-  }
+  if (is_started) {
+    picojson::object param;
+    param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk);
+    param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle());
+    param[kServiceResultType] = picojson::value("onStart");
 
-  opened_channels.push_back(ch_ptr.release());
+    // totu
+    convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback,
+                                    cur_listener_id, true, param);
+  } else {
+    UpdateListener(cur_listener_id, REMOTE_SERVICE_START);
+  
+    const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr);
+    if (CONV_ERROR_NONE != error) {
+      LoggerD("conv_service_start [fail] %d %s", error, get_error_message(error));
+      return LogAndCreateTizenError(AbortError, "conv_service_start [fail]");
+    }
+  
+    opened_channels.push_back(ch_ptr.release());
+  }
 
   return TizenSuccess();
 }
@@ -371,14 +389,33 @@ common::TizenResult ConvergenceAppCommunicationServerService::Start(
     return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
   }
 
-  UpdateListener(cur_listener_id, LOCAL_SERVICE_START);
 
-  const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr);
-  if (CONV_ERROR_NONE != error) {
-    return LogAndCreateTizenError(AbortError, "conv_service_start [fail]");
-  }
+  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_handle, channel->GetHandle(), &is_started);
+
+  if (is_started) {
+    picojson::object param;
+    param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk);
+    param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle());
+    param[kServiceResultType] = picojson::value("onStart");
 
-  opened_channels.push_back(ch_ptr.release());
+    // totu
+    convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback,
+                                    cur_listener_id, true, param);
+  } else {
+    UpdateListener(cur_listener_id, LOCAL_SERVICE_START);
+  
+    const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr);
+    if (CONV_ERROR_NONE != error) {
+      LoggerD("conv_service_start [fail] %d %s", error, get_error_message(error));
+      return LogAndCreateTizenError(AbortError, "conv_service_start [fail]");
+    }
+  
+    opened_channels.push_back(ch_ptr.release());
+  }
 
   return TizenSuccess();
 }