}
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
}
var s = convergenceServices[lid];
- var result_type = result.result_type;
-
switch (result_type) {
case 'Connected':
if (s) { // Service MUST NOT be null here
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);
]);
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', {
} 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_,
}
} 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,