From b3fd4d80857bd5efb4afa38be0956fe41c02f91d Mon Sep 17 00:00:00 2001
From: "Piotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics"
Date: Mon, 9 Dec 2019 11:26:39 +0100
Subject: [PATCH] [Messageport] Fixed listener issues
[Bugs]
* There was a problem with missing unregistration of
listeners for local ports, it was added.
* There was invalid calling of listeners (only latest listener was called),
now each registered listener is called properly.
[Verification] Messageport TCT passrate 100%.
Below scenario calls 3 different callbacks:
abc = tizen.messageport.requestLocalMessagePort("abc");
abc.addMessagePortListener((data, name) => {console.log(abc.messagePortName + " -> \"" + data + "\" : \"" + name + "\"")} );
abc.addMessagePortListener((data, name) => {console.log("2" + abc.messagePortName + " -> \"" + data + "\" : \"" + name + "\"")} );
abc.addMessagePortListener((data, name) => {console.log("3" + abc.messagePortName + " -> \"" + data + "\" : \"" + name + "\"")} );
abc_remote = tizen.messageport.requestRemoteMessagePort(tizen.application.getCurrentApplication().appInfo.id, "abc");
abc_remote.sendMessage([{key: "key1", value: "val1"}]);
Change-Id: If3a4b362de76599904c83737137c0d0cd4d023c7
---
src/messageport/messageport_api.js | 10 ++++++----
src/messageport/messageport_instance.cc | 14 ++++++++++++++
src/messageport/messageport_instance.h | 2 ++
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/messageport/messageport_api.js b/src/messageport/messageport_api.js
index 2cb4de7..031eb59 100755
--- a/src/messageport/messageport_api.js
+++ b/src/messageport/messageport_api.js
@@ -35,10 +35,12 @@ extension.setMessageListener(function(json) {
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];
- setTimeout(function() {
- func(msg.message, rmp);
- }, 0);
+ setTimeout(
+ function(f) {
+ f(msg.message, rmp);
+ }.bind(null, listeners[i][0]),
+ 0
+ );
}
});
diff --git a/src/messageport/messageport_instance.cc b/src/messageport/messageport_instance.cc
index 28df499..9310888 100644
--- a/src/messageport/messageport_instance.cc
+++ b/src/messageport/messageport_instance.cc
@@ -54,6 +54,18 @@ MessageportInstance::MessageportInstance() {
MessageportInstance::~MessageportInstance() {
ScopeLogger();
+ for (int port : local_ports) {
+ int ret = message_port_unregister_local_port(port);
+ if (MESSAGE_PORT_ERROR_NONE != ret) {
+ LoggerW("Failed to unregister local port listener during instance destructor.");
+ }
+ }
+ for (int port : local_trusted_ports) {
+ int ret = message_port_unregister_trusted_local_port(port);
+ if (MESSAGE_PORT_ERROR_NONE != ret) {
+ LoggerW("Failed to unregister local trusted port listener during instance destructor");
+ }
+ }
}
enum MessageportCallbacks {
@@ -219,6 +231,7 @@ void MessageportInstance::MessagePortManagerRequestlocalmessageport(const picojs
break;
}
} else {
+ local_ports.push_back(portId);
ReportSuccess(picojson::value(static_cast(portId)), out);
}
}
@@ -261,6 +274,7 @@ void MessageportInstance::MessagePortManagerRequesttrustedlocalmessageport(
break;
}
} else {
+ local_trusted_ports.push_back(portId);
ReportSuccess(picojson::value(static_cast(portId)), out);
}
}
diff --git a/src/messageport/messageport_instance.h b/src/messageport/messageport_instance.h
index 9e711f6..f51a0c6 100644
--- a/src/messageport/messageport_instance.h
+++ b/src/messageport/messageport_instance.h
@@ -41,6 +41,8 @@ class MessageportInstance : public common::ParsedInstance {
void MessagePortManagerRequesttrustedremotemessageport(const picojson::value& args,
picojson::object& out);
void RemoteMessagePortSendmessage(const picojson::value& args, picojson::object& out);
+ std::vector local_ports;
+ std::vector local_trusted_ports;
};
} // namespace messageport
--
2.7.4