[Convergence] launch() adjusted to the native api change. 88/106688/1
authorTomasz Marciniak <t.marciniak@samsung.com>
Wed, 21 Dec 2016 13:49:19 +0000 (14:49 +0100)
committerTomasz Marciniak <t.marciniak@samsung.com>
Thu, 22 Dec 2016 11:16:17 +0000 (12:16 +0100)
[Verification] Code compiles. In case of launch failure
error callback is called.

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

index 993c4472622b17ae8bac2a6b5c798d44d10e5dba..220b5c2001988c17fa91edce413a80af4b591620 100644 (file)
@@ -260,7 +260,9 @@ function Service(connectionState_, type_) {
 }
 
 native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(result) {
-  if (native_.isFailure(result)) {
+  var result_type = result.result_type;
+
+  if (native_.isFailure(result) && 'onPublish' != result_type) {
     //native_.callIfPossible(errorCallback, native_.getErrorObject(result));
   } else {
     // Invoke corresponding callback
@@ -270,8 +272,6 @@ native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(result) {
     }
     var s = convergenceServices[lid];
 
-    var result_type = result.result_type;
-
     switch (result_type) {
     case 'Connected':
       if (s) { // Service MUST NOT be null here
@@ -282,17 +282,18 @@ native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(result) {
       break;
     case 'onPublish':
       var remote_func = result.remote_function;
-      if ('launch' === remote_func) {
-        native_.callIfPossible(s._remoteAppControlCallback);
-      } else if ('launchAppControl' === remote_func) {
-        var callback = result.callback_result;
-        var d = undefined;
-        if ('onsuccess' === callback) {
-          d = result.reply ? new tizen.ApplicationControlData('reply', [result.reply]) : null;
-        }
+      var callback = result.callback_result;
+      var d = undefined;
 
-        native_.callIfPossible(s._remoteAppControlCallback[callback], d);
+      if ('launchAppControl' === remote_func && 'onsuccess' === callback) {
+        d = result.reply ? new tizen.ApplicationControlData('reply', [result.reply]) : null;
       }
+
+      if ('launch' === remote_func && 'onfailure' === callback) {
+        d = new WebAPIException(WebAPIException.ABORT_ERR, 'Launching application failed');
+      }
+
+      native_.callIfPossible(s._remoteAppControlCallback[callback], d);
       break;
     case 'onStart':
       native_.callIfPossible(s._startCallback, s);
@@ -515,11 +516,15 @@ RemoteAppControlService.prototype.launch = function(appId, successCallback, erro
   ]);
 
   var lid = this._serviceId;
-  // TODO In fact it must be a list of callbacks
-  // But until D2D FW supports transaction management, it is meaningless to
-  // have more than one callback, because all payload is delivered to
-  // a single point without identification of initial request
-  this._remoteAppControlCallback = successCallback;
+
+  //Both callbacks have to be saved as launch on remote device
+  //can be finished with success or error, e.g. when there
+  //is no application with given Id
+  var remoteCallback = {};
+  remoteCallback.onsuccess = successCallback;
+  remoteCallback.onfailure = errorCallback;
+
+  this._remoteAppControlCallback = remoteCallback;
   convergenceServices[lid] = this;
 
   var result = native_.call('RemoteAppControlService_launch', {
index d10a370bcaaf17e21b8f644d6822003d0ade0fd5..596dbd6bae05a8660933fac9e22546e40a2bf0ad 100644 (file)
@@ -239,10 +239,10 @@ void ConvergenceRemoteAppControlService::ServiceListenerCb(conv_service_h servic
         } else {
           param[kCbResult] = picojson::value("onfailure");
         }
+      } else if (kLaunch == callbackParam->remote_method_) {
+        param[kCbResult] = picojson::value("onsuccess");
       }
 
-      //in case of launch() method there is no information received if it finished
-      //with success or error, so we assume optimistic success
       param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk);
       callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback,
         callbackParam->callback_id_,
@@ -257,6 +257,12 @@ void ConvergenceRemoteAppControlService::ServiceListenerCb(conv_service_h servic
     }
   } else {
     // Error occurred during connection
+    // if error was caused by launch() function (onPublish) it has to be handled saparately
+    if (kServiceResultTypeOnPublish == result_type && kLaunch == callbackParam->remote_method_) {
+      param[kRemoteFunc] = picojson::value(callbackParam->remote_method_);
+      param[kCbResult] = picojson::value("onfailure");
+    }
+
     param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusError);
     param[kServiceListenerError] = picojson::value(static_cast<double>(error));
     callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback,