From ce19229652e4dc852971ffeafa8d675f28df0eaa Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 23 Jun 2017 20:59:51 +0900 Subject: [PATCH] ActiveUserMonitor subscribes signals from ServiceProxy, instead of using a timer Change-Id: I0a22f18f9553145feec9fb20b6a086351c0a71a5 Signed-off-by: Mu-Woong Lee --- src/server/ActiveUserMonitor.cpp | 38 +++++++++++++------------------- src/server/ActiveUserMonitor.h | 5 ++++- src/server/ServiceRunner.cpp | 4 ++-- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/server/ActiveUserMonitor.cpp b/src/server/ActiveUserMonitor.cpp index 0da7cc1..999fd1b 100644 --- a/src/server/ActiveUserMonitor.cpp +++ b/src/server/ActiveUserMonitor.cpp @@ -19,7 +19,6 @@ #include "ActiveUserMonitor.h" #define ROOT_UID 0 -#define USER_CHK_DELAY 3000 using namespace ctx; @@ -29,7 +28,8 @@ ActiveUserMonitor::ActiveUserMonitor() : __deactivateUser(NULL), __activeUid(ROOT_UID), __userNewSignalId(0), - __userRemovedSignalId(0) + __userRemovedSignalId(0), + __newClientSignalId(0) { } @@ -51,13 +51,16 @@ void ActiveUserMonitor::start(GDBusConnection* conn, uid_cb_t activateUser, uid_ NULL, "org.freedesktop.login1.Manager", "UserRemoved", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __onUserRemoved, this, NULL); - g_timeout_add(USER_CHK_DELAY, __checkCurrentUser, this); + __newClientSignalId = g_dbus_connection_signal_subscribe(__connection, + NULL, CTX_DBUS_IFACE, CTX_SIGNAL_NEW_CLIENT, CTX_DBUS_PATH, + NULL, G_DBUS_SIGNAL_FLAGS_NONE, __onNewClient, this, NULL); } void ActiveUserMonitor::stop() { g_dbus_connection_signal_unsubscribe(__connection, __userNewSignalId); g_dbus_connection_signal_unsubscribe(__connection, __userRemovedSignalId); + g_dbus_connection_signal_unsubscribe(__connection, __newClientSignalId); } void ActiveUserMonitor::__onUserSessionStarted(GDBusConnection* conn, const gchar* sender, @@ -113,37 +116,26 @@ void ActiveUserMonitor::__onUserRemoved(GDBusConnection* conn, const gchar* send monitor->__activeUid = ROOT_UID; } -static bool __isUserDirectoryReady(uid_t uid) +void ActiveUserMonitor::__onNewClient(GDBusConnection* conn, const gchar* sender, + const gchar* path, const gchar* iface, const gchar* name, + GVariant* param, gpointer userData) { - std::string dbDir = util::getUserPath(uid, TZ_USER_DB, EMPTY_STR); - DIR* dir = opendir(dbDir.c_str()); - if (!dir) { - _W("User not ready"); - return false; - } - closedir(dir); - return true; -} + _D(GREEN("A new ServiceProxy signaled")); -gboolean ActiveUserMonitor::__checkCurrentUser(gpointer userData) -{ ActiveUserMonitor* monitor = static_cast(userData); - IF_FAIL_RETURN(monitor->__activeUid == ROOT_UID, G_SOURCE_REMOVE); + IF_FAIL_VOID(monitor->__activeUid == ROOT_UID); uid_t* users = NULL; int numUsers = sd_get_active_uids(&users); - IF_FAIL_RETURN(numUsers > 0, G_SOURCE_CONTINUE); + IF_FAIL_VOID(numUsers > 0); uid_t activeUid = users[0]; g_free(users); - if (activeUid == ROOT_UID || !__isUserDirectoryReady(activeUid)) - return G_SOURCE_CONTINUE; - - monitor->__activeUid = activeUid; + IF_FAIL_VOID(activeUid != ROOT_UID); _D("UID: %u", monitor->__activeUid); - monitor->__activateUser(monitor->__activeUid); - return G_SOURCE_REMOVE; + monitor->__activeUid = activeUid; + monitor->__activateUser(activeUid); } diff --git a/src/server/ActiveUserMonitor.h b/src/server/ActiveUserMonitor.h index 7ed0fa2..d84fc9c 100644 --- a/src/server/ActiveUserMonitor.h +++ b/src/server/ActiveUserMonitor.h @@ -41,7 +41,9 @@ namespace ctx { const gchar* path, const gchar* iface, const gchar* name, GVariant* param, gpointer userData); - static gboolean __checkCurrentUser(gpointer userData); + static void __onNewClient(GDBusConnection* conn, const gchar* sender, + const gchar* path, const gchar* iface, const gchar* name, + GVariant* param, gpointer userData); GDBusConnection* __connection; uid_cb_t __activateUser; @@ -49,6 +51,7 @@ namespace ctx { uid_t __activeUid; guint __userNewSignalId; guint __userRemovedSignalId; + guint __newClientSignalId; }; } diff --git a/src/server/ServiceRunner.cpp b/src/server/ServiceRunner.cpp index da72446..3308ea0 100644 --- a/src/server/ServiceRunner.cpp +++ b/src/server/ServiceRunner.cpp @@ -29,8 +29,8 @@ ServiceRunner::ServiceRunner(GDBusConnection* conn, IService* service) : __mainLoop(NULL), __gthread(NULL), __connection(conn), - __objPath(CTX_DBUS_PATH), - __interface(CTX_DBUS_IFACE), + __objPath(CTX_DBUS_PATH "/"), + __interface(CTX_DBUS_IFACE "."), __nodeInfo(NULL), __registrationId(0) { -- 2.34.1