[Convergence] Reporting error while disconnect fails 48/101548/6
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 1 Dec 2016 11:19:11 +0000 (12:19 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 5 Dec 2016 13:41:15 +0000 (14:41 +0100)
Change-Id: I0c75536ffa79d89f1fd999646256195a5b33000c
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/convergence/convergence_api.js
src/convergence/convergence_app_communication_service.cc
src/convergence/convergence_remote_app_control_service.cc

index 9e362c5ec8bd7ca41519b412d0af5d47fffcd52c..615b81cce8ee863e8b2c1b202373ea8e3130e703 100644 (file)
@@ -421,21 +421,21 @@ RemoteAppControlService.prototype.disconnect = function(successCallback, errorCa
     throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
   }
 
+  var that = this;
   var result = native_.call('RemoteAppControlService_disconnect', {
                   deviceId: this._deviceId
                }, function(result) {
                   if (native_.isFailure(result)) {
                     native_.callIfPossible(errorCallback, native_.getErrorObject(result));
+                  } else {
+                    updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, that);
+                    native_.callIfPossible(successCallback, that);
                   }
                });
 
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
-  } else {
-    updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, this);
   }
-
-  native_.callIfPossible(successCallback, this);
 };
 
 RemoteAppControlService.prototype.start = function() {
@@ -1054,20 +1054,20 @@ AppCommunicationClientService.prototype.disconnect = function(successCallback, e
   if (this.connectionState != ConnectionState.CONNECTED)
     throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
 
+  var that = this;
   var result = native_.call('AppCommunicationClientService_disconnect', {
                   deviceId: this._deviceId
                }, function(result) {
                   if (native_.isFailure(result)) {
                     native_.callIfPossible(errorCallback, native_.getErrorObject(result));
                   } else {
-                    native_.callIfPossible(successCallback, this);
+                    updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, that);
+                    native_.callIfPossible(successCallback, that);
                   }
                });
 
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
-  } else {
-    updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, this);
   }
 };
 
index 42ce200f53ba284284360aafc3a440932044db31..4272e4eeb6aef44b6ec6bc7cdcf4cc7ed6679cbf 100644 (file)
@@ -467,14 +467,27 @@ common::TizenResult ConvergenceAppCommunicationClientService::Disconnect() {
   if (!service)
     return LogAndCreateTizenError(AbortError, "Service is NULL");
 
-  const int error = conv_service_disconnect(service);
+  int error = conv_service_disconnect(service);
   if (CONV_ERROR_NONE != error) {
-    // TODO: Handle error
     trace_conv_error(error, __LINE__, "conv_service_disconnect");
     return LogAndCreateTizenError(AbortError, "conv_service_disconnect [fail]");
   }
 
-  return TizenSuccess();
+  conv_service_connection_state_e state = CONV_SERVICE_CONNECTION_STATE_NONE;
+  error = conv_service_get_connection_state(service, &state);
+  if (CONV_ERROR_NONE != error) {
+    LoggerE("Error gathering state [%d] : %s", error, get_error_message(error));
+    return LogAndCreateTizenError(AbortError, "Error gathering state");
+  } else {
+    LoggerD("state: %d" , state);
+
+  }
+  if (CONV_SERVICE_CONNECTION_STATE_NOT_CONNECTED == state) {
+    return TizenSuccess();
+  } else {
+    LoggerE("Service is still connected, reporting error");
+    return LogAndCreateTizenError(AbortError, "Disconnecting failed.");
+  }
 }
 
 
index 201b26d8696400197110c0003d5249d0e1a87d9a..bd9612b5cddaafc4fac2d96ce072ed6ff5222d93 100644 (file)
@@ -123,7 +123,7 @@ TizenResult ConvergenceRemoteAppControlService::Disconnect() {
     return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
   }
 
-  const int error = conv_service_disconnect(service);
+  int error = conv_service_disconnect(service);
   if (CONV_ERROR_NONE != error) {
     return LogAndCreateTizenError(AbortError, "conv_service_disconnect [Fail]");
   } else {
@@ -132,7 +132,21 @@ TizenResult ConvergenceRemoteAppControlService::Disconnect() {
     LoggerI("Disconnected from the remote service");
   }
 
-  return TizenSuccess();
+  conv_service_connection_state_e state = CONV_SERVICE_CONNECTION_STATE_NONE;
+  error = conv_service_get_connection_state(service, &state);
+  if (CONV_ERROR_NONE != error) {
+    LoggerE("Error gathering state [%d] : %s", error, get_error_message(error));
+    return LogAndCreateTizenError(AbortError, "Error gathering state");
+  } else {
+    LoggerD("state: %d" , state);
+
+  }
+  if (CONV_SERVICE_CONNECTION_STATE_NOT_CONNECTED == state) {
+    return TizenSuccess();
+  } else {
+    LoggerE("Service is still connected, reporting error");
+    return LogAndCreateTizenError(AbortError, "Disconnecting failed.");
+  }
 }
 
 TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const int cur_listener_id) {