var callbackId = 0;
var callbacks = {};
+var ports = [];
extension.setMessageListener(function(json) {
var msg = JSON.parse(json);
var listeners = callbacks[msg['local_port_id']];
+ var rmp;
console.log('Listeners length:' + listeners.length);
- var rmp = new RemoteMessagePort(msg.remotePort, msg.remoteAppId, msg.trusted);
+ if (!msg.hasOwnProperty('remotePort'))
+ rmp = null;
+ else
+ rmp = new RemoteMessagePort(msg.remotePort, msg.remoteAppId, msg.trusted);
for (var i = 0; i < listeners.length; i++) {
-
var func = listeners[i][0];
func(msg.message, rmp);
}
var args = validator_.validateArgs(arguments, [
{'name' : 'localMessagePortName', 'type': types_.STRING}
]);
-
+ var localPortId;
var nativeParam = {
'localMessagePortName': args.localMessagePortName
};
try {
- var localPortId = callNative('MessagePortManager_requestLocalMessagePort', nativeParam);
+ localPortId = callNative('MessagePortManager_requestLocalMessagePort', nativeParam);
} catch (e) {
throw e;
}
- var returnObject = new LocalMessagePort(localPortId, args.localMessagePortName, false);
+ var returnObject = new LocalMessagePort(args.localMessagePortName, false);
+ ports[nativeParam.localMessagePortName] = localPortId;
return returnObject;
};
throw e;
}
- var returnObject = new LocalMessagePort(localPortId, args.localMessagePortName, true);
+ var returnObject = new LocalMessagePort(args.localMessagePortName, true);
+ ports[nativeParam.localMessagePortName] = localPortId;
return returnObject;
};
-MessagePortManager.prototype.requestRemoteMessagePort = function(appId, remoteMessagePortName) {
+MessagePortManager.prototype.requestRemoteMessagePort =
+ function(appId, remoteMessagePortName) {
var args = validator_.validateArgs(arguments, [
{'name' : 'appId', 'type': types_.STRING},
{'name' : 'remoteMessagePortName', 'type': types_.STRING}
]);
var nativeParam = {
+ 'appId' : args.appId,
'remoteMessagePortName': args.remoteMessagePortName
};
};
-function LocalMessagePort(id, messagePortName, isTrusted) {
+function LocalMessagePort(messagePortName, isTrusted) {
Object.defineProperties(this, {
- 'id': { value: id, writable: false },
- 'messagePortName': { value: messagePortName, writable: false, enumerable: false },
- 'isTrusted': { value: !!isTrusted, writable: false }
+ 'messagePortName': { value: messagePortName, writable: false, enumerable: true },
+ 'isTrusted': { value: !!isTrusted, writable: false, enumerable: true }
});
}
{'name' : 'listener', 'type': types_.FUNCTION, 'nullable': false}
]);
- if (!callbacks.hasOwnProperty(this.id)) callbacks[this.id] = [];
+ var portId = ports[this.messagePortName];
+
+ if (!callbacks.hasOwnProperty(portId)) callbacks[portId] = [];
callbackId++;
- callbacks[this.id].push([listener, callbackId]);
+ callbacks[portId].push([listener, callbackId]);
return callbackId;
LocalMessagePort.prototype.removeMessagePortListener = function(watchId) {
var args = validator_.validateArgs(arguments, [
- {'name' : 'watchId', 'type': types_.LONG }
+ {'name' : 'watchId', 'type': types_.LONG, 'nullable': false, 'optional': false }
]);
- if (args.watchId <= 0)
- throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
- 'The input parameter contains an invalid value.');
-
var to_delete;
- var listeners = callbacks[this.id];
+ var listeners = callbacks[ports[this.messagePortName]];
for (var i = 0, j = listeners.length; i < j; i++) {
var listener_id = listeners[i][1];
}
}
- if (typeof to_delete == 'undefined')
+ if (typeof to_delete === 'undefined')
throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
'The port of the target application is not found.');
'messagePortName': this.messagePortName,
'data': filtered_data,
'trusted': this.isTrusted,
- 'local_port_id': args.localMessagePort ? args.localMessagePort.id : -1
+ 'local_port_id': args.localMessagePort ? ports[args.localMessagePort.messagePortName] : -1
};
try {
picojson::value::array data;
o["local_port_id"] = picojson::value(static_cast<double>(local_port_id));
- o["remoteAppId"] = picojson::value(remote_app_id);
- o["remotePort"] = picojson::value(remote_port);
- o["trusted_remote_port"] = picojson::value(trusted_remote_port);
- LoggerD("Msg received from: %s", remote_app_id);
+ if (remote_port) {
+ o["remoteAppId"] = picojson::value(remote_app_id);
+ o["remotePort"] = picojson::value(remote_port);
+ o["trusted"] = picojson::value(trusted_remote_port);
+ LoggerD("Msg received from: %s", remote_app_id);
+ }
+
+ LoggerD("Msg received");
bundle_iterate(message, BundleJsonIterator, &data);
portId < 0 ? "false" : "true");
- if(portId < 0){
-
+ if (portId < 0) {
switch (portId) {
case MESSAGE_PORT_ERROR_INVALID_PARAMETER:
ReportError(InvalidValuesException
- ("The input parameter contains an invalid value."),out);
+ ("The input parameter contains an invalid value."), out);
break;
case MESSAGE_PORT_ERROR_OUT_OF_MEMORY:
- ReportError(UnknownException("Out of memory."),out);
+ ReportError(UnknownException("Out of memory."), out);
break;
case MESSAGE_PORT_ERROR_IO_ERROR:
- ReportError(UnknownException("Internal I/O error ocurred."),out);
- break;
+ ReportError(UnknownException("Internal I/O error ocurred."), out);
+ break;
default:
- ReportError(UnknownException("Unknown Exception"),out);
+ ReportError(UnknownException("Unknown Exception"), out);
break;
}
- }
- else
+ } else {
ReportSuccess(picojson::value(static_cast<double>(portId)), out);
+ }
}
void MessageportInstance::
LoggerD("Registering trusted local port %s:%s", localMessagePortName.c_str(),
portId < 0 ? "false" : "true");
- if(portId < 0){
-
+ if (portId < 0) {
switch (portId) {
case MESSAGE_PORT_ERROR_INVALID_PARAMETER:
ReportError(InvalidValuesException
- ("The input parameter contains an invalid value."),out);
+ ("The input parameter contains an invalid value."), out);
break;
case MESSAGE_PORT_ERROR_OUT_OF_MEMORY:
- ReportError(UnknownException("Out of memory."),out);
+ ReportError(UnknownException("Out of memory."), out);
break;
case MESSAGE_PORT_ERROR_IO_ERROR:
- ReportError(UnknownException("Internal I/O error ocurred."),out);
- break;
+ ReportError(UnknownException("Internal I/O error ocurred."), out);
+ break;
default:
- ReportError(UnknownException("Unknown Exception"),out);
+ ReportError(UnknownException("Unknown Exception"), out);
break;
}
- }
- else
+ } else {
ReportSuccess(picojson::value(static_cast<double>(portId)), out);
-
+ }
}
void MessageportInstance::
LoggerD("Checking remote port of %s: %s", remoteMessagePortName.c_str(),
portCheck ? "true" : "false");
- if(ret == MESSAGE_PORT_ERROR_NONE){
+ if (ret == MESSAGE_PORT_ERROR_NONE) {
if (portCheck) ReportSuccess(out);
else
ReportError(NotFoundException
("The port of the target application is not found"), out);
- }
- else if(ret == MESSAGE_PORT_ERROR_INVALID_PARAMETER)
+ } else if (ret == MESSAGE_PORT_ERROR_INVALID_PARAMETER) {
ReportError(InvalidValuesException
- ("An input parameter contains an invalid value."),out);
- else if(ret == MESSAGE_PORT_ERROR_OUT_OF_MEMORY)
+ ("An input parameter contains an invalid value."), out);
+ } else if (ret == MESSAGE_PORT_ERROR_OUT_OF_MEMORY) {
ReportError(UnknownException("Out of memory."), out);
- else if(ret == MESSAGE_PORT_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error ocurred."),out);
- else
- ReportError(UnknownException("Unknown Error"),out);
-
+ } else if (ret == MESSAGE_PORT_ERROR_IO_ERROR) {
+ ReportError(UnknownException("Internal I/O error ocurred."), out);
+ } else {
+ ReportError(UnknownException("Unknown Error"), out);
+ }
}
void MessageportInstance::
LoggerD("Checking trusted remoteport of %s:%s",
remoteMessagePortName.c_str(), portCheck ? "true":"false");
-
- if(ret == MESSAGE_PORT_ERROR_NONE){
+ if (ret == MESSAGE_PORT_ERROR_NONE) {
if (portCheck) ReportSuccess(out);
else
ReportError(NotFoundException
("The port of the target application is not found"), out);
- }
- else if(ret == MESSAGE_PORT_ERROR_INVALID_PARAMETER)
+ } else if (ret == MESSAGE_PORT_ERROR_INVALID_PARAMETER) {
ReportError(InvalidValuesException
- ("An input parameter contains an invalid value."),out);
- else if(ret == MESSAGE_PORT_ERROR_OUT_OF_MEMORY)
+ ("An input parameter contains an invalid value."), out);
+ } else if (ret == MESSAGE_PORT_ERROR_OUT_OF_MEMORY) {
ReportError(UnknownException("Out of memory."), out);
- else if(ret == MESSAGE_PORT_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error ocurred."),out);
- else if(ret == MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH)
+ } else if (ret == MESSAGE_PORT_ERROR_IO_ERROR) {
+ ReportError(UnknownException("Internal I/O error ocurred."), out);
+ } else if (ret == MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH) {
ReportError(UnknownException(
- "The remote application is not signed with the same certificate"),out);
- else
- ReportError(UnknownException("Unknown Error"),out);
-
+ "The remote application is not signed with the same certificate"), out);
+ } else {
+ ReportError(UnknownException("Unknown Error"), out);
+ }
}
void MessageportInstance::RemoteMessagePortSendmessage
if (local_port_id < 0) {
result = message_port_send_message
(appId.c_str(), message_port_name.c_str(), bundle);
+ LoggerD("-----------%s & %s---------------",
+ appId.c_str(), message_port_name.c_str());
} else {
result = message_port_send_message_with_local_port
(appId.c_str(), message_port_name.c_str(), bundle, local_port_id);
bundle_free(bundle);
- if(result == MESSAGE_PORT_ERROR_NONE)
+ if (result == MESSAGE_PORT_ERROR_NONE)
ReportSuccess(out);
- else if(result == MESSAGE_PORT_ERROR_INVALID_PARAMETER)
+ else if (result == MESSAGE_PORT_ERROR_INVALID_PARAMETER)
ReportError(InvalidValuesException
- ("An input parameter contains an invalid value."),out);
- else if(result == MESSAGE_PORT_ERROR_PORT_NOT_FOUND)
+ ("An input parameter contains an invalid value.") , out);
+ else if (result == MESSAGE_PORT_ERROR_PORT_NOT_FOUND)
ReportError(NotFoundException
- ("The port of the target application is not found"),out);
- else if(result == MESSAGE_PORT_ERROR_MAX_EXCEEDED)
+ ("The port of the target application is not found"), out);
+ else if (result == MESSAGE_PORT_ERROR_MAX_EXCEEDED)
ReportError(QuotaExceededException
- ("The size of message has exceeded the maximum limit."),out);
- else if(result == MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE)
- ReportError(UnknownException("A resource is temporarily unavailable."),out);
- else if(result == MESSAGE_PORT_ERROR_OUT_OF_MEMORY)
- ReportError(UnknownException("Out of memory."),out);
- else if(result == MESSAGE_PORT_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error ocurred."),out);
- else if(result == MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH)
+ ("The size of message has exceeded the maximum limit."), out);
+ else if (result == MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE)
+ ReportError(UnknownException("A resource is temporarily unavailable"), out);
+ else if (result == MESSAGE_PORT_ERROR_OUT_OF_MEMORY)
+ ReportError(UnknownException("Out of memory."), out);
+ else if (result == MESSAGE_PORT_ERROR_IO_ERROR)
+ ReportError(UnknownException("Internal I/O error ocurred."), out);
+ else if (result == MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH)
ReportError(UnknownException
- ("The remote application is not signed with the same certificate"),out);
- else ReportError(UnknownException("Unknown Exception"),out);
-
+ ("The remote application is not signed with the same certificate") , out);
+ else
+ ReportError(UnknownException("Unknown Exception"), out);
}