case 2:
return ConnectionState.CONNECTING;
default:
- console.log('ERROR: Unknown connection state');
- return 'UNKNOWN'; // TODO throw exception
+ return 'UNKNOWN';
}
}
ConvergenceManager.prototype.startDiscovery = function(successCallback,
errorCallback, timeout) {
- console.log('Entered ConvergenceManager.startDiscovery()');
var args = validator_.validateArgs(arguments, [
{name: 'successCallback', type: types_.LISTENER, values: ['onfound', 'onfinished' ]},
convergenceDevices = [];
native_.addListener('CONVERGENCE_DISCOVERY_LISTENER', function(result) {
- console.log('Entered discovery listener');
if (native_.isFailure(result)) {
native_.callIfPossible(errorCallback, native_.getErrorObject(result));
// Prepare service array
if (!result || !result.device || !result.device.services) {
- console.log('INVALID device info obtained from Native API'); // TODO throw exception
return;
}
- console.log('Service number: ' + result.device.services.length);
var services = [];
var id = result.device.id;
for (var i = 0; i < result.device.services.length; ++i) {
} else if (service_data.serviceType == 1) { // Remote App Control
s = new RemoteAppControlService();
} else {
- // Error: unknown service type
- // TODO throw exception
- console.log('UNKNOWN SERVICE TYPE: ' + service_data.serviceType);
continue;
}
convergenceDevices = [];
} else {
- console.log('UNKNOWN discovery state exception'); // TODO throw exception
+ console.log('UNKNOWN discovery state exception');
}
}
});
};
ConvergenceManager.prototype.stopDiscovery = function() {
- console.log('Entered ConvergenceManager.stopDiscovery()');
-
if (discoveryStarted === false)
throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has not started yet.');
};
function Service(connectionState_, type_) {
- console.log('Entered Service.constructor()');
-
var connectionState = connectionState_;
Object.defineProperties(this, {
native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(result) {
if (native_.isFailure(result)) {
//native_.callIfPossible(errorCallback, native_.getErrorObject(result));
- console.log('Error in REMOTE_APP_CONTROL_SERVICE_LISTENER');
} else {
-
- console.log('');
- console.log('REMOTE_APP_CONTROL_SERVICE_LISTENER invoked with data');
- console.log(JSON.stringify(result));
- console.log('');
-
// Invoke corresponding callback
var lid = result.curListenerId;
if (!lid || !convergenceServices.hasOwnProperty(lid)) {
- console.log('ERROR: Remote App Ctrl listener is not registered [' + lid + ']');
return; // Something is wrong: listener MUST be there
}
var s = convergenceServices[lid];
native_.callIfPossible(s._stopCallback, null);
break;
default:
- console.log('Ignoring result type: [' + result_type + ']');
break;
}
}
});
function RemoteAppControlService() {
- console.log('Entered RemoteAppControlService.constructor()');
-
validator_.isConstructorCall(this, RemoteAppControlService);
// The device id is needed for getting the valid service handle on the
RemoteAppControlService.prototype.constructor = RemoteAppControlService;
RemoteAppControlService.prototype.connect = function(successCallback, errorCallback) {
- console.log('Entered RemoteAppControlService.connect()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
};
RemoteAppControlService.prototype.disconnect = function(successCallback, errorCallback) {
- console.log('Entered RemoteAppControlService.disconnect()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
nullable: true
}]);
-
if (this.connectionState === ConnectionState.NOT_CONNECTED) {
throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
}
};
RemoteAppControlService.prototype.launch = function(appId, successCallback, errorCallback) {
- console.log('Entered RemoteAppControlService.launch()');
var args = validator_.validateArgs(arguments, [
{
name: 'appId',
};
function AppCommunicationService(connectionState_, type_) {
- console.log('Entered AppCommunicationService.constructor()');
-
Service.call(this, connectionState_, type_);
// The device id is needed for getting the valid service handle on the
// native layer
}
});
- // TODO add callbacks in runtime instead of constructor
-
// Registering the service in the table of issued services
convergenceServices[this._serviceId] = this;
}
native_.addListener('APP_COMMUNICATION_SERVICE_LISTENER', function(result) {
- console.log('On App Communication Service Success Callback');
-
if (native_.isFailure(result)) {
- console.log('ERROR in APP_COMMUNICATION_SERVICE_LISTENER');
//native_.callIfPossible(errorCallback, native_.getErrorObject(result));
} else {
-
- console.log('');
- console.log('APP_COMMUNICATION_SERVICE_LISTENER invoked with data');
- console.log(JSON.stringify(result));
- console.log('');
-
// Invoke corresponding callback
var lid = result.curListenerId;
if (!lid || !convergenceServices.hasOwnProperty(lid)) {
- console.log('ERROR: App Comm listener is not registered [' + lid + ']');
return; // Something is wrong: listener MUST be there
}
var s = convergenceServices[lid];
}
break;
default:
- console.log('Ignoring result type: [' + result_type + ']');
break;
}
}
});
AppCommunicationService.prototype.start = function(channel, successCallback, errorCallback) {
- console.log('Entered AppCommunicationService.start()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'channel',
};
AppCommunicationService.prototype.stop = function(channel, successCallback, errorCallback) {
- console.log('Entered AppCommunicationService.stop()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'channel',
};
AppCommunicationService.prototype.send = function(channel, payload, successCallback, errorCallback) {
- console.log('Entered AppCommunicationService.send()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'channel',
};
AppCommunicationService.prototype.setListener = function(listenerCallback) {
- console.log('Entered AppCommunicationService.setListener()');
var args = validator_.validateArgs(arguments, [
{name: 'listenerCallback', type: types_.FUNCTION}
]);
var lid = this._serviceId;
- // TODO in fact, it should be even the list of callbacks instead of
- // the single callback
this._listenerCallback = listenerCallback;
convergenceServices[lid] = this;
- console.log('');
- console.log('AppCommunicationServiceCommandListeners ADDED [' + lid + ']');
- console.log('');
-
var result = native_.callSync('AppCommunicationService_setListener', {
deviceId: this._deviceId,
curListenerId: lid
if (native_.isFailure(result))
throw native_.getErrorObject(result);
- return args.curListenerId; // TODO return proper index of listener
+ return args.curListenerId;
};
AppCommunicationService.prototype.unsetListener = function(id) {
- console.log('Entered AppCommunicationService.unsetListener()');
var args = validator_.validateArgs(arguments, [
{name: 'id', type: types_.LONG, optional: false}
]);
var result = native_.callSync('AppCommunicationService_unsetListener', {
deviceId: this._deviceId
- //curListenerId: id // not needed in below layers
});
if (native_.isFailure(result))
throw native_.getErrorObject(result);
var lid = this._serviceId;
- if (this._listenerCallback) {// TODO extend this to manage the list of callbacks
- //delete this._listenerCallback;
+ if (this._listenerCallback) {
this._listenerCallback = null;
}
convergenceServices[lid] = this;
};
function AppCommunicationServerService() {
- console.log('Entered AppCommunicationServerService.constructor()');
-
validator_.isConstructorCall(this, AppCommunicationServerService);
AppCommunicationService.call(this, ConnectionState.NOT_CONNECTED, ServiceType.APP_COMM_SERVER);
AppCommunicationServerService.prototype.constructor = AppCommunicationServerService;
function AppCommunicationClientService() {
- console.log('Entered AppCommunicationClientService.constructor()');
-
validator_.isConstructorCall(this, AppCommunicationClientService);
AppCommunicationService.call(this, ConnectionState.NOT_CONNECTED, ServiceType.APP_COMM_CLIENT);
AppCommunicationClientService.prototype.constructor = AppCommunicationClientService;
AppCommunicationClientService.prototype.connect = function(successCallback, errorCallback) {
- console.log('Entered AppCommunicationClientService.connect()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
};
AppCommunicationClientService.prototype.disconnect = function(successCallback, errorCallback) {
- console.log('Entered AppCommunicationClientService.disconnect()');
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
type: types_.FUNCTION,
- //values: ConnectSuccessCallback,
optional: true,
nullable: true
},
{
name: 'errorCallback',
type: types_.FUNCTION,
- //values: ErrorCallback,
optional: true,
nullable: true
}
]);
- if (this.connectionState != ConnectionState.CONNECTED)
+ if (this.connectionState != ConnectionState.CONNECTED) {
throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
+ }
var that = this;
var result = native_.call('AppCommunicationClientService_disconnect', {
conv_payload_h payload = nullptr;
app_control_h app_control = nullptr;
- //regarding to native team app_control can be released
- //after setting it in payload handle, unfortunately
- //when it is done here or in triggered callback or even
- //if they are kept in vector and released in
- //~ConvergenceRemoteAppControlService() application crashes.
- //it seems that ownership is taken over somewhere and
- //handle is released. We need to wait for convergence
- //native team answer. Now app_control_destroy is commented
SCOPE_EXIT {
if (payload) {
conv_payload_destroy(payload);
}
if (app_control) {
- //uncomment below line when issue will be explained
- //app_control_destroy(app_control);
+ app_control_destroy(app_control);
}
};
return LogAndCreateTizenError(AbortError, "Failed to set app control in payload");
}
- //if the 'reply' was set callback was not triggered because
- //D2D-CONV-MANAGER received error IOTCON_ERROR_INVALID_PARAMETER -22
- //RemoteAppControlServiceProvider.cpp: __on_response(741) > iotcon_response_get_result() Fail(-22)
-
// Update listener: assign it if it is not yet assigned
- UpdateListener(cur_listener_id, "launch");
+ UpdateListener(cur_listener_id, "launch");
// Sending app control on the remote device
ret = conv_service_publish(service_handle, nullptr, payload);
conv_payload_h payload = nullptr;
app_control_h app_control = nullptr;
- //regarding to native team app_control can be released
- //after setting it in payload handle, unfortunately
- //when it is done here or in triggered callback or even
- //if they are kept in vector and released in
- //~ConvergenceRemoteAppControlService() application crashes.
- //it seems that ownership is taken over somewhere and
- //handle is released. We need to wait for convergence
- //native team answer. Now app_control_destroy is commented
SCOPE_EXIT {
if (payload) {
conv_payload_destroy(payload);
}
if (app_control) {
- //uncomment below line when issue will be explained
- //app_control_destroy(app_control);
+ app_control_destroy(app_control);
}
};