Replace gdbus APIs to klay dbus APIs 60/106060/1 accepted/tizen/3.0/common/20161227.101806 accepted/tizen/3.0/ivi/20161227.005551 accepted/tizen/3.0/mobile/20161227.005353 accepted/tizen/3.0/tv/20161227.005512 accepted/tizen/3.0/wearable/20161227.005529 submit/tizen_3.0/20161226.022346
authorSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 20 Dec 2016 09:22:12 +0000 (18:22 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 20 Dec 2016 09:22:12 +0000 (18:22 +0900)
Change-Id: I9b9c3d1aac7a53aa556026427afdaaf3ec42a85b
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
server/manager.cpp

index 93c953c..dad5a1b 100644 (file)
@@ -66,7 +66,7 @@ const std::string KRATE_SKEL_PATH = "/etc/skel";
 const std::string KRATE_CREATE_HOOK_PATH = "/etc/gumd/useradd.d";
 const std::string KRATE_REMOVE_HOOK_PATH = "/etc/gumd/userdel.d";
 
-std::string KRATE_DEFAULT_OWNER = "owner";
+std::string KRATE_DEFAULT_OWNER;
 
 std::list<std::string> createdKrateList;
 static std::atomic<bool> isKrateForeground(false);
@@ -237,42 +237,6 @@ void initializeCreatedKrateList()
 
 #define NT_ERROR_NONE   NOTIFICATION_ERROR_NONE
 
-void krateProcessCallback(GDBusConnection *connection,
-                                                const gchar *sender, const gchar *objectPath,
-                                                const gchar *interface, const gchar *signalName,
-                                                GVariant *params, gpointer userData)
-{
-       static runtime::User owner(KRATE_DEFAULT_OWNER);
-       int pid, status;
-
-       notification_h noti = reinterpret_cast<notification_h>(userData);
-
-       g_variant_get(params, "(ii)", &status, &pid);
-
-       if (status != 5) {
-               return;
-       }
-
-       struct stat st;
-       std::string proc("/proc/" + std::to_string(pid));
-       if (::stat(proc.c_str(), &st) != 0) {
-               return;
-       }
-
-       if (st.st_uid == owner.getUid() || st.st_uid == 0) {
-               if (isKrateForeground) {
-                       notification_delete_for_uid(noti, owner.getUid());
-                       isKrateForeground = false;
-               }
-       } else {
-               if (!isKrateForeground) {
-                       notification_set_text(noti, NT_CONTENT, NT_APPINFO, NULL, NT_NONE);
-                       notification_post_for_uid(noti, owner.getUid());
-                       isKrateForeground = true;
-               }
-       }
-}
-
 notification_h createNotification()
 {
        notification_h noti = notification_create(NOTIFICATION_TYPE_ONGOING);
@@ -309,31 +273,46 @@ notification_h createNotification()
 
 void krateProcessMonitor()
 {
-       GError *error = NULL;
-       GDBusConnection* connection;
-       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (connection == NULL) {
-               ERROR("GBus Connection failed");
-               g_error_free(error);
-               return;
-       }
-
+       dbus::Connection& systemDBus = dbus::Connection::getSystem();
        notification_h noti = createNotification();
        if (noti == NULL) {
                ERROR("Failed to created notification");
                return;
        }
 
-       g_dbus_connection_signal_subscribe(connection,
-                                                                               NULL,
-                                                                               "org.tizen.resourced.process",
-                                                                               "ProcStatus",
-                                                                               "/Org/Tizen/ResourceD/Process",
-                                                                               NULL,
-                                                                               G_DBUS_SIGNAL_FLAGS_NONE,
-                                                                               krateProcessCallback,
-                                                                               reinterpret_cast<gpointer>(noti),
-                                                                               NULL);
+       systemDBus.subscribeSignal("",
+               "org.tizen.resourced.process",
+               "ProcStatus",
+               "/Org/Tizen/ResourceD/Process",
+               [noti] (dbus::Variant param) {
+                       static runtime::User owner(KRATE_DEFAULT_OWNER);
+                       int pid, status;
+                       struct stat st;
+
+                       param.get("(ii)", &status, &pid);
+
+                       if (status != 5) {
+                               return;
+                       }
+
+                       std::string proc("/proc/" + std::to_string(pid));
+                       if (::stat(proc.c_str(), &st) != 0) {
+                               return;
+                       }
+
+                       if (st.st_uid == owner.getUid() || st.st_uid == 0) {
+                               if (isKrateForeground) {
+                                       notification_delete_for_uid(noti, owner.getUid());
+                                       isKrateForeground = false;
+                               }
+                       } else {
+                               if (!isKrateForeground) {
+                                       notification_set_text(noti, NT_CONTENT, NT_APPINFO, NULL, NT_NONE);
+                                       notification_post_for_uid(noti, owner.getUid());
+                                       isKrateForeground = true;
+                               }
+                       }
+       });
 }
 
 void notiProxyInsert(const runtime::User& owner, const runtime::User& user, int privId, notification_h noti)