[Convergence] Set readonly attributes for Service. 45/100645/3
authorTomasz Marciniak <t.marciniak@samsung.com>
Tue, 29 Nov 2016 00:02:59 +0000 (09:02 +0900)
committerTomasz Marciniak <t.marciniak@samsung.com>
Tue, 29 Nov 2016 05:36:18 +0000 (14:36 +0900)
[Verification] Code compiles.

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

index faa26b42e854750e2e023e7a9e0f771a51337bd3..59e2d2d11e79101565822d1f36c44a21f7206c75 100644 (file)
@@ -68,6 +68,18 @@ function SetReadOnlyProperty(obj, n, v) {
     });
 }
 
+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) {
@@ -172,8 +184,9 @@ ConvergenceManager.prototype.startDiscovery = function(successCallback,
             continue;
           }
 
-          s.connectionState = getServiceConnectionStateName(
-            result.device.services[i].connectionState);
+          var state = getServiceConnectionStateName(result.device.services[i].connectionState);
+          updateWithInternalData({ connectionState: state }, s);
+
           s._deviceId = id;
           services.push(s);
         }
@@ -234,11 +247,29 @@ ConvergenceManager.prototype.stopDiscovery = function() {
     throw native_.getErrorObject(result);
 };
 
-function Service() {
+function Service(connectionState_, type_) {
   console.log('Entered Service.constructor()');
 
-  //validator_.isConstructorCall(this, Service);
-  this.connectionState = ConnectionState.NOT_CONNECTED;
+  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) {
@@ -265,7 +296,7 @@ native_.addListener('REMOTE_APP_CONTROL_SERVICE_LISTENER', function(result) {
     switch (result_type) {
     case 'Connected':
       if (s) { // Service MUST NOT be null here
-        s.connectionState = ConnectionState.CONNECTED;
+        updateWithInternalData({ connectionState: ConnectionState.CONNECTED }, s);
         convergenceServices[lid] = s;
       }
       native_.callIfPossible(s._connectCallback, s);
@@ -321,13 +352,14 @@ function RemoteAppControlService() {
     }
   });
 
-  this.type = ServiceType.REMOTE_APP_CONTROL;
+  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) {
   console.log('Entered RemoteAppControlService.connect()');
@@ -404,7 +436,7 @@ RemoteAppControlService.prototype.disconnect = function(successCallback, errorCa
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
   } else {
-    this.connectionState = ConnectionState.NOT_CONNECTED;
+    updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, this);
   }
 
   native_.callIfPossible(successCallback, this);
@@ -581,9 +613,10 @@ RemoteAppControlService.prototype.launchAppControl = function() {
   }
 };
 
-function AppCommunicationService() {
+function AppCommunicationService(connectionState_, type_) {
   console.log('Entered AppCommunicationService.constructor()');
 
+  Service.call(this, connectionState_, type_);
   // The device id is needed for getting the valid service handle on the
   // native layer
   // I have to implement this property here instead of base constructor in order
@@ -640,6 +673,7 @@ function AppCommunicationService() {
 }
 
 AppCommunicationService.prototype = new Service();
+AppCommunicationService.prototype.constructor = AppCommunicationService;
 
 native_.addListener('APP_COMMUNICATION_SERVICE_LISTENER', function(result) {
 
@@ -668,7 +702,7 @@ native_.addListener('APP_COMMUNICATION_SERVICE_LISTENER', function(result) {
     switch (result_type) {
     case 'Connected':
       if (s) { // Service MUST NOT be null here
-        s.connectionState = ConnectionState.CONNECTED;
+        updateWithInternalData({ connectionState: ConnectionState.CONNECTED }, s);
         convergenceServices[lid] = s;
       }
       native_.callIfPossible(s._connectCallback, s);
@@ -948,8 +982,7 @@ function AppCommunicationServerService() {
 
   validator_.isConstructorCall(this, AppCommunicationServerService);
 
-  this.connectionState = ConnectionState.NOT_CONNECTED;
-  this.type = ServiceType.APP_COMM_SERVER;
+  AppCommunicationService.call(this, ConnectionState.NOT_CONNECTED, ServiceType.APP_COMM_SERVER);
 
   native_.callSync('AppCommunicationServerService_constructLocal', {
       deviceId: this._deviceId
@@ -957,17 +990,18 @@ function AppCommunicationServerService() {
 }
 
 AppCommunicationServerService.prototype = new AppCommunicationService();
+AppCommunicationServerService.prototype.constructor = AppCommunicationServerService;
 
 function AppCommunicationClientService() {
   console.log('Entered AppCommunicationClientService.constructor()');
 
   validator_.isConstructorCall(this, AppCommunicationClientService);
 
-  this.connectionState = ConnectionState.NOT_CONNECTED;
-  this.type = ServiceType.APP_COMM_CLIENT;
+  AppCommunicationService.call(this, ConnectionState.NOT_CONNECTED, ServiceType.APP_COMM_CLIENT);
 }
 
 AppCommunicationClientService.prototype = new AppCommunicationService();
+AppCommunicationClientService.prototype.constructor = AppCommunicationClientService;
 
 AppCommunicationClientService.prototype.connect = function(successCallback, errorCallback) {
   console.log('Entered AppCommunicationClientService.connect()');
@@ -1042,7 +1076,7 @@ AppCommunicationClientService.prototype.disconnect = function(successCallback, e
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
   } else {
-    this.connectionState = ConnectionState.NOT_CONNECTED;
+    updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, this);
   }
 
   native_.callIfPossible(successCallback, this);