Fix RequestBroker 65/237165/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 25 Jun 2020 11:05:42 +0000 (20:05 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 26 Jun 2020 02:32:13 +0000 (11:32 +0900)
Check if already subscribed when subscribed.
Add Unsubscribe method.

Change-Id: Ia0674b35eefb79e060f684f74d7a15177d77ea41
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme/dbus/request_broker.cc
src/theme/dbus/request_broker.h
test/unit_tests/test_request_broker.cc

index 44b2bdbcf31775afee79705625b73fe8ce7cf1a8..5279dca7bc129d845dc8d11fe18a9e0116a602ea 100644 (file)
@@ -176,6 +176,8 @@ bool RequestBroker::Listen() {
 }
 
 bool RequestBroker::Subscribe() {
+  if (subscribe_id_ > 0)
+    return true;
   subscribe_id_ = g_dbus_connection_signal_subscribe(connection_, nullptr,
       kDbusInterfaceName, nullptr, kDbusObjectPath, nullptr,
       G_DBUS_SIGNAL_FLAGS_NONE,
@@ -201,6 +203,14 @@ bool RequestBroker::Subscribe() {
   return subscribe_id_ > 0;
 }
 
+void RequestBroker::Unsubscribe() {
+  if (!subscribe_id_)
+    return;
+
+  g_dbus_connection_signal_unsubscribe(connection_, subscribe_id_);
+  subscribe_id_ = 0;
+}
+
 tizen_base::Bundle RequestBroker::SendData(Command cmd,
     tizen_base::Bundle& data) {
   GError* err = nullptr;
index 260570ebf70c9dc6b1eb73c0e8c280c11fd114c6..5948861a95e7bc7414b8b0502b7bb44ff9853f7c 100644 (file)
@@ -38,6 +38,7 @@ class RequestBroker {
       Command cmd, tizen_base::Bundle data);
   bool Listen();
   bool Subscribe();
+  void Unsubscribe();
   tizen_base::Bundle SendData(Command cmd, tizen_base::Bundle&);
   void SendDataAsync(Command cmd, tizen_base::Bundle&);
 
index 0919b61127cc2a3bcda934f21c6e2dcb43a81e49..d7e4d2902c34bb006ed6603ff88339fe6a8210f3 100644 (file)
@@ -189,6 +189,7 @@ TEST_F(RequestBrokerTest, Subscribe) {
       g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _)).
           WillOnce(Invoke(__g_dbus_connection_signal_subscribe_fake));
   EXPECT_EQ(broker_.Subscribe(), true);
+  broker_.Unsubscribe();
 }
 
 TEST_F(RequestBrokerTest, SendData_N1) {