Commit c4a86eba authored by Dan Winship's avatar Dan Winship

libnm: remove redundant NM name watching code

NMClient was watching to see whether NetworkManager was running, but
its parent class NMObject was already doing that anyway, so NMClient
doesn't need to do it itself.

This also requires making NMClient:init_async() wait for NMObject's
init_async() code to finish before calling GetPermissions, rather than
running the two in parallel like before (since we don't know if NM is
running or not until after NMObject's init_async() returns). This is
probably more correct anyway in terms of inheritance, and it's not as
much slower than the original code as it sounds, since previously
we were calling NameHasOwner twice (in serial) anyway.
parent 8ce06b81
This diff is collapsed.
......@@ -87,4 +87,7 @@ typedef void (*NMObjectTypeAsyncFunc) (DBusGConnection *, const char *, NMObject
void _nm_object_register_type_func (GType base_type, NMObjectTypeFunc type_func,
NMObjectTypeAsyncFunc type_async_func);
#define NM_OBJECT_NM_RUNNING "nm-running-internal"
gboolean _nm_object_get_nm_running (NMObject *self);
#endif /* NM_OBJECT_PRIVATE_H */
......@@ -84,6 +84,7 @@ enum {
PROP_0,
PROP_DBUS_CONNECTION,
PROP_DBUS_PATH,
PROP_NM_RUNNING,
LAST_PROP
};
......@@ -122,15 +123,15 @@ proxy_name_owner_changed (DBusGProxy *proxy,
{
NMObject *self = NM_OBJECT (user_data);
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
gboolean now_running;
if (g_strcmp0 (name, NM_DBUS_SERVICE) == 0) {
gboolean old_good = (old_owner && old_owner[0]);
gboolean new_good = (new_owner && new_owner[0]);
if (g_strcmp0 (name, NM_DBUS_SERVICE) != 0)
return;
if (!old_good && new_good)
priv->nm_running = TRUE;
else if (old_good && !new_good)
priv->nm_running = FALSE;
now_running = (new_owner && new_owner[0]);
if (now_running != priv->nm_running) {
priv->nm_running = now_running;
g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING);
}
}
......@@ -232,8 +233,8 @@ init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_
}
static void
init_async_got_manager_running (DBusGProxy *proxy, DBusGProxyCall *call,
gpointer user_data)
init_async_got_nm_running (DBusGProxy *proxy, DBusGProxyCall *call,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
NMObject *self;
......@@ -289,7 +290,7 @@ init_async (GAsyncInitable *initable, int io_priority,
else {
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_manager_running,
init_async_got_nm_running,
simple, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
......@@ -379,6 +380,9 @@ get_property (GObject *object, guint prop_id,
case PROP_DBUS_PATH:
g_value_set_string (value, priv->path);
break;
case PROP_NM_RUNNING:
g_value_set_boolean (value, priv->nm_running);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -428,6 +432,18 @@ nm_object_class_init (NMObjectClass *nm_object_class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NMObject:manager-running: (skip)
*
* Internal use only.
*/
g_object_class_install_property
(object_class, PROP_NM_RUNNING,
g_param_spec_boolean (NM_OBJECT_NM_RUNNING, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/* signals */
/**
......@@ -1431,3 +1447,9 @@ _nm_object_is_connection_private (NMObject *self)
{
return _nm_dbus_is_connection_private (NM_OBJECT_GET_PRIVATE (self)->connection);
}
gboolean
_nm_object_get_nm_running (NMObject *self)
{
return NM_OBJECT_GET_PRIVATE (self)->nm_running;
}
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