ActiveUserMonitor subscribes signals from ServiceProxy, instead of using a timer 48/135648/4
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 23 Jun 2017 11:59:51 +0000 (20:59 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 26 Jun 2017 09:14:23 +0000 (18:14 +0900)
Change-Id: I0a22f18f9553145feec9fb20b6a086351c0a71a5
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/server/ActiveUserMonitor.cpp
src/server/ActiveUserMonitor.h
src/server/ServiceRunner.cpp

index 0da7cc1..999fd1b 100644 (file)
@@ -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<ActiveUserMonitor*>(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);
 }
index 7ed0fa2..d84fc9c 100644 (file)
@@ -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;
        };
 
 }
index da72446..3308ea0 100644 (file)
@@ -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)
 {