Commit 3af40acf authored by Thomas Haller's avatar Thomas Haller

core: declare nm_agent_manager_get() using NM_DEFINE_SINGLETON_GETTER()

Also move the initilization of the instance into the constructed()
method.

NMAgentManager now owns a reference to the DBUS manager and Auth
manager and the dispose() function properly unregisters itself from
both.
parent d45c1b84
......@@ -50,9 +50,8 @@ G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, G_TYPE_OBJECT)
NMAgentManagerPrivate))
typedef struct {
gboolean disposed;
NMDBusManager *dbus_mgr;
NMAuthManager *auth_mgr;
/* Auth chains for checking agent permissions */
GSList *chains;
......@@ -1537,35 +1536,7 @@ authority_changed_cb (NMAuthManager *auth_manager, NMAgentManager *self)
/*************************************************************/
NMAgentManager *
nm_agent_manager_get (void)
{
static NMAgentManager *singleton = NULL;
NMAgentManagerPrivate *priv;
if (singleton)
return g_object_ref (singleton);
singleton = (NMAgentManager *) g_object_new (NM_TYPE_AGENT_MANAGER, NULL);
g_assert (singleton);
priv = NM_AGENT_MANAGER_GET_PRIVATE (singleton);
priv->dbus_mgr = nm_dbus_manager_get ();
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_AGENT_MANAGER, singleton);
g_signal_connect (priv->dbus_mgr,
NM_DBUS_MANAGER_NAME_OWNER_CHANGED,
G_CALLBACK (name_owner_changed_cb),
singleton);
g_signal_connect (nm_auth_manager_get (),
NM_AUTH_MANAGER_SIGNAL_CHANGED,
G_CALLBACK (authority_changed_cb),
singleton);
return singleton;
}
NM_DEFINE_SINGLETON_GETTER (NMAgentManager, nm_agent_manager_get, NM_TYPE_AGENT_MANAGER);
static void
nm_agent_manager_init (NMAgentManager *self)
......@@ -1580,23 +1551,57 @@ nm_agent_manager_init (NMAgentManager *self)
}
static void
dispose (GObject *object)
constructed (GObject *object)
{
NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (object);
if (!priv->disposed) {
priv->disposed = TRUE;
G_OBJECT_CLASS (nm_agent_manager_parent_class)->constructed (object);
g_signal_handlers_disconnect_by_func (nm_auth_manager_get (),
G_CALLBACK (authority_changed_cb),
object);
priv->dbus_mgr = g_object_ref (nm_dbus_manager_get ());
priv->auth_mgr = g_object_ref (nm_auth_manager_get ());
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_AGENT_MANAGER, object);
g_slist_free_full (priv->chains, (GDestroyNotify) nm_auth_chain_unref);
g_signal_connect (priv->dbus_mgr,
NM_DBUS_MANAGER_NAME_OWNER_CHANGED,
G_CALLBACK (name_owner_changed_cb),
object);
g_signal_connect (priv->auth_mgr,
NM_AUTH_MANAGER_SIGNAL_CHANGED,
G_CALLBACK (authority_changed_cb),
object);
}
static void
dispose (GObject *object)
{
NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (object);
g_slist_free_full (priv->chains, (GDestroyNotify) nm_auth_chain_unref);
priv->chains = NULL;
if (priv->agents) {
g_hash_table_destroy (priv->agents);
priv->agents = NULL;
}
if (priv->requests) {
g_hash_table_destroy (priv->requests);
priv->requests = NULL;
}
priv->dbus_mgr = NULL;
if (priv->auth_mgr) {
g_signal_handlers_disconnect_by_func (priv->auth_mgr,
G_CALLBACK (authority_changed_cb),
object);
g_clear_object (&priv->auth_mgr);
}
if (priv->dbus_mgr) {
g_signal_handlers_disconnect_by_func (priv->dbus_mgr,
G_CALLBACK (name_owner_changed_cb),
object);
nm_dbus_manager_unregister_object (priv->dbus_mgr, object);
g_clear_object (&priv->dbus_mgr);
}
G_OBJECT_CLASS (nm_agent_manager_parent_class)->dispose (object);
......@@ -1610,6 +1615,7 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class)
g_type_class_add_private (agent_manager_class, sizeof (NMAgentManagerPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
/* Signals */
......
......@@ -2200,7 +2200,7 @@ nm_settings_connection_init (NMSettingsConnection *self)
priv->session_changed_id = nm_session_monitor_connect (session_changed_cb, self);
priv->agent_mgr = nm_agent_manager_get ();
priv->agent_mgr = g_object_ref (nm_agent_manager_get ());
priv->seen_bssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
......
......@@ -1877,7 +1877,7 @@ nm_settings_init (NMSettings *self)
* transient, and we don't want the agent manager to get destroyed and
* recreated often.
*/
priv->agent_mgr = nm_agent_manager_get ();
priv->agent_mgr = g_object_ref (nm_agent_manager_get ());
g_signal_connect (priv->agent_mgr, "agent-registered", G_CALLBACK (secret_agent_registered), self);
}
......
......@@ -1582,7 +1582,6 @@ static void
really_activate (NMVpnConnection *connection, const char *username)
{
NMVpnConnectionPrivate *priv;
NMAgentManager *agent_mgr;
GHashTable *details;
g_return_if_fail (NM_IS_VPN_CONNECTION (connection));
......@@ -1621,8 +1620,7 @@ really_activate (NMVpnConnection *connection, const char *username)
* dialog and we won't get the secrets we need. In this case fall back to
* the old Connect() call.
*/
agent_mgr = nm_agent_manager_get ();
if (nm_agent_manager_all_agents_have_capability (agent_mgr,
if (nm_agent_manager_all_agents_have_capability (nm_agent_manager_get (),
nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (connection)),
NM_SECRET_AGENT_CAPABILITY_VPN_HINTS)) {
nm_log_dbg (LOGD_VPN, "Allowing interactive secrets as all agents have that capability");
......@@ -1638,7 +1636,6 @@ really_activate (NMVpnConnection *connection, const char *username)
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, priv->connect_hash,
G_TYPE_INVALID);
}
g_object_unref (agent_mgr);
g_hash_table_destroy (details);
_set_vpn_state (connection, STATE_CONNECT, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment