From: taekeun.kang Date: Wed, 23 Nov 2016 01:21:33 +0000 (+0900) Subject: [Convergence] Fix error handling codes to satisfy spec. X-Git-Tag: submit/tizen_3.0/20161130.085250~2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c9ad016cfce16b50890866308f44c31cea8c1fe;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Convergence] Fix error handling codes to satisfy spec. Change-Id: Ic829ccab2bd4702cd7eb4ff06082c019e6a74dff Signed-off-by: taekeun.kang --- diff --git a/src/convergence/convergence_api.js b/src/convergence/convergence_api.js index ab9bf66d..faa26b42 100644 --- a/src/convergence/convergence_api.js +++ b/src/convergence/convergence_api.js @@ -124,7 +124,7 @@ ConvergenceManager.prototype.startDiscovery = function(successCallback, console.log('Entered ConvergenceManager.startDiscovery()'); if (discoveryStarted) - throw new WebAPIException('InvalidStateError', 'Discovery has been started.'); + throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has been started.'); var args = validator_.validateArgs(arguments, [ {name: 'successCallback', type: types_.LISTENER, values: ['onfound', 'onfinished' ]}, @@ -133,6 +133,9 @@ ConvergenceManager.prototype.startDiscovery = function(successCallback, ]); // Indicate, that discovery procedure is on + if (discoveryStarted === true) + throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has already started.'); + discoveryStarted = true; // Reset currently available device list @@ -185,6 +188,9 @@ ConvergenceManager.prototype.startDiscovery = function(successCallback, native_.callIfPossible(successCallback.onfound, d); } else if (result.discovery_status == 'discovery_finished') { + + discoveryStarted = false; + // Unregister discovery listener, because Convergence Manager is a // singleton object and no one else can receive discovery results native_.removeListener('CONVERGENCE_DISCOVERY_LISTENER'); @@ -208,7 +214,9 @@ ConvergenceManager.prototype.startDiscovery = function(successCallback, native_.callIfPossible(errorCallback, native_.getErrorObject(result)); } }); + if (native_.isFailure(result)) { + discoveryStarted = false; throw native_.getErrorObject(result); } }; @@ -216,8 +224,8 @@ ConvergenceManager.prototype.startDiscovery = function(successCallback, ConvergenceManager.prototype.stopDiscovery = function() { console.log('Entered ConvergenceManager.stopDiscovery()'); - if (!discoveryStarted) - throw new WebAPIException('InvalidStateError', 'Discovery has not started yet.'); + if (discoveryStarted === false) + throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has not started yet.'); discoveryStarted = false; @@ -341,7 +349,7 @@ RemoteAppControlService.prototype.connect = function(successCallback, errorCallb } ]); - if (this.connectionState == ConnectionState.CONNECTED) { + if (this.connectionState === ConnectionState.CONNECTED) { throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is connected already.'); } @@ -356,6 +364,7 @@ RemoteAppControlService.prototype.connect = function(successCallback, errorCallb if (native_.isFailure(result)) native_.callIfPossible(errorCallback, native_.getErrorObject(result)); }); + if (native_.isFailure(result)) throw native_.getErrorObject(result); }; @@ -380,7 +389,7 @@ RemoteAppControlService.prototype.disconnect = function(successCallback, errorCa } ]); - if (this.connectionState != ConnectionState.CONNECTED) { + if (this.connectionState !== ConnectionState.CONNECTED) { throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.'); } @@ -414,10 +423,10 @@ RemoteAppControlService.prototype.start = function() { nullable: true }]); -/* - if (this.serviceState == ConnectionState.CONNECTED) - throw new WebAPIException('InvalidStateError', 'Service is connected already.'); -*/ + + if (this.connectionState === ConnectionState.NOT_CONNECTED) { + throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.'); + } var lid = this._serviceId; this._startCallback = args.successCallback; @@ -905,6 +914,7 @@ AppCommunicationService.prototype.setListener = function(listenerCallback) { deviceId: this._deviceId, curListenerId: lid }); + if (native_.isFailure(result)) throw native_.getErrorObject(result); @@ -921,6 +931,7 @@ AppCommunicationService.prototype.unsetListener = function(id) { deviceId: this._deviceId //curListenerId: id // not needed in below layers }); + if (native_.isFailure(result)) throw native_.getErrorObject(result); @@ -979,7 +990,7 @@ AppCommunicationClientService.prototype.connect = function(successCallback, erro ]); if (this.connectionState == ConnectionState.CONNECTED) - throw new WebAPIException('InvalidStateError', 'Service is connected already.'); + throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is connected already.'); var lid = this._serviceId; this._connectCallback = successCallback; @@ -1018,7 +1029,7 @@ AppCommunicationClientService.prototype.disconnect = function(successCallback, e } ]); if (this.connectionState != ConnectionState.CONNECTED) - throw new WebAPIException('InvalidStateError', 'Service is not connected yet.'); + throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.'); var result = native_.call('AppCommunicationClientService_disconnect', { deviceId: this._deviceId diff --git a/src/convergence/convergence_app_communication_service.cc b/src/convergence/convergence_app_communication_service.cc index 41b8fca2..42ce200f 100644 --- a/src/convergence/convergence_app_communication_service.cc +++ b/src/convergence/convergence_app_communication_service.cc @@ -76,7 +76,7 @@ common::TizenResult ConvergenceAppCommunicationService::Start( const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr); if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "Failed to start service"); + return LogAndCreateTizenError(AbortError, "conv_service_start [fail]"); } opened_channels.push_back(ch_ptr.release()); @@ -113,8 +113,7 @@ common::TizenResult ConvergenceAppCommunicationService::GetClientList(Convergenc conv_service_h service_handle = FindServiceHandle(); if (!service_handle) { - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } UpdateListener(cur_listener_id); @@ -142,7 +141,7 @@ common::TizenResult ConvergenceAppCommunicationService::Send( const int error = conv_service_publish(service_handle, channel->GetHandle(), payload.GetHandle()); if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "Failed to publish message"); + return LogAndCreateTizenError(AbortError, "conv_service_publish [fail]"); } else { LoggerI("PUBLISHED SUCCESSFULY listener is [%d]", cur_listener_id); } @@ -171,8 +170,7 @@ void ConvergenceAppCommunicationService::ServiceListenerCb(conv_service_h servic if (CONV_ERROR_NONE != error) { // Error occured during connection picojson::object param; - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusError); - param[kServiceListenerError] = picojson::value(static_cast(error)); + param[kServiceListenerError] = LogAndCreateTizenError(AbortError, "DiscoveryCb return CONV_DISCOVERY_RESULT_ERROR").ToJSON(); callbackParam->plugin_->ReplyAsync(kAppCommunicationListenerCallback, callbackParam->callback_id_, false, param); return; @@ -274,9 +272,9 @@ void ConvergenceAppCommunicationService::UpdateListener(const int cur_listener_i common::TizenResult ConvergenceAppCommunicationService::SetListener(const int cur_listener_id) { ScopeLogger(); conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + if (!service_handle) { + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); + } UpdateListener(cur_listener_id); @@ -288,17 +286,12 @@ common::TizenResult ConvergenceAppCommunicationService::RemoveListener() { conv_service_h service_handle = FindServiceHandle(); if (!service_handle) { - LoggerE("AAAAAA!!! Service not found"); - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } const int error = conv_service_unset_listener_cb(service_handle); if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_service_set_listener_cb"); - return LogAndCreateTizenError(NotFoundError, - "Unset Listener Failed"); + return LogAndCreateTizenError(AbortError, "conv_service_unset_listener_cb [Fail]"); } return TizenSuccess(); @@ -449,8 +442,7 @@ common::TizenResult ConvergenceAppCommunicationClientService::Connect(const int conv_service_h service = FindServiceHandle(); if (!service) { - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service is NULL"); } // TODO: make a garbage collection and release this memory when service is disconnected @@ -462,6 +454,7 @@ common::TizenResult ConvergenceAppCommunicationClientService::Connect(const int if (CONV_ERROR_NONE != error) { // TODO: Handle error trace_conv_error(error, __LINE__, "conv_service_connect"); + return LogAndCreateTizenError(AbortError, "conv_service_connect [fail]"); } return TizenSuccess(); @@ -472,13 +465,13 @@ common::TizenResult ConvergenceAppCommunicationClientService::Disconnect() { conv_service_h service = FindServiceHandle(); if (!service) - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service is NULL"); const 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(); @@ -486,4 +479,4 @@ common::TizenResult ConvergenceAppCommunicationClientService::Disconnect() { } // namespace convergence -} // namespace extension +} // namespace extension diff --git a/src/convergence/convergence_instance.cc b/src/convergence/convergence_instance.cc index c905ee4f..7e8dc0ad 100644 --- a/src/convergence/convergence_instance.cc +++ b/src/convergence/convergence_instance.cc @@ -204,7 +204,8 @@ common::TizenResult ConvergenceInstance::RemoteAppControlServiceConnect(const pi ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_REMOTE_APP_CONTROL)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { // Running the service connect procedure result = service->Connect(static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); @@ -237,7 +238,8 @@ common::TizenResult ConvergenceInstance::RemoteAppControlServiceDisconnect(const ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_REMOTE_APP_CONTROL)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { result = service->Disconnect(); } @@ -273,7 +275,8 @@ common::TizenResult ConvergenceInstance::RemoteAppControlServiceStart(const pico ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_REMOTE_APP_CONTROL)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { // Running the service start procedure result = service->Start(static_cast(ConvergenceUtils::GetArg(args, kJSArgumentReply).get()), @@ -311,7 +314,8 @@ common::TizenResult ConvergenceInstance::RemoteAppControlServiceStop(const picoj ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_REMOTE_APP_CONTROL)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { // Running the service stop procedure result = service->Stop(static_cast(ConvergenceUtils::GetArg(args, kJSArgumentReply).get()), @@ -349,7 +353,8 @@ common::TizenResult ConvergenceInstance::RemoteAppControlServiceLaunch(const pic ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_REMOTE_APP_CONTROL)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { result = service->Launch( ConvergenceUtils::GetArg(args, kJSArgumentAppId).to_str().c_str(), @@ -389,7 +394,8 @@ common::TizenResult ConvergenceInstance::RemoteAppControlServiceLaunchAppControl ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_REMOTE_APP_CONTROL)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { result = service->LaunchAppControl(ConvergenceUtils::GetArg(args, kJSArgumentAppControl).get(), ConvergenceUtils::GetArg(args, kJSArgumentAppId).to_str().c_str(), @@ -427,14 +433,16 @@ common::TizenResult ConvergenceInstance::AppCommunicationServiceStart(const pico ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Service is NULL", + ("Service is NULL")); } else { // Running the service start procedure auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel); std::vector::iterator channel_it = service->GetChannel(channel_arg); if (service->IsChannelStarted(channel_it)) { - result = LogAndCreateTizenError(InvalidStateError, "Service is already started for the channel."); + result = LogAndCreateTizenError(InvalidStateError, "Service is already started for the channel.", + ("Service is already started for the channel.")); } else { ConvergenceChannel* channel = new ConvergenceChannel(channel_arg); // memory would be managed in Start method const int id = static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); @@ -477,14 +485,16 @@ common::TizenResult ConvergenceInstance::AppCommunicationServiceSend(const picoj ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "service is NULL", + ("service is NULL")); } else { // Running the service send procedure auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel); std::vector::iterator channel_it = service->GetChannel(channel_arg); if (!service->IsChannelStarted(channel_it)) { - result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel."); + result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.", + ("Service is not started for the channel.")); } else { ConvergencePayloadArray payload(ConvergenceUtils::GetArg(args, kJSArgumentPayload)); const int id = static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); @@ -526,14 +536,16 @@ common::TizenResult ConvergenceInstance::AppCommunicationServiceStop(const picoj ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Service is NULL", + ("Service is NULL")); } else { // Running the service stop procedure auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel); std::vector::iterator channel_it = service->GetChannel(channel_arg); if (!service->IsChannelStarted(channel_it)) { - result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel."); + result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.", + ("Service is not started for the channel.")); } else { const int id = static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); @@ -577,14 +589,16 @@ common::TizenResult ConvergenceInstance::AppCommunicationServiceGetClientList(co ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } else { // Running the service getClientList procedure auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel); std::vector::iterator channel_it = service->GetChannel(channel_arg); if (!service->IsChannelStarted(channel_it)) { - result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel."); + result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.", + ("Service is not started for the channel.")); } else { const int id = static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); @@ -618,7 +632,8 @@ common::TizenResult ConvergenceInstance::AppCommunicationServiceSetListener(cons ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - LogAndReturnTizenError(common::NotFoundError("Can not find the service type = 1")); + return LogAndCreateTizenError(AbortError, "service is NULL", + ("service is NULL")); } // Running the service stop procedure @@ -640,7 +655,8 @@ common::TizenResult ConvergenceInstance::AppCommunicationServiceUnsetListener(co ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - LogAndReturnTizenError(common::NotFoundError("Can not find the service type = 1")); + return LogAndCreateTizenError(AbortError, "service is NULL", + ("service is NULL")); } // Running the service stop procedure @@ -658,7 +674,8 @@ common::TizenResult ConvergenceInstance::AppCommunicationServerServiceConstructL ConvergenceManager::GetInstance(this).RegisterLocalService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - LogAndReturnTizenError(common::NotFoundError("Can not find the service type = 1")); + return LogAndCreateTizenError(AbortError, "Can not find the service type = 1", + ("Can not find the service type = 1")); } return common::TizenSuccess(); @@ -667,6 +684,8 @@ common::TizenResult ConvergenceInstance::AppCommunicationServerServiceConstructL common::TizenResult ConvergenceInstance::AppCommunicationClientServiceConnect(const picojson::object& args, const common::AsyncToken& token) { ScopeLogger(); + + // [TK] SecurityError CHECK_PRIVILEGE(kPrivilegeInternet); CHECK_PRIVILEGE(kPrivilegeBluetooth); @@ -685,7 +704,8 @@ common::TizenResult ConvergenceInstance::AppCommunicationClientServiceConnect(co ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Service is NULL", + ("service is NULL")); } else { // Running the service connect procedure result = service->Connect(static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); @@ -717,7 +737,8 @@ common::TizenResult ConvergenceInstance::AppCommunicationClientServiceDisconnect ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), CONV_SERVICE_APP_TO_APP_COMMUNICATION)); if (!service) { - result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1"); + result = LogAndCreateTizenError(AbortError, "Service is NULL", + ("Service is NULL")); } else { // Running the service disconnect procedure result = service->Disconnect(); diff --git a/src/convergence/convergence_manager.cc b/src/convergence/convergence_manager.cc index e7ae08fe..c7f67840 100644 --- a/src/convergence/convergence_manager.cc +++ b/src/convergence/convergence_manager.cc @@ -41,7 +41,7 @@ static const std::string kDiscoveryStatus = "discovery_status"; static const std::string kDiscoveryStatusDeviceFound = "device_found"; static const std::string kDiscoveryStatusFinished = "discovery_finished"; static const std::string kDiscoveryStatusError = "discovery_error"; -static const std::string kDiscoveryError = "discovery_error"; +static const std::string kDiscoveryError = "error"; } // namespace @@ -185,8 +185,7 @@ void ConvergenceManager::DiscoveryCb(conv_device_h device_handle, case CONV_DISCOVERY_RESULT_ERROR: { LoggerE("Discovery Error"); picojson::object param; - param[kDiscoveryStatus] = picojson::value(kDiscoveryStatusError); - param[kDiscoveryError] = picojson::value(static_cast(result)); + param[kDiscoveryError] = LogAndCreateTizenError(AbortError, "DiscoveryCb return CONV_DISCOVERY_RESULT_ERROR").ToJSON(); owner->convergence_plugin_->ReplyAsync(kConvergenceManagerDiscoveryCallback, -1, false, @@ -205,8 +204,7 @@ TizenResult ConvergenceManager::StartDiscovery(long timeout) { const int error = conv_discovery_start(convergence_manager_, (const int)timeout, DiscoveryCb, this); if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_discovery_start"); + return LogAndCreateTizenError(AbortError, "conv_discovery_start [fail]"); } return TizenSuccess(); } @@ -215,8 +213,7 @@ TizenResult ConvergenceManager::StopDiscovery() { ScopeLogger(); const int error = conv_discovery_stop(convergence_manager_); if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_discovery_stop"); + return LogAndCreateTizenError(AbortError, "conv_discovery_stop [fail]"); } return TizenSuccess(); } diff --git a/src/convergence/convergence_remote_app_control_service.cc b/src/convergence/convergence_remote_app_control_service.cc index c957e63c..c0ec611d 100644 --- a/src/convergence/convergence_remote_app_control_service.cc +++ b/src/convergence/convergence_remote_app_control_service.cc @@ -98,17 +98,14 @@ TizenResult ConvergenceRemoteAppControlService::Connect(const int cur_listener_i conv_service_h service = FindServiceHandle(); if (!service) { - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } CallbackParam *param = new CallbackParam(convergence_plugin_, cur_listener_id); const int error = conv_service_connect(service, ServiceConnectedCb, param); - if (CONV_ERROR_NONE != error) { - // TODO: Handle error delete param; - trace_conv_error(error, __LINE__, "conv_service_connect"); + return LogAndCreateTizenError(AbortError, "conv_service_connect [Fail]"); } else { // Hopefully we are sure that the service is disconnected connect_callback_param_ = param; @@ -123,14 +120,11 @@ TizenResult ConvergenceRemoteAppControlService::Disconnect() { conv_service_h service = FindServiceHandle(); if (!service) - return LogAndCreateTizenError(NotFoundError, - "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); const 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]"); } else { delete connect_callback_param_; connect_callback_param_ = nullptr; @@ -149,7 +143,7 @@ TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const in conv_service_h service = FindServiceHandle(); if (!service) { - return LogAndCreateTizenError(NotFoundError, "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } if (reply) { @@ -176,7 +170,7 @@ TizenResult ConvergenceRemoteAppControlService::Stop(const bool reply, const int conv_service_h service = FindServiceHandle(); if (!service) { - return LogAndCreateTizenError(NotFoundError, "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } if (reply) { @@ -275,7 +269,7 @@ TizenResult ConvergenceRemoteAppControlService::Launch(const char *appId, bool r conv_service_h service_handle = FindServiceHandle(); if (!service_handle) { - return LogAndCreateTizenError(NotFoundError, "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } int ret = conv_payload_create(&payload); @@ -351,7 +345,7 @@ TizenResult ConvergenceRemoteAppControlService::LaunchAppControl(const picojson: // Get service_handle conv_service_h service_handle = FindServiceHandle(); if (!service_handle) { - return LogAndCreateTizenError(NotFoundError, "Service with specified type does not exist"); + return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); } // Create payload diff --git a/src/convergence/convergence_utils.cc b/src/convergence/convergence_utils.cc index 525b4284..bfc67b0b 100644 --- a/src/convergence/convergence_utils.cc +++ b/src/convergence/convergence_utils.cc @@ -74,5 +74,28 @@ const picojson::value& ConvergenceUtils::GetArg(const picojson::object& args, co } } +common::TizenResult ConvergenceUtils::ConvertConvergenceError(int error) { + switch (error) { + case CONV_ERROR_NONE: + return common::TizenSuccess(); + case CONV_ERROR_INVALID_OPERATION: + case CONV_ERROR_PERMISSION_DENIED: // Never return + case CONV_ERROR_NOT_SUPPORTED: // Never return + case CONV_ERROR_INVALID_PARAMETER: // Never return + return common::InvalidStateError(error); + case CONV_ERROR_OUT_OF_MEMORY: + case CONV_ERROR_NO_DATA: + + // return common::IoError(error); + // return common::SecurityError(error); + // return common::NotSupportedError(error); + // return common::InvalidValuesError(error); + // return common::TimeoutError(error); + // return common::TypeMismatchError(error); + // return common::InvalidStateError(error); + return common::AbortError(error); + } +} + } // namespace convergence -} // namespace extension +} // namespace extension \ No newline at end of file diff --git a/src/convergence/convergence_utils.h b/src/convergence/convergence_utils.h index a7aa2806..ab4570ef 100644 --- a/src/convergence/convergence_utils.h +++ b/src/convergence/convergence_utils.h @@ -57,7 +57,7 @@ static const std::string kServiceConnectionStatusNotConnected = "service_not_con static const std::string kServiceListenerStatus = "listener_status"; static const std::string kServiceListenerStatusOk = "listener_ok"; static const std::string kServiceListenerStatusError = "listener_error"; -static const std::string kServiceListenerError = "listener_error"; +static const std::string kServiceListenerError = "error"; } // namespace struct CallbackParam { @@ -73,6 +73,7 @@ void trace_conv_error(const int error, int line_number, const char *extra_text); class ConvergenceUtils { public: static const picojson::value& GetArg(const picojson::object& args, const std::string& name); + static common::TizenResult ConvertConvergenceError(int error); }; } // namespace convergence