Apply the changes of ScopedGMainLoop 51/167251/5
authoryeji01.kim <yeji01.kim@samsung.com>
Tue, 16 Jan 2018 10:44:01 +0000 (19:44 +0900)
committeryeji01.kim <yeji01.kim@samsung.com>
Thu, 18 Jan 2018 05:54:17 +0000 (14:54 +0900)
Change-Id: I4561998d82558dc858946a01209fb6891967f1e3
Signed-off-by: yeji01.kim <yeji01.kim@samsung.com>
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
libs/policy-client.cpp

index 7d39ec2..67f336c 100644 (file)
@@ -54,16 +54,20 @@ int DevicePolicyClient::subscribeSignal(const std::string& name,
        if (!getMaintenanceMode())
                return 0;
 
+       int ret = -1;
        try {
-               auto dispatch = [name, handler, data](dbus::Variant variant) {
-                       char *state = NULL;
-                       variant.get("(s)", &state);
-
-                       handler(name.c_str(), state, data);
-               };
-
-               dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
-               return receiver.subscribe(name, dispatch);
+               mainloop->dispatch([&]() {
+                       auto task = [name, handler, data](dbus::Variant variant) {
+                               char *state = NULL;
+                               variant.get("(s)", &state);
+
+                               handler(name.c_str(), state, data);
+                       };
+
+                       dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
+                       ret = receiver.subscribe(name, std::move(task));
+               });
+               return ret;
        } catch (runtime::Exception& e) {
                ERROR(e.what());
                return -1;
@@ -76,8 +80,11 @@ int DevicePolicyClient::unsubscribeSignal(int id) noexcept
                return 0;
 
        try {
-               dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
-               receiver.unsubscribe(id);
+               mainloop->dispatch([&]() {
+                       dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
+                       receiver.unsubscribe(id);
+               });
+
                return 0;
        } catch (runtime::Exception& e) {
                ERROR(e.what());