});
}
+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) {
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);
}
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) {
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);
}
});
- 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()');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
- this.connectionState = ConnectionState.NOT_CONNECTED;
+ updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, this);
}
native_.callIfPossible(successCallback, this);
}
};
-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
}
AppCommunicationService.prototype = new Service();
+AppCommunicationService.prototype.constructor = AppCommunicationService;
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);
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
}
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()');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
} else {
- this.connectionState = ConnectionState.NOT_CONNECTED;
+ updateWithInternalData({ connectionState: ConnectionState.NOT_CONNECTED }, this);
}
native_.callIfPossible(successCallback, this);