mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 07:50:17 +01:00
session-monitor: explicitly use singleton instance
Some functions from nm-session-monitor.c have an implicit access to nm_session_monitor_get(). This is non-obvious behavior. Instead require the explicit session-monitor instance to be provided -- where needed.
This commit is contained in:
parent
ab0e3a223d
commit
24d191d06c
4 changed files with 35 additions and 20 deletions
|
|
@ -277,12 +277,11 @@ ck_finalize (NMSessionMonitor *monitor)
|
|||
|
||||
/********************************************************************/
|
||||
|
||||
NMSessionMonitor *nm_session_monitor_get(void);
|
||||
|
||||
NM_DEFINE_SINGLETON_GETTER (NMSessionMonitor, nm_session_monitor_get, NM_TYPE_SESSION_MONITOR);
|
||||
|
||||
/**
|
||||
* nm_session_monitor_connect:
|
||||
* @self: the session monitor
|
||||
* @callback: The callback.
|
||||
* @user_data: User data for the callback.
|
||||
*
|
||||
|
|
@ -291,9 +290,13 @@ NM_DEFINE_SINGLETON_GETTER (NMSessionMonitor, nm_session_monitor_get, NM_TYPE_SE
|
|||
* Returns: Handler ID to be used with nm_session_monitor_disconnect().
|
||||
*/
|
||||
gulong
|
||||
nm_session_monitor_connect (NMSessionCallback callback, gpointer user_data)
|
||||
nm_session_monitor_connect (NMSessionMonitor *self,
|
||||
NMSessionCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
return g_signal_connect (nm_session_monitor_get (),
|
||||
g_return_val_if_fail (NM_IS_SESSION_MONITOR (self), 0);
|
||||
|
||||
return g_signal_connect (self,
|
||||
NM_SESSION_MONITOR_CHANGED,
|
||||
G_CALLBACK (callback),
|
||||
user_data);
|
||||
|
|
@ -301,14 +304,18 @@ nm_session_monitor_connect (NMSessionCallback callback, gpointer user_data)
|
|||
|
||||
/**
|
||||
* nm_session_monitor_disconnect:
|
||||
* @self: the session monitor
|
||||
* @handler_id: Handler ID returned by nm_session_monitor-connect().
|
||||
*
|
||||
* Disconnect callback from the session handler.
|
||||
*/
|
||||
void
|
||||
nm_session_monitor_disconnect (gulong handler_id)
|
||||
nm_session_monitor_disconnect (NMSessionMonitor *self,
|
||||
gulong handler_id)
|
||||
{
|
||||
g_signal_handler_disconnect (nm_session_monitor_get (), handler_id);
|
||||
g_return_if_fail (NM_IS_SESSION_MONITOR (self));
|
||||
|
||||
g_signal_handler_disconnect (self, handler_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -357,6 +364,7 @@ nm_session_monitor_user_to_uid (const char *user, uid_t *out_uid)
|
|||
|
||||
/**
|
||||
* nm_session_monitor_session_exists:
|
||||
* @self: the session monitor
|
||||
* @uid: A user ID.
|
||||
* @active: Ignore inactive sessions.
|
||||
*
|
||||
|
|
@ -369,19 +377,19 @@ nm_session_monitor_user_to_uid (const char *user, uid_t *out_uid)
|
|||
* logged into an active session.
|
||||
*/
|
||||
gboolean
|
||||
nm_session_monitor_session_exists (uid_t uid, gboolean active)
|
||||
nm_session_monitor_session_exists (NMSessionMonitor *self,
|
||||
uid_t uid,
|
||||
gboolean active)
|
||||
{
|
||||
#if defined(SESSION_TRACKING_SYSTEMD) || defined(SESSION_TRACKING_CONSOLEKIT)
|
||||
NMSessionMonitor *monitor = nm_session_monitor_get ();
|
||||
#endif
|
||||
g_return_val_if_fail (NM_IS_SESSION_MONITOR (self), FALSE);
|
||||
|
||||
#ifdef SESSION_TRACKING_SYSTEMD
|
||||
if (sd_session_exists (monitor, uid, active))
|
||||
if (sd_session_exists (self, uid, active))
|
||||
return TRUE;
|
||||
#endif
|
||||
|
||||
#ifdef SESSION_TRACKING_CONSOLEKIT
|
||||
if (ck_session_exists (monitor, uid, active))
|
||||
if (ck_session_exists (self, uid, active))
|
||||
return TRUE;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -41,12 +41,19 @@ typedef void (*NMSessionCallback) (NMSessionMonitor *monitor, gpointer user_data
|
|||
|
||||
GType nm_session_monitor_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gulong nm_session_monitor_connect (NMSessionCallback callback, gpointer user_data);
|
||||
void nm_session_monitor_disconnect (gulong handler_id);
|
||||
NMSessionMonitor *nm_session_monitor_get (void);
|
||||
|
||||
gulong nm_session_monitor_connect (NMSessionMonitor *self,
|
||||
NMSessionCallback callback,
|
||||
gpointer user_data);
|
||||
void nm_session_monitor_disconnect (NMSessionMonitor *self,
|
||||
gulong handler_id);
|
||||
|
||||
gboolean nm_session_monitor_uid_to_user (uid_t uid, const char **out_user);
|
||||
gboolean nm_session_monitor_user_to_uid (const char *user, uid_t *out_uid);
|
||||
gboolean nm_session_monitor_session_exists (uid_t uid, gboolean active);
|
||||
gboolean nm_session_monitor_session_exists (NMSessionMonitor *self,
|
||||
uid_t uid,
|
||||
gboolean active);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -517,8 +517,8 @@ agent_compare_func (gconstpointer aa, gconstpointer bb, gpointer user_data)
|
|||
}
|
||||
|
||||
/* Prefer agents in active sessions */
|
||||
a_active = nm_session_monitor_session_exists (nm_secret_agent_get_owner_uid (a), TRUE);
|
||||
b_active = nm_session_monitor_session_exists (nm_secret_agent_get_owner_uid (b), TRUE);
|
||||
a_active = nm_session_monitor_session_exists (nm_session_monitor_get (), nm_secret_agent_get_owner_uid (a), TRUE);
|
||||
b_active = nm_session_monitor_session_exists (nm_session_monitor_get (), nm_secret_agent_get_owner_uid (b), TRUE);
|
||||
if (a_active && !b_active)
|
||||
return -1;
|
||||
else if (a_active == b_active)
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ nm_settings_connection_recheck_visibility (NMSettingsConnection *self)
|
|||
continue;
|
||||
if (!nm_session_monitor_user_to_uid (user, &uid))
|
||||
continue;
|
||||
if (!nm_session_monitor_session_exists (uid, FALSE))
|
||||
if (!nm_session_monitor_session_exists (nm_session_monitor_get (), uid, FALSE))
|
||||
continue;
|
||||
|
||||
set_visible (self, TRUE);
|
||||
|
|
@ -2325,7 +2325,7 @@ nm_settings_connection_init (NMSettingsConnection *self)
|
|||
priv->visible = FALSE;
|
||||
priv->ready = TRUE;
|
||||
|
||||
priv->session_changed_id = nm_session_monitor_connect (session_changed_cb, self);
|
||||
priv->session_changed_id = nm_session_monitor_connect (nm_session_monitor_get (), session_changed_cb, self);
|
||||
|
||||
priv->agent_mgr = g_object_ref (nm_agent_manager_get ());
|
||||
|
||||
|
|
@ -2388,7 +2388,7 @@ dispose (GObject *object)
|
|||
set_visible (self, FALSE);
|
||||
|
||||
if (priv->session_changed_id) {
|
||||
nm_session_monitor_disconnect (priv->session_changed_id);
|
||||
nm_session_monitor_disconnect (nm_session_monitor_get (), priv->session_changed_id);
|
||||
priv->session_changed_id = 0;
|
||||
}
|
||||
g_clear_object (&priv->agent_mgr);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue