From: Tomasz Marciniak Date: Wed, 28 Dec 2016 13:04:15 +0000 (+0100) Subject: [Convergence] Fix for invalid state exception. X-Git-Tag: submit/tizen_3.0/20161229.023338~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb4ef3203e99eee46c7eb54a3af1c7467992e6df;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Convergence] Fix for invalid state exception. [Verification] Code compiles. InvalidStateError for RemoteAppControlService is thrown now. Change-Id: Ic958784cb266d886a30b414b46671089da0469ea Signed-off-by: Tomasz Marciniak --- diff --git a/src/convergence/convergence_api.js b/src/convergence/convergence_api.js index 220b5c20..49d6b210 100644 --- a/src/convergence/convergence_api.js +++ b/src/convergence/convergence_api.js @@ -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; diff --git a/src/convergence/convergence_remote_app_control_service.cc b/src/convergence/convergence_remote_app_control_service.cc index 596dbd6b..5d4db99b 100644 --- a/src/convergence/convergence_remote_app_control_service.cc +++ b/src/convergence/convergence_remote_app_control_service.cc @@ -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; diff --git a/src/convergence/convergence_remote_app_control_service.h b/src/convergence/convergence_remote_app_control_service.h index bf1de55f..240667a2 100644 --- a/src/convergence/convergence_remote_app_control_service.h +++ b/src/convergence/convergence_remote_app_control_service.h @@ -64,7 +64,6 @@ class ConvergenceRemoteAppControlService : public ConvergenceService { private: std::vector callback_param_gc_; CallbackParam* connect_callback_param_; - bool started_; }; } // namespace convergence