[Convergence] Fix for invalid state exception. 77/107577/1
authorTomasz Marciniak <t.marciniak@samsung.com>
Wed, 28 Dec 2016 13:04:15 +0000 (14:04 +0100)
committerTomasz Marciniak <t.marciniak@samsung.com>
Wed, 28 Dec 2016 13:28:41 +0000 (14:28 +0100)
[Verification] Code compiles. InvalidStateError
for RemoteAppControlService is thrown now.

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

index 220b5c2001988c17fa91edce413a80af4b591620..49d6b210349d861d46a6638dce4def87de91901c 100644 (file)
@@ -296,9 +296,11 @@ native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(result) {
       native_.callIfPossible(s._remoteAppControlCallback[callback], d);
       break;
     case 'onStart':
+      s._isStarted = true;
       native_.callIfPossible(s._startCallback, s);
       break;
     case 'onStop':
+      s._isStarted = false;
       native_.callIfPossible(s._stopCallback, null);
       break;
     default:
@@ -336,6 +338,11 @@ function RemoteAppControlService() {
       value: null,
       writable: true,
       enumerable: false
+    },
+    _isStarted : {
+      value: false,
+      writable: true,
+      enumerable: false
     }
   });
 
@@ -434,8 +441,8 @@ RemoteAppControlService.prototype.start = function() {
       nullable: true
     }]);
 
-  if (this.connectionState === ConnectionState.NOT_CONNECTED) {
-    throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
+  if (this._isStarted) {
+    throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is already started.');
   }
 
   var lid = this._serviceId;
@@ -472,6 +479,10 @@ RemoteAppControlService.prototype.stop = function() {
       nullable: true
     }]);
 
+  if (!this._isStarted) {
+    throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not started.');
+  }
+
   var lid = this._serviceId;
   this._stopCallback = args.successCallback;
   convergenceServices[lid] = this;
@@ -515,6 +526,10 @@ RemoteAppControlService.prototype.launch = function(appId, successCallback, erro
     }
   ]);
 
+  if (!this._isStarted) {
+    throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not started.');
+  }
+
   var lid = this._serviceId;
 
   //Both callbacks have to be saved as launch on remote device
@@ -569,6 +584,10 @@ RemoteAppControlService.prototype.launchAppControl = function() {
     nullable: true
   }]);
 
+  if (!this._isStarted) {
+    throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not started.');
+  }
+
   var lid = this._serviceId;
   this._remoteAppControlCallback = args.replyCallback;
   convergenceServices[lid] = this;
index 596dbd6bae05a8660933fac9e22546e40a2bf0ad..5d4db99bf76567d4d6089c0d77967b4c9740bc30 100644 (file)
@@ -44,15 +44,13 @@ using common::TizenSuccess;
 
 ConvergenceRemoteAppControlService::ConvergenceRemoteAppControlService()
  : ConvergenceService()
- , connect_callback_param_(nullptr)
- , started_(false) {
+ , connect_callback_param_(nullptr) {
   ScopeLogger();
 }
 
 ConvergenceRemoteAppControlService::ConvergenceRemoteAppControlService(conv_device_h device, ConvergenceInstance *convergence_plugin)
  : ConvergenceService(device, CONV_SERVICE_REMOTE_APP_CONTROL, convergence_plugin)
- , connect_callback_param_(nullptr)
- , started_(false) {
+ , connect_callback_param_(nullptr) {
   ScopeLogger();
 }
 
@@ -157,10 +155,6 @@ TizenResult ConvergenceRemoteAppControlService::Disconnect() {
 TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const int cur_listener_id) {
   ScopeLogger();
 
-  if (started_) {
-    return LogAndCreateTizenError(InvalidStateError, "RemoteAppControlService already started");
-  }
-
   conv_service_h service = FindServiceHandle();
   if (!service) {
     return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
@@ -175,7 +169,6 @@ TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const in
     return LogAndCreateTizenError(AbortError, "conv_service_start error");
   } else {
     LoggerI("RemoteAppControlService started");
-    started_ = true;
   }
 
   return TizenSuccess();
@@ -184,10 +177,6 @@ TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const in
 TizenResult ConvergenceRemoteAppControlService::Stop(const bool reply, const int cur_listener_id) {
   ScopeLogger();
 
-  if (!started_) {
-    return LogAndCreateTizenError(InvalidStateError, "RemoteAppControlService is not started yet");
-  }
-
   conv_service_h service = FindServiceHandle();
   if (!service) {
     return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
@@ -202,7 +191,6 @@ TizenResult ConvergenceRemoteAppControlService::Stop(const bool reply, const int
     return LogAndCreateTizenError(AbortError, "conv_service_stop error");
   } else {
     LoggerI("RemoteAppControlService stopped");
-    started_ = false;
   }
 
   return TizenSuccess();
@@ -299,10 +287,6 @@ void ConvergenceRemoteAppControlService::UpdateListener(const int cur_listener_i
 TizenResult ConvergenceRemoteAppControlService::Launch(const char *appId, const int cur_listener_id) {
   ScopeLogger();
 
-  if (!started_) {
-    return LogAndCreateTizenError(InvalidStateError, "RemoteAppControlService not started");
-  }
-
   conv_payload_h payload = nullptr;
   app_control_h app_control = nullptr;
 
@@ -366,10 +350,6 @@ TizenResult ConvergenceRemoteAppControlService::LaunchAppControl(const picojson:
                                                                          const int cur_listener_id) {
   ScopeLogger();
 
-  if (!started_) {
-    return LogAndCreateTizenError(InvalidStateError, "RemoteAppControlService not started");
-  }
-
   conv_payload_h payload = nullptr;
   app_control_h app_control = nullptr;
 
index bf1de55f9da17aef65c1672a0ede48ff77fc6a99..240667a20f9816f507c54c1236b7e7f4a0b546f9 100644 (file)
@@ -64,7 +64,6 @@ class ConvergenceRemoteAppControlService : public ConvergenceService {
  private:
   std::vector<CallbackParam *> callback_param_gc_;
   CallbackParam* connect_callback_param_;
-  bool started_;
 };
 
 } // namespace convergence