From ce68b94feea0728ec9cd2796385c8da0048647dd Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Tue, 20 Dec 2016 18:22:12 +0900 Subject: [PATCH] Replace gdbus APIs to klay dbus APIs Change-Id: I9b9c3d1aac7a53aa556026427afdaaf3ec42a85b Signed-off-by: Sungbae Yoo --- server/manager.cpp | 91 +++++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 56 deletions(-) diff --git a/server/manager.cpp b/server/manager.cpp index 93c953c..dad5a1b 100644 --- a/server/manager.cpp +++ b/server/manager.cpp @@ -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 createdKrateList; static std::atomic 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(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(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) -- 2.7.4