From 5f6a2eb49a28948ef0038545af3d15b2f49d904e Mon Sep 17 00:00:00 2001 From: Szymon Jastrzebski Date: Mon, 25 Sep 2017 11:28:02 +0200 Subject: [PATCH] [Convergence] Removing Convergence API segwon.han has requested to remove Convergence API. Code compiles. Change-Id: I89ab9f753de111277e444ca1b659ce301a13ae1a Signed-off-by: Szymon Jastrzebski --- packaging/webapi-plugins.spec | 10 - src/convergence/convergence.gyp | 48 - src/convergence/convergence_api.js | 1104 -------------------- .../convergence_app_communication_service.cc | 540 ---------- .../convergence_app_communication_service.h | 109 -- src/convergence/convergence_channel_info.cc | 136 --- src/convergence/convergence_channel_info.h | 59 -- src/convergence/convergence_client_info.cc | 82 -- src/convergence/convergence_client_info.h | 56 - src/convergence/convergence_device.cc | 195 ---- src/convergence/convergence_device.h | 79 -- src/convergence/convergence_extension.cc | 43 - src/convergence/convergence_extension.h | 31 - src/convergence/convergence_instance.cc | 780 -------------- src/convergence/convergence_instance.h | 98 -- src/convergence/convergence_manager.cc | 256 ----- src/convergence/convergence_manager.h | 72 -- src/convergence/convergence_payload.cc | 184 ---- src/convergence/convergence_payload.h | 118 --- .../convergence_remote_app_control_service.cc | 526 ---------- .../convergence_remote_app_control_service.h | 69 -- src/convergence/convergence_service.cc | 218 ---- src/convergence/convergence_service.h | 82 -- src/convergence/convergence_utils.cc | 104 -- src/convergence/convergence_utils.h | 93 -- src/tizen-wrt.gyp | 7 - src/utils/utils_api.js | 1 - 27 files changed, 5100 deletions(-) delete mode 100644 src/convergence/convergence.gyp delete mode 100644 src/convergence/convergence_api.js delete mode 100644 src/convergence/convergence_app_communication_service.cc delete mode 100644 src/convergence/convergence_app_communication_service.h delete mode 100644 src/convergence/convergence_channel_info.cc delete mode 100644 src/convergence/convergence_channel_info.h delete mode 100644 src/convergence/convergence_client_info.cc delete mode 100644 src/convergence/convergence_client_info.h delete mode 100644 src/convergence/convergence_device.cc delete mode 100644 src/convergence/convergence_device.h delete mode 100644 src/convergence/convergence_extension.cc delete mode 100644 src/convergence/convergence_extension.h delete mode 100644 src/convergence/convergence_instance.cc delete mode 100644 src/convergence/convergence_instance.h delete mode 100644 src/convergence/convergence_manager.cc delete mode 100644 src/convergence/convergence_manager.h delete mode 100644 src/convergence/convergence_payload.cc delete mode 100644 src/convergence/convergence_payload.h delete mode 100644 src/convergence/convergence_remote_app_control_service.cc delete mode 100644 src/convergence/convergence_remote_app_control_service.h delete mode 100644 src/convergence/convergence_service.cc delete mode 100644 src/convergence/convergence_service.h delete mode 100644 src/convergence/convergence_utils.cc delete mode 100644 src/convergence/convergence_utils.h diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index e6719b6..5440623 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -210,8 +210,6 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_tvinputdevice_support 0 -%define tizen_feature_convergence_support 0 - %endif # tizen_profile_mobile #################################################################### @@ -309,8 +307,6 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_nbs_support 0 %endif -%define tizen_feature_convergence_support 0 - %endif # tizen_profile_wearable #################################################################### @@ -367,7 +363,6 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_wi_fi_support 1 %define tizen_feature_inputdevice_support 0 %define tizen_feature_tvinputdevice_support 1 -%define tizen_feature_convergence_support 0 %endif # tizen_profile_tv @@ -547,10 +542,6 @@ BuildRequires: pkgconfig(capi-system-sensor) BuildRequires: pkgconfig(capi-system-media-key) %endif -%if 0%{?tizen_feature_convergence_support} -BuildRequires: pkgconfig(d2d-conv-manager) -%endif - %if 0%{?tizen_feature_widget_service_support} BuildRequires: pkgconfig(widget_service) %endif @@ -627,7 +618,6 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_web_setting_support=%{?tizen_feature_w GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_feature_widget_service_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_feature_wi_fi_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_feature_tvinputdevice_support}" -GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_convergence_support=%{?tizen_feature_convergence_support}" ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp diff --git a/src/convergence/convergence.gyp b/src/convergence/convergence.gyp deleted file mode 100644 index 1f6f14b..0000000 --- a/src/convergence/convergence.gyp +++ /dev/null @@ -1,48 +0,0 @@ -{ - 'includes':[ - '../common/common.gypi', - ], - 'targets': [ - { - 'target_name': 'tizen_convergence', - 'type': 'loadable_module', - 'dependencies': [ - '../common/common.gyp:tizen_common', - ], - 'sources': [ - 'convergence_api.js', - 'convergence_extension.cc', - 'convergence_extension.h', - 'convergence_instance.cc', - 'convergence_instance.h', - 'convergence_utils.cc', - 'convergence_utils.h', - 'convergence_manager.cc', - 'convergence_manager.h', - 'convergence_device.cc', - 'convergence_device.h', - 'convergence_service.cc', - 'convergence_service.h', - 'convergence_remote_app_control_service.cc', - 'convergence_remote_app_control_service.h', - 'convergence_app_communication_service.cc', - 'convergence_app_communication_service.h', - 'convergence_channel_info.cc', - 'convergence_channel_info.h', - 'convergence_payload.cc', - 'convergence_payload.h', - 'convergence_client_info.cc', - 'convergence_client_info.h', - ], - 'conditions': [ - ['tizen == 1', { - 'variables': { - 'packages': [ - 'd2d-conv-manager', - ] - }, - }], - ], - }, - ], -} diff --git a/src/convergence/convergence_api.js b/src/convergence/convergence_api.js deleted file mode 100644 index 120f4ab..0000000 --- a/src/convergence/convergence_api.js +++ /dev/null @@ -1,1104 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -var JSON_ = xwalk.JSON; -var validator_ = xwalk.utils.validator; -var types_ = validator_.Types; -var utils_ = xwalk.utils; -var native_ = new utils_.NativeManager(extension); -var T_ = utils_.type; -var converter_ = utils_.converter; - -// Flag showing if the discovery procedure has started -var discoveryStarted = false; - -// Currently available devices -var convergenceDevices = []; - -// Issued service objects -// We should stor it for proper calling user callbacks -var nextServiceId = 0; // Next service id (internally used on JS layer) -var convergenceServices = {}; // Issued services - -var ConnectionState = { - CONNECTED: 'CONNECTED', - NOT_CONNECTED: 'NOT_CONNECTED', - CONNECTING: 'CONNECTING' -}; - -var DeviceProfile = { - MOBILE: 'MOBILE', - WEARABLE: 'WEARABLE', - TV: 'TV' -}; - -var ServiceType = { - APP_COMM_CLIENT: 'APP_COMM_CLIENT', - APP_COMM_SERVER: 'APP_COMM_SERVER', - REMOTE_APP_CONTROL: 'REMOTE_APP_CONTROL' -}; - -function SetReadOnlyProperty(obj, n, v) { - if (arguments.length > 2) - Object.defineProperty( - obj, n, { - value: v, - writable: false, - enumerable: true, - configurable: true - }); - else - Object.defineProperty(obj, n, { - writable: false, - enumerable: true, - configurable: true - }); -} - -function InternalData(d) { - for (var prop in d) { - if (d.hasOwnProperty(prop)) { - this[prop] = d[prop]; - } - } -} - -function updateWithInternalData(src, dst) { - var d = new InternalData(src); - dst.connectionState = d; -} - -function getServiceConnectionStateName(connectionStateNumber) { - switch(connectionStateNumber) { - case 0: - return ConnectionState.CONNECTED; - case 1: - return ConnectionState.NOT_CONNECTED; - case 2: - return ConnectionState.CONNECTING; - default: - return 'UNKNOWN'; - } -} - -function Device(id_, name_, type_, services_) { - validator_.isConstructorCall(this, Device); - - var services = []; - if (services_) { - services = services_; - } - - Object.defineProperties(this, { - id: { - value: id_, - writable: false, - enumerable: true - }, - name: { - value: name_, - writable: false, - enumerable: true - }, - type: { - value: type_, - writable: false, - enumerable: true - }, - services: { - enumerable: true, - set : function(){}, - get : function(){ return services.slice(); } - }, - }); -} - -function ConvergenceManager() { - // constructor of ConvergenceManager -} - -ConvergenceManager.prototype.startDiscovery = function(successCallback, - errorCallback, timeout) { - - var args = validator_.validateArgs(arguments, [ - {name: 'successCallback', type: types_.LISTENER, values: ['onfound', 'onfinished' ]}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'timeout', type: types_.LONG, optional: true, nullable: true} - ]); - - // 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 - convergenceDevices = []; - - native_.addListener('CONVERGENCE_DISCOVERY_LISTENER', function(result) { - - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } else { - if (result.discovery_status == 'device_found') { - - // Prepare service array - if (!result || !result.device || !result.device.services) { - return; - } - - var services = []; - var id = result.device.id; - for (var i = 0; i < result.device.services.length; ++i) { - var service_data = result.device.services[i]; - var s; - if (service_data.serviceType == 0) { // App Communication Client - s = new AppCommunicationClientService(); - } else if (service_data.serviceType == 1) { // Remote App Control - s = new RemoteAppControlService(); - } else { - continue; - } - - var state = getServiceConnectionStateName(result.device.services[i].connectionState); - updateWithInternalData({ connectionState: state }, s); - - s._deviceId = id; - services.push(s); - } - - // Create an instance of the device - var d = new Device(id, result.device.name, result.device.type, services); - - // Store newly found device internally - convergenceDevices.push(d); - - // Invoke user callback retrieving newly found device - 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'); - - // Notify the customer about discovery results - native_.callIfPossible(successCallback.onfinished, convergenceDevices.slice()); - discoveryStarted = false; - convergenceDevices = []; - - } else { - utils_.log('UNKNOWN discovery state exception'); - } - } - }); - - // Start the discovery using Native API - var result = native_.call('ConvergenceManager_startDiscovery', { - timeout: (args.timeout) ? args.timeout : 0 - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - discoveryStarted = false; - } - }); - - if (native_.isFailure(result)) { - discoveryStarted = false; - throw native_.getErrorObject(result); - } -}; - -ConvergenceManager.prototype.stopDiscovery = function() { - if (discoveryStarted === false) - throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has not started yet.'); - - discoveryStarted = false; - - var result = native_.callSync('ConvergenceManager_stopDiscovery', null); - if (native_.isFailure(result)) - throw native_.getErrorObject(result); -}; - -function Service(connectionState_, type_) { - var connectionState = connectionState_; - - Object.defineProperties(this, { - connectionState: { - enumerable: true, - get: function() { - return connectionState; - }, - set: function(v) { - if (v instanceof InternalData && v.hasOwnProperty('connectionState')) { - connectionState = v['connectionState']; - } - } - }, - type: { - value: type_, - writable: false, - enumerable: true - } - }) -} - -native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(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 lid = result.curListenerId; - if (!lid || !convergenceServices.hasOwnProperty(lid)) { - return; // Something is wrong: listener MUST be there - } - var s = convergenceServices[lid]; - - switch (result_type) { - case 'Connected': - if (s) { // Service MUST NOT be null here - updateWithInternalData({ connectionState: ConnectionState.CONNECTED }, s); - convergenceServices[lid] = s; - } - native_.callIfPossible(s._connectCallback, s); - break; - case 'onPublish': - var remote_func = result.remote_function; - var callback = result.callback_result; - var d = undefined; - - 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': - s._isStarted = true; - native_.callIfPossible(s._startCallback, s); - break; - case 'onStop': - s._isStarted = false; - native_.callIfPossible(s._stopCallback, null); - break; - default: - break; - } - } -}); - -function RemoteAppControlService() { - validator_.isConstructorCall(this, RemoteAppControlService); - - // The device id is needed for getting the valid service handle on the - // native layer - // I have to implement this property here instead of base constructor in order - // to mask it from accessing - Object.defineProperties(this, { - _serviceId : { - value: ++nextServiceId, - writable: false, - enumerable: false - }, - // The id of device of the service or 'localhost' for local service - _deviceId : { - value: 'localhost', - writable: true, - enumerable: false - }, - // Remote App Control Service user-defined callbacks - _connectCallback : { - value: null, - writable: true, - enumerable: false - }, - _remoteAppControlCallback : { - value: null, - writable: true, - enumerable: false - }, - _isStarted : { - value: false, - writable: true, - enumerable: false - } - }); - - Service.call(this, ConnectionState.NOT_CONNECTED, ServiceType.REMOTE_APP_CONTROL); - - // Registering the service in the table of issued services - convergenceServices[this._serviceId] = this; -} - -RemoteAppControlService.prototype = new Service(); -RemoteAppControlService.prototype.constructor = RemoteAppControlService; - -RemoteAppControlService.prototype.connect = function(successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'successCallback', - type: types_.FUNCTION, - optional: false, - nullable: false - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - if (this.connectionState === ConnectionState.CONNECTED) { - throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is connected already.'); - } - - var lid = this._serviceId; - this._connectCallback = successCallback; - convergenceServices[lid] = this; - - var result = native_.call('RemoteAppControlService_connect', { - deviceId: this._deviceId, - curListenerId: lid - }, function(result) { - if (native_.isFailure(result)) - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - }); - - if (native_.isFailure(result)) - throw native_.getErrorObject(result); -}; - -RemoteAppControlService.prototype.disconnect = function(successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - if (this.connectionState !== ConnectionState.CONNECTED) { - throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.'); - } - - var that = this; - var result = native_.call('RemoteAppControlService_disconnect', { - deviceId: this._deviceId - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } else { - updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, that); - native_.callIfPossible(successCallback, that); - } - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -RemoteAppControlService.prototype.start = function() { - var args = validator_.validateArgs(arguments, [{ - name: 'successCallback', - type: types_.FUNCTION, - optional: false, - nullable: false - }, { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }]); - - if (this._isStarted) { - throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is already started.'); - } - - var lid = this._serviceId; - this._startCallback = args.successCallback; - convergenceServices[lid] = this; - - var callArgs = {}; - callArgs.reply = !!args.successCallback; - callArgs.deviceId = this._deviceId; - callArgs.curListenerId = lid; - - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - } - }; - - var result = native_.call('RemoteAppControlService_start', callArgs, callback); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -RemoteAppControlService.prototype.stop = function() { - var args = validator_.validateArgs(arguments, [{ - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - 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; - - var callArgs = {}; - callArgs.reply = !!args.successCallback; - callArgs.deviceId = this._deviceId; - callArgs.curListenerId = lid; - - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - } - }; - - var result = native_.call('RemoteAppControlService_stop', callArgs, callback); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -RemoteAppControlService.prototype.launch = function(appId, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'appId', - type: types_.STRING, - optional: false, - nullable:false - }, - { - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - 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 - //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', { - appId: args.appId, - deviceId: this._deviceId, - curListenerId: lid - }, function(result) { - if (native_.isFailure(result)) - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - }); - if (native_.isFailure(result)) - throw native_.getErrorObject(result); -}; - -RemoteAppControlService.prototype.launchAppControl = function() { - var args = validator_.validateArgs(arguments, [{ - name: 'appControl', - type: types_.PLATFORM_OBJECT, - values: tizen.ApplicationControl, - optional: false, - nullable:false - }, { - name: 'appId', - type: types_.STRING, - optional: true, - nullable: true - }, { - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, { - name: 'replyCallback', - type : types_.LISTENER, - values : ['onsuccess', 'onfailure'], - optional: true, - 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; - - var callArgs = {}; - callArgs.appControl = args.appControl; - callArgs.appId = args.appId ? args.appId : ""; - callArgs.reply = !!args.replyCallback; - callArgs.deviceId = this._deviceId; - callArgs.curListenerId = lid; - - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - } else { - native_.callIfPossible(args.successCallback); - } - }; - - var result = native_.call('RemoteAppControlService_launchAppControl', callArgs, callback); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -function AppCommunicationService(connectionState_, type_) { - Service.call(this, connectionState_, type_); - // The device id is needed for getting the valid service handle on the - // native layer - // I have to implement this property here instead of base constructor in order - // to mask it from accessing - Object.defineProperties(this, { - _serviceId : { - value: ++nextServiceId, - writable: false, - enumerable: false - }, - // The id of device of the service or 'localhost' for local service - _deviceId : { - value: 'localhost', - writable: true, - enumerable: false - }, - // App Communication Service basic callbacks - _connectCallback : { - value: null, - writable: true, - enumerable: false - }, - _startCallback : { - value: null, - writable: true, - enumerable: false - }, - _sendCallback : { - value: null, - writable: true, - enumerable: false - }, - _stopCallback : { - value: null, - writable: true, - enumerable: false - }, - _listenerCallback : { - value: null, - writable: true, - enumerable: false - }, - _getClientListCallback : { - value: null, - writable: true, - enumerable: false - } - }); - - // Registering the service in the table of issued services - convergenceServices[this._serviceId] = this; -} - -AppCommunicationService.prototype = new Service(); -AppCommunicationService.prototype.constructor = AppCommunicationService; - -native_.addListener('APP_COMMUNICATION_SERVICE_LISTENER', function(result) { - - if (native_.isFailure(result)) { - //native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } else { - // Invoke corresponding callback - var lid = result.curListenerId; - if (!lid || !convergenceServices.hasOwnProperty(lid)) { - return; // Something is wrong: listener MUST be there - } - var s = convergenceServices[lid]; - - var result_type = result.result_type; - - switch (result_type) { - case 'Connected': - if (s) { // Service MUST NOT be null here - updateWithInternalData({ connectionState: ConnectionState.CONNECTED }, s); - convergenceServices[lid] = s; - } - native_.callIfPossible(s._connectCallback, s); - break; - case 'onStart': - var clientInfo = (result.clientInfo ? new ClientInfo(result.clientInfo) : null); - native_.callIfPossible(s._startCallback, - new ConvergenceChannelInfo(result.channel.uri, result.channel.id), clientInfo); - break; - case 'onPublish': - native_.callIfPossible(s._sendCallback, - new ConvergenceChannelInfo(result.channel.uri, result.channel.id), null); - break; - case 'onStop': - native_.callIfPossible(s._stopCallback, - new ConvergenceChannelInfo(result.channel.uri, result.channel.id), null); - break; - case 'onRead': - var clients_array = []; - - for(var i = 0; i < result.payload.length; i++) { - if (result.payload[i].key === 'client_list') { - var value = JSON_.parse(result.payload[i].value); - var client = new ClientInfo(value); - clients_array.push(client); - } - } - native_.callIfPossible(s._getClientListCallback, clients_array); - break; - case 'onMessage': { - var payload = result.payload; - native_.callIfPossible(s._listenerCallback, - new ConvergenceChannelInfo(result.channel.uri, result.channel.id), - payload, result.senderId); - } - break; - default: - break; - } - } -}); - -AppCommunicationService.prototype.start = function(channel, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'channel', - type: types_.PLATFORM_OBJECT, - values: tizen.ConvergenceChannelInfo, - optional: false, - nullable: false - }, - { - name: 'successCallback', - type: types_.FUNCTION, - optional: false, - nullable: false - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - var lid = this._serviceId; - this._startCallback = successCallback; - convergenceServices[lid] = this; - - var result = native_.call('AppCommunicationService_start', { - deviceId: this._deviceId, - curListenerId: lid, - channel_data: channel - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -AppCommunicationService.prototype.stop = function(channel, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'channel', - type: types_.PLATFORM_OBJECT, - values: tizen.ConvergenceChannelInfo, - optional: false, - nullable: false - }, - { - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - var lid = -1; - if (successCallback) { - lid = this._serviceId; - this._stopCallback = successCallback; - convergenceServices[lid] = this; - } - - var result = native_.call('AppCommunicationService_stop', { - deviceId: this._deviceId, - curListenerId: lid, - channel_data: channel - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -AppCommunicationService.prototype.send = function(channel, payload, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'channel', - type: types_.PLATFORM_OBJECT, - values: tizen.ConvergenceChannelInfo, - optional: false, - nullable: false - }, - { - name: 'payload', - type: types_.ARRAY, - optional: false, - nullable: false - }, - { - name: 'successCallback', - type: types_.FUNCTION, - optional: false, - nullable: false - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - var lid = this._serviceId; - this._sendCallback = successCallback; - convergenceServices[lid] = this; - - var result = native_.call('AppCommunicationService_send', { - deviceId: this._deviceId, - curListenerId: lid, - channel_data: channel, - payload: payload - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -AppCommunicationService.prototype.getClientList = function() { - var args = validator_.validateArgs(arguments, [{ - name: 'channel', - type: types_.PLATFORM_OBJECT, - values: tizen.ConvergenceChannelInfo, - optional: false, - nullable: false - }, { - name: 'successCallback', - type: types_.FUNCTION, - optional: false, - nullable: false - }, { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - var lid = this._serviceId; - this._getClientListCallback = args.successCallback; - convergenceServices[lid] = this; - - var callArgs = {}; - callArgs.deviceId = this._deviceId; - callArgs.curListenerId = lid; - callArgs.channel_data = args.channel; - - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - } - }; - - var result = native_.call('AppCommunicationService_getClientList', callArgs, callback); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -AppCommunicationService.prototype.setListener = function(listenerCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'listenerCallback', type: types_.FUNCTION} - ]); - - var lid = this._serviceId; - this._listenerCallback = listenerCallback; - convergenceServices[lid] = this; - - var result = native_.callSync('AppCommunicationService_setListener', { - deviceId: this._deviceId, - curListenerId: lid - }); - - if (native_.isFailure(result)) - throw native_.getErrorObject(result); - - return args.curListenerId; -}; - -AppCommunicationService.prototype.unsetListener = function(id) { - var args = validator_.validateArgs(arguments, [ - {name: 'id', type: types_.LONG, optional: false} - ]); - - var result = native_.callSync('AppCommunicationService_unsetListener', { - deviceId: this._deviceId - }); - - if (native_.isFailure(result)) - throw native_.getErrorObject(result); - - var lid = this._serviceId; - if (this._listenerCallback) { - this._listenerCallback = null; - } - convergenceServices[lid] = this; -}; - -function AppCommunicationServerService() { - validator_.isConstructorCall(this, AppCommunicationServerService); - - AppCommunicationService.call(this, ConnectionState.NOT_CONNECTED, ServiceType.APP_COMM_SERVER); - - native_.callSync('AppCommunicationServerService_constructLocal', { - deviceId: this._deviceId - }); -} - -AppCommunicationServerService.prototype = new AppCommunicationService(); -AppCommunicationServerService.prototype.constructor = AppCommunicationServerService; - -function AppCommunicationClientService() { - validator_.isConstructorCall(this, AppCommunicationClientService); - - AppCommunicationService.call(this, ConnectionState.NOT_CONNECTED, ServiceType.APP_COMM_CLIENT); -} - -AppCommunicationClientService.prototype = new AppCommunicationService(); -AppCommunicationClientService.prototype.constructor = AppCommunicationClientService; - -AppCommunicationClientService.prototype.connect = function(successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'successCallback', - type: types_.FUNCTION, - optional: false, - nullable: false - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - if (this.connectionState == ConnectionState.CONNECTED) - throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is connected already.'); - - var lid = this._serviceId; - this._connectCallback = successCallback; - convergenceServices[lid] = this; - - var result = native_.call('AppCommunicationClientService_connect', { - deviceId: this._deviceId, - curListenerId: lid - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } - }); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -AppCommunicationClientService.prototype.disconnect = function(successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - { - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - 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', { - deviceId: this._deviceId - }, function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - } else { - updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, that); - native_.callIfPossible(successCallback, that); - } - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}; - -function ConvergenceChannelInfo(uri_, id_) { - validator_.isConstructorCall(this, ConvergenceChannelInfo); - - var id = ''; - var uri = ''; - - if (id_) { - id = converter_.toString(id_); - } - - if (uri_) { - uri = converter_.toString(uri_); - } - - Object.defineProperties(this, { - id: { - enumerable: true, - get: function() { - return id; - }, - set: function(v) { - id = converter_.toString(v); - } - }, - uri: { - enumerable: true, - get: function() { - return uri; - }, - set: function(v) { - uri = converter_.toString(v); - } - } - }); -} - -function ClientInfo(data) { - validator_.isConstructorCall(this, ClientInfo); - Object.defineProperties(this, { - isHost: { - value: converter_.toBoolean(data.isHost), - writable: false, - enumerable: true - }, - clientId: { - value: converter_.toString(data.clientId), - writable: false, - enumerable: true - }, - connectionTime: { - value: converter_.toLong(data.connectTime), - writable: false, - enumerable: true - } - }); -} - -exports = new ConvergenceManager(); -tizen.AppCommunicationServerService = AppCommunicationServerService; -tizen.ConvergenceChannelInfo = ConvergenceChannelInfo; diff --git a/src/convergence/convergence_app_communication_service.cc b/src/convergence/convergence_app_communication_service.cc deleted file mode 100644 index f4ac7d1..0000000 --- a/src/convergence/convergence_app_communication_service.cc +++ /dev/null @@ -1,540 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_app_communication_service.h" - -#include -#include -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_channel_info.h" -#include "convergence/convergence_client_info.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_payload.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -using common::TizenResult; -using common::TizenSuccess; - -namespace { -static const std::string kChannel = "channel"; -static const std::string kClientInfo = "clientInfo"; -} // namespace - -ConvergenceAppCommunicationService::ConvergenceAppCommunicationService() : ConvergenceService() { - ScopeLogger(); -} - -ConvergenceAppCommunicationService::ConvergenceAppCommunicationService( - conv_device_h device, ConvergenceInstance *convergence_plugin) - : ConvergenceService(device, CONV_SERVICE_APP_TO_APP_COMMUNICATION, convergence_plugin) { - ScopeLogger(); -} - -ConvergenceAppCommunicationService::~ConvergenceAppCommunicationService() { - ScopeLogger(); - - // Release all memory, used by callback paramerers - for (size_t i = 0; i < callback_param_gc_.size(); i++) { - delete callback_param_gc_[i]; - } - callback_param_gc_.clear(); -} - -common::TizenResult ConvergenceAppCommunicationService::Start(ConvergenceChannel *channel, - const int cur_listener_id) { - ScopeLogger(); - - LoggerI("Starting service [0x%x] with handle [0x%x]", this, service_handle_); - std::unique_ptr ch_ptr(channel); // auto release memory in case of error - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - bool is_started = false; - // regarding to native team returned value should not be checked - // as CONV_ERROR_NONE means service is started, otherwise not started - // check only passed bool variable - conv_service_is_started(service_handle, channel->GetHandle(), &is_started); - - if (is_started) { - picojson::object param; - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle()); - param[kServiceResultType] = picojson::value("onStart"); - - // totu - convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback, cur_listener_id, true, - param); - } else { - UpdateListener(cur_listener_id, REMOTE_SERVICE_START); - - const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr); - if (CONV_ERROR_NONE != error) { - LoggerD("conv_service_start [fail] %d %s", error, get_error_message(error)); - return LogAndCreateTizenError(AbortError, "conv_service_start [fail]"); - } - - opened_channels.push_back(ch_ptr.release()); - } - - return TizenSuccess(); -} - -common::TizenResult ConvergenceAppCommunicationService::Stop(ConvergenceChannel *channel, - const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - UpdateListener(cur_listener_id); - - const int error = conv_service_stop(service_handle, channel->GetHandle(), nullptr); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "Failed to stop service channel"); - } - - delete channel; - channel = nullptr; - - return TizenSuccess(); -} - -common::TizenResult ConvergenceAppCommunicationService::GetClientList(ConvergenceChannel *channel, - const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - UpdateListener(cur_listener_id); - - const int ret = conv_service_read(service_handle, channel->GetHandle(), nullptr); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "conv_service_read error"); - } - - return TizenSuccess(); -} - -common::TizenResult ConvergenceAppCommunicationService::Send(ConvergenceChannel *channel, - ConvergencePayloadArray &payload, - const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - UpdateListener(cur_listener_id); - - const int error = conv_service_publish(service_handle, channel->GetHandle(), payload.GetHandle()); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "conv_service_publish [fail]"); - } else { - LoggerI("PUBLISHED SUCCESSFULY listener is [%d]", cur_listener_id); - } - - return TizenSuccess(); -} - -// TODO move to Payload class - -void ConvergenceAppCommunicationService::ServiceListenerCb(conv_service_h service_handle, - conv_channel_h channel_handle, - conv_error_e error, - conv_payload_h result, void *user_data) { - ScopeLogger(); - - CallbackParam *callbackParam = static_cast(user_data); - if (!callbackParam) { - LoggerE("ERROR! NULL user data in Service Listener Callback"); - return; - } - - // TODO Send all payload and channel to the JS layer and parse it there - - // TODO parse the payload and fill the param - LoggerI("YAY! Got the Callback (TODO implement it)"); - - if (CONV_ERROR_NONE != error) { // Error occured during connection - picojson::object param; - param[kServiceListenerError] = - LogAndCreateTizenError(AbortError, "DiscoveryCb return CONV_DISCOVERY_RESULT_ERROR") - .ToJSON(); - callbackParam->plugin_->ReplyAsync(kAppCommunicationListenerCallback, - callbackParam->callback_id_, false, param); - return; - } - - // Parse the payload - const std::string result_type = - ConvergencePayloadArray::ExtractPayloadString(result, kServiceResultType.c_str()); - LoggerI("Callback type [%s]", result_type.c_str()); - - picojson::object param; - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - param[kChannel] = ConvergenceChannel::ToJson(channel_handle); - param[kServiceResultType] = picojson::value(result_type); - - if (kServiceResultTypeOnStart == result_type) { - if (callbackParam->client_info_) { - param[kClientInfo] = callbackParam->client_info_->ToJson(); - } - } else if ((kServiceResultTypeOnPublish == result_type) || - (kServiceResultTypeOnStop == result_type)) { - // The service doesn't send any callback with thie response - } else if (kServiceResultTypeOnMessage == result_type) { - param["senderId"] = picojson::value(ConvergencePayloadArray::ExtractPayloadString( - result, "from")); // Define the string as a constant - param[kPayload] = ConvergencePayloadArray::ToJson(result); - } else if (kServiceResultTypeOnConnect == result_type) { - // just filling client_info_ member in CallbackParam - if (!callbackParam->client_info_) { - callbackParam->client_info_ = new ConvergenceClientInfo(result); - } - if (LOCAL_SERVICE_START != callbackParam->type_) { - // for non-local services just set clientInfo and not trigger callback - return; - } else { - // but trigger this callback for local services and pretend that this is onStart signal - param[kServiceResultType] = picojson::value(kServiceResultTypeOnStart); - if (callbackParam->client_info_) { - param[kClientInfo] = callbackParam->client_info_->ToJson(); - } - } - } else if (kServiceResultTypeOnClientConnect == result_type) { - // TODO the service doesn't send any callback with thie response - return; // TODO - } else if (kServiceResultTypeOnDisconnect == result_type) { - return; // TODO - } else if (kServiceResultTypeOnClientDisconnect == result_type) { - return; // TODO - } else if (kServiceResultTypeOnRead == result_type) { - param[kPayload] = ConvergencePayloadArray::ToJson(result); - } else { - // Unsupported payload type, ignoring it - LoggerE("ERROR: Unsupported payload type; ignored"); - return; - } - - callbackParam->plugin_->ReplyAsync(kAppCommunicationListenerCallback, callbackParam->callback_id_, - true, param); -} - -void ConvergenceAppCommunicationService::UpdateListener(const int cur_listener_id, - ServiceRequestType type) { - ScopeLogger(); - - // TODO make sure that callback is not called twice for the same listener - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - LoggerE("Service not found"); - return; - } - - { // dbg - LoggerI("...found service handle [%x0x]", service_handle); - - conv_service_e t = CONV_SERVICE_NONE; - int e = conv_service_get_type(service_handle, &t); - if (CONV_ERROR_NONE != e) { - trace_conv_error(e, __LINE__, "get service type"); - } - LoggerI("....type [%d]", t); - - char *sid = nullptr; - e = conv_service_get_property_string(service_handle, CONV_SERVICE_ID, &sid); - if (CONV_ERROR_NONE != e) { - trace_conv_error(e, __LINE__, "get service id"); - } - LoggerI("....id [%s]", sid); - free(sid); - - char *sver = nullptr; - e = conv_service_get_property_string(service_handle, CONV_SERVICE_VERSION, &sver); - if (CONV_ERROR_NONE != e) { - trace_conv_error(e, __LINE__, "get service version"); - } - LoggerI("....ver [%s]", sver); - free(sver); - } - - CallbackParam *param = new CallbackParam(convergence_plugin_, cur_listener_id, type); - const int error = conv_service_set_listener_cb(service_handle, ServiceListenerCb, param); - - if (CONV_ERROR_NONE != error) { - // TODO: Handle error - - delete param; - trace_conv_error(error, __LINE__, "conv_service_set_listener_cb"); - } else { - callback_param_gc_.push_back(param); - LoggerI("APP COMMUNICATION SERVICE LISTENER SET SUCCESSFULY [%d]", cur_listener_id); - } -} - -common::TizenResult ConvergenceAppCommunicationService::SetListener(const int cur_listener_id) { - ScopeLogger(); - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - UpdateListener(cur_listener_id); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceAppCommunicationService::RemoveListener() { - ScopeLogger(); - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - 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) { - return LogAndCreateTizenError(AbortError, "conv_service_unset_listener_cb [Fail]"); - } - - return TizenSuccess(); -} - -ConvergenceAppCommunicationServerService::ConvergenceAppCommunicationServerService() - : ConvergenceAppCommunicationService() { - ScopeLogger(); -} - -ConvergenceAppCommunicationServerService::ConvergenceAppCommunicationServerService( - conv_device_h device, ConvergenceInstance *convergence_plugin) - : ConvergenceAppCommunicationService(device, convergence_plugin) { - ScopeLogger(); - - // Creating the handle of local service instance - int error = conv_service_create(&service_handle_); - if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_service_create App Comm Service"); - } - - error = conv_service_set_type(service_handle_, CONV_SERVICE_APP_TO_APP_COMMUNICATION); - if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_service_set_type App Comm Service"); - } - - /* - * Consider a constructor of App Communication Server Service with parameters: - * - Id - * - Version - */ - - error = conv_service_set_property_string(service_handle_, CONV_SERVICE_ID, - "test_app"); // TODO set a proper service ID - if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_service_set_property Id"); - } - - error = conv_service_set_property_string(service_handle_, CONV_SERVICE_VERSION, "1.0"); - if (CONV_ERROR_NONE != error) { - // TODO: Handle error - trace_conv_error(error, __LINE__, "conv_service_set_property Version"); - } -} - -ConvergenceAppCommunicationServerService::~ConvergenceAppCommunicationServerService() { - ScopeLogger(); -} - -common::TizenResult ConvergenceAppCommunicationServerService::Start(ConvergenceChannel *channel, - const int cur_listener_id) { - ScopeLogger(); - - LoggerI("Starting service [0x%x] with handle [0x%x]", this, service_handle_); - std::unique_ptr ch_ptr(channel); // auto release memory in case of error - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - bool is_started = false; - // regarding to native team returned value should not be checked - // as CONV_ERROR_NONE means service is started, otherwise not started - // check only passed bool variable - conv_service_is_started(service_handle, channel->GetHandle(), &is_started); - - if (is_started) { - picojson::object param; - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle()); - param[kServiceResultType] = picojson::value("onStart"); - - // totu - convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback, cur_listener_id, true, - param); - } else { - UpdateListener(cur_listener_id, LOCAL_SERVICE_START); - - const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr); - if (CONV_ERROR_NONE != error) { - LoggerD("conv_service_start [fail] %d %s", error, get_error_message(error)); - return LogAndCreateTizenError(AbortError, "conv_service_start [fail]"); - } - - opened_channels.push_back(ch_ptr.release()); - } - - return TizenSuccess(); -} - -common::TizenResult ConvergenceAppCommunicationServerService::Stop(ConvergenceChannel *channel, - const int cur_listener_id) { - ScopeLogger(); - - /* By implementation, the local App Communication Service doesn't send - * the callback confirming that the Start is successful. - * So we are sending this callback manually - */ - picojson::object param; - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - - param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle()); - param[kServiceResultType] = picojson::value(kServiceResultTypeOnStop); - - common::TizenResult result = ConvergenceAppCommunicationService::Stop(channel, cur_listener_id); - if (!result) { - return result; - } - - convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback, cur_listener_id, true, param); - return result; -} - -ConvergenceAppCommunicationClientService::ConvergenceAppCommunicationClientService() - : ConvergenceAppCommunicationService() { - ScopeLogger(); -} - -ConvergenceAppCommunicationClientService::ConvergenceAppCommunicationClientService( - conv_device_h device, ConvergenceInstance *convergence_plugin) - : ConvergenceAppCommunicationService(device, convergence_plugin) { - ScopeLogger(); -} - -ConvergenceAppCommunicationClientService::~ConvergenceAppCommunicationClientService() { - ScopeLogger(); -} - -void ConvergenceAppCommunicationClientService::ServiceConnectedCb(conv_service_h service_handle, - conv_error_e error, - conv_payload_h result, - void *user_data) { - ScopeLogger(); - - CallbackParam *callbackParam = static_cast(user_data); - if (!callbackParam) { - LoggerE("ERROR! NULL user data in Service Connect Callback"); - return; - } - - picojson::object param; - param[kPayload] = ConvergencePayloadArray::ToJson(result); - param[kServiceResultType] = picojson::value("Connected"); - - if (CONV_ERROR_NONE == error) { - param[kServiceConnectionStatus] = picojson::value(kServiceConnectionStatusConnected); - callbackParam->plugin_->ReplyAsync(kAppCommunicationListenerCallback, - callbackParam->callback_id_, true, param); - } else { - // Error occured during connection - param[kServiceConnectionStatus] = picojson::value(kServiceConnectionStatusNotConnected); - callbackParam->plugin_->ReplyAsync(kAppCommunicationListenerCallback, - callbackParam->callback_id_, false, param); - } -} - -common::TizenResult ConvergenceAppCommunicationClientService::Connect(const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service = FindServiceHandle(); - if (!service) { - return LogAndCreateTizenError(AbortError, "Service is NULL"); - } - - // TODO: make a garbage collection and release this memory when service is disconnected - // and when whole manager is destructed - CallbackParam *param = new CallbackParam(convergence_plugin_, cur_listener_id); - callback_param_gc_.push_back(param); - - const int error = conv_service_connect(service, ServiceConnectedCb, param); - 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(); -} - -common::TizenResult ConvergenceAppCommunicationClientService::Disconnect() { - ScopeLogger(); - - conv_service_h service = FindServiceHandle(); - if (!service) return LogAndCreateTizenError(AbortError, "Service is NULL"); - - int error = conv_service_disconnect(service); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_service_disconnect"); - return LogAndCreateTizenError(AbortError, "conv_service_disconnect [fail]"); - } - - conv_service_connection_state_e state = CONV_SERVICE_CONNECTION_STATE_NONE; - error = conv_service_get_connection_state(service, &state); - if (CONV_ERROR_NONE != error) { - LoggerE("Error gathering state [%d] : %s", error, get_error_message(error)); - return LogAndCreateTizenError(AbortError, "Error gathering state"); - } else { - LoggerD("state: %d", state); - } - if (CONV_SERVICE_CONNECTION_STATE_NOT_CONNECTED == state) { - return TizenSuccess(); - } else { - LoggerE("Service is still connected, reporting error"); - return LogAndCreateTizenError(AbortError, "Disconnecting failed."); - } -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_app_communication_service.h b/src/convergence/convergence_app_communication_service.h deleted file mode 100644 index e77113b..0000000 --- a/src/convergence/convergence_app_communication_service.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_APP_COMMUNICATION_SERVICE_H__ -#define CONVERGENCE_CONVERGENCE_APP_COMMUNICATION_SERVICE_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" -#include "convergence/convergence_service.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -class ConvergenceChannel; -class ConvergencePayloadArray; - -class ConvergenceAppCommunicationService : public ConvergenceService { - public: - ConvergenceAppCommunicationService(); - ConvergenceAppCommunicationService(conv_device_h device, ConvergenceInstance* convergence_plugin); - virtual ~ConvergenceAppCommunicationService(); - ConvergenceAppCommunicationService(const ConvergenceAppCommunicationService&) = delete; - ConvergenceAppCommunicationService(ConvergenceAppCommunicationService&&) = delete; - ConvergenceAppCommunicationService& operator=(const ConvergenceAppCommunicationService&) = delete; - ConvergenceAppCommunicationService& operator=(ConvergenceAppCommunicationService&&) = delete; - - public: - virtual common::TizenResult Start(ConvergenceChannel* channel, const int cur_listener_id); - virtual common::TizenResult Stop(ConvergenceChannel* channel, const int cur_listener_id); - virtual common::TizenResult GetClientList(ConvergenceChannel* channel, const int cur_listener_id); - virtual common::TizenResult Send(ConvergenceChannel* channel, ConvergencePayloadArray& payload, - const int cur_listener_id); - common::TizenResult SetListener(const int cur_listener_id); - common::TizenResult RemoveListener(); - - private: - static void ServiceListenerCb(conv_service_h service_handle, conv_channel_h channel_handle, - conv_error_e error, conv_payload_h result, void* user_data); - - protected: - void UpdateListener(const int cur_listener_id, ServiceRequestType type = UNKNOWN_REQUEST_TYPE); - std::vector callback_param_gc_; -}; - -class ConvergenceAppCommunicationServerService : public ConvergenceAppCommunicationService { - public: - ConvergenceAppCommunicationServerService(); - ConvergenceAppCommunicationServerService(conv_device_h device, - ConvergenceInstance* convergence_plugin); - virtual ~ConvergenceAppCommunicationServerService(); - ConvergenceAppCommunicationServerService(const ConvergenceAppCommunicationServerService&) = - delete; - ConvergenceAppCommunicationServerService(ConvergenceAppCommunicationServerService&&) = delete; - ConvergenceAppCommunicationServerService& operator=( - const ConvergenceAppCommunicationServerService&) = delete; - ConvergenceAppCommunicationServerService& operator=(ConvergenceAppCommunicationServerService&&) = - delete; - - public: - virtual common::TizenResult Start(ConvergenceChannel* channel, const int cur_listener_id); - virtual common::TizenResult Stop(ConvergenceChannel* channel, const int cur_listener_id); -}; - -class ConvergenceAppCommunicationClientService : public ConvergenceAppCommunicationService { - public: - ConvergenceAppCommunicationClientService(); - ConvergenceAppCommunicationClientService(conv_device_h device, - ConvergenceInstance* convergence_plugin); - virtual ~ConvergenceAppCommunicationClientService(); - ConvergenceAppCommunicationClientService(const ConvergenceAppCommunicationClientService&) = - delete; - ConvergenceAppCommunicationClientService(ConvergenceAppCommunicationClientService&&) = delete; - ConvergenceAppCommunicationClientService& operator=( - const ConvergenceAppCommunicationClientService&) = delete; - ConvergenceAppCommunicationClientService& operator=(ConvergenceAppCommunicationClientService&&) = - delete; - - public: - common::TizenResult Connect(const int cur_listener_id); - common::TizenResult Disconnect(); - - private: - static void ServiceConnectedCb(conv_service_h service_handle, conv_error_e error, - conv_payload_h result, void* user_data); -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_APP_COMMUNICATION_SERVICE_H__ diff --git a/src/convergence/convergence_channel_info.cc b/src/convergence/convergence_channel_info.cc deleted file mode 100644 index aac2557..0000000 --- a/src/convergence/convergence_channel_info.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_channel_info.h" - -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -// Channel keys -static const std::string kId = "id"; // This id is used in arguments (comes from JS layer) -static const std::string kChannelId = - "channel_id"; // This id is used in the App Comm Service engine -static const std::string kUri = "uri"; -} // namespace - -ConvergenceChannel::ConvergenceChannel() : channel_handle_(nullptr) { - ScopeLogger(); -} - -ConvergenceChannel::ConvergenceChannel(const picojson::value &channel_json) - : channel_handle_(nullptr) { - ScopeLogger(); - FromJson(channel_json); -} - -ConvergenceChannel::~ConvergenceChannel() { - ScopeLogger(); - - if (channel_handle_) { - conv_channel_destroy(channel_handle_); - channel_handle_ = NULL; - } -} - -conv_channel_h ConvergenceChannel::GetHandle() const { - ScopeLogger(); - return channel_handle_; -} - -std::string ConvergenceChannel::GetUri() const { - return uri_; -} - -std::string ConvergenceChannel::GetId() const { - return id_; -} - -void ConvergenceChannel::FromJson(const picojson::value &channel_json) { - ScopeLogger(); - if (channel_json.is()) { - LoggerE("ERROR: Channel json value is NULL"); - return; - } - - if (channel_handle_) { - conv_channel_destroy(channel_handle_); - channel_handle_ = NULL; - } - - int error = conv_channel_create(&channel_handle_); - if ((CONV_ERROR_NONE != error) || !channel_handle_) { - trace_conv_error(error, __LINE__, "creating channel handle"); - return; - } - - id_ = channel_json.get(kId).to_str(); - error = conv_channel_set_string(channel_handle_, kChannelId.c_str(), id_.c_str()); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "setting channel string Id"); - } - - uri_ = channel_json.get(kUri).to_str(); - error = conv_channel_set_string(channel_handle_, kUri.c_str(), uri_.c_str()); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "setting channel string URI"); - } -} - -picojson::value ConvergenceChannel::ToJson(conv_channel_h channel_handle) { - ScopeLogger(); - - picojson::object channel_object; - if (!channel_handle) { - LoggerE("Error: trying to convert NULL channel handle to json"); - return picojson::value(channel_object); - } - - { // Extracting channel ID - char *id = nullptr; - const int error = conv_channel_get_string(channel_handle, kChannelId.c_str(), &id); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "getting channel string Id"); - } else { - channel_object[kId] = picojson::value(id); - free(id); - } - } - - { // Extracting channel URI - char *uri = nullptr; - const int error = conv_channel_get_string(channel_handle, kUri.c_str(), &uri); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "getting channel string URI"); - } else { - channel_object[kUri] = picojson::value(uri); - free(uri); - } - }; - - return picojson::value(channel_object); -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_channel_info.h b/src/convergence/convergence_channel_info.h deleted file mode 100644 index c89ff70..0000000 --- a/src/convergence/convergence_channel_info.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_CHANNEL_H__ -#define CONVERGENCE_CONVERGENCE_CHANNEL_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" - -namespace extension { -namespace convergence { - -class ConvergenceChannel { - public: - ConvergenceChannel(); - ConvergenceChannel(const picojson::value& channel_json); - virtual ~ConvergenceChannel(); - ConvergenceChannel(const ConvergenceChannel&) = delete; - ConvergenceChannel(ConvergenceChannel&&) = delete; - ConvergenceChannel& operator=(const ConvergenceChannel&) = delete; - ConvergenceChannel& operator=(ConvergenceChannel&&) = delete; - - public: - conv_channel_h GetHandle() const; - std::string GetId() const; - std::string GetUri() const; - void FromJson(const picojson::value& channel_json); - - public: - static picojson::value ToJson(conv_channel_h channel_handle); - - private: - conv_channel_h channel_handle_; - std::string id_; - std::string uri_; -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_CHANNEL_H__ diff --git a/src/convergence/convergence_client_info.cc b/src/convergence/convergence_client_info.cc deleted file mode 100644 index 8d501aa..0000000 --- a/src/convergence/convergence_client_info.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_client_info.h" - -#include -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -// Service keys -static const std::string kIsHost = "client_is_host"; -static const std::string kConnectionTime = "client_connect_time"; //-- -static const std::string kClientId = "client_id"; -} // namespace - -ConvergenceClientInfo::ConvergenceClientInfo() : isHost_(false), connectionTime_(0) { - ScopeLogger(); -} - -ConvergenceClientInfo::ConvergenceClientInfo(conv_payload_h payload) - : isHost_(false), connectionTime_(0) { - ScopeLogger(); - - isHost_ = ExtractPayloadString(payload, "client_is_host") == "1"; - connectionTime_ = atol(ExtractPayloadString(payload, "client_connect_time").c_str()); - clientId_ = ExtractPayloadString(payload, "client_id").c_str(); -} - -ConvergenceClientInfo::~ConvergenceClientInfo() { - ScopeLogger(); -} - -std::string ConvergenceClientInfo::ExtractPayloadString(conv_payload_h payload, const char *key) { - ScopeLogger(); - char *value = nullptr; - const int error = conv_payload_get_string(payload, key, &value); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_payload_get_string"); - return ""; - } - - if (value) { - const std::string result = std::string(value); - free(value); - return result; - } - return ""; -} - -picojson::value ConvergenceClientInfo::ToJson() const { - ScopeLogger(); - picojson::object clientInfo; - clientInfo["isHost"] = picojson::value(static_cast(isHost_)); - clientInfo["connectTime"] = picojson::value(static_cast(connectionTime_)); - clientInfo["clientId"] = picojson::value(clientId_); - return picojson::value(clientInfo); -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_client_info.h b/src/convergence/convergence_client_info.h deleted file mode 100644 index b8f68e9..0000000 --- a/src/convergence/convergence_client_info.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_CLIENT_INFO_H__ -#define CONVERGENCE_CONVERGENCE_CLIENT_INFO_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" - -namespace extension { -namespace convergence { - -class ConvergenceClientInfo { - public: - ConvergenceClientInfo(); - ConvergenceClientInfo(conv_payload_h payload); - virtual ~ConvergenceClientInfo(); - ConvergenceClientInfo(const ConvergenceClientInfo&) = delete; - ConvergenceClientInfo(ConvergenceClientInfo&&) = delete; - ConvergenceClientInfo& operator=(const ConvergenceClientInfo&) = delete; - ConvergenceClientInfo& operator=(ConvergenceClientInfo&&) = delete; - - public: - picojson::value ToJson() const; - - private: - std::string ExtractPayloadString(conv_payload_h payload, const char* key); - - private: - bool isHost_; - std::string clientId_; - long connectionTime_; -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_CLIENT_INFO_H__ diff --git a/src/convergence/convergence_device.cc b/src/convergence/convergence_device.cc deleted file mode 100644 index 3abc98c..0000000 --- a/src/convergence/convergence_device.cc +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_device.h" - -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_app_communication_service.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_remote_app_control_service.h" -#include "convergence/convergence_service.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -// Service keys -static const std::string kId = "id"; -static const std::string kName = "name"; //-- -static const std::string kDeviceType = "type"; -static const std::string kDeviceServices = "services"; -} // namespace - -ConvergenceDevice::ConvergenceDevice() : device_handle_(nullptr), convergence_plugin_(NULL) { - ScopeLogger(); -} - -ConvergenceDevice::ConvergenceDevice(conv_device_h device, ConvergenceInstance *convergence_plugin) - : device_handle_(device), convergence_plugin_(convergence_plugin) { - ScopeLogger(); -} - -ConvergenceDevice::~ConvergenceDevice() { - ScopeLogger(); - - // Releasing all registered services - for (auto it = services_.begin(); it != services_.end(); ++it) { - delete it->second; - } - services_.clear(); - - conv_device_destroy(device_handle_); -} - -std::string ConvergenceDevice::ExtractDevicePropery(const char *property) { - ScopeLogger(); - char *value = nullptr; - const int error = conv_device_get_property_string(device_handle_, property, &value); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_device_get_property_string"); - return ""; - } - - if (value) { - const std::string result = std::string(value); - free(value); - return result; - } - return ""; -} - -ConvergenceService *ConvergenceDevice::SwapService(const int service_type) { - ScopeLogger(); - LoggerI("Swapping service of type [%d]", service_type); - if (services_.count(service_type) <= 0) { - switch (service_type) { - case CONV_SERVICE_APP_TO_APP_COMMUNICATION: { - services_[service_type] = - new ConvergenceAppCommunicationService(device_handle_, convergence_plugin_); - break; - } - case CONV_SERVICE_REMOTE_APP_CONTROL: { - LoggerI("Adding Remote App Control service"); - services_[service_type] = - new ConvergenceRemoteAppControlService(device_handle_, convergence_plugin_); - break; - } - default: { - LoggerE("ERROR! UNKNOWN SERVICE TYPE [%d]", service_type); - return nullptr; - } - } - } - return services_[service_type]; -} - -ConvergenceService *ConvergenceDevice::RegisterLocalService(const int service_type) { - ScopeLogger(); - LoggerI("Registering the local service of type [%d]", service_type); - if (services_.count(service_type) <= 0) { - switch (service_type) { - case CONV_SERVICE_APP_TO_APP_COMMUNICATION: { - services_[service_type] = - new ConvergenceAppCommunicationServerService(device_handle_, convergence_plugin_); - LoggerI("Registered for local device [%s] the service [0x%0x] of type [%d]", id_.c_str(), - services_[service_type], CONV_SERVICE_APP_TO_APP_COMMUNICATION); - break; - } - default: { - LoggerE("ERROR! UNKNOWN SERVICE TYPE [%d]", service_type); - return nullptr; - } - } - } - return services_[service_type]; -} - -void ConvergenceDevice::ForEachServiceCb(conv_service_h service_handle, void *user_data) { - ScopeLogger(); - if (!service_handle || !user_data) { - LoggerE("ERROR! Invalid parameters of D2D API Callback"); - return; - } - ConvergenceDevice *owner = static_cast(user_data); - - // Extracting service type - conv_service_e type = CONV_SERVICE_NONE; - int error = conv_service_get_type(service_handle, &type); - if (CONV_ERROR_NONE != error) { - LoggerE("ERROR! D2D API Get Service Type error [%d]", error); - return; - } - - ConvergenceService *s = owner->SwapService(type); - if (!s) { - LoggerE("ERROR! Cannot add NULL service"); - return; - } - - s->Refresh(); -} - -void ConvergenceDevice::Refresh() { - ScopeLogger(); - // Getting device properties from handle - id_ = ExtractDevicePropery(CONV_DEVICE_ID); - name_ = ExtractDevicePropery(CONV_DEVICE_NAME); - type_ = ExtractDevicePropery(CONV_DEVICE_TYPE); - - LoggerE("Refreshed device id [%s] name [%s] type [%s]", id_.c_str(), name_.c_str(), - type_.c_str()); - - // Extracting services - const int error = conv_device_foreach_service(device_handle_, ForEachServiceCb, this); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_device_foreach_service"); - } -} - -picojson::value ConvergenceDevice::ToJson() const { - ScopeLogger(); - picojson::object device_json; - - // Convert device props and services into JSON - device_json[kId] = picojson::value(id_); - device_json[kName] = picojson::value(name_); - device_json[kDeviceType] = picojson::value(type_); - - picojson::array services; - for (auto it = services_.begin(); it != services_.end(); ++it) { - ConvergenceService *s = it->second; - services.push_back(s->ToJson()); - } - device_json[kDeviceServices] = picojson::value(services); - - return picojson::value(device_json); -} - -ConvergenceService *ConvergenceDevice::GetService(const int service_type) const { - ScopeLogger(); - if (services_.count(service_type) <= 0) - return nullptr; - else - return services_[service_type]; -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_device.h b/src/convergence/convergence_device.h deleted file mode 100644 index d187d02..0000000 --- a/src/convergence/convergence_device.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_DEVICE_H__ -#define CONVERGENCE_CONVERGENCE_DEVICE_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" - -namespace extension { -namespace convergence { - -class ConvergenceInstance; -class ConvergenceService; - -class ConvergenceDevice { - public: - ConvergenceDevice(); - ConvergenceDevice(conv_device_h device_handle, ConvergenceInstance *convergence_plugin); - virtual ~ConvergenceDevice(); - ConvergenceDevice(const ConvergenceDevice &) = delete; - ConvergenceDevice(ConvergenceDevice &&) = delete; - ConvergenceDevice &operator=(const ConvergenceDevice &) = delete; - ConvergenceDevice &operator=(ConvergenceDevice &&) = delete; - - public: - void Refresh(); - ConvergenceService *GetService(const int service_type) const; - // picojson::object ToJson() const; - picojson::value ToJson() const; - // std::string get_device() const {return device_handle_; } - int ServiceCount() { - return services_.size(); - }; - - public: - ConvergenceService *RegisterLocalService(const int service_type); - void SetId(const std::string &id) { - id_ = id; - } - - private: - ConvergenceService *SwapService(const int service_type); - std::string ExtractDevicePropery(const char *property); - static void ForEachServiceCb(conv_service_h service_handle, void *user_data); - - private: - conv_device_h device_handle_; - ConvergenceInstance *convergence_plugin_; - mutable std::unordered_map services_; - - private: - std::string id_; - std::string name_; - std::string type_; // Device profile: mobile, wearable, TV -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_DEVICE_H__ diff --git a/src/convergence/convergence_extension.cc b/src/convergence/convergence_extension.cc deleted file mode 100644 index c84dbdc..0000000 --- a/src/convergence/convergence_extension.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "convergence/convergence_extension.h" - -#include "convergence/convergence_instance.h" - -// This will be generated from convergence_api.js -extern const char kSource_convergence_api[]; - -common::Extension* CreateExtension() { - return new ConvergenceExtension; -} - -ConvergenceExtension::ConvergenceExtension() { - SetExtensionName("tizen.convergence"); - SetJavaScriptAPI(kSource_convergence_api); - - const char* entry_points[] = { - "tizen.RemoteAppControlService", "tizen.AppCommunicationServerService", - "tizen.AppCommunicationClientService", "tizen.ConvergenceChannelInfo", nullptr}; - SetExtraJSEntryPoints(entry_points); -} - -ConvergenceExtension::~ConvergenceExtension() { -} - -common::Instance* ConvergenceExtension::CreateInstance() { - return new extension::convergence::ConvergenceInstance; -} diff --git a/src/convergence/convergence_extension.h b/src/convergence/convergence_extension.h deleted file mode 100644 index e9edfc7..0000000 --- a/src/convergence/convergence_extension.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_EXTENSION_H_ -#define CONVERGENCE_CONVERGENCE_EXTENSION_H_ - -#include "common/extension.h" - -class ConvergenceExtension : public common::Extension { - public: - ConvergenceExtension(); - virtual ~ConvergenceExtension(); - - private: - virtual common::Instance* CreateInstance(); -}; - -#endif // CONVERGENCE_CONVERGENCE_EXTENSION_H_ diff --git a/src/convergence/convergence_instance.cc b/src/convergence/convergence_instance.cc deleted file mode 100644 index d30451d..0000000 --- a/src/convergence/convergence_instance.cc +++ /dev/null @@ -1,780 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "convergence/convergence_instance.h" - -#include -#include -#include - -#include "common/logger.h" -#include "common/picojson.h" -#include "common/task-queue.h" -#include "common/tools.h" -#include "convergence/convergence_app_communication_service.h" -#include "convergence/convergence_channel_info.h" -#include "convergence/convergence_manager.h" -#include "convergence/convergence_payload.h" -#include "convergence/convergence_remote_app_control_service.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -// The privileges that required in Convergence API -const std::string kPrivilegeInternet = "http://tizen.org/privilege/internet"; -const std::string kPrivilegeBluetooth = "http://tizen.org/privilege/bluetooth"; -const std::string kPrivilegeDataSharing = "http://tizen.org/privilege/datasharing"; - -// JS listener keys -static const std::string kJSListenerStatus = "status"; -static const std::string kJSCurrentListenerId = "curListenerId"; -static const std::string kJSTargetListenerId = "listenerId"; -static const std::string kSuccess = "success"; -static const std::string kError = "error"; - -// Arguments, passed from JS -static const std::string kJSCallbackId = "callbackId"; -static const std::string kJSArgumentDeviceId = "deviceId"; -static const std::string kJSArgumentServiceTypeNumber = "serviceTypeNumber"; -static const std::string kJSArgumentChannel = "channel_data"; -static const std::string kJSArgumentPayload = "payload"; -static const std::string kJSArgumentAppId = "appId"; -static const std::string kJSArgumentReply = "reply"; -static const std::string kJSArgumentTimeout = "timeout"; -static const std::string kJSArgumentService = "service"; -static const std::string kJSArgumentAppControl = "appControl"; -} // namespace - -using namespace common; - -ConvergenceInstance::ConvergenceInstance() { - using namespace std::placeholders; -#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&ConvergenceInstance::x, this, _1)) - - REGISTER_SYNC("ConvergenceManager_stopDiscovery", ConvergenceManagerStopDiscovery); - REGISTER_SYNC("AppCommunicationService_setListener", AppCommunicationServiceSetListener); - REGISTER_SYNC("AppCommunicationService_unsetListener", AppCommunicationServiceUnsetListener); - REGISTER_SYNC("AppCommunicationServerService_constructLocal", - AppCommunicationServerServiceConstructLocal); -#undef REGISTER_SYNC - -#define REGISTER_ASYNC(c, x) RegisterHandler(c, std::bind(&ConvergenceInstance::x, this, _1, _2)) - REGISTER_ASYNC("ConvergenceManager_startDiscovery", ConvergenceManagerStartDiscovery); - REGISTER_ASYNC("AppCommunicationClientService_connect", AppCommunicationClientServiceConnect); - REGISTER_ASYNC("AppCommunicationClientService_disconnect", - AppCommunicationClientServiceDisconnect); - REGISTER_ASYNC("AppCommunicationService_start", AppCommunicationServiceStart); - REGISTER_ASYNC("AppCommunicationService_stop", AppCommunicationServiceStop); - REGISTER_ASYNC("AppCommunicationService_getClientList", AppCommunicationServiceGetClientList); - REGISTER_ASYNC("AppCommunicationService_send", AppCommunicationServiceSend); - REGISTER_ASYNC("RemoteAppControlService_disconnect", RemoteAppControlServiceDisconnect); - REGISTER_ASYNC("RemoteAppControlService_connect", RemoteAppControlServiceConnect); - REGISTER_ASYNC("RemoteAppControlService_start", RemoteAppControlServiceStart); - REGISTER_ASYNC("RemoteAppControlService_stop", RemoteAppControlServiceStop); - REGISTER_ASYNC("RemoteAppControlService_launch", RemoteAppControlServiceLaunch); - REGISTER_ASYNC("RemoteAppControlService_launchAppControl", - RemoteAppControlServiceLaunchAppControl); -#undef REGISTER_ASYNC -} - -ConvergenceInstance::~ConvergenceInstance() { - ConvergenceManager::GetInstance(this).ResetInternalData(); -} - -void ConvergenceInstance::ReplyAsync(ConvergenceCallbacks callback_function_type, int curListenerId, - bool isSuccess, picojson::object& param) { - ScopeLogger(); - - param[kJSListenerStatus] = picojson::value(isSuccess ? kSuccess : kError); - param[kJSCurrentListenerId] = picojson::value(static_cast(curListenerId)); - - switch (callback_function_type) { - case kConvergenceManagerDiscoveryCallback: { - param[kJSTargetListenerId] = picojson::value("CONVERGENCE_DISCOVERY_LISTENER"); - break; - } - /*case kRemoteAppControlServiceConnectCallback: { - param[kJSTargetListenerId] = - picojson::value("REMOTE_APP_CONTROL_SERVICE_CONNECT_LISTENER"); - break; - }*/ - case kRemoteAppControlListenerCallback: { - param[kJSTargetListenerId] = picojson::value("REMOTE_APP_CONTROL_SERVICE_LISTENER"); - break; - } - /*case kAppCommunicationSuccessCallback: { - param[kJSTargetListenerId] = - picojson::value("APP_COMMUNICATION_SERVICE_SUCCESS_LISTENER"); - break; - }*/ - case kAppCommunicationListenerCallback: { - param[kJSTargetListenerId] = picojson::value("APP_COMMUNICATION_SERVICE_LISTENER"); - break; - } - /*case kAppCommunicationClientServiceConnectCallback: { - param[kJSTargetListenerId] = - picojson::value("APP_COMMUNICATON_CLIENT_SERVICE_CONNECT_LISTENER"); - break; - }*/ - default: { - LoggerE("Invalid Callback Type"); - return; - } - } - - picojson::value result = picojson::value(param); - LoggerD("---> %s", result.serialize().c_str()); // TODO remove - - TaskQueue::GetInstance().Async( - [this, result]() { Instance::PostMessage(this, result.serialize().c_str()); }); -} - -common::TizenResult ConvergenceInstance::ConvergenceManagerStartDiscovery( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - CHECK_EXIST(args, kJSArgumentTimeout); - CHECK_EXIST(args, kJSCallbackId); - - auto start_discovery = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("start_discovery"); - - // Start the discovery procedure - TizenResult result = ConvergenceManager::GetInstance(this).StartDiscovery( - static_cast(ConvergenceUtils::GetArg(args, kJSArgumentTimeout).get())); - this->Post(token, result); - }; - - std::thread(start_discovery, token).detach(); - - return common::TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::ConvergenceManagerStopDiscovery( - const picojson::object& args) { - ScopeLogger(); - - /*CHECK_PRIVILEGE(kPrivilegeInternet) - CHECK_PRIVILEGE(kPrivilegeBluetooth) - CHECK_PRIVILEGE(kPrivilegeWifiDirect)*/ - - // Running the discovery stop procedure - return ConvergenceManager::GetInstance(this).StopDiscovery(); -} - -common::TizenResult ConvergenceInstance::RemoteAppControlServiceConnect( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto connect = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("connect"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceRemoteAppControlService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_REMOTE_APP_CONTROL)); - if (!service) { - 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())); - } - - // only in case of failure call callback - // other cases are handled by conv_service_connected_cb() - if (!result) { - this->Post(token, result); - } - }; - - std::thread(connect, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::RemoteAppControlServiceDisconnect( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - auto disconnect = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("disconnect"); - - TizenResult result = TizenSuccess(); - - ConvergenceRemoteAppControlService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_REMOTE_APP_CONTROL)); - if (!service) { - result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", - ("Can not find the service type = 1")); - } else { - result = service->Disconnect(); - } - - this->Post(token, result); - }; - - std::thread(disconnect, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::RemoteAppControlServiceStart( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentReply); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto start = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("start"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceRemoteAppControlService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_REMOTE_APP_CONTROL)); - if (!service) { - 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()), - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); - } - - // only in case of failure call callback - // other cases are handled by conv_service_listener_cb() - if (!result) { - this->Post(token, result); - } - }; - - std::thread(start, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::RemoteAppControlServiceStop( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentReply); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto stop = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("stop"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceRemoteAppControlService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_REMOTE_APP_CONTROL)); - if (!service) { - 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()), - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); - } - - // only in case of failure call callback - // other cases are handled by conv_service_listener_cb() - if (!result) { - this->Post(token, result); - } - }; - - std::thread(stop, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::RemoteAppControlServiceLaunch( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - CHECK_PRIVILEGE(kPrivilegeDataSharing); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentAppId); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto launch = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("launch"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceRemoteAppControlService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_REMOTE_APP_CONTROL)); - if (!service) { - result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1", - ("Can not find the service type = 1")); - } else { - std::string id = ConvergenceUtils::GetArg(args, kJSArgumentAppId).to_str(); - if (id.empty()) { - result = LogAndCreateTizenError(InvalidValuesError, "Invalid app id", ("Invalid app id")); - } else { - result = service->Launch( - id.c_str(), - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); - } - } - - // only in case of failure call callback - // other cases are handled by conv_service_listener_cb() - if (!result) { - this->Post(token, result); - } - }; - - std::thread(launch, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::RemoteAppControlServiceLaunchAppControl( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - CHECK_PRIVILEGE(kPrivilegeDataSharing); - - CHECK_EXIST(args, kJSArgumentAppControl); - CHECK_EXIST(args, kJSArgumentAppId); - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentReply); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto launch_app_control = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("launch_app_control"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceRemoteAppControlService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_REMOTE_APP_CONTROL)); - if (!service) { - 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(), - ConvergenceUtils::GetArg(args, kJSArgumentReply).get(), - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); - } - - this->Post(token, result); - }; - - std::thread(launch_app_control, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServiceStart( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - CHECK_PRIVILEGE(kPrivilegeDataSharing); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentChannel); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto start = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("start"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceAppCommunicationService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - 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.", - ("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()); - - result = service->Start(channel, id); - } - } - - // in case of failure call error callback, success callback will be triggered by listener - if (!result) { - this->Post(token, result); - } - }; - - std::thread(start, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServiceSend( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - CHECK_PRIVILEGE(kPrivilegeDataSharing); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentChannel); - CHECK_EXIST(args, kJSArgumentPayload); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto send = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("send"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceAppCommunicationService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - 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.", - ("Service is not started for the channel.")); - } else { - ConvergencePayloadArray payload(ConvergenceUtils::GetArg(args, kJSArgumentPayload)); - const int id = - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); - - result = service->Send(*channel_it, payload, id); - } - } - - // in case of failure call error callback, success callback will be triggered by listener - if (!result) { - this->Post(token, result); - } - }; - - std::thread(send, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServiceStop( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - CHECK_PRIVILEGE(kPrivilegeDataSharing); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentChannel); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto stop = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("stop"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceAppCommunicationService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - 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.", - ("Service is not started for the channel.")); - } else { - const int id = - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); - - result = service->Stop(*channel_it, id); - if (result) { - service->RemoveChannel(channel_it); - } - } - } - - // in case of failure call error callback, success callback will be triggered by listener - if (!result) { - this->Post(token, result); - } - }; - - std::thread(stop, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServiceGetClientList( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - CHECK_PRIVILEGE(kPrivilegeDataSharing); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSArgumentChannel); - CHECK_EXIST(args, kJSCurrentListenerId); - - auto get_client_list = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("get_client_list"); - - TizenResult result = TizenSuccess(); - - // Finding the service - ConvergenceAppCommunicationService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - 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.", - ("Service is not started for the channel.")); - } else { - const int id = - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get()); - - result = service->GetClientList(*channel_it, id); - } - } - - // in case of failure call error callback, success callback will be triggered by listener - if (!result) { - this->Post(token, result); - } - }; - - std::thread(get_client_list, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServiceSetListener( - const picojson::object& args) { - ScopeLogger(); - - /*CHECK_PRIVILEGE(kPrivilegeInternet) - CHECK_PRIVILEGE(kPrivilegeBluetooth) - CHECK_PRIVILEGE(kPrivilegeWifiDirect)*/ - - LoggerI("ARGS: %s", picojson::value(args).serialize().c_str()); - - // Finding the service - ConvergenceAppCommunicationService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - return LogAndCreateTizenError(AbortError, "service is NULL", ("service is NULL")); - } - - // Running the service stop procedure - service->SetListener( - static_cast(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get())); - - return common::TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServiceUnsetListener( - const picojson::object& args) { - ScopeLogger(); - - /*CHECK_PRIVILEGE(kPrivilegeInternet) - CHECK_PRIVILEGE(kPrivilegeBluetooth) - CHECK_PRIVILEGE(kPrivilegeWifiDirect)*/ - - // Finding the service - ConvergenceAppCommunicationService* service = static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - return LogAndCreateTizenError(AbortError, "service is NULL", ("service is NULL")); - } - - // Running the service stop procedure - service->RemoveListener(); - - return common::TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationServerServiceConstructLocal( - const picojson::object& args) { - ScopeLogger(); - - // Finding the service - ConvergenceAppCommunicationClientService* service = - static_cast( - ConvergenceManager::GetInstance(this).RegisterLocalService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - return LogAndCreateTizenError(AbortError, "Can not find the service type = 1", - ("Can not find the service type = 1")); - } - - return common::TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationClientServiceConnect( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - - // [TK] SecurityError - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - CHECK_EXIST(args, kJSArgumentDeviceId); - CHECK_EXIST(args, kJSCurrentListenerId); - - LoggerI("ARGS: %s", picojson::value(args).serialize().c_str()); - - auto connect = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("connect"); - - TizenResult result = TizenSuccess(); - - ConvergenceAppCommunicationClientService* service = - static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - 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())); - } - - this->Post(token, result); - }; - - std::thread(connect, token).detach(); - - return TizenSuccess(); -} - -common::TizenResult ConvergenceInstance::AppCommunicationClientServiceDisconnect( - const picojson::object& args, const common::AsyncToken& token) { - ScopeLogger(); - CHECK_PRIVILEGE(kPrivilegeInternet); - CHECK_PRIVILEGE(kPrivilegeBluetooth); - - // LoggerI("ARGS: %s", picojson::value(args).serialize().c_str()); - - auto disconnect = [this, args](const common::AsyncToken& token) -> void { - ScopeLogger("disconnect"); - - TizenResult result = TizenSuccess(); - - ConvergenceAppCommunicationClientService* service = - static_cast( - ConvergenceManager::GetInstance(this).GetService( - ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(), - CONV_SERVICE_APP_TO_APP_COMMUNICATION)); - if (!service) { - result = LogAndCreateTizenError(AbortError, "Service is NULL", ("Service is NULL")); - } else { - // Running the service disconnect procedure - result = service->Disconnect(); - } - - this->Post(token, result); - }; - - std::thread(disconnect, token).detach(); - - return TizenSuccess(); -} - -#undef CHECK_EXIST - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_instance.h b/src/convergence/convergence_instance.h deleted file mode 100644 index 94758c3..0000000 --- a/src/convergence/convergence_instance.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_INSTANCE_H_ -#define CONVERGENCE_CONVERGENCE_INSTANCE_H_ - -#include -#include "common/extension.h" -#include "common/tizen_instance.h" -#include "common/tizen_result.h" - -namespace extension { -namespace convergence { - -enum ConvergenceCallbacks { - // Convergence Manager Discovery - kConvergenceManagerDiscoveryCallback, - - // Remote App Control - // kRemoteAppControlServiceConnectCallback, - kRemoteAppControlListenerCallback, - - // App Communication - // kAppCommunicationSuccessCallback, - kAppCommunicationListenerCallback, - - // App Communication Client - // kAppCommunicationClientServiceConnectCallback -}; - -class ConvergenceInstance : public common::TizenInstance { - public: - ConvergenceInstance(); - virtual ~ConvergenceInstance(); - - public: - void ReplyAsync(ConvergenceCallbacks cbfunc, int curListenerId, bool isSuccess, - picojson::object& param); - - private: - // Convergence Manager - common::TizenResult ConvergenceManagerStartDiscovery(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult ConvergenceManagerStopDiscovery(const picojson::object& args); - - // Remote App Control Service - common::TizenResult RemoteAppControlServiceConnect(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult RemoteAppControlServiceDisconnect(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult RemoteAppControlServiceStart(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult RemoteAppControlServiceStop(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult RemoteAppControlServiceLaunch(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult RemoteAppControlServiceLaunchAppControl(const picojson::object& args, - const common::AsyncToken& token); - - // App Communication Service - common::TizenResult AppCommunicationServiceStart(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult AppCommunicationServiceStop(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult AppCommunicationServiceGetClientList(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult AppCommunicationServiceSend(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult AppCommunicationServiceSetListener(const picojson::object& args); - common::TizenResult AppCommunicationServiceUnsetListener(const picojson::object& args); - - // App Communication Server Service - common::TizenResult AppCommunicationServerServiceConstructLocal(const picojson::object& args); - - // App Communication Client Service - common::TizenResult AppCommunicationClientServiceConnect(const picojson::object& args, - const common::AsyncToken& token); - common::TizenResult AppCommunicationClientServiceDisconnect(const picojson::object& args, - const common::AsyncToken& token); -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_INSTANCE_H_ diff --git a/src/convergence/convergence_manager.cc b/src/convergence/convergence_manager.cc deleted file mode 100644 index ea005c5..0000000 --- a/src/convergence/convergence_manager.cc +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "convergence/convergence_manager.h" - -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_device.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_service.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -using common::TizenResult; -using common::TizenSuccess; - -namespace { -// Device keys -static const std::string kDevice = "device"; - -// Discovery keys -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 = "error"; -} // namespace - -//////////////////////////////////////////////////////////////////////////////// - -ConvergenceManager &ConvergenceManager::GetInstance(ConvergenceInstance *owner) { - static ConvergenceManager instance; - instance.convergence_plugin_ = owner; - return instance; -} - -ConvergenceManager::ConvergenceManager() - : convergence_plugin_(nullptr), convergence_manager_(nullptr) { - ScopeLogger(); - const int error = conv_create(&convergence_manager_); - if (CONV_ERROR_NONE != error) { - // Handle error - trace_conv_error(error, __LINE__, "conv_create"); - } -} - -ConvergenceManager::~ConvergenceManager() { - ScopeLogger(); - - // Releasing all registered devices - for (auto it = registered_devices_.begin(); it != registered_devices_.end(); ++it) { - delete it->second; - } - registered_devices_.clear(); - - int error = conv_destroy(convergence_manager_); - if (CONV_ERROR_NONE != error) { - // Handle error - trace_conv_error(error, __LINE__, "conv_destroy"); - } - convergence_manager_ = nullptr; -} - -void ConvergenceManager::ResetInternalData() { - ScopeLogger(); - // Releasing all registered devices - for (auto it = registered_devices_.begin(); it != registered_devices_.end(); ++it) { - delete it->second; - } - registered_devices_.clear(); - - // release handle - int error = conv_destroy(convergence_manager_); - if (CONV_ERROR_NONE != error) { - // Handle error - trace_conv_error(error, __LINE__, "conv_destroy"); - } - convergence_manager_ = nullptr; - convergence_plugin_ = nullptr; - - // create native handle - error = conv_create(&convergence_manager_); - if (CONV_ERROR_NONE != error) { - // Handle error - trace_conv_error(error, __LINE__, "conv_create"); - } -} - -ConvergenceDevice *ConvergenceManager::SwapDevice(const char *device_id, - conv_device_h device_handle) { - ScopeLogger(); - if (registered_devices_.count(device_id) <= 0) { - ConvergenceDevice *d = new ConvergenceDevice(device_handle, convergence_plugin_); - d->SetId(device_id); - registered_devices_[device_id] = d; - LoggerI("...registering the device [%s, %x]", device_id, device_handle); - // Assume that there are only two services - } else if (registered_devices_[device_id]->ServiceCount() < 2) { - registered_devices_.erase(device_id); - ConvergenceDevice *d = new ConvergenceDevice(device_handle, convergence_plugin_); - d->SetId(device_id); - registered_devices_[device_id] = d; - } - return registered_devices_[device_id]; -} - -void ConvergenceManager::DiscoveryCb(conv_device_h device_handle, conv_discovery_result_e result, - void *user_data) { - ScopeLogger(); - - if (!user_data) { - LoggerE("ERROR! NULL user data in discovery callback"); - return; - } - - ConvergenceManager *owner = static_cast(user_data); - - switch (result) { - case CONV_DISCOVERY_RESULT_SUCCESS: { - LoggerI("...found a device"); - - char *id = nullptr; - int error = conv_device_get_property_string(device_handle, CONV_DEVICE_ID, &id); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_device_get_property_string ID"); - } - if (!id) { - LoggerE("BAD ERROR: Device ID is NULL"); - return; // TODO report error - } - - conv_device_h clone_device = nullptr; - error = conv_device_clone(device_handle, &clone_device); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_device_clone"); - break; - } - ConvergenceDevice *d = owner->SwapDevice(id, clone_device); - free(id); - - if (!d) { - // Handle bad error - LoggerE("BAD ERROR: Cannot swap the device"); - break; - } - - d->Refresh(); - - picojson::object param; - param[kDiscoveryStatus] = picojson::value(kDiscoveryStatusDeviceFound); - param[kDevice] = d->ToJson(); - owner->convergence_plugin_->ReplyAsync(kConvergenceManagerDiscoveryCallback, -1, true, param); - - break; - } - case CONV_DISCOVERY_RESULT_FINISHED: { - LoggerE("...discovery finished"); - - picojson::object param; - param[kDiscoveryStatus] = picojson::value(kDiscoveryStatusFinished); - owner->convergence_plugin_->ReplyAsync(kConvergenceManagerDiscoveryCallback, -1, true, param); - break; - } - case CONV_DISCOVERY_RESULT_ERROR: { - LoggerE("Discovery Error"); - picojson::object param; - param[kDiscoveryError] = - LogAndCreateTizenError(AbortError, "DiscoveryCb return CONV_DISCOVERY_RESULT_ERROR") - .ToJSON(); - owner->convergence_plugin_->ReplyAsync(kConvergenceManagerDiscoveryCallback, -1, false, - param); - break; - } - default: { - LoggerE("Unknown discovery result"); - break; - } - } -} - -TizenResult ConvergenceManager::StartDiscovery(long timeout) { - ScopeLogger(); - const int error = - conv_discovery_start(convergence_manager_, (const int)timeout, DiscoveryCb, this); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "conv_discovery_start [fail]"); - } - return TizenSuccess(); -} - -TizenResult ConvergenceManager::StopDiscovery() { - ScopeLogger(); - const int error = conv_discovery_stop(convergence_manager_); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "conv_discovery_stop [fail]"); - } - return TizenSuccess(); -} - -//------------- -// TODO Implement the NULL Object pattern for Service, -// so this function would return always valid pointers -//------------- -ConvergenceService *ConvergenceManager::GetService(const char *device_id, - const int service_type) const { - ScopeLogger(); - - LoggerI("Getting the service object for id [%s], type [%d]", device_id, service_type); - if (registered_devices_.count(device_id) <= 0) { - LoggerE("Device ID not found"); - return nullptr; - } - - ConvergenceDevice *d = registered_devices_[device_id]; - if (!d) { - LoggerE("Device object not found"); - return nullptr; - } - - return d->GetService(service_type); -} - -ConvergenceService *ConvergenceManager::RegisterLocalService(const char *device_id, - const int service_type) { - ScopeLogger(); - - LoggerI("Registering local service [%d] for device id [%s]", service_type, device_id); - - ConvergenceDevice *d = SwapDevice(device_id, nullptr); - if (!d) { - LoggerE("Device object not found"); - return nullptr; - } - - return d->RegisterLocalService(service_type); -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_manager.h b/src/convergence/convergence_manager.h deleted file mode 100644 index d9ffb29..0000000 --- a/src/convergence/convergence_manager.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_MANAGER_H__ -#define CONVERGENCE_CONVERGENCE_MANAGER_H__ - -#include - -#include -#include - -#include "common/tizen_result.h" - -namespace extension { -namespace convergence { - -class ConvergenceDevice; -class ConvergenceService; - -// TODO rename to Discovery Manager -// TODO extract service start, stop, read, send to Service Manager class -class ConvergenceManager { - public: - static ConvergenceManager &GetInstance(class ConvergenceInstance *owner); - - public: - ConvergenceManager(); - ~ConvergenceManager(); - ConvergenceManager(const ConvergenceManager &) = delete; - ConvergenceManager(ConvergenceManager &&) = delete; - ConvergenceManager &operator=(const ConvergenceManager &) = delete; - ConvergenceManager &operator=(ConvergenceManager &&) = delete; - - public: - common::TizenResult StartDiscovery(long timeout); - common::TizenResult StopDiscovery(); - - public: - ConvergenceService *GetService(const char *device_id, const int service_type) const; - ConvergenceService *RegisterLocalService(const char *device_id, const int service_type); - - void ResetInternalData(); - - private: - static void DiscoveryCb(conv_device_h device_handle, conv_discovery_result_e result, - void *user_data); - ConvergenceDevice *SwapDevice(const char *device_id, conv_device_h device_handle); - - private: - class ConvergenceInstance *convergence_plugin_; - conv_h convergence_manager_; - mutable std::unordered_map - registered_devices_; // TODO rename to discovered_devices_ or simply devices_ -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_MANAGER_H__ diff --git a/src/convergence/convergence_payload.cc b/src/convergence/convergence_payload.cc deleted file mode 100644 index 22fd23b..0000000 --- a/src/convergence/convergence_payload.cc +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_payload.h" - -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -// Payload data keys and some values -static const std::string kKey = "key"; -static const std::string kValue = "value"; -} // namespace - -ConvergencePayloadArray::ConvergencePayloadArray() : payload_handle_(nullptr) { - ScopeLogger(); -} - -ConvergencePayloadArray::ConvergencePayloadArray(const picojson::value &payload_json) - : payload_handle_(nullptr) { - ScopeLogger(); - FromJson(payload_json); -} - -ConvergencePayloadArray::~ConvergencePayloadArray() { - ScopeLogger(); - - if (payload_handle_) { - conv_payload_destroy(payload_handle_); - payload_handle_ = nullptr; - } -} - -conv_payload_h ConvergencePayloadArray::GetHandle() const { - ScopeLogger(); - return payload_handle_; -} - -void ConvergencePayloadArray::FromJson(const picojson::value &payload_json) { - ScopeLogger(); - if (payload_json.is()) { - LoggerE("ERROR: trying to convert NULL payload json value"); - return; - } - - if (payload_handle_) { - conv_payload_destroy(payload_handle_); - payload_handle_ = nullptr; - } - - int error = conv_payload_create(&payload_handle_); - if ((CONV_ERROR_NONE != error) || !payload_handle_) { - trace_conv_error(error, __LINE__, "creating payload handle"); - return; - } - - if (!payload_json.is()) { - LoggerE("ERROR: Payload json is not an array"); - return; - } - - const picojson::array &payload_items = payload_json.get(); - for (size_t i = 0; i < payload_items.size(); i++) { - int error = CONV_ERROR_NONE; - picojson::value item = payload_items[i]; - - const std::string key = item.get(kKey).to_str(); - - if (item.get(kValue).is()) { - const std::string value = item.get(kValue).get(); - - error = conv_payload_set_string(payload_handle_, key.c_str(), value.c_str()); - } else if (item.get(kValue).is()) { - const picojson::array &value = item.get(kValue).get(); - - unsigned int length = value.size(); - unsigned char *bytes = new unsigned char[length]; - - for (std::size_t i = 0; i < length; ++i) { - bytes[i] = static_cast(value.at(i).get()); - } - - error = conv_payload_set_byte(payload_handle_, key.c_str(), length, bytes); - delete[] bytes; - } else { - LoggerD("Unknown type"); - } - - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "setting payload failed"); - } - } -} - -picojson::value ConvergencePayloadArray::ToJson(conv_payload_h payload_handle) { - ScopeLogger(); - - picojson::array payloads; // Array of payloads to deliver to JS layer - - do { - if (!payload_handle) { - LoggerE("ERROR: trying to convert NULL payload handle to json"); - break; - } - - picojson::value parsed_payload; - { - char *payload_json_str = nullptr; - int error = conv_payload_internal_export_to_string(payload_handle, &payload_json_str); - if ((CONV_ERROR_NONE != error) || !payload_json_str) { - trace_conv_error(error, __LINE__, "converting payload handle to json"); - break; - } - - std::string err; - picojson::parse(parsed_payload, payload_json_str, payload_json_str + strlen(payload_json_str), - &err); - free(payload_json_str); - if (!err.empty()) { - LoggerE("Error parsing payload json: %s", err.c_str()); - break; - } - } - - if (!parsed_payload.is()) { - LoggerE("ERROR: Payload is not an object"); - break; - } - - const picojson::object &payload_items = parsed_payload.get(); - for (auto it = std::begin(payload_items); it != std::end(payload_items); ++it) { - const std::string item_name = it->first; - const picojson::value item_value = it->second; - - picojson::object payload_object; - payload_object[kKey] = picojson::value(item_name); - payload_object[kValue] = item_value; - - payloads.push_back(picojson::value(payload_object)); - } - } while (false); - - return picojson::value(payloads); -} - -std::string ConvergencePayloadArray::ExtractPayloadString(conv_payload_h payload, const char *key) { - ScopeLogger(); - char *value = nullptr; - const int error = conv_payload_get_string(payload, key, &value); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_payload_get_string"); - return ""; - } - - if (value) { - const std::string result = std::string(value); - free(value); - return result; - } - return ""; -} -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_payload.h b/src/convergence/convergence_payload.h deleted file mode 100644 index f5f3035..0000000 --- a/src/convergence/convergence_payload.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_PAYLOAD_H__ -#define CONVERGENCE_CONVERGENCE_PAYLOAD_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" - -namespace extension { -namespace convergence { - -namespace { -static const std::string kPayload = "payload"; -} // namespace - -/*enum ConvergencePayloadType { - kUnknownPayload = -1, - kStringPayload, - kRawBytesPayload -};*/ - -// TODO rename to simply Payload -class ConvergencePayloadArray { - public: - ConvergencePayloadArray(); - ConvergencePayloadArray(const picojson::value &payload_json); - virtual ~ConvergencePayloadArray(); - ConvergencePayloadArray(const ConvergencePayloadArray &) = delete; - ConvergencePayloadArray(ConvergencePayloadArray &&) = delete; - ConvergencePayloadArray &operator=(const ConvergencePayloadArray &) = delete; - ConvergencePayloadArray &operator=(ConvergencePayloadArray &&) = delete; - - public: - conv_payload_h GetHandle() const; - void FromJson(const picojson::value &payload_json); - - public: - static picojson::value ToJson(conv_payload_h payload_handle); - static std::string ExtractPayloadString(conv_payload_h payload, const char *key); - - private: - conv_payload_h payload_handle_; -}; - -/* -class ConvergencePayload { - public: - ConvergencePayload(); - virtual ~ConvergencePayload(); - ConvergencePayload(const ConvergencePayload&) = delete; - ConvergencePayload(ConvergencePayload&&) = delete; - ConvergencePayload& operator=(const ConvergencePayload&) = delete; - ConvergencePayload& operator=(ConvergencePayload&&) = delete; - - public: - void FromJson(const picojson::value &payload_json); - - protected: - std::string id_; - ConvergencePayloadType type_; -}; - -class ConvergencePayloadString : public ConvergencePayload { - public: - ConvergencePayloadString(); - virtual ~ConvergencePayloadString(); - ConvergencePayloadString(const ConvergencePayloadString&) = delete; - ConvergencePayloadString(ConvergencePayloadString&&) = delete; - ConvergencePayloadString& operator=(const ConvergencePayloadString&) = delete; - ConvergencePayloadString& operator=(ConvergencePayloadString&&) = delete; - - public: - void FromJson(const picojson::value &payload_json); - - private: - std::string string_value_; -}; - -class ConvergencePayloadRawBytes : public ConvergencePayload { - public: - ConvergencePayloadRawBytes(); - virtual ~ConvergencePayloadRawBytes(); - ConvergencePayloadRawBytes(const ConvergencePayloadRawBytes&) = delete; - ConvergencePayloadRawBytes(ConvergencePayloadRawBytes&&) = delete; - ConvergencePayloadRawBytes& operator=(const ConvergencePayloadRawBytes&) = delete; - ConvergencePayloadRawBytes& operator=(ConvergencePayloadRawBytes&&) = delete; - - public: - void FromJson(const picojson::value &payload_json); - - private: - std::vector raw_bytes_value_; -}; -*/ - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_PAYLOAD_H__ diff --git a/src/convergence/convergence_remote_app_control_service.cc b/src/convergence/convergence_remote_app_control_service.cc deleted file mode 100644 index c81b0a8..0000000 --- a/src/convergence/convergence_remote_app_control_service.cc +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_remote_app_control_service.h" - -#include -#include - -#include "common/logger.h" -#include "common/scope_exit.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_payload.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -static const char* kAppControl = "app_control"; -static const char* kReply = "reply"; -static const char* kCbResult = "callback_result"; -static const char* kRemoteFunc = "remote_function"; -static const char* kJSCurrentListenerId = "curListenerId"; - -static const std::string kLaunch = "launch"; -static const std::string kLaunchAppControl = "launchAppControl"; -} // namespace - -using common::TizenResult; -using common::TizenSuccess; - -ConvergenceRemoteAppControlService::ConvergenceRemoteAppControlService() - : ConvergenceService(), 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) { - ScopeLogger(); -} - -ConvergenceRemoteAppControlService::~ConvergenceRemoteAppControlService() { - ScopeLogger(); - - // Release all memory, used by callback parameters - for (size_t i = 0; i < callback_param_gc_.size(); i++) { - delete callback_param_gc_[i]; - } - callback_param_gc_.clear(); - - delete connect_callback_param_; -} - -void ConvergenceRemoteAppControlService::ServiceConnectedCb(conv_service_h service_handle, - conv_error_e error, - conv_payload_h result, - void* user_data) { - ScopeLogger(); - - CallbackParam* callbackParam = static_cast(user_data); - if (!callbackParam) { - LoggerE("ERROR! NULL user data in Service Connect Callback"); - return; - } - - picojson::object param; - param[kServiceResultType] = picojson::value("Connected"); - param[kPayload] = ConvergencePayloadArray::ToJson(result); - - if (CONV_ERROR_NONE == error) { - param[kServiceConnectionStatus] = picojson::value(kServiceConnectionStatusConnected); - callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback, - callbackParam->callback_id_, true, param); - } else { - // Error occurred during connection - param[kServiceConnectionStatus] = picojson::value(kServiceConnectionStatusNotConnected); - callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback, - callbackParam->callback_id_, false, param); - } -} - -TizenResult ConvergenceRemoteAppControlService::Connect(const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service = FindServiceHandle(); - if (!service) { - 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) { - delete param; - return LogAndCreateTizenError(AbortError, "conv_service_connect [Fail]"); - } else { - // Hopefully we are sure that the service is disconnected - connect_callback_param_ = param; - LoggerI("Connected to the remote service"); - } - - return TizenSuccess(); -} - -TizenResult ConvergenceRemoteAppControlService::Disconnect() { - ScopeLogger(); - - conv_service_h service = FindServiceHandle(); - if (!service) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - int error = conv_service_disconnect(service); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "conv_service_disconnect [Fail]"); - } else { - delete connect_callback_param_; - connect_callback_param_ = nullptr; - LoggerI("Disconnected from the remote service"); - } - - conv_service_connection_state_e state = CONV_SERVICE_CONNECTION_STATE_NONE; - error = conv_service_get_connection_state(service, &state); - if (CONV_ERROR_NONE != error) { - LoggerE("Error gathering state [%d] : %s", error, get_error_message(error)); - return LogAndCreateTizenError(AbortError, "Error gathering state"); - } else { - LoggerD("state: %d", state); - } - if (CONV_SERVICE_CONNECTION_STATE_NOT_CONNECTED == state) { - return TizenSuccess(); - } else { - LoggerE("Service is still connected, reporting error"); - return LogAndCreateTizenError(AbortError, "Disconnecting failed."); - } -} - -TizenResult ConvergenceRemoteAppControlService::Start(const bool reply, const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service = FindServiceHandle(); - if (!service) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - bool is_started = false; - // regarding to native team returned value should not be checked - // as CONV_ERROR_NONE means service is started, otherwise not started - // check only passed bool variable - conv_service_is_started(service, nullptr, &is_started); - - if (is_started) { - // just call success callback - picojson::object param; - param[kServiceResultType] = picojson::value("onStart"); - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - param[kJSCurrentListenerId] = picojson::value(static_cast(cur_listener_id)); - - convergence_plugin_->ReplyAsync(kRemoteAppControlListenerCallback, cur_listener_id, true, - param); - } else { - if (reply) { - UpdateListener(cur_listener_id); - } - - const int error = conv_service_start(service, nullptr, nullptr); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "conv_service_start error"); - } else { - LoggerI("RemoteAppControlService started"); - } - } - - return TizenSuccess(); -} - -TizenResult ConvergenceRemoteAppControlService::Stop(const bool reply, const int cur_listener_id) { - ScopeLogger(); - - conv_service_h service = FindServiceHandle(); - if (!service) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - if (reply) { - UpdateListener(cur_listener_id); - } - - const int error = conv_service_stop(service, nullptr, nullptr); - if (CONV_ERROR_NONE != error) { - return LogAndCreateTizenError(AbortError, "conv_service_stop error"); - } else { - LoggerI("RemoteAppControlService stopped"); - } - - return TizenSuccess(); -} - -void ConvergenceRemoteAppControlService::ServiceListenerCb(conv_service_h service_handle, - conv_channel_h channel_handle, - conv_error_e error, - conv_payload_h result, void* user_data) { - ScopeLogger(); - - CallbackParam* callbackParam = static_cast(user_data); - if (!callbackParam) { - LoggerE("ERROR! NULL user data in Service Listener Callback"); - return; - } - - picojson::object param; - const std::string result_type = - ConvergencePayloadArray::ExtractPayloadString(result, kServiceResultType.c_str()); - param[kServiceResultType] = picojson::value(result_type); - - if (CONV_ERROR_NONE == error) { - // onPublish are triggered by launch() and launchAppControl() methods - if (kServiceResultTypeOnPublish == result_type) { - param[kRemoteFunc] = picojson::value(callbackParam->remote_method_); - // there is no information which method caused callback execution - // so it is needed to provide such information via callbackParam - if (kLaunchAppControl == callbackParam->remote_method_) { - const std::string app_control_result = ConvergencePayloadArray::ExtractPayloadString( - result, kServiceReplyControlResult.c_str()); - if ("0" == app_control_result) { - const std::string app_control_reply = - ConvergencePayloadArray::ExtractPayloadString(result, kServiceReplyResult.c_str()); - - param[kCbResult] = picojson::value("onsuccess"); - param[kReply] = picojson::value(app_control_reply); - } else { - param[kCbResult] = picojson::value("onfailure"); - } - } else if (kLaunch == callbackParam->remote_method_) { - param[kCbResult] = picojson::value("onsuccess"); - } - - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback, - callbackParam->callback_id_, true, param); - } else { - param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk); - callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback, - callbackParam->callback_id_, true, param); - } - } 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(error)); - callbackParam->plugin_->ReplyAsync(kRemoteAppControlListenerCallback, - callbackParam->callback_id_, false, param); - } -} - -void ConvergenceRemoteAppControlService::UpdateListener(const int cur_listener_id, - std::string remote_method) { - ScopeLogger(); - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - LoggerE("Service not found"); - return; - } - - CallbackParam* param = new CallbackParam(convergence_plugin_, cur_listener_id); - param->remote_method_ = remote_method; - const int error = conv_service_set_listener_cb(service_handle, ServiceListenerCb, param); - - if (CONV_ERROR_NONE != error) { - // TODO: Handle error - - delete param; - trace_conv_error(error, __LINE__, "conv_service_set_listener_cb"); - } else { - callback_param_gc_.push_back(param); - LoggerI("Listener is set correctly"); - } -} - -TizenResult ConvergenceRemoteAppControlService::Launch(const char* appId, - const int cur_listener_id) { - ScopeLogger(); - - conv_payload_h payload = nullptr; - app_control_h app_control = nullptr; - - SCOPE_EXIT { - if (payload) { - conv_payload_destroy(payload); - } - if (app_control) { - app_control_destroy(app_control); - } - }; - - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - int ret = conv_payload_create(&payload); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to create payload handle"); - } - - ret = app_control_create(&app_control); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to create app control handle"); - } - - ret = app_control_set_app_id(app_control, appId); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app ID in app control"); - } - - ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_MAIN); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set operation in app control"); - } - - ret = conv_payload_set_app_control(payload, kAppControl, app_control); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app control in payload"); - } - - // Update listener: assign it if it is not yet assigned - UpdateListener(cur_listener_id, "launch"); - - // Sending app control on the remote device - ret = conv_service_publish(service_handle, nullptr, payload); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to launch appControl"); - } else { - LoggerD("appControl launched"); - } - - return TizenSuccess(); -} - -TizenResult ConvergenceRemoteAppControlService::LaunchAppControl( - const picojson::object& jsonAppControl, const char* appId, bool reply, - const int cur_listener_id) { - ScopeLogger(); - - conv_payload_h payload = nullptr; - app_control_h app_control = nullptr; - - SCOPE_EXIT { - if (payload) { - conv_payload_destroy(payload); - } - if (app_control) { - app_control_destroy(app_control); - } - }; - - // Get service_handle - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - return LogAndCreateTizenError(AbortError, "Service with specified type does not exist"); - } - - // Create payload - int ret = conv_payload_create(&payload); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to create payload handle"); - } - - // Create app control - ret = app_control_create(&app_control); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to create app control handle"); - } - - // Set app id - if (appId && strlen(appId)) { - ret = app_control_set_app_id(app_control, appId); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app ID in app control"); - } - } - - // Set app control - const auto it_operation = jsonAppControl.find("operation"); - const auto it_uri = jsonAppControl.find("uri"); - const auto it_mime = jsonAppControl.find("mime"); - const auto it_category = jsonAppControl.find("category"); - const auto it_data = jsonAppControl.find("data"); - const auto it_app_control_end = jsonAppControl.end(); - - if (it_operation == it_app_control_end || it_uri == it_app_control_end || - it_mime == it_app_control_end || it_category == it_app_control_end || - it_data == it_app_control_end || !it_operation->second.is() || - !it_data->second.is()) { - return LogAndCreateTizenError(InvalidValuesError, "Invalid parameter was passed."); - } - - // operation - ret = app_control_set_operation(app_control, it_operation->second.get().c_str()); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app control operation"); - } - - // uri - if (it_uri->second.is()) { - ret = app_control_set_uri(app_control, it_uri->second.get().c_str()); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app control uri"); - } - } - - // mime - if (it_mime->second.is()) { - ret = app_control_set_mime(app_control, it_mime->second.get().c_str()); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app control mime"); - } - } - - // category - if (it_category->second.is()) { - ret = app_control_set_category(app_control, it_category->second.get().c_str()); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app control category"); - } - } - - // ApplicationControlData - const picojson::array& data = it_data->second.get(); - - for (auto iter = data.begin(); iter != data.end(); ++iter) { - if (iter->is()) { - TizenResult result = - ApplicationControlDataToServiceExtraData(iter->get(), app_control); - if (!result) { - return result; - } - } - } - - ret = conv_payload_set_app_control(payload, kAppControl, app_control); - if (APP_CONTROL_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set app control in payload"); - } - - if (reply) { - ret = conv_payload_set_string(payload, kReply, "1"); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to set string in payload"); - } - } - - // Update listener: assign it if it is not yet assigned - if (reply) { - UpdateListener(cur_listener_id, "launchAppControl"); - } - - // Sending app control on the remote device - ret = conv_service_publish(service_handle, nullptr, payload); - if (CONV_ERROR_NONE != ret) { - return LogAndCreateTizenError(AbortError, "Failed to launch appControl"); - } else { - LoggerD("appControl launched"); - } - - return TizenSuccess(); -} - -TizenResult ConvergenceRemoteAppControlService::ApplicationControlDataToServiceExtraData( - const picojson::object& app_control_data, app_control_h app_control) { - ScopeLogger(); - - const auto it_key = app_control_data.find("key"); - const auto it_value = app_control_data.find("value"); - const auto it_app_control_data_end = app_control_data.end(); - - if (it_key == it_app_control_data_end || it_value == it_app_control_data_end || - !it_key->second.is() || !it_value->second.is()) { - return LogAndCreateTizenError(InvalidValuesError, "Invalid parameter was passed."); - } - - const std::string& key = it_key->second.get(); - const picojson::array& value = it_value->second.get(); - - const size_t size = value.size(); - const char** arr = new const char*[size]; - size_t i = 0; - - for (auto iter = value.begin(); iter != value.end(); ++iter, ++i) { - arr[i] = iter->get().c_str(); - } - - if (1 == size) { - app_control_add_extra_data(app_control, key.c_str(), arr[0]); - } else { - app_control_add_extra_data_array(app_control, key.c_str(), arr, size); - } - - delete[] arr; - - return TizenSuccess(); -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_remote_app_control_service.h b/src/convergence/convergence_remote_app_control_service.h deleted file mode 100644 index 0fb5f3b..0000000 --- a/src/convergence/convergence_remote_app_control_service.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_REMOTE_APP_CONTROL_SERVICE_H__ -#define CONVERGENCE_CONVERGENCE_REMOTE_APP_CONTROL_SERVICE_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" -#include "convergence/convergence_service.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -class ConvergenceRemoteAppControlService : public ConvergenceService { - public: - ConvergenceRemoteAppControlService(); - ConvergenceRemoteAppControlService(conv_device_h device, ConvergenceInstance* convergence_plugin); - virtual ~ConvergenceRemoteAppControlService(); - ConvergenceRemoteAppControlService(const ConvergenceRemoteAppControlService&) = delete; - ConvergenceRemoteAppControlService(ConvergenceRemoteAppControlService&&) = delete; - ConvergenceRemoteAppControlService& operator=(const ConvergenceRemoteAppControlService&) = delete; - ConvergenceRemoteAppControlService& operator=(ConvergenceRemoteAppControlService&&) = delete; - - public: - common::TizenResult Connect(const int cur_listener_id); - common::TizenResult Disconnect(); - common::TizenResult Start(const bool reply, const int cur_listener_id); - common::TizenResult Stop(const bool reply, const int cur_listener_id); - common::TizenResult Launch(const char* appId, const int cur_listener_id); - common::TizenResult LaunchAppControl(const picojson::object& jsonAppControl, const char* appId, - bool reply, const int cur_listener_id); - - private: - common::TizenResult ApplicationControlDataToServiceExtraData( - const picojson::object& app_control_data, app_control_h app_control); - void UpdateListener(const int cur_listener_id, std::string remote_method = ""); - static void ServiceConnectedCb(conv_service_h service_handle, conv_error_e error, - conv_payload_h result, void* user_data); - static void ServiceListenerCb(conv_service_h service_handle, conv_channel_h channel_handle, - conv_error_e error, conv_payload_h result, void* user_data); - - private: - std::vector callback_param_gc_; - CallbackParam* connect_callback_param_; -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_REMOTE_APP_CONTROL_SERVICE_H__ diff --git a/src/convergence/convergence_service.cc b/src/convergence/convergence_service.cc deleted file mode 100644 index 087de10..0000000 --- a/src/convergence/convergence_service.cc +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_service.h" - -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -namespace { -// Service keys -static const std::string kServiceType = "serviceType"; -static const std::string kServiceConnectionState = "connectionState"; -static const std::string kId = "id"; -static const std::string kUri = "uri"; -static const std::string kVersion = "version"; -} // namespace - -ConvergenceService::ConvergenceService() - : convergence_plugin_(nullptr), - device_(nullptr), - type_(CONV_SERVICE_NONE), - service_handle_(nullptr), - connection_state_(CONV_SERVICE_CONNECTION_STATE_NONE) { - ScopeLogger(); -} - -ConvergenceService::ConvergenceService(conv_device_h device, conv_service_e type, - ConvergenceInstance *convergence_plugin) - : convergence_plugin_(convergence_plugin), - device_(device), - type_(type), - service_handle_(nullptr), - connection_state_(CONV_SERVICE_CONNECTION_STATE_NONE) { - ScopeLogger(); -} - -ConvergenceService::~ConvergenceService() { - ScopeLogger(); - LoggerI("!!! DESTROYING SERVICE HANDLE [0x0%x] in ConvergenceService destr", service_handle_); - // first try to stop service - int error = conv_service_unset_listener_cb(service_handle_); - if (CONV_ERROR_NONE != error) { - LoggerW("unset_listener error %d [%s]", error, get_error_message(error)); - } else { - LoggerD("listener unset"); - } - - std::for_each(opened_channels.begin(), opened_channels.end(), [this](ConvergenceChannel *c) { - int error = conv_service_stop(service_handle_, c->GetHandle(), nullptr); - if (CONV_ERROR_NONE != error) { - LoggerW("2 service was not stopped - error %d [%s]", error, get_error_message(error)); - } else { - LoggerD("2 service stopped"); - } - delete c; - }); - - // later destroy handle - conv_service_destroy(service_handle_); -} - -struct ServiceSearchQuery { - conv_service_h handle; - conv_service_e type; -}; - -void ConvergenceService::ForEachServiceCb(conv_service_h service_handle, void *user_data) { - ScopeLogger(); - ServiceSearchQuery *query = static_cast(user_data); - if (!query) return; - if (query->handle) - return; // Already found a required service handle (no need to analyze something else) - - conv_service_e type = CONV_SERVICE_NONE; - int error = conv_service_get_type(service_handle, &type); - if (error != CONV_ERROR_NONE) { - // TODO Handle error - } - - if (type != query->type) { - return; - } - conv_service_h clone = nullptr; - error = conv_service_clone(service_handle, &clone); - if (error != CONV_ERROR_NONE) { - // TODO Handle error - } - query->handle = clone; -} - -conv_service_h ConvergenceService::FindServiceHandle() const { - ScopeLogger(); - if (!service_handle_) { - if (!device_) { - LoggerE("ERROR: Device handle is NULL, can not get device services"); - return nullptr; - } - - ServiceSearchQuery query = {nullptr, type_}; - const int error = conv_device_foreach_service(device_, ForEachServiceCb, &query); - if (CONV_ERROR_NONE != error) { - // TODO Handle error - trace_conv_error(error, __LINE__, "conv_device_foreach_service"); - } - service_handle_ = query.handle; - } - return service_handle_; -} - -std::string ConvergenceService::ExtractServicePropery(conv_service_h service_handle, - const char *property) { - ScopeLogger(); - char *value = nullptr; - const int error = conv_service_get_property_string(service_handle, property, &value); - if (CONV_ERROR_NONE != error) { - trace_conv_error(error, __LINE__, "conv_service_get_property_string"); - return ""; - } - - if (value) { - const std::string result = std::string(value); - free(value); - return result; - } - return ""; -} - -void ConvergenceService::Refresh() { - ScopeLogger(); - conv_service_h service_handle = FindServiceHandle(); - if (!service_handle) { - LoggerE("Service not found"); - return; - } - - conv_service_connection_state_e state = CONV_SERVICE_CONNECTION_STATE_NONE; - const int error = conv_service_get_connection_state(service_handle, &state); - if (CONV_ERROR_NONE != error) { - LoggerE("ERROR! D2D API Get Service Connection State error [%d]", error); - trace_conv_error(error, __LINE__, "conv_service_get_connection_state"); - } else { - connection_state_ = state; - } - - id_ = ExtractServicePropery(service_handle, CONV_SERVICE_ID); - version_ = ExtractServicePropery(service_handle, CONV_SERVICE_VERSION); - - LoggerE("Refreshed service id [%s] version [%s] connection state [%d]", id_.c_str(), - version_.c_str(), connection_state_); - - // conv_service_destroy(service_handle); - // LoggerI("DESTROYING SERVICE HANDLE [0x0%x] in ConvergenceService Refresh", service_handle_); -} - -picojson::value ConvergenceService::ToJson() const { - ScopeLogger(); - picojson::object service_json; - - service_json[kServiceType] = picojson::value(static_cast(type_)); - service_json[kServiceConnectionState] = picojson::value(static_cast(connection_state_)); - - // Following fields are not used in Web API layer now, but I parse it for - // future extensions - service_json[kId] = picojson::value(id_); - service_json[kVersion] = picojson::value(version_); - - return picojson::value(service_json); -} - -std::vector::iterator ConvergenceService::GetChannel( - const picojson::value &channel_json) { - ScopeLogger(); - const auto id = channel_json.get(kId).get(); - const auto uri = channel_json.get(kUri).get(); - - for (auto it = opened_channels.begin(); it != opened_channels.end(); ++it) { - if ((*it)->GetUri() == uri && (*it)->GetId() == id) { - LoggerD("Found channel uri: [%s] id: [%s]", uri.c_str(), id.c_str()); - return it; - } - } - - return opened_channels.end(); -} - -bool ConvergenceService::IsChannelStarted(std::vector::iterator it) { - ScopeLogger(); - return it != opened_channels.end(); -} - -void ConvergenceService::RemoveChannel(std::vector::iterator it) { - ScopeLogger(); - opened_channels.erase(it); -} - -} // namespace convergence -} // namespace extension diff --git a/src/convergence/convergence_service.h b/src/convergence/convergence_service.h deleted file mode 100644 index 6137136..0000000 --- a/src/convergence/convergence_service.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_SERVICE_H__ -#define CONVERGENCE_CONVERGENCE_SERVICE_H__ - -// TODO check includes -#include - -#include -#include -#include - -#include "common/tizen_result.h" -#include "convergence/convergence_channel_info.h" - -namespace extension { -namespace convergence { - -class ConvergenceInstance; - -class ConvergenceService { - public: - ConvergenceService(); - ConvergenceService(conv_device_h device, conv_service_e type, - ConvergenceInstance *convergence_plugin); - virtual ~ConvergenceService(); - ConvergenceService(const ConvergenceService &) = delete; - ConvergenceService(ConvergenceService &&) = delete; - ConvergenceService &operator=(const ConvergenceService &) = delete; - ConvergenceService &operator=(ConvergenceService &&) = delete; - - public: - void Refresh(); - std::vector::iterator GetChannel(const picojson::value &channel_json); - bool IsChannelStarted(std::vector::iterator); - void RemoveChannel(std::vector::iterator); - - public: - // conv_service_e get_type() const { return type_; } - // conv_device_h get_device() const {return device_; } - picojson::value ToJson() const; - - protected: - conv_service_h FindServiceHandle() const; - static void ForEachServiceCb(conv_service_h service_handle, void *user_data); - std::string ExtractServicePropery(conv_service_h service_handle, const char *property); - - protected: - ConvergenceInstance *convergence_plugin_; - - // private: - protected: // TODO switch back to private: - conv_device_h device_; // TODO rename to device_handle_ - conv_service_e type_; - mutable conv_service_h service_handle_; - std::vector opened_channels; - friend class ConvergenceAppCommunicationServerService; // It is needed to register the local - // service - private: - conv_service_connection_state_e connection_state_; - std::string id_; - std::string version_; -}; - -} // namespace convergence -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_SERVICE_H__ diff --git a/src/convergence/convergence_utils.cc b/src/convergence/convergence_utils.cc deleted file mode 100644 index 3af817a..0000000 --- a/src/convergence/convergence_utils.cc +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO check includes -#include "convergence/convergence_service.h" - -#include -#include - -#include "common/logger.h" -#include "convergence/convergence_instance.h" -#include "convergence/convergence_utils.h" - -namespace extension { -namespace convergence { - -void trace_conv_error(const int error, int line_number, const char* extra_text) { - std::string error_text; - switch (error) { - case CONV_ERROR_NONE: - error_text = "CONV_ERROR_NONE"; - break; - case CONV_ERROR_INVALID_PARAMETER: - error_text = "CONV_ERROR_INVALID_PARAMETER"; - break; - case CONV_ERROR_INVALID_OPERATION: - error_text = "CONV_ERROR_INVALID_OPERATION"; - break; - case CONV_ERROR_OUT_OF_MEMORY: - error_text = "CONV_ERROR_OUT_OF_MEMORY"; - break; - case CONV_ERROR_PERMISSION_DENIED: - error_text = "CONV_ERROR_PERMISSION_DENIED"; - break; - case CONV_ERROR_NOT_SUPPORTED: - error_text = "CONV_ERROR_NOT_SUPPORTED"; - break; - case CONV_ERROR_NO_DATA: - error_text = "CONV_ERROR_NO_DATA"; - break; - default: - error_text = "UNSUPPORTED D2D ERROR CODE"; - break; - } - - if (extra_text) { - LoggerE("ERROR! D2D API error [%s], line %d: %s", error_text.c_str(), line_number, extra_text); - } else { - LoggerE("ERROR! D2D API error [%s], line %d", error_text.c_str(), line_number); - } -} - -const picojson::value& ConvergenceUtils::GetArg(const picojson::object& args, - const std::string& name) { - static const picojson::value kNull; - - auto it = args.find(name); - if (args.end() == it) { - return kNull; - } else { - return it->second; - } -} - -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); - } - - return common::TizenSuccess(); -} - -} // namespace convergence -} // namespace extension \ No newline at end of file diff --git a/src/convergence/convergence_utils.h b/src/convergence/convergence_utils.h deleted file mode 100644 index 6a7441f..0000000 --- a/src/convergence/convergence_utils.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CONVERGENCE_CONVERGENCE_UTILS_H__ -#define CONVERGENCE_CONVERGENCE_UTILS_H__ - -// TODO check includes -#include - -#include -#include - -#include "common/tizen_result.h" -#include "convergence_client_info.h" - -namespace extension { -namespace convergence { - -#define CHECK_EXIST(args, name) \ - if (args.end() == args.find(name)) { \ - return common::TypeMismatchError(std::string(name) + " is required argument"); \ - } - -class ConvergenceInstance; - -namespace { -// Service result type -static const std::string kServiceResultType = "result_type"; -static const std::string kServiceReplyResult = "app_control_reply"; -static const std::string kServiceReplyControlResult = "app_control_result"; -static const std::string kServiceResultTypeOnStart = "onStart"; -static const std::string kServiceResultTypeOnStop = "onStop"; -static const std::string kServiceResultTypeOnConnect = "onConnect"; -static const std::string kServiceResultTypeOnDisconnect = "onDisconnect"; -static const std::string kServiceResultTypeOnClientConnect = "onClientConnect"; -static const std::string kServiceResultTypeOnClientDisconnect = "onClientDisconnect"; -static const std::string kServiceResultTypeOnPublish = "onPublish"; -static const std::string kServiceResultTypeOnMessage = "onMessage"; -static const std::string kServiceResultTypeOnRead = "onRead"; - -// Service connection status keys -static const std::string kServiceConnectionStatus = "connect_status"; -static const std::string kServiceConnectionStatusConnected = "service_connected"; -static const std::string kServiceConnectionStatusNotConnected = "service_not_connected"; - -// Service listener status keys -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 = "error"; -} // namespace - -enum ServiceRequestType { LOCAL_SERVICE_START, REMOTE_SERVICE_START, UNKNOWN_REQUEST_TYPE }; - -struct CallbackParam { - CallbackParam(ConvergenceInstance* plg, int cbId, ServiceRequestType type = UNKNOWN_REQUEST_TYPE) - : plugin_(plg), callback_id_(cbId), remote_method_(), client_info_(nullptr), type_(type) { - } - ~CallbackParam() { - delete client_info_; - } - ConvergenceInstance* plugin_; - int callback_id_; - std::string remote_method_; - ConvergenceClientInfo* client_info_; - ServiceRequestType type_; -}; - -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 -} // namespace extension - -#endif // CONVERGENCE_CONVERGENCE_UTILS_H__ diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index c53aba3..407e545 100755 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -322,13 +322,6 @@ ], }, ], - [ - 'tizen_feature_convergence_support==1', { - 'dependencies': [ - 'convergence/convergence.gyp:*', - ], - }, - ], ], # end conditions }, ], # end targets diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js index 2410c48..51e9104 100644 --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@ -99,7 +99,6 @@ function Utils() { CONTACT_WRITE: 'http://tizen.org/privilege/contact.write', CONTENT_READ: 'http://tizen.org/privilege/content.write', CONTENT_WRITE: 'http://tizen.org/privilege/content.write', - D2D_DATASHARING: 'http://tizen.org/privilege/d2d.datasharing', DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer', DATASYNC: 'http://tizen.org/privilege/datasync', DOWNLOAD: 'http://tizen.org/privilege/download', -- 2.7.4