#include "ActiveUserMonitor.h"
#define ROOT_UID 0
-#define USER_CHK_DELAY 3000
using namespace ctx;
__deactivateUser(NULL),
__activeUid(ROOT_UID),
__userNewSignalId(0),
- __userRemovedSignalId(0)
+ __userRemovedSignalId(0),
+ __newClientSignalId(0)
{
}
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,
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);
}
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;
uid_t __activeUid;
guint __userNewSignalId;
guint __userRemovedSignalId;
+ guint __newClientSignalId;
};
}