diff options
41 files changed, 891 insertions, 1725 deletions
diff --git a/Makefile.am b/Makefile.am index e23ea47d3d..5ad1249785 100644 --- a/Makefile.am +++ b/Makefile.am @@ -228,7 +228,9 @@ nodist_introspection_libnmdbus_la_SOURCES = \ introspection/nmdbus-vpn-connection.c \ introspection/nmdbus-vpn-connection.h \ introspection/nmdbus-vpn-plugin.c \ - introspection/nmdbus-vpn-plugin.h + introspection/nmdbus-vpn-plugin.h \ + introspection/nmdbus-wimax-nsp.c \ + introspection/nmdbus-wimax-nsp.h DBUS_INTERFACE_DOCS = \ introspection/nmdbus-access-point-org.freedesktop.NetworkManager.AccessPoint.xml \ @@ -668,7 +670,6 @@ libnm_libnm_la_private_headers = \ libnm/nm-ip4-config.h \ libnm/nm-ip6-config.h \ libnm/nm-manager.h \ - libnm/nm-object-cache.h \ libnm/nm-object-private.h \ libnm/nm-remote-connection-private.h \ libnm/nm-remote-settings.h @@ -704,7 +705,6 @@ libnm_libnm_la_sources = \ libnm/nm-ip4-config.c \ libnm/nm-ip6-config.c \ libnm/nm-manager.c \ - libnm/nm-object-cache.c \ libnm/nm-object.c \ libnm/nm-remote-connection.c \ libnm/nm-remote-settings.c \ diff --git a/docs/libnm/Makefile.am b/docs/libnm/Makefile.am index f3f0cf7eb5..1aae42f53f 100644 --- a/docs/libnm/Makefile.am +++ b/docs/libnm/Makefile.am @@ -45,7 +45,6 @@ IGNORE_HFILES= \ nm-ip4-config.h \ nm-ip6-config.h \ nm-manager.h \ - nm-object-cache.h \ nm-object-private.h \ nm-property-compare.h \ nm-remote-connection-private.h \ diff --git a/libnm/nm-access-point.c b/libnm/nm-access-point.c index d9b1c502ef..60b8e33d16 100644 --- a/libnm/nm-access-point.c +++ b/libnm/nm-access-point.c @@ -485,8 +485,6 @@ nm_access_point_class_init (NMAccessPointClass *ap_class) g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_ACCESS_POINT); - /* virtual methods */ object_class->get_property = get_property; object_class->finalize = finalize; diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index 2f04eff095..6a823403c4 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -28,7 +28,6 @@ #include "nm-object-private.h" #include "nm-core-internal.h" #include "nm-device.h" -#include "nm-device-private.h" #include "nm-connection.h" #include "nm-vpn-connection.h" #include "nm-dbus-helpers.h" @@ -38,14 +37,7 @@ #include "nm-ip6-config.h" #include "nm-remote-connection.h" -static GType _nm_active_connection_decide_type (GVariant *value); - -G_DEFINE_TYPE_WITH_CODE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT, - _nm_object_register_type_func (g_define_type_id, - _nm_active_connection_decide_type, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - "Vpn"); - ) +G_DEFINE_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT); #define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate)) @@ -88,16 +80,6 @@ enum { LAST_PROP }; -static GType -_nm_active_connection_decide_type (GVariant *value) -{ - /* @value is the value of the o.fd.NM.ActiveConnection property "VPN" */ - if (g_variant_get_boolean (value)) - return NM_TYPE_VPN_CONNECTION; - else - return NM_TYPE_ACTIVE_CONNECTION; -} - /** * nm_active_connection_get_connection: * @connection: a #NMActiveConnection @@ -519,8 +501,6 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) g_type_class_add_private (ap_class, sizeof (NMActiveConnectionPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_ACTIVE_CONNECTION); - /* virtual methods */ object_class->get_property = get_property; object_class->dispose = dispose; diff --git a/libnm/nm-client.c b/libnm/nm-client.c index e655dbd43b..d17b7a36dc 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -29,13 +29,72 @@ #include "nm-remote-settings.h" #include "nm-device-ethernet.h" #include "nm-device-wifi.h" -#include "nm-device-private.h" #include "nm-core-internal.h" #include "nm-active-connection.h" #include "nm-vpn-connection.h" #include "nm-remote-connection.h" -#include "nm-object-cache.h" #include "nm-dbus-helpers.h" +#include "nm-wimax-nsp.h" +#include "nm-object-private.h" + +#include "nmdbus-manager.h" +#include "nmdbus-settings.h" +#include "nmdbus-access-point.h" +#include "nmdbus-active-connection.h" +#include "nmdbus-device-adsl.h" +#include "nmdbus-device-bond.h" +#include "nmdbus-device-bridge.h" +#include "nmdbus-device-bt.h" +#include "nmdbus-device-ethernet.h" +#include "nmdbus-device-generic.h" +#include "nmdbus-device-infiniband.h" +#include "nmdbus-device-ip-tunnel.h" +#include "nmdbus-device-macvlan.h" +#include "nmdbus-device-modem.h" +#include "nmdbus-device-olpc-mesh.h" +#include "nmdbus-device-team.h" +#include "nmdbus-device-tun.h" +#include "nmdbus-device-vlan.h" +#include "nmdbus-device-vxlan.h" +#include "nmdbus-device-wifi.h" +#include "nmdbus-device-wimax.h" +#include "nmdbus-device.h" +#include "nmdbus-dhcp4-config.h" +#include "nmdbus-dhcp6-config.h" +#include "nmdbus-ip4-config.h" +#include "nmdbus-ip6-config.h" +#include "nmdbus-settings-connection.h" +#include "nmdbus-vpn-connection.h" +#include "nmdbus-wimax-nsp.h" + +#include "nm-access-point.h" +#include "nm-active-connection.h" +#include "nm-device-adsl.h" +#include "nm-device-bond.h" +#include "nm-device-bridge.h" +#include "nm-device-bt.h" +#include "nm-device-ethernet.h" +#include "nm-device-generic.h" +#include "nm-device-infiniband.h" +#include "nm-device-ip-tunnel.h" +#include "nm-device-macvlan.h" +#include "nm-device-modem.h" +#include "nm-device-olpc-mesh.h" +#include "nm-device-team.h" +#include "nm-device-tun.h" +#include "nm-device-vlan.h" +#include "nm-device-vxlan.h" +#include "nm-device-wifi.h" +#include "nm-device-wimax.h" +#include "nm-dhcp4-config.h" +#include "nm-dhcp6-config.h" +#include "nm-dhcp-config.h" +#include "nm-ip4-config.h" +#include "nm-ip6-config.h" +#include "nm-manager.h" +#include "nm-remote-connection.h" +#include "nm-remote-settings.h" +#include "nm-vpn-connection.h" void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled); @@ -52,6 +111,8 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT, typedef struct { NMManager *manager; NMRemoteSettings *settings; + GDBusObjectManager *object_manager; + GCancellable *new_object_manager_cancellable; } NMClientPrivate; enum { @@ -97,6 +158,8 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +static const GPtrArray empty = { 0, }; + /*****************************************************************************/ /** @@ -150,6 +213,9 @@ nm_client_get_version (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return NULL; + return nm_manager_get_version (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -166,6 +232,9 @@ nm_client_get_state (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN); + if (!nm_client_get_nm_running (client)) + return NM_STATE_UNKNOWN; + return nm_manager_get_state (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -181,7 +250,10 @@ nm_client_get_state (NMClient *client) gboolean nm_client_get_startup (NMClient *client) { - g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN); + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + + if (!nm_client_get_nm_running (client)) + return FALSE; return nm_manager_get_startup (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -199,7 +271,7 @@ nm_client_get_nm_running (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - return nm_manager_get_nm_running (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->manager != NULL; } /** @@ -215,6 +287,9 @@ nm_client_networking_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_networking_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -255,6 +330,9 @@ nm_client_wireless_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_wireless_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -270,7 +348,7 @@ nm_client_wireless_set_enabled (NMClient *client, gboolean enabled) { g_return_if_fail (NM_IS_CLIENT (client)); - if (!_nm_client_check_nm_running (client, NULL)) + if (!nm_client_get_nm_running (client)) return; nm_manager_wireless_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled); @@ -289,6 +367,9 @@ nm_client_wireless_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_wireless_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -305,6 +386,9 @@ nm_client_wwan_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_wwan_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -339,6 +423,9 @@ nm_client_wwan_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_wwan_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -355,6 +442,9 @@ nm_client_wimax_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_wimax_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -370,7 +460,7 @@ nm_client_wimax_set_enabled (NMClient *client, gboolean enabled) { g_return_if_fail (NM_IS_CLIENT (client)); - if (!_nm_client_check_nm_running (client, NULL)) + if (!nm_client_get_nm_running (client)) return; nm_manager_wimax_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled); @@ -389,6 +479,9 @@ nm_client_wimax_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!nm_client_get_nm_running (client)) + return FALSE; + return nm_manager_wimax_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -459,6 +552,9 @@ nm_client_get_permission_result (NMClient *client, NMClientPermission permission { g_return_val_if_fail (NM_IS_CLIENT (client), NM_CLIENT_PERMISSION_RESULT_UNKNOWN); + if (!nm_client_get_nm_running (client)) + return NM_CLIENT_PERMISSION_RESULT_UNKNOWN; + return nm_manager_get_permission_result (NM_CLIENT_GET_PRIVATE (client)->manager, permission); } @@ -478,6 +574,9 @@ nm_client_get_connectivity (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); + if (!nm_client_get_nm_running (client)) + return NM_CONNECTIVITY_UNKNOWN; + return nm_manager_get_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -614,6 +713,9 @@ nm_client_save_hostname (NMClient *client, { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + if (!_nm_client_check_nm_running (client, error)) + return FALSE; + return nm_remote_settings_save_hostname (NM_CLIENT_GET_PRIVATE (client)->settings, hostname, cancellable, error); } @@ -720,6 +822,9 @@ nm_client_get_devices (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return ∅ + return nm_manager_get_devices (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -748,6 +853,9 @@ nm_client_get_all_devices (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return ∅ + return nm_manager_get_all_devices (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -766,6 +874,9 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (object_path, NULL); + if (!nm_client_get_nm_running (client)) + return NULL; + return nm_manager_get_device_by_path (NM_CLIENT_GET_PRIVATE (client)->manager, object_path); } @@ -784,6 +895,9 @@ nm_client_get_device_by_iface (NMClient *client, const char *iface) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (iface, NULL); + if (!nm_client_get_nm_running (client)) + return NULL; + return nm_manager_get_device_by_iface (NM_CLIENT_GET_PRIVATE (client)->manager, iface); } @@ -806,6 +920,9 @@ nm_client_get_active_connections (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return ∅ + return nm_manager_get_active_connections (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -833,6 +950,9 @@ nm_client_get_primary_connection (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return NULL; + return nm_manager_get_primary_connection (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -852,6 +972,9 @@ nm_client_get_activating_connection (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return NULL; + return nm_manager_get_activating_connection (NM_CLIENT_GET_PRIVATE (client)->manager); } @@ -1093,7 +1216,7 @@ nm_client_deactivate_connection (NMClient *client, g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE); - if (!_nm_client_check_nm_running (client, NULL)) + if (!nm_client_get_nm_running (client)) return TRUE; return nm_manager_deactivate_connection (NM_CLIENT_GET_PRIVATE (client)->manager, @@ -1200,6 +1323,9 @@ nm_client_get_connections (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + if (!nm_client_get_nm_running (client)) + return ∅ + return nm_remote_settings_get_connections (NM_CLIENT_GET_PRIVATE (client)->settings); } @@ -1222,6 +1348,9 @@ nm_client_get_connection_by_id (NMClient *client, const char *id) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (id != NULL, NULL); + if (!nm_client_get_nm_running (client)) + NULL; + return nm_remote_settings_get_connection_by_id (NM_CLIENT_GET_PRIVATE (client)->settings, id); } @@ -1244,6 +1373,9 @@ nm_client_get_connection_by_path (NMClient *client, const char *path) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (path != NULL, NULL); + if (!nm_client_get_nm_running (client)) + NULL; + return nm_remote_settings_get_connection_by_path (NM_CLIENT_GET_PRIVATE (client)->settings, path); } @@ -1266,6 +1398,9 @@ nm_client_get_connection_by_uuid (NMClient *client, const char *uuid) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (uuid != NULL, NULL); + if (!nm_client_get_nm_running (client)) + NULL; + return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid); } @@ -1769,15 +1904,200 @@ manager_active_connection_removed (NMManager *manager, g_signal_emit (client, signals[ACTIVE_CONNECTION_REMOVED], 0, active_connection); } +/****************************************************************/ +/* Object Initialization */ +/****************************************************************/ + +static GType +proxy_type (GDBusObjectManagerClient *manager, + const gchar *object_path, + const gchar *interface_name, + gpointer user_data) +{ + /* ObjectManager asks us for an object proxy. Unfortunatelly, we can't + * decide that by interface name and GDBusObjectManager doesn't allow + * us to look at the known interface list. Thus we need to create a + * generic GDBusObject and only couple a NMObject subclass later. */ + if (!interface_name) + return G_TYPE_DBUS_OBJECT_PROXY; + + /* An interface proxy */ + if (strcmp (interface_name, NM_DBUS_INTERFACE) == 0) + return NMDBUS_TYPE_MANAGER_PROXY; + else if (strcmp (interface_name, NM_DBUS_INTERFACE_DEVICE_WIRELESS) == 0) + return NMDBUS_TYPE_DEVICE_WIFI_PROXY; + else if (strcmp (interface_name, NM_DBUS_INTERFACE_DEVICE) == 0) + return NMDBUS_TYPE_DEVICE_PROXY; + else if (strcmp (interface_name, NM_DBUS_INTERFACE_SETTINGS_CONNECTION) == 0) + return NMDBUS_TYPE_SETTINGS_CONNECTION_PROXY; + else if (strcmp (interface_name, NM_DBUS_INTERFACE_SETTINGS) == 0) + return NMDBUS_TYPE_SETTINGS_PROXY; + else if (strcmp (interface_name, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0) + return NMDBUS_TYPE_VPN_CONNECTION_PROXY; + + /* Use a generic D-Bus Proxy whenever we can. The typed GDBusProxy + * subclasses actually use quite some memory, so they're better avoided. */ + return G_TYPE_DBUS_PROXY; +} + +static NMObject * +obj_nm_for_gdbus_object (GDBusObject *object, GDBusObjectManager *object_manager) +{ + GList *interfaces; + GList *l; + GType type = G_TYPE_INVALID; + NMObject *obj_nm; + + g_return_val_if_fail (G_IS_DBUS_OBJECT_PROXY (object), NULL); + + interfaces = g_dbus_object_get_interfaces (object); + for (l = interfaces; l; l = l->next) { + GDBusProxy *proxy = G_DBUS_PROXY (l->data); + const char *ifname = g_dbus_proxy_get_interface_name (proxy); + + /* This is a performance/scalability hack. It makes sense to call it + * from here, since this is in the common object creation path. */ + _nm_dbus_proxy_replace_match (proxy); + + if (strcmp (ifname, NM_DBUS_INTERFACE) == 0) + type = NM_TYPE_MANAGER; + else if (strcmp (ifname, NM_DBUS_INTERFACE_ACCESS_POINT) == 0) + type = NM_TYPE_ACCESS_POINT; + else if (strcmp (ifname, NM_DBUS_INTERFACE_ACTIVE_CONNECTION) == 0 && type != NM_TYPE_VPN_CONNECTION) + type = NM_TYPE_ACTIVE_CONNECTION; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_ADSL) == 0) + type = NM_TYPE_DEVICE_ADSL; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BOND) == 0) + type = NM_TYPE_DEVICE_BOND; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BRIDGE) == 0) + type = NM_TYPE_DEVICE_BRIDGE; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH) == 0) + type = NM_TYPE_DEVICE_BT; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIRED) == 0) + type = NM_TYPE_DEVICE_ETHERNET; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_GENERIC) == 0) + type = NM_TYPE_DEVICE_GENERIC; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_INFINIBAND) == 0) + type = NM_TYPE_DEVICE_INFINIBAND; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL) == 0) + type = NM_TYPE_DEVICE_IP_TUNNEL; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_MACVLAN) == 0) + type = NM_TYPE_DEVICE_MACVLAN; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_MODEM) == 0) + type = NM_TYPE_DEVICE_MODEM; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_OLPC_MESH) == 0) + type = NM_TYPE_DEVICE_OLPC_MESH; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_TEAM) == 0) + type = NM_TYPE_DEVICE_TEAM; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_TUN) == 0) + type = NM_TYPE_DEVICE_TUN; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_VLAN) == 0) + type = NM_TYPE_DEVICE_VLAN; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_VXLAN) == 0) + type = NM_TYPE_DEVICE_VXLAN; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIRELESS) == 0) + type = NM_TYPE_DEVICE_WIFI; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIMAX) == 0) + type = NM_TYPE_DEVICE_WIMAX; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DHCP4_CONFIG) == 0) + type = NM_TYPE_DHCP4_CONFIG; + else if (strcmp (ifname, NM_DBUS_INTERFACE_DHCP6_CONFIG) == 0) + type = NM_TYPE_DHCP6_CONFIG; + else if (strcmp (ifname, NM_DBUS_INTERFACE_IP4_CONFIG) == 0) + type = NM_TYPE_IP4_CONFIG; + else if (strcmp (ifname, NM_DBUS_INTERFACE_IP6_CONFIG) == 0) + type = NM_TYPE_IP6_CONFIG; + else if (strcmp (ifname, NM_DBUS_INTERFACE_SETTINGS_CONNECTION) == 0) + type = NM_TYPE_REMOTE_CONNECTION; + else if (strcmp (ifname, NM_DBUS_INTERFACE_SETTINGS) == 0) + type = NM_TYPE_REMOTE_SETTINGS; + else if (strcmp (ifname, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0) + type = NM_TYPE_VPN_CONNECTION; + else if (strcmp (ifname, NM_DBUS_INTERFACE_WIMAX_NSP) == 0) + type = NM_TYPE_WIMAX_NSP; + + if (type != G_TYPE_INVALID) + break; + } + + g_list_free_full (interfaces, g_object_unref); + if (type == G_TYPE_INVALID) + return NULL; + + obj_nm = g_object_new (type, + NM_OBJECT_DBUS_OBJECT, object, + NM_OBJECT_DBUS_OBJECT_MANAGER, object_manager, + NULL); + g_object_set_qdata_full (G_OBJECT (object), _nm_object_obj_nm_quark (), + obj_nm, g_object_unref); + return obj_nm; +} + +static void +obj_nm_inited (GObject *object, GAsyncResult *result, gpointer user_data) +{ + if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, NULL)) { + /* This is a can-not-happen situation, the NMObject subclasses are not + * supposed to fail initialization. */ + g_warn_if_reached (); + } +} + + static void -constructed (GObject *object) +object_added (GDBusObjectManager *object_manager, GDBusObject *object, gpointer user_data) +{ + NMObject *obj_nm; + + obj_nm = obj_nm_for_gdbus_object (object, object_manager); + if (obj_nm) { + g_async_initable_init_async (G_ASYNC_INITABLE (obj_nm), + G_PRIORITY_DEFAULT, NULL, + obj_nm_inited, NULL); + } +} + +static void +object_removed (GDBusObjectManager *object_manager, GDBusObject *object, gpointer user_data) +{ + g_object_set_qdata (G_OBJECT (object), _nm_object_obj_nm_quark (), NULL); +} + +static gboolean +objects_created (NMClient *client, GDBusObjectManager *object_manager, GError **error) { - NMClient *client = NM_CLIENT (object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); + gs_unref_object GDBusObject *manager = NULL; + gs_unref_object GDBusObject *settings = NULL; + NMObject *obj_nm; + GList *objects, *iter; + + /* First just ensure all the NMObjects for known GDBusObjects exist. */ + objects = g_dbus_object_manager_get_objects (object_manager); + for (iter = objects; iter; iter = iter->next) + obj_nm_for_gdbus_object (iter->data, object_manager); + g_list_free_full (objects, g_object_unref); + + manager = g_dbus_object_manager_get_object (object_manager, NM_DBUS_PATH); + if (!manager) { + g_set_error_literal (error, + NM_CLIENT_ERROR, + NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, + "Manager object not found"); + return FALSE; + } + + obj_nm = g_object_get_qdata (G_OBJECT (manager), _nm_object_obj_nm_quark ()); + if (!obj_nm) { + g_set_error_literal (error, + NM_CLIENT_ERROR, + NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, + "Manager object lacks the proper interface"); + return FALSE; + } + + priv->manager = NM_MANAGER (g_object_ref (obj_nm)); - priv->manager = g_object_new (NM_TYPE_MANAGER, - NM_OBJECT_PATH, NM_DBUS_PATH, - NULL); g_signal_connect (priv->manager, "notify", G_CALLBACK (subobject_notify), client); g_signal_connect (priv->manager, "device-added", @@ -1795,9 +2115,26 @@ constructed (GObject *object) g_signal_connect (priv->manager, "active-connection-removed", G_CALLBACK (manager_active_connection_removed), client); - priv->settings = g_object_new (NM_TYPE_REMOTE_SETTINGS, - NM_OBJECT_PATH, NM_DBUS_PATH_SETTINGS, - NULL); + settings = g_dbus_object_manager_get_object (object_manager, NM_DBUS_PATH_SETTINGS); + if (!settings) { + g_set_error_literal (error, + NM_CLIENT_ERROR, + NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, + "Settings object not found"); + return FALSE; + } + + obj_nm = g_object_get_qdata (G_OBJECT (settings), _nm_object_obj_nm_quark ()); + if (!obj_nm) { + g_set_error_literal (error, + NM_CLIENT_ERROR, + NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, + "Settings object lacks the proper interface"); + return FALSE; + } + + priv->settings = NM_REMOTE_SETTINGS (g_object_ref (obj_nm)); + g_signal_connect (priv->settings, "notify", G_CALLBACK (subobject_notify), client); g_signal_connect (priv->settings, "connection-added", @@ -1805,29 +2142,74 @@ constructed (GObject *object) g_signal_connect (priv->settings, "connection-removed", G_CALLBACK (settings_connection_removed), client); - G_OBJECT_CLASS (nm_client_parent_class)->constructed (object); + /* The handlers don't really use the client instance. However + * it makes it convenient to unhook them by data. */ + g_signal_connect (object_manager, "object-added", + G_CALLBACK (object_added), client); + g_signal_connect (object_manager, "object-removed", + G_CALLBACK (object_removed), client); + + return TRUE; } +/* Synchronous initialization. */ + +static void name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data); + static gboolean init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { NMClient *client = NM_CLIENT (initable); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); + GList *objects, *iter; + gchar *name_owner; - if (!g_initable_init (G_INITABLE (priv->manager), cancellable, error)) - return FALSE; - if (!g_initable_init (G_INITABLE (priv->settings), cancellable, error)) + priv->object_manager = g_dbus_object_manager_client_new_for_bus_sync (_nm_dbus_bus_type (), + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, + "org.freedesktop.NetworkManager", + "/org/freedesktop", + proxy_type, NULL, NULL, + cancellable, error); + + if (!priv->object_manager) return FALSE; + name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager)); + if (name_owner) { + g_free (name_owner); + if (!objects_created (client, priv->object_manager, error)) + return FALSE; + + objects = g_dbus_object_manager_get_objects (priv->object_manager); + for (iter = objects; iter; iter = iter->next) { + NMObject *obj_nm; + + obj_nm = g_object_get_qdata (iter->data, _nm_object_obj_nm_quark ()); + if (!obj_nm) + continue; + + if (!g_initable_init (G_INITABLE (obj_nm), cancellable, NULL)) { + /* This is a can-not-happen situation, the NMObject subclasses are not + * supposed to fail initialization. */ + g_warn_if_reached (); + } + } + g_list_free_full (objects, g_object_unref); + } + + g_signal_connect (priv->object_manager, "notify::name-owner", + G_CALLBACK (name_owner_changed), client); + return TRUE; } +/* Asynchronous initialization. */ + typedef struct { NMClient *client; GCancellable *cancellable; GSimpleAsyncResult *result; - gboolean manager_inited; - gboolean settings_inited; + int pending_init; } NMClientInitData; static void @@ -1840,7 +2222,7 @@ init_async_complete (NMClientInitData *init_data) } static void -init_async_inited_manager (GObject *object, GAsyncResult *result, gpointer user_data) +async_inited_obj_nm (GObject *object, GAsyncResult *result, gpointer user_data) { NMClientInitData *init_data = user_data; GError *error = NULL; @@ -1848,46 +2230,181 @@ init_async_inited_manager (GObject *object, GAsyncResult *result, gpointer user_ if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) g_simple_async_result_take_error (init_data->result, error); - init_data->manager_inited = TRUE; - if (init_data->settings_inited) - init_async_complete (init_data); + if (init_data) { + init_data->pending_init--; + if (init_data->pending_init == 0) + init_async_complete (init_data); + } } static void -init_async_inited_settings (GObject *object, GAsyncResult *result, gpointer user_data) +init_async (GAsyncInitable *initable, int io_priority, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data); + +static void +unhook_om (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + GList *objects, *iter; + + if (priv->manager) { + const GPtrArray *active_connections; + const GPtrArray *devices; + int i; + + active_connections = nm_manager_get_active_connections (priv->manager); + for (i = 0; i < active_connections->len; i++) + g_signal_emit (self, signals[ACTIVE_CONNECTION_REMOVED], 0, active_connections->pdata[i]); + + devices = nm_manager_get_all_devices (priv->manager); + for (i = 0; i < devices->len; i++) + g_signal_emit (self, signals[DEVICE_REMOVED], 0, devices->pdata[i]); + + g_signal_handlers_disconnect_by_data (priv->manager, self); + g_clear_object (&priv->manager); + g_object_notify (G_OBJECT (self), NM_CLIENT_ACTIVE_CONNECTIONS); + g_object_notify (G_OBJECT (self), NM_CLIENT_NM_RUNNING); + } + if (priv->settings) { + const GPtrArray *connections; + guint i; + + connections = nm_remote_settings_get_connections (priv->settings); + for (i = 0; i < connections->len; i++) + g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connections->pdata[i]); + + g_signal_handlers_disconnect_by_data (priv->settings, self); + g_clear_object (&priv->settings); + g_object_notify (G_OBJECT (self), NM_CLIENT_CONNECTIONS); + g_object_notify (G_OBJECT (self), NM_CLIENT_HOSTNAME); + g_object_notify (G_OBJECT (self), NM_CLIENT_CAN_MODIFY); + } + + objects = g_dbus_object_manager_get_objects (priv->object_manager); + for (iter = objects; iter; iter = iter->next) + g_object_set_qdata (iter->data, _nm_object_obj_nm_quark (), NULL); + g_list_free_full (objects, g_object_unref); +} + +static void +new_object_manager (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (source_object); + + g_object_notify (G_OBJECT (user_data), NM_CLIENT_NM_RUNNING); + g_clear_object (&priv->new_object_manager_cancellable); +} + +static void +got_object_manager (GObject *object, GAsyncResult *result, gpointer user_data) { NMClientInitData *init_data = user_data; + NMClient *client; + NMClientPrivate *priv; + GList *objects, *iter; + gchar *name_owner; GError *error = NULL; + GDBusObjectManager *object_manager; + + object_manager = g_dbus_object_manager_client_new_for_bus_finish (result, &error); + if (object_manager == NULL) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_simple_async_result_take_error (init_data->result, error); + init_async_complete (init_data); + } + return; + } - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) - g_simple_async_result_take_error (init_data->result, error); - - init_data->settings_inited = TRUE; - if (init_data->manager_inited) + client = init_data->client; + priv = NM_CLIENT_GET_PRIVATE (client); + priv->object_manager = object_manager; + + name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager)); + if (name_owner) { + g_free (name_owner); + if (!objects_created (client, priv->object_manager, &error)) { + g_simple_async_result_take_error (init_data->result, error); + init_async_complete (init_data); + return; + } + + objects = g_dbus_object_manager_get_objects (priv->object_manager); + for (iter = objects; iter; iter = iter->next) { + NMObject *obj_nm; + + obj_nm = g_object_get_qdata (iter->data, _nm_object_obj_nm_quark ()); + if (!obj_nm) + continue; + + init_data->pending_init++; + g_async_initable_init_async (G_ASYNC_INITABLE (obj_nm), + G_PRIORITY_DEFAULT, init_data->cancellable, + async_inited_obj_nm, init_data); + } + g_list_free_full (objects, g_object_unref); + + } else init_async_complete (init_data); + + g_signal_connect (priv->object_manager, "notify::name-owner", + G_CALLBACK (name_owner_changed), client); } static void -init_async (GAsyncInitable *initable, int io_priority, - GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data) +prepare_object_manager (NMClient *client, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (initable); NMClientInitData *init_data; init_data = g_slice_new0 (NMClientInitData); - init_data->client = NM_CLIENT (initable); + init_data->client = client; init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, + init_data->result = g_simple_async_result_new (G_OBJECT (client), callback, user_data, init_async); g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); - g_async_initable_init_async (G_ASYNC_INITABLE (priv->manager), - G_PRIORITY_DEFAULT, init_data->cancellable, - init_async_inited_manager, init_data); - g_async_initable_init_async (G_ASYNC_INITABLE (priv->settings), - G_PRIORITY_DEFAULT, init_data->cancellable, - init_async_inited_settings, init_data); + g_dbus_object_manager_client_new_for_bus (_nm_dbus_bus_type (), + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, + "org.freedesktop.NetworkManager", + "/org/freedesktop", + proxy_type, NULL, NULL, + init_data->cancellable, + got_object_manager, + init_data); +} + +static void +name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + GDBusObjectManager *object_manager = G_DBUS_OBJECT_MANAGER (object); + gchar *name_owner; + + name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (object)); + if (name_owner) { + g_free (name_owner); + g_object_unref (object_manager); + if (priv->new_object_manager_cancellable) + g_cancellable_cancel (priv->new_object_manager_cancellable); + priv->new_object_manager_cancellable = g_cancellable_new (); + prepare_object_manager (self, priv->new_object_manager_cancellable, + new_object_manager, user_data); + } else { + g_signal_handlers_disconnect_by_func (object_manager, object_added, self); + unhook_om (self); + } +} + +static void +init_async (GAsyncInitable *initable, int io_priority, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) +{ + prepare_object_manager (NM_CLIENT (initable), cancellable, callback, user_data); } static gboolean @@ -1906,15 +2423,26 @@ dispose (GObject *object) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); + if (priv->new_object_manager_cancellable) { + g_cancellable_cancel (priv->new_object_manager_cancellable); + g_clear_object (&priv->new_object_manager_cancellable); + } + if (priv->manager) { g_signal_handlers_disconnect_by_data (priv->manager, object); g_clear_object (&priv->manager); } + if (priv->settings) { g_signal_handlers_disconnect_by_data (priv->settings, object); g_clear_object (&priv->settings); } + if (priv->object_manager) { + g_signal_handlers_disconnect_by_data (priv->object_manager, object); + g_clear_object (&priv->object_manager); + } + G_OBJECT_CLASS (nm_client_parent_class)->dispose (object); } @@ -1922,13 +2450,15 @@ static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); + switch (prop_id) { case PROP_NETWORKING_ENABLED: case PROP_WIRELESS_ENABLED: case PROP_WWAN_ENABLED: case PROP_WIMAX_ENABLED: - g_object_set_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager), - pspec->name, value); + if (priv->manager) + g_object_set_property (G_OBJECT (priv->manager), pspec->name, value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1940,33 +2470,97 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { + NMClient *self = NM_CLIENT (object); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); + switch (prop_id) { + case PROP_NM_RUNNING: + g_value_set_boolean (value, nm_client_get_nm_running (self)); + break; + + /* Manager properties. */ case PROP_VERSION: + g_value_set_string (value, nm_client_get_version (self)); + break; case PROP_STATE: + g_value_set_enum (value, nm_client_get_state (self)); + break; case PROP_STARTUP: - case PROP_NM_RUNNING: + g_value_set_boolean (value, nm_client_get_startup (self)); + break; case PROP_NETWORKING_ENABLED: + g_value_set_boolean (value, nm_client_networking_get_enabled (self)); + break; case PROP_WIRELESS_ENABLED: + g_value_set_boolean (value, nm_client_wireless_get_enabled (self)); + break; case PROP_WIRELESS_HARDWARE_ENABLED: + if (priv->manager) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_set_boolean (value, FALSE); + break; case PROP_WWAN_ENABLED: + g_value_set_boolean (value, nm_client_wwan_get_enabled (self)); + break; case PROP_WWAN_HARDWARE_ENABLED: + if (priv->manager) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_set_boolean (value, FALSE); + break; case PROP_WIMAX_ENABLED: + g_value_set_boolean (value, nm_client_wimax_get_enabled (self)); + break; case PROP_WIMAX_HARDWARE_ENABLED: + if (priv->manager) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_set_boolean (value, FALSE); + break; case PROP_ACTIVE_CONNECTIONS: + g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_active_connections (self))); + break; case PROP_CONNECTIVITY: + g_value_set_enum (value, nm_client_get_connectivity (self)); + break; case PROP_PRIMARY_CONNECTION: + g_value_set_object (value, nm_client_get_primary_connection (self)); + break; case PROP_ACTIVATING_CONNECTION: + g_value_set_object (value, nm_client_get_activating_connection (self)); + break; case PROP_DEVICES: + g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_devices (self))); + break; case PROP_METERED: + if (priv->manager) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_set_uint (value, NM_METERED_UNKNOWN); + break; case PROP_ALL_DEVICES: - g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager), - pspec->name, value); + g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_all_devices (self))); break; + + /* Settings properties. */ case PROP_CONNECTIONS: + if (priv->settings) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_take_boxed (value, _nm_utils_copy_object_array (&empty)); + break; case PROP_HOSTNAME: + if (priv->settings) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_set_string (value, NULL); + break; case PROP_CAN_MODIFY: - g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->settings), - pspec->name, value); + if (priv->settings) + g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); + else + g_value_set_boolean (value, FALSE); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1982,7 +2576,6 @@ nm_client_class_init (NMClientClass *client_class) g_type_class_add_private (client_class, sizeof (NMClientPrivate)); /* virtual methods */ - object_class->constructed = constructed; object_class->set_property = set_property; object_class->get_property = get_property; object_class->dispose = dispose; diff --git a/libnm/nm-dbus-helpers.c b/libnm/nm-dbus-helpers.c index 3076674a4f..f835b59141 100644 --- a/libnm/nm-dbus-helpers.c +++ b/libnm/nm-dbus-helpers.c @@ -98,24 +98,6 @@ _nm_dbus_is_connection_private (GDBusConnection *connection) return g_dbus_connection_get_unique_name (connection) == NULL; } -static GHashTable *proxy_types; - -#undef _nm_dbus_register_proxy_type -void -_nm_dbus_register_proxy_type (const char *interface, - GType proxy_type) -{ - if (!proxy_types) - proxy_types = g_hash_table_new (g_str_hash, g_str_equal); - - g_assert (g_hash_table_lookup (proxy_types, interface) == NULL); - g_hash_table_insert (proxy_types, (char *) interface, GSIZE_TO_POINTER (proxy_type)); -} - -/* We don't (currently) use GDBus's property-handling code */ -#define NM_DBUS_PROXY_FLAGS (G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | \ - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START) - /* D-Bus has an upper limit on number of Match rules and it's rather easy * to hit as the proxy likes to add one for each object. Let's remove the Match * rule the proxy added and ensure a less granular rule is present instead. @@ -126,15 +108,13 @@ _nm_dbus_register_proxy_type (const char *interface, * Ideally, we should be able to tell glib not to hook its rules: * https://bugzilla.gnome.org/show_bug.cgi?id=758749 */ -static void +void _nm_dbus_proxy_replace_match (GDBusProxy *proxy) { GDBusConnection *connection = g_dbus_proxy_get_connection (proxy); static unsigned match_counter = 1024; gchar *match; - nm_assert (!g_strcmp0 (g_dbus_proxy_get_name (proxy), NM_DBUS_SERVICE)); - if (match_counter == 1) { /* If we hit the low matches watermark, install a * less granular one. */ @@ -177,83 +157,6 @@ _nm_dbus_proxy_replace_match (GDBusProxy *proxy) g_free (match); } -GDBusProxy * -_nm_dbus_new_proxy_for_connection (GDBusConnection *connection, - const char *path, - const char *interface, - GCancellable *cancellable, - GError **error) -{ - GDBusProxy *proxy; - GType proxy_type; - const char *name; - - proxy_type = GPOINTER_TO_SIZE (g_hash_table_lookup (proxy_types, interface)); - if (!proxy_type) - proxy_type = G_TYPE_DBUS_PROXY; - - if (_nm_dbus_is_connection_private (connection)) - name = NULL; - else - name = NM_DBUS_SERVICE; - - proxy = g_initable_new (proxy_type, cancellable, error, - "g-connection", connection, - "g-flags", NM_DBUS_PROXY_FLAGS, - "g-name", name, - "g-object-path", path, - "g-interface-name", interface, - NULL); - _nm_dbus_proxy_replace_match (proxy); - - return proxy; -} - -void -_nm_dbus_new_proxy_for_connection_async (GDBusConnection *connection, - const char *path, - const char *interface, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GType proxy_type; - const char *name; - - proxy_type = GPOINTER_TO_SIZE (g_hash_table_lookup (proxy_types, interface)); - if (!proxy_type) - proxy_type = G_TYPE_DBUS_PROXY; - - if (_nm_dbus_is_connection_private (connection)) - name = NULL; - else - name = NM_DBUS_SERVICE; - - g_async_initable_new_async (proxy_type, G_PRIORITY_DEFAULT, - cancellable, callback, user_data, - "g-connection", connection, - "g-flags", NM_DBUS_PROXY_FLAGS, - "g-name", name, - "g-object-path", path, - "g-interface-name", interface, - NULL); -} - -GDBusProxy * -_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result, - GError **error) -{ - GObject *source; - GDBusProxy *proxy; - - source = g_async_result_get_source_object (result); - proxy = G_DBUS_PROXY (g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, error)); - g_object_unref (source); - _nm_dbus_proxy_replace_match (proxy); - - return proxy; -} - /* Binds the properties on a generated server-side GDBus object to the * corresponding properties on the public object. */ diff --git a/libnm/nm-dbus-helpers.h b/libnm/nm-dbus-helpers.h index 4ec8988a17..1847da1d21 100644 --- a/libnm/nm-dbus-helpers.h +++ b/libnm/nm-dbus-helpers.h @@ -36,26 +36,7 @@ GDBusConnection *_nm_dbus_new_connection_finish (GAsyncResult *result, gboolean _nm_dbus_is_connection_private (GDBusConnection *connection); -void _nm_dbus_register_proxy_type (const char *interface, - GType proxy_type); -/* Guarantee that @interface is a static string */ -#define _nm_dbus_register_proxy_type(interface, proxy_type) \ - _nm_dbus_register_proxy_type (interface "", proxy_type) \ - -GDBusProxy *_nm_dbus_new_proxy_for_connection (GDBusConnection *connection, - const char *path, - const char *interface, - GCancellable *cancellable, - GError **error); - -void _nm_dbus_new_proxy_for_connection_async (GDBusConnection *connection, - const char *path, - const char *interface, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GDBusProxy *_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result, - GError **error); +void _nm_dbus_proxy_replace_match (GDBusProxy *proxy); void _nm_dbus_bind_properties (gpointer object, gpointer skeleton); diff --git a/libnm/nm-device-adsl.c b/libnm/nm-device-adsl.c index 6c66f717f8..3285745dd7 100644 --- a/libnm/nm-device-adsl.c +++ b/libnm/nm-device-adsl.c @@ -25,7 +25,6 @@ #include <string.h> -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-setting-adsl.h" @@ -89,7 +88,6 @@ get_setting_type (NMDevice *device) static void nm_device_adsl_init (NMDeviceAdsl *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ADSL); } static void @@ -135,8 +133,6 @@ nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class) g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_ADSL); - /* virtual methods */ object_class->get_property = get_property; diff --git a/libnm/nm-device-bond.c b/libnm/nm-device-bond.c index 0a9fae86a2..963348400b 100644 --- a/libnm/nm-device-bond.c +++ b/libnm/nm-device-bond.c @@ -27,7 +27,6 @@ #include "nm-utils.h" #include "nm-device-bond.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-core-internal.h" @@ -137,8 +136,6 @@ nm_device_bond_init (NMDeviceBond *device) { NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device); - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BOND); - priv->slaves = g_ptr_array_new (); } @@ -213,8 +210,6 @@ nm_device_bond_class_init (NMDeviceBondClass *bond_class) g_type_class_add_private (bond_class, sizeof (NMDeviceBondPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_BOND); - /* virtual methods */ object_class->dispose = dispose; object_class->finalize = finalize; diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c index cd885b4afb..55f09a20fa 100644 --- a/libnm/nm-device-bridge.c +++ b/libnm/nm-device-bridge.c @@ -27,7 +27,6 @@ #include "nm-utils.h" #include "nm-device-bridge.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-core-internal.h" @@ -137,8 +136,6 @@ nm_device_bridge_init (NMDeviceBridge *device) { NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device); - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BRIDGE); - priv->slaves = g_ptr_array_new (); } @@ -213,8 +210,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class) g_type_class_add_private (bridge_class, sizeof (NMDeviceBridgePrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_BRIDGE); - /* virtual methods */ object_class->dispose = dispose; object_class->finalize = finalize; diff --git a/libnm/nm-device-bt.c b/libnm/nm-device-bt.c index f41b7abd8c..0fcd28b9e8 100644 --- a/libnm/nm-device-bt.c +++ b/libnm/nm-device-bt.c @@ -28,7 +28,6 @@ #include "nm-utils.h" #include "nm-device-bt.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-enum-types.h" @@ -183,7 +182,6 @@ get_hw_address (NMDevice *device) static void nm_device_bt_init (NMDeviceBt *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BT); } static void @@ -248,8 +246,6 @@ nm_device_bt_class_init (NMDeviceBtClass *bt_class) g_type_class_add_private (bt_class, sizeof (NMDeviceBtPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index 966ad2d73e..727ea8a64f 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -29,7 +29,6 @@ #include "nm-utils.h" #include "nm-device-ethernet.h" -#include "nm-device-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE) @@ -282,7 +281,6 @@ get_hw_address (NMDevice *device) static void nm_device_ethernet_init (NMDeviceEthernet *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ETHERNET); } static void @@ -357,8 +355,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class) g_type_class_add_private (eth_class, sizeof (NMDeviceEthernetPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_WIRED); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-generic.c b/libnm/nm-device-generic.c index 6bc1336219..62cb89ebf7 100644 --- a/libnm/nm-device-generic.c +++ b/libnm/nm-device-generic.c @@ -23,7 +23,6 @@ #include <string.h> #include "nm-device-generic.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-setting-generic.h" #include "nm-setting-connection.h" @@ -113,7 +112,6 @@ get_setting_type (NMDevice *device) static void nm_device_generic_init (NMDeviceGeneric *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_GENERIC); } static void @@ -175,8 +173,6 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_GENERIC); - object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-infiniband.c b/libnm/nm-device-infiniband.c index 665542881e..1ed942b5be 100644 --- a/libnm/nm-device-infiniband.c +++ b/libnm/nm-device-infiniband.c @@ -27,7 +27,6 @@ #include "nm-utils.h" #include "nm-device-infiniband.h" -#include "nm-device-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) @@ -132,7 +131,6 @@ get_hw_address (NMDevice *device) static void nm_device_infiniband_init (NMDeviceInfiniband *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_INFINIBAND); } static void @@ -192,8 +190,6 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *ib_class) g_type_class_add_private (ib_class, sizeof (NMDeviceInfinibandPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_INFINIBAND); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-ip-tunnel.c b/libnm/nm-device-ip-tunnel.c index 41748aba10..e0dfc0f4e0 100644 --- a/libnm/nm-device-ip-tunnel.c +++ b/libnm/nm-device-ip-tunnel.c @@ -27,7 +27,6 @@ #include "nm-utils.h" #include "nm-device-ip-tunnel.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-core-internal.h" @@ -269,7 +268,6 @@ get_setting_type (NMDevice *device) static void nm_device_ip_tunnel_init (NMDeviceIPTunnel *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_IP_TUNNEL); } static void @@ -369,8 +367,6 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) g_type_class_add_private (bond_class, sizeof (NMDeviceIPTunnelPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-macvlan.c b/libnm/nm-device-macvlan.c index a370ed1e67..e647721988 100644 --- a/libnm/nm-device-macvlan.c +++ b/libnm/nm-device-macvlan.c @@ -28,7 +28,6 @@ #include "nm-utils.h" #include "nm-device-macvlan.h" -#include "nm-device-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMDeviceMacvlan, nm_device_macvlan, NM_TYPE_DEVICE) @@ -186,7 +185,6 @@ get_setting_type (NMDevice *device) static void nm_device_macvlan_init (NMDeviceMacvlan *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MACVLAN); } static void @@ -260,8 +258,6 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) g_type_class_add_private (gre_class, sizeof (NMDeviceMacvlanPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_MACVLAN); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-modem.c b/libnm/nm-device-modem.c index ae011812f2..7fc843f6df 100644 --- a/libnm/nm-device-modem.c +++ b/libnm/nm-device-modem.c @@ -28,7 +28,6 @@ #include "nm-setting-cdma.h" #include "nm-device-modem.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-enum-types.h" @@ -158,7 +157,6 @@ get_setting_type (NMDevice *device) static void nm_device_modem_init (NMDeviceModem *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MODEM); } static void @@ -208,8 +206,6 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class) g_type_class_add_private (modem_class, sizeof (NMDeviceModemPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_MODEM); - /* virtual methods */ object_class->get_property = get_property; diff --git a/libnm/nm-device-olpc-mesh.c b/libnm/nm-device-olpc-mesh.c index c69d0b3748..875f11a99c 100644 --- a/libnm/nm-device-olpc-mesh.c +++ b/libnm/nm-device-olpc-mesh.c @@ -26,7 +26,6 @@ #include "nm-setting-olpc-mesh.h" #include "nm-device-olpc-mesh.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-device-wifi.h" @@ -130,7 +129,6 @@ get_setting_type (NMDevice *device) static void nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_OLPC_MESH); } static void @@ -204,8 +202,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class) g_type_class_add_private (olpc_mesh_class, sizeof (NMDeviceOlpcMeshPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_OLPC_MESH); - /* virtual methods */ object_class->dispose = dispose; object_class->finalize = finalize; diff --git a/libnm/nm-device-private.h b/libnm/nm-device-private.h index 66fc6b6b4a..e69de29bb2 100644 --- a/libnm/nm-device-private.h +++ b/libnm/nm-device-private.h @@ -1,26 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2012 Red Hat, Inc. - */ - -#ifndef __NM_DEVICE_PRIVATE_H__ -#define __NM_DEVICE_PRIVATE_H__ - -void _nm_device_set_device_type (NMDevice *device, NMDeviceType dtype); - -#endif /* __NM_DEVICE_PRIVATE_H__ */ diff --git a/libnm/nm-device-team.c b/libnm/nm-device-team.c index 0c5383deea..0b62b864b4 100644 --- a/libnm/nm-device-team.c +++ b/libnm/nm-device-team.c @@ -27,7 +27,6 @@ #include "nm-utils.h" #include "nm-device-team.h" -#include "nm-device-private.h" #include "nm-object-private.h" #include "nm-core-internal.h" @@ -158,8 +157,6 @@ nm_device_team_init (NMDeviceTeam *device) { NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_TEAM); - priv->slaves = g_ptr_array_new (); } @@ -239,8 +236,6 @@ nm_device_team_class_init (NMDeviceTeamClass *team_class) g_type_class_add_private (team_class, sizeof (NMDeviceTeamPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_TEAM); - /* virtual methods */ object_class->dispose = dispose; object_class->finalize = finalize; diff --git a/libnm/nm-device-tun.c b/libnm/nm-device-tun.c index 52ba8fd7da..2c88bf3393 100644 --- a/libnm/nm-device-tun.c +++ b/libnm/nm-device-tun.c @@ -28,7 +28,6 @@ #include "nm-utils.h" #include "nm-device-tun.h" -#include "nm-device-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE) @@ -239,7 +238,6 @@ get_hw_address (NMDevice *device) static void nm_device_tun_init (NMDeviceTun *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_TUN); } static void @@ -320,8 +318,6 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) g_type_class_add_private (gre_class, sizeof (NMDeviceTunPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_TUN); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-vlan.c b/libnm/nm-device-vlan.c index b67ad373ca..5728d404d6 100644 --- a/libnm/nm-device-vlan.c +++ b/libnm/nm-device-vlan.c @@ -28,7 +28,6 @@ #include "nm-utils.h" #include "nm-device-vlan.h" -#include "nm-device-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE) @@ -172,7 +171,6 @@ get_hw_address (NMDevice *device) static void nm_device_vlan_init (NMDeviceVlan *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_VLAN); } static void @@ -241,8 +239,6 @@ nm_device_vlan_class_init (NMDeviceVlanClass *vlan_class) g_type_class_add_private (vlan_class, sizeof (NMDeviceVlanPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_VLAN); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-vxlan.c b/libnm/nm-device-vxlan.c index ee356749da..27b9c981a1 100644 --- a/libnm/nm-device-vxlan.c +++ b/libnm/nm-device-vxlan.c @@ -27,7 +27,6 @@ #include "nm-utils.h" #include "nm-device-vxlan.h" -#include "nm-device-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMDeviceVxlan, nm_device_vxlan, NM_TYPE_DEVICE) @@ -415,7 +414,6 @@ get_hw_address (NMDevice *device) static void nm_device_vxlan_init (NMDeviceVxlan *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_VXLAN); } static void @@ -542,8 +540,6 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) g_type_class_add_private (vxlan_class, sizeof (NMDeviceVxlanPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_VXLAN); - /* virtual methods */ object_class->finalize = finalize; object_class->get_property = get_property; diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c index f705dbd2ea..5ed23130a8 100644 --- a/libnm/nm-device-wifi.c +++ b/libnm/nm-device-wifi.c @@ -31,9 +31,7 @@ #include "nm-utils.h" #include "nm-access-point.h" -#include "nm-device-private.h" #include "nm-object-private.h" -#include "nm-object-cache.h" #include "nm-core-internal.h" #include "nm-dbus-helpers.h" @@ -660,8 +658,6 @@ nm_device_wifi_init (NMDeviceWifi *device) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_WIFI); - g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (state_changed_cb), @@ -797,10 +793,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class) g_type_class_add_private (wifi_class, sizeof (NMDeviceWifiPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_WIRELESS); - _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_DEVICE_WIRELESS, - NMDBUS_TYPE_DEVICE_WIFI_PROXY); - /* virtual methods */ object_class->get_property = get_property; object_class->dispose = dispose; diff --git a/libnm/nm-device-wimax.c b/libnm/nm-device-wimax.c index 98c651d3d6..fd0a2dc5c0 100644 --- a/libnm/nm-device-wimax.c +++ b/libnm/nm-device-wimax.c @@ -30,9 +30,7 @@ #include "nm-device-wimax.h" #include "nm-wimax-nsp.h" #include "nm-object-private.h" -#include "nm-object-cache.h" #include "nm-core-internal.h" -#include "nm-device-private.h" G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE) @@ -355,8 +353,6 @@ get_hw_address (NMDevice *device) static void nm_device_wimax_init (NMDeviceWimax *device) { - _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_WIMAX); - g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (state_changed_cb), @@ -531,8 +527,6 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) g_type_class_add_private (wimax_class, sizeof (NMDeviceWimaxPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_WIMAX); - /* virtual methods */ object_class->get_property = get_property; object_class->dispose = dispose; diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 228e60b70b..25788d92b1 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -28,29 +28,12 @@ #include "nm-dbus-interface.h" #include "nm-active-connection.h" -#include "nm-device-ethernet.h" -#include "nm-device-adsl.h" -#include "nm-device-wifi.h" -#include "nm-device-modem.h" #include "nm-device-bt.h" -#include "nm-device-olpc-mesh.h" -#include "nm-device-wimax.h" -#include "nm-device-infiniband.h" -#include "nm-device-bond.h" -#include "nm-device-team.h" -#include "nm-device-bridge.h" -#include "nm-device-vlan.h" -#include "nm-device-vxlan.h" -#include "nm-device-generic.h" -#include "nm-device-ip-tunnel.h" -#include "nm-device-macvlan.h" -#include "nm-device-private.h" #include "nm-dhcp4-config.h" #include "nm-dhcp6-config.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" #include "nm-object-private.h" -#include "nm-object-cache.h" #include "nm-remote-connection.h" #include "nm-core-internal.h" #include "nm-utils.h" @@ -60,16 +43,10 @@ #include "nmdbus-device.h" -static GType _nm_device_decide_type (GVariant *value); static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error); static NMLldpNeighbor *nm_lldp_neighbor_dup (NMLldpNeighbor *neighbor); -G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT, - _nm_object_register_type_func (g_define_type_id, - _nm_device_decide_type, - NM_DBUS_INTERFACE_DEVICE, - "DeviceType"); - ) +G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_OBJECT); #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) @@ -213,11 +190,7 @@ demarshal_lldp_neighbors (NMObject *object, GParamSpec *pspec, GVariant *value, } static void -device_state_changed (NMDBusDevice *proxy, - guint new_state, - guint old_state, - guint reason, - gpointer user_data); +device_state_reason_changed (GObject *object, GParamSpec *pspec, gpointer user_data); static void init_dbus (NMObject *object) @@ -263,136 +236,19 @@ init_dbus (NMObject *object) NM_DBUS_INTERFACE_DEVICE, property_info); - g_signal_connect (priv->proxy, "state-changed", - G_CALLBACK (device_state_changed), object); + g_signal_connect (priv->proxy, "notify::state-reason", + G_CALLBACK (device_state_reason_changed), object); } -typedef struct { - NMDeviceState old_state; - NMDeviceState new_state; - NMDeviceStateReason reason; -} StateChangeData; - static void -device_state_change_reloaded (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - NMDevice *self = NM_DEVICE (object); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - StateChangeData *data = user_data; - NMDeviceState old_state = data->old_state; - NMDeviceState new_state = data->new_state; - NMDeviceStateReason reason = data->reason; - - g_slice_free (StateChangeData, data); - - _nm_object_reload_properties_finish (NM_OBJECT (object), result, NULL); - - /* If the device changes state several times in rapid succession, then we'll - * queue several reload_properties() calls, and there's no guarantee that - * they'll finish in the right order. In that case, only emit the signal - * for the last one. - */ - if (priv->last_seen_state != new_state) - return; - - /* Ensure that nm_device_get_state() will return the right value even if - * we haven't processed the corresponding PropertiesChanged yet. - */ - priv->state = new_state; - - g_signal_emit (self, signals[STATE_CHANGED], 0, - new_state, old_state, reason); -} - -static void -device_state_changed (NMDBusDevice *proxy, - guint new_state, - guint old_state, - guint reason, - gpointer user_data) +device_state_reason_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NMDevice *self = NM_DEVICE (user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - StateChangeData *data; - - if (old_state == new_state) - return; - - /* Our object-valued properties (eg, ip4_config) will still - * have their old values at this point, because NMObject is - * in the process of asynchronously reading the new values. - * Wait for that to finish before emitting the signal. - */ - priv->last_seen_state = new_state; - - data = g_slice_new (StateChangeData); - data->old_state = old_state; - data->new_state = new_state; - data->reason = reason; - _nm_object_reload_properties_async (NM_OBJECT (user_data), - NULL, - device_state_change_reloaded, - data); -} - -static GType -_nm_device_gtype_from_dtype (NMDeviceType dtype) -{ - switch (dtype) { - case NM_DEVICE_TYPE_VETH: - case NM_DEVICE_TYPE_ETHERNET: - return NM_TYPE_DEVICE_ETHERNET; - case NM_DEVICE_TYPE_WIFI: - return NM_TYPE_DEVICE_WIFI; - case NM_DEVICE_TYPE_MODEM: - return NM_TYPE_DEVICE_MODEM; - case NM_DEVICE_TYPE_BT: - return NM_TYPE_DEVICE_BT; - case NM_DEVICE_TYPE_ADSL: - return NM_TYPE_DEVICE_ADSL; - case NM_DEVICE_TYPE_OLPC_MESH: - return NM_TYPE_DEVICE_OLPC_MESH; - case NM_DEVICE_TYPE_WIMAX: - return NM_TYPE_DEVICE_WIMAX; - case NM_DEVICE_TYPE_INFINIBAND: - return NM_TYPE_DEVICE_INFINIBAND; - case NM_DEVICE_TYPE_BOND: - return NM_TYPE_DEVICE_BOND; - case NM_DEVICE_TYPE_TEAM: - return NM_TYPE_DEVICE_TEAM; - case NM_DEVICE_TYPE_BRIDGE: - return NM_TYPE_DEVICE_BRIDGE; - case NM_DEVICE_TYPE_VLAN: - return NM_TYPE_DEVICE_VLAN; - case NM_DEVICE_TYPE_GENERIC: - return NM_TYPE_DEVICE_GENERIC; - case NM_DEVICE_TYPE_TUN: - return NM_TYPE_DEVICE_TUN; - case NM_DEVICE_TYPE_IP_TUNNEL: - return NM_TYPE_DEVICE_IP_TUNNEL; - case NM_DEVICE_TYPE_MACVLAN: - return NM_TYPE_DEVICE_MACVLAN; - case NM_DEVICE_TYPE_VXLAN: - return NM_TYPE_DEVICE_VXLAN; - default: - g_warning ("Unknown device type %d", dtype); - return G_TYPE_INVALID; - } -} - -static void -constructed (GObject *object) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); - - G_OBJECT_CLASS (nm_device_parent_class)->constructed (object); - /* Catch failure of subclasses to call _nm_device_set_device_type() */ - g_warn_if_fail (priv->device_type != NM_DEVICE_TYPE_UNKNOWN); - /* Catch a subclass setting the wrong type */ - g_warn_if_fail (G_OBJECT_TYPE (object) == _nm_device_gtype_from_dtype (priv->device_type)); + g_signal_emit (self, signals[STATE_CHANGED], 0, + priv->state, priv->last_seen_state, priv->reason); + priv->last_seen_state = priv->state; } static void @@ -571,11 +427,7 @@ nm_device_class_init (NMDeviceClass *device_class) g_type_class_add_private (device_class, sizeof (NMDevicePrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE); - _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_DEVICE, NMDBUS_TYPE_DEVICE_PROXY); - /* virtual methods */ - object_class->constructed = constructed; object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; @@ -954,35 +806,6 @@ nm_device_class_init (NMDeviceClass *device_class) } /** - * _nm_device_set_device_type: - * @device: the device - * @dtype: the NM device type - * - * Sets the NM device type if it wasn't set during construction. INTERNAL - * ONLY METHOD. - **/ -void -_nm_device_set_device_type (NMDevice *device, NMDeviceType dtype) -{ - NMDevicePrivate *priv; - - g_return_if_fail (device != NULL); - g_return_if_fail (dtype != NM_DEVICE_TYPE_UNKNOWN); - - priv = NM_DEVICE_GET_PRIVATE (device); - if (priv->device_type == NM_DEVICE_TYPE_UNKNOWN) - priv->device_type = dtype; - else - g_warn_if_fail (dtype == priv->device_type); -} - -static GType -_nm_device_decide_type (GVariant *value) -{ - return _nm_device_gtype_from_dtype (g_variant_get_uint32 (value)); -} - -/** * nm_device_get_iface: * @device: a #NMDevice * diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c index 26e89c2766..0e783576b3 100644 --- a/libnm/nm-dhcp4-config.c +++ b/libnm/nm-dhcp4-config.c @@ -33,7 +33,4 @@ nm_dhcp4_config_init (NMDhcp4Config *config) static void nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) { - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP4_CONFIG); } diff --git a/libnm/nm-dhcp6-config.c b/libnm/nm-dhcp6-config.c index f1556b208b..9252e734f8 100644 --- a/libnm/nm-dhcp6-config.c +++ b/libnm/nm-dhcp6-config.c @@ -33,7 +33,4 @@ nm_dhcp6_config_init (NMDhcp6Config *config) static void nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class) { - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP6_CONFIG); } diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index a57fc30f5c..322ea4e808 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -33,7 +33,4 @@ nm_ip4_config_init (NMIP4Config *config) static void nm_ip4_config_class_init (NMIP4ConfigClass *config_class) { - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_IP4_CONFIG); } diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c index 983c0465fa..93cdf332b6 100644 --- a/libnm/nm-ip6-config.c +++ b/libnm/nm-ip6-config.c @@ -33,7 +33,4 @@ nm_ip6_config_init (NMIP6Config *config) static void nm_ip6_config_class_init (NMIP6ConfigClass *config_class) { - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_IP6_CONFIG); } diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index e490104803..5a2918b7a9 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -29,12 +29,10 @@ #include "nm-common-macros.h" #include "nm-device-ethernet.h" #include "nm-device-wifi.h" -#include "nm-device-private.h" #include "nm-core-internal.h" #include "nm-object-private.h" #include "nm-active-connection.h" #include "nm-vpn-connection.h" -#include "nm-object-cache.h" #include "nm-dbus-helpers.h" #include "nmdbus-manager.h" @@ -91,7 +89,6 @@ enum { PROP_VERSION, PROP_STATE, PROP_STARTUP, - PROP_NM_RUNNING, PROP_NETWORKING_ENABLED, PROP_WIRELESS_ENABLED, PROP_WIRELESS_HARDWARE_ENABLED, @@ -124,10 +121,6 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -static void nm_running_changed_cb (GObject *object, - GParamSpec *pspec, - gpointer user_data); - /*****************************************************************************/ static void @@ -402,14 +395,6 @@ nm_manager_get_startup (NMManager *manager) } gboolean -nm_manager_get_nm_running (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return _nm_object_get_nm_running (NM_OBJECT (manager)); -} - -gboolean nm_manager_networking_get_enabled (NMManager *manager) { g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); @@ -758,8 +743,6 @@ typedef struct { char *new_connection_path; } ActivateInfo; -static void active_removed (NMObject *object, NMActiveConnection *active, gpointer user_data); - static void activate_info_complete (ActivateInfo *info, NMActiveConnection *active, @@ -767,7 +750,6 @@ activate_info_complete (ActivateInfo *info, { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (info->manager); - g_signal_handlers_disconnect_by_func (info->manager, G_CALLBACK (active_removed), info); if (active) g_simple_async_result_set_op_res_gpointer (info->simple, g_object_ref (active), g_object_unref); else @@ -812,6 +794,10 @@ recheck_pending_activations (NMManager *self) NMActiveConnection *candidate; const GPtrArray *devices; NMDevice *device; + GDBusObjectManager *object_manager = NULL; + GError *error; + + object_manager = _nm_object_get_dbus_object_manager (NM_OBJECT (self)); /* For each pending activation, look for an active connection that has the * pending activation's object path, where the active connection and its @@ -820,9 +806,25 @@ recheck_pending_activations (NMManager *self) */ for (iter = priv->pending_activations; iter; iter = next) { ActivateInfo *info = iter->data; + gs_unref_object GDBusObject *dbus_obj = NULL; next = g_slist_next (iter); + if (!info->active_path) + continue; + + /* Check that the object manager still knows about the object. + * It could be that it vanished before we even learned its name. */ + dbus_obj = g_dbus_object_manager_get_object (object_manager, info->active_path); + if (!dbus_obj) { + error = g_error_new_literal (NM_CLIENT_ERROR, + NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, + _("Active connection removed before it was initialized")); + activate_info_complete (info, NULL, error); + g_clear_error (&error); + break; + } + candidate = find_active_connection_by_path (self, info->active_path); if (!candidate) continue; @@ -858,22 +860,6 @@ activation_cancelled (GCancellable *cancellable, } static void -active_removed (NMObject *object, NMActiveConnection *active, gpointer user_data) -{ - ActivateInfo *info = user_data; - GError *error = NULL; - - if (strcmp (info->active_path, nm_object_get_path (NM_OBJECT (active)))) - return; - - error = g_error_new_literal (NM_CLIENT_ERROR, - NM_CLIENT_ERROR_FAILED, - _("Active connection could not be attached to the device")); - activate_info_complete (info, NULL, error); - g_clear_error (&error); -} - -static void activate_cb (GObject *object, GAsyncResult *result, gpointer user_data) @@ -889,9 +875,6 @@ activate_cb (GObject *object, G_CALLBACK (activation_cancelled), info); } - g_signal_connect (info->manager, "active-connection-removed", - G_CALLBACK (active_removed), info); - recheck_pending_activations (info->manager); } else { g_dbus_error_strip_remote_error (error); @@ -968,9 +951,6 @@ add_activate_cb (GObject *object, G_CALLBACK (activation_cancelled), info); } - g_signal_connect (info->manager, "active-connection-removed", - G_CALLBACK (active_removed), info); - recheck_pending_activations (info->manager); } else { g_dbus_error_strip_remote_error (error); @@ -1076,33 +1056,7 @@ static void active_connection_removed (NMManager *self, NMActiveConnection *ac) { g_signal_handlers_disconnect_by_func (ac, G_CALLBACK (ac_devices_changed), self); -} - -static void -object_creation_failed (NMObject *object, const char *failed_path) -{ - NMManager *self = NM_MANAGER (object); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - GError *error; - GSList *iter; - - /* A newly activated connection failed due to some immediate error - * and disappeared from active connection list. Make sure the - * callback gets called. - */ - error = g_error_new_literal (NM_CLIENT_ERROR, - NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, - _("Active connection removed before it was initialized")); - - for (iter = priv->pending_activations; iter; iter = iter->next) { - ActivateInfo *info = iter->data; - - if (g_strcmp0 (failed_path, info->active_path) == 0) { - activate_info_complete (info, NULL, error); - g_error_free (error); - return; - } - } + recheck_pending_activations (self); } gboolean @@ -1187,145 +1141,19 @@ nm_manager_deactivate_connection_finish (NMManager *manager, /*****************************************************************************/ static void -free_devices (NMManager *manager, gboolean in_dispose) +free_active_connections (NMManager *manager) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - gs_unref_ptrarray GPtrArray *real_devices = NULL; - gs_unref_ptrarray GPtrArray *all_devices = NULL; - GPtrArray *devices = NULL; - guint i, j; - - real_devices = priv->devices; - all_devices = priv->all_devices; - - if (in_dispose) { - priv->devices = NULL; - priv->all_devices = NULL; - } else { - priv->devices = g_ptr_array_new_with_free_func (g_object_unref); - priv->all_devices = g_ptr_array_new_with_free_func (g_object_unref); - } - - if (all_devices && all_devices->len > 0) - devices = all_devices; - else if (real_devices && real_devices->len > 0) - devices = real_devices; - - if (real_devices && devices != real_devices) { - for (i = 0; i < real_devices->len; i++) { - NMDevice *d = real_devices->pdata[i]; - - if (all_devices) { - for (j = 0; j < all_devices->len; j++) { - if (d == all_devices->pdata[j]) - goto next; - } - } - if (in_dispose) - device_removed (manager, d); - else - g_signal_emit (manager, signals[DEVICE_REMOVED], 0, d); -next: - ; - } - } - if (devices) { - for (i = 0; i < devices->len; i++) { - NMDevice *d = devices->pdata[i]; - - if (in_dispose) - device_removed (manager, d); - else - g_signal_emit (manager, signals[DEVICE_REMOVED], 0, d); - } - } -} - -static void -free_active_connections (NMManager *manager, gboolean in_dispose) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - GPtrArray *active_connections; - NMActiveConnection *active_connection; int i; if (!priv->active_connections) return; - active_connections = priv->active_connections; - if (in_dispose) - priv->active_connections = NULL; - else - priv->active_connections = g_ptr_array_new (); - - for (i = 0; i < active_connections->len; i++) { - active_connection = active_connections->pdata[i]; - g_signal_emit (manager, signals[ACTIVE_CONNECTION_REMOVED], 0, active_connection); - /* Break circular refs */ - g_object_run_dispose (G_OBJECT (active_connection)); - } - g_ptr_array_unref (active_connections); - - if (!in_dispose) - g_object_notify (G_OBJECT (manager), NM_MANAGER_ACTIVE_CONNECTIONS); -} - -static void -updated_properties (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMManager *manager = NM_MANAGER (user_data); - GError *error = NULL; - - if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s: error reading NMManager properties: %s", __func__, error->message); - g_error_free (error); - } - - _nm_object_queue_notify (NM_OBJECT (manager), NM_MANAGER_NM_RUNNING); -} - -static void -nm_running_changed_cb (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - NMManager *manager = NM_MANAGER (object); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - - if (!nm_manager_get_nm_running (manager)) { - nm_clear_g_cancellable (&priv->props_cancellable); - - priv->state = NM_STATE_UNKNOWN; - priv->startup = FALSE; - _nm_object_queue_notify (NM_OBJECT (manager), NM_MANAGER_NM_RUNNING); - _nm_object_suppress_property_updates (NM_OBJECT (manager), TRUE); - poke_wireless_devices_with_rf_status (manager); - free_devices (manager, FALSE); - free_active_connections (manager, FALSE); - update_permissions (manager, NULL); - priv->wireless_enabled = FALSE; - priv->wireless_hw_enabled = FALSE; - priv->wwan_enabled = FALSE; - priv->wwan_hw_enabled = FALSE; - priv->wimax_enabled = FALSE; - priv->wimax_hw_enabled = FALSE; - g_free (priv->version); - priv->version = NULL; - - /* Clear object cache to ensure bad refcounting by managers doesn't - * keep objects in the cache. - */ - _nm_object_cache_clear (); - } else { - _nm_object_suppress_property_updates (NM_OBJECT (manager), FALSE); - - nm_clear_g_cancellable (&priv->props_cancellable); - priv->props_cancellable = g_cancellable_new (); - _nm_object_reload_properties_async (NM_OBJECT (manager), priv->props_cancellable, updated_properties, manager); - - manager_recheck_permissions (priv->manager_proxy, manager); - } + /* Break circular refs */ + for (i = 0; i < priv->active_connections->len; i++) + g_object_run_dispose (G_OBJECT (priv->active_connections->pdata[i])); + g_ptr_array_unref (priv->active_connections); + priv->active_connections = NULL; } /*****************************************************************************/ @@ -1335,9 +1163,6 @@ constructed (GObject *object) { G_OBJECT_CLASS (nm_manager_parent_class)->constructed (object); - g_signal_connect (object, "notify::" NM_OBJECT_NM_RUNNING, - G_CALLBACK (nm_running_changed_cb), NULL); - g_signal_connect (object, "notify::" NM_MANAGER_WIRELESS_ENABLED, G_CALLBACK (wireless_enabled_cb), NULL); } @@ -1350,8 +1175,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) if (!nm_manager_parent_initable_iface->init (initable, cancellable, error)) return FALSE; - if ( nm_manager_get_nm_running (manager) - && !get_permissions_sync (manager, error)) + if (!get_permissions_sync (manager, error)) return FALSE; return TRUE; @@ -1402,11 +1226,6 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d return; } - if (!nm_manager_get_nm_running (init_data->manager)) { - init_async_complete (init_data); - return; - } - nmdbus_manager_call_get_permissions (priv->manager_proxy, init_data->cancellable, init_async_got_permissions, init_data); @@ -1452,8 +1271,17 @@ dispose (GObject *object) g_clear_object (&priv->perm_call_cancellable); } - free_devices (manager, TRUE); - free_active_connections (manager, TRUE); + + if (priv->devices) { + g_ptr_array_unref (priv->devices); + priv->devices = NULL; + } + if (priv->all_devices) { + g_ptr_array_unref (priv->all_devices); + priv->all_devices = NULL; + } + + free_active_connections (manager); g_clear_object (&priv->primary_connection); g_clear_object (&priv->activating_connection); @@ -1539,9 +1367,6 @@ get_property (GObject *object, case PROP_STARTUP: g_value_set_boolean (value, nm_manager_get_startup (self)); break; - case PROP_NM_RUNNING: - g_value_set_boolean (value, nm_manager_get_nm_running (self)); - break; case PROP_NETWORKING_ENABLED: g_value_set_boolean (value, nm_manager_networking_get_enabled (self)); break; @@ -1598,9 +1423,6 @@ nm_manager_class_init (NMManagerClass *manager_class) g_type_class_add_private (manager_class, sizeof (NMManagerPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE); - _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE, NMDBUS_TYPE_MANAGER_PROXY); - /* virtual methods */ object_class->constructed = constructed; object_class->set_property = set_property; @@ -1609,7 +1431,6 @@ nm_manager_class_init (NMManagerClass *manager_class) object_class->finalize = finalize; nm_object_class->init_dbus = init_dbus; - nm_object_class->object_creation_failed = object_creation_failed; manager_class->device_added = device_added; manager_class->device_removed = device_removed; @@ -1638,12 +1459,6 @@ nm_manager_class_init (NMManagerClass *manager_class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property - (object_class, PROP_NM_RUNNING, - g_param_spec_boolean (NM_MANAGER_NM_RUNNING, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, PROP_NETWORKING_ENABLED, g_param_spec_boolean (NM_MANAGER_NETWORKING_ENABLED, "", "", TRUE, diff --git a/libnm/nm-manager.h b/libnm/nm-manager.h index 2785c680f6..362b5f2f43 100644 --- a/libnm/nm-manager.h +++ b/libnm/nm-manager.h @@ -37,7 +37,6 @@ G_BEGIN_DECLS #define NM_MANAGER_VERSION "version" #define NM_MANAGER_STATE "state" #define NM_MANAGER_STARTUP "startup" -#define NM_MANAGER_NM_RUNNING "nm-running" #define NM_MANAGER_NETWORKING_ENABLED "networking-enabled" #define NM_MANAGER_WIRELESS_ENABLED "wireless-enabled" #define NM_MANAGER_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled" @@ -80,7 +79,6 @@ GType nm_manager_get_type (void); const char *nm_manager_get_version (NMManager *manager); NMState nm_manager_get_state (NMManager *manager); gboolean nm_manager_get_startup (NMManager *manager); -gboolean nm_manager_get_nm_running (NMManager *manager); gboolean nm_manager_networking_get_enabled (NMManager *manager); gboolean nm_manager_networking_set_enabled (NMManager *manager, diff --git a/libnm/nm-object-cache.c b/libnm/nm-object-cache.c deleted file mode 100644 index fa56ace53b..0000000000 --- a/libnm/nm-object-cache.c +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include <string.h> - -#include "nm-object-cache.h" -#include "nm-object.h" - -static GHashTable *cache = NULL; - -static void -_init_cache (void) -{ - if (G_UNLIKELY (cache == NULL)) - cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); -} - -static void -_nm_object_cache_remove_by_path (char *path) -{ - _init_cache (); - g_hash_table_remove (cache, path); - g_free (path); -} - -void -_nm_object_cache_add (NMObject *object) -{ - char *path; - - _init_cache (); - path = g_strdup (nm_object_get_path (object)); - g_hash_table_insert (cache, path, object); - g_object_set_data_full (G_OBJECT (object), "nm-object-cache-tag", - g_strdup (path), (GDestroyNotify) _nm_object_cache_remove_by_path); -} - -NMObject * -_nm_object_cache_get (const char *path) -{ - NMObject *object; - - _init_cache (); - object = g_hash_table_lookup (cache, path); - return object ? g_object_ref (object) : NULL; -} - -void -_nm_object_cache_clear (void) -{ - GHashTableIter iter; - GObject *obj; - const char *path; - char *foo; - - if (!cache) - return; - - g_hash_table_iter_init (&iter, cache); - while (g_hash_table_iter_next (&iter, (gpointer) &path, (gpointer) &obj)) { - /* Remove the callback so that if the object isn't yet released - * by a client, when it does finally get unrefed, it won't trigger - * the cache removal for a new object with the same path as the - * one being released. - */ - foo = g_object_steal_data (obj, "nm-object-cache-tag"); - g_free (foo); - - g_hash_table_iter_remove (&iter); - } -} diff --git a/libnm/nm-object-cache.h b/libnm/nm-object-cache.h deleted file mode 100644 index b29692faa1..0000000000 --- a/libnm/nm-object-cache.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 Red Hat, Inc. - */ - -#ifndef __NM_OBJECT_CACHE_H__ -#define __NM_OBJECT_CACHE_H__ - -#include "nm-object.h" - -G_BEGIN_DECLS - -/* Returns referenced object from the cache */ -NMObject *_nm_object_cache_get (const char *path); -void _nm_object_cache_add (NMObject *object); -void _nm_object_cache_clear (void); - -G_END_DECLS - -#endif /* __NM_OBJECT_CACHE_H__ */ diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h index ad78f92ba0..63c4142d81 100644 --- a/libnm/nm-object-private.h +++ b/libnm/nm-object-private.h @@ -39,23 +39,13 @@ void _nm_object_register_properties (NMObject *object, const char *interface, const NMPropertiesInfo *info); -void _nm_object_reload_properties_async (NMObject *object, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean _nm_object_reload_properties_finish (NMObject *object, - GAsyncResult *result, - GError **error); - void _nm_object_queue_notify (NMObject *object, const char *property); -void _nm_object_suppress_property_updates (NMObject *object, gboolean suppress); +GDBusObjectManager *_nm_object_get_dbus_object_manager (NMObject *object); -/* DBus property accessors */ +GQuark _nm_object_obj_nm_quark (void); -void _nm_object_reload_property (NMObject *object, - const char *interface, - const char *prop_name); +/* DBus property accessors */ void _nm_object_set_property (NMObject *object, const char *interface, @@ -63,19 +53,6 @@ void _nm_object_set_property (NMObject *object, const char *format_string, ...); -/* object demarshalling support */ -typedef GType (*NMObjectDecideTypeFunc) (GVariant *); - -void _nm_object_register_type_func (GType base_type, - NMObjectDecideTypeFunc type_func, - const char *interface, - const char *property); - -#define NM_OBJECT_NM_RUNNING "nm-running-internal" -gboolean _nm_object_get_nm_running (NMObject *self); - -void _nm_object_class_add_interface (NMObjectClass *object_class, - const char *interface); GDBusProxy *_nm_object_get_proxy (NMObject *object, const char *interface); diff --git a/libnm/nm-object.c b/libnm/nm-object.c index aa1c177b2f..abade94b8d 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -29,7 +29,6 @@ #include "nm-utils.h" #include "nm-dbus-interface.h" -#include "nm-object-cache.h" #include "nm-object-private.h" #include "nm-dbus-helpers.h" #include "nm-client.h" @@ -38,25 +37,18 @@ static gboolean debug = FALSE; #define dbgmsg(f,...) if (G_UNLIKELY (debug)) { g_message (f, ## __VA_ARGS__ ); } +G_DEFINE_QUARK (nm-obj-nm, _nm_object_obj_nm); + static void nm_object_initable_iface_init (GInitableIface *iface); static void nm_object_async_initable_iface_init (GAsyncInitableIface *iface); typedef struct { - NMObjectDecideTypeFunc type_func; - char *interface; - char *property; -} NMObjectTypeFuncData; - -static GHashTable *type_funcs; - -typedef struct { GSList *interfaces; } NMObjectClassPrivate; #define NM_OBJECT_CLASS_GET_PRIVATE(k) (G_TYPE_CLASS_GET_PRIVATE ((k), NM_TYPE_OBJECT, NMObjectClassPrivate)) G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMObject, nm_object, G_TYPE_OBJECT, - type_funcs = g_hash_table_new (NULL, NULL); g_type_add_class_private (g_define_type_id, sizeof (NMObjectClassPrivate)); G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_object_initable_iface_init); G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_object_async_initable_iface_init); @@ -75,15 +67,11 @@ static void reload_complete (NMObject *object, gboolean emit_now); static gboolean demarshal_generic (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field); typedef struct { - GDBusConnection *connection; - gboolean nm_running; + GDBusObject *object; + GDBusObjectManager *object_manager; - char *path; - GHashTable *proxies; - GDBusProxy *properties_proxy; GSList *property_tables; NMObject *parent; - gboolean suppress_property_updates; gboolean inited; /* async init finished? */ GSList *waiters; /* if async init did not finish, users of this object need @@ -104,50 +92,27 @@ enum { PROP_PATH, PROP_DBUS_CONNECTION, PROP_NM_RUNNING, + PROP_DBUS_OBJECT, + PROP_DBUS_OBJECT_MANAGER, LAST_PROP }; /** - * _nm_object_class_add_interface: - * @object_class: an #NMObjectClass - * @interface: a D-Bus interface name - * - * Registers that @object_class implements @interface. A proxy for that - * interface will automatically be created at construction time, and can - * be retrieved with _nm_object_get_proxy(). - */ -void -_nm_object_class_add_interface (NMObjectClass *object_class, - const char *interface) -{ - NMObjectClassPrivate *cpriv; - - g_return_if_fail (NM_IS_OBJECT_CLASS (object_class)); - g_return_if_fail (interface); - - cpriv = NM_OBJECT_CLASS_GET_PRIVATE (object_class); - - g_return_if_fail (g_slist_find_custom (cpriv->interfaces, interface, (GCompareFunc) g_strcmp0) == NULL); - - cpriv->interfaces = g_slist_prepend (cpriv->interfaces, g_strdup (interface)); -} - -/** * nm_object_get_path: * @object: a #NMObject * * Gets the DBus path of the #NMObject. * * Returns: the object's path. This is the internal string used by the - * device, and must not be modified. + * object, and must not be modified. **/ const char * nm_object_get_path (NMObject *object) { g_return_val_if_fail (NM_IS_OBJECT (object), NULL); - return NM_OBJECT_GET_PRIVATE (object)->path; + return g_dbus_object_get_object_path (NM_OBJECT_GET_PRIVATE (object)->object); } /** @@ -163,13 +128,14 @@ GDBusProxy * _nm_object_get_proxy (NMObject *object, const char *interface) { - GDBusProxy *proxy; + GDBusInterface *proxy; g_return_val_if_fail (NM_IS_OBJECT (object), NULL); - proxy = g_hash_table_lookup (NM_OBJECT_GET_PRIVATE (object)->proxies, interface); + proxy = g_dbus_object_get_interface (NM_OBJECT_GET_PRIVATE (object)->object, interface); g_return_val_if_fail (proxy != NULL, NULL); - return proxy; + + return G_DBUS_PROXY (proxy); } typedef enum { @@ -351,97 +317,6 @@ _nm_object_queue_notify (NMObject *object, const char *property) _nm_object_queue_notify_full (object, property, NULL, FALSE, NULL); } -void -_nm_object_register_type_func (GType base_type, - NMObjectDecideTypeFunc type_func, - const char *interface, - const char *property) -{ - NMObjectTypeFuncData *type_data; - - g_return_if_fail (type_func != NULL); - g_return_if_fail (interface != NULL); - g_return_if_fail (property != NULL); - - type_data = g_slice_new (NMObjectTypeFuncData); - type_data->type_func = type_func; - type_data->interface = g_strdup (interface); - type_data->property = g_strdup (property); - - g_hash_table_insert (type_funcs, - GSIZE_TO_POINTER (base_type), - type_data); -} - -static GObject * -_nm_object_create (GType type, GDBusConnection *connection, const char *path) -{ - NMObjectTypeFuncData *type_data; - GObject *object; - GError *error = NULL; - - type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type)); - if (type_data) { - GDBusProxy *proxy; - GVariant *ret, *value; - - proxy = _nm_dbus_new_proxy_for_connection (connection, path, - DBUS_INTERFACE_PROPERTIES, - NULL, &error); - if (!proxy) { - g_warning ("Could not create proxy for %s: %s.", path, error->message); - g_error_free (error); - return NULL; - } - - ret = g_dbus_proxy_call_sync (proxy, - "Get", - g_variant_new ("(ss)", - type_data->interface, - type_data->property), - G_DBUS_CALL_FLAGS_NONE, -1, - NULL, &error); - g_object_unref (proxy); - if (!ret) { - dbgmsg ("Could not fetch property '%s' of interface '%s' on %s: %s\n", - type_data->property, type_data->interface, path, error->message); - g_error_free (error); - return NULL; - } - - g_variant_get (ret, "(v)", &value); - type = type_data->type_func (value); - g_variant_unref (value); - g_variant_unref (ret); - } - - if (type == G_TYPE_INVALID) { - dbgmsg ("Could not create object for %s: unknown object type", path); - return NULL; - } - - object = g_object_new (type, - NM_OBJECT_PATH, path, - NM_OBJECT_DBUS_CONNECTION, connection, - NULL); - /* Cache the object before initializing it (and in particular, loading its - * property values); this is necessary to make circular references work (eg, - * when creating an NMActiveConnection, it will create an NMDevice which - * will in turn try to create the parent NMActiveConnection). Since we don't - * support multi-threaded use, we know that we will have inited the object - * before any external code sees it. - */ - _nm_object_cache_add (NM_OBJECT (object)); - NM_OBJECT_GET_PRIVATE (object)->inited = TRUE; - if (!g_initable_init (G_INITABLE (object), NULL, &error)) { - dbgmsg ("Could not create object for %s: %s", path, error->message); - g_error_free (error); - g_clear_object (&object); - } - - return object; -} - typedef struct { NMObject *self; PropertyInfo *pi; @@ -465,176 +340,6 @@ odata_free (gpointer data) static void object_property_maybe_complete (NMObject *self); - -typedef void (*NMObjectCreateCallbackFunc) (GObject *, const char *, gpointer); -typedef struct { - char *path; - NMObjectCreateCallbackFunc callback; - gpointer user_data; - NMObjectTypeFuncData *type_data; - GDBusConnection *connection; -} NMObjectTypeAsyncData; - -static void -create_async_complete (GObject *object, NMObjectTypeAsyncData *async_data) -{ - async_data->callback (object, async_data->path, async_data->user_data); - - g_free (async_data->path); - g_object_unref (async_data->connection); - g_slice_free (NMObjectTypeAsyncData, async_data); -} - -static void -create_async_inited (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - NMObjectPrivate *odata_priv; - NMObjectTypeAsyncData *async_data = user_data; - GError *error = NULL; - ObjectCreatedData *odata; - - priv->inited = TRUE; - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) { - dbgmsg ("Could not create object for %s: %s", - nm_object_get_path (NM_OBJECT (object)), - error->message); - - while (priv->waiters) { - odata = priv->waiters->data; - odata_priv = NM_OBJECT_GET_PRIVATE (odata->self); - - priv->waiters = g_slist_remove (priv->waiters, odata); - if (!odata_priv->reload_error) - odata_priv->reload_error = g_error_copy (error); - odata_priv->reload_remaining--; - reload_complete (odata->self, FALSE); - } - - g_error_free (error); - g_clear_object (&object); - } - - create_async_complete (object, async_data); - - if (object) { - /* There are some object properties whose creation couldn't proceed - * because it depended on this object. */ - while (priv->waiters) { - odata = priv->waiters->data; - priv->waiters = g_slist_remove (priv->waiters, odata); - object_property_maybe_complete (odata->self); - } - } -} - -static void -create_async_got_type (NMObjectTypeAsyncData *async_data, GType type) -{ - GObject *object; - - /* Ensure we don't have the object already; we may get multiple type - * requests for the same object if there are multiple properties on - * other objects that refer to the object at this path. One of those - * other requests may have already completed. - */ - object = (GObject *) _nm_object_cache_get (async_data->path); - if (object) { - create_async_complete (object, async_data); - return; - } - - if (type == G_TYPE_INVALID) { - /* Don't know how to create this object */ - create_async_complete (NULL, async_data); - return; - } - - object = g_object_new (type, - NM_OBJECT_PATH, async_data->path, - NM_OBJECT_DBUS_CONNECTION, async_data->connection, - NULL); - _nm_object_cache_add (NM_OBJECT (object)); - g_async_initable_init_async (G_ASYNC_INITABLE (object), G_PRIORITY_DEFAULT, - NULL, create_async_inited, async_data); -} - -static void -create_async_got_property (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - NMObjectTypeAsyncData *async_data = user_data; - NMObjectTypeFuncData *type_data = async_data->type_data; - GVariant *ret, *value; - GError *error = NULL; - GType type; - - ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, - G_VARIANT_TYPE ("(v)"), &error); - if (ret) { - g_variant_get (ret, "(v)", &value); - type = type_data->type_func (value); - g_variant_unref (value); - g_variant_unref (ret); - } else { - dbgmsg ("Could not fetch property '%s' of interface '%s' on %s: %s\n", - type_data->property, type_data->interface, async_data->path, - error->message); - g_clear_error (&error); - type = G_TYPE_INVALID; - } - - create_async_got_type (async_data, type); -} - -static void -create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMObjectTypeAsyncData *async_data = user_data; - GDBusProxy *proxy; - GError *error = NULL; - - proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error); - if (!proxy) { - g_warning ("Could not create proxy for %s: %s.", async_data->path, error->message); - g_error_free (error); - create_async_complete (NULL, async_data); - return; - } - - g_dbus_proxy_call (proxy, - "Get", - g_variant_new ("(ss)", - async_data->type_data->interface, - async_data->type_data->property), - G_DBUS_CALL_FLAGS_NONE, -1, - NULL, - create_async_got_property, async_data); -} - -static void -_nm_object_create_async (GType type, GDBusConnection *connection, const char *path, - NMObjectCreateCallbackFunc callback, gpointer user_data) -{ - NMObjectTypeAsyncData *async_data; - - async_data = g_slice_new (NMObjectTypeAsyncData); - async_data->path = g_strdup (path); - async_data->callback = callback; - async_data->user_data = user_data; - async_data->connection = g_object_ref (connection); - - async_data->type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type)); - if (async_data->type_data) { - _nm_dbus_new_proxy_for_connection_async (connection, path, - DBUS_INTERFACE_PROPERTIES, - NULL, - create_async_got_proxy, async_data); - return; - } - - create_async_got_type (async_data, type); -} - /* Stolen from dbus-glib */ static char* wincaps_to_dash (const char *caps) @@ -855,15 +560,16 @@ object_created (GObject *obj, const char *path, gpointer user_data) object_class->object_creation_failed (odata->self, path); } - odata->objects[--odata->remaining] = obj; + odata->objects[--odata->remaining] = obj ? g_object_ref (obj) : NULL; object_property_maybe_complete (odata->self); } static gboolean handle_object_property (NMObject *self, const char *property_name, GVariant *value, - PropertyInfo *pi, gboolean synchronously) + PropertyInfo *pi) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + gs_unref_object GDBusObject *object = NULL; GObject *obj; const char *path; ObjectCreatedData *odata; @@ -886,31 +592,28 @@ handle_object_property (NMObject *self, const char *property_name, GVariant *val return TRUE; } - obj = G_OBJECT (_nm_object_cache_get (path)); - if (obj) { - object_created (obj, path, odata); - return TRUE; - } else if (synchronously) { - obj = _nm_object_create (pi->object_type, priv->connection, path); - object_created (obj, path, odata); - return obj != NULL; - } else { - _nm_object_create_async (pi->object_type, priv->connection, path, - object_created, odata); - /* Assume success */ - return TRUE; + object = g_dbus_object_manager_get_object (priv->object_manager, path); + if (!object) { + /* This is a server bug -- a dangling object path for an object + * that does not exist. */ + g_warning ("No object known for %s", path); + return FALSE; } + + obj = g_object_get_qdata (G_OBJECT (object), _nm_object_obj_nm_quark ()); + object_created (obj, path, odata); + + return TRUE; } static gboolean handle_object_array_property (NMObject *self, const char *property_name, GVariant *value, - PropertyInfo *pi, gboolean synchronously) + PropertyInfo *pi) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); GObject *obj; GVariantIter iter; gsize npaths; - GPtrArray **array = pi->field; const char *path; ObjectCreatedData *odata; @@ -934,34 +637,28 @@ handle_object_array_property (NMObject *self, const char *property_name, GVarian g_variant_iter_init (&iter, value); while (g_variant_iter_next (&iter, "&o", &path)) { + gs_unref_object GDBusObject *object = NULL; + if (!strcmp (path, "/")) { /* FIXME: can't happen? */ continue; } - obj = G_OBJECT (_nm_object_cache_get (path)); - if (obj) { - object_created (obj, path, odata); - } else if (synchronously) { - obj = _nm_object_create (pi->object_type, priv->connection, path); - object_created (obj, path, odata); - } else { - _nm_object_create_async (pi->object_type, priv->connection, path, - object_created, odata); + object = g_dbus_object_manager_get_object (priv->object_manager, path); + if (!object) { + g_warning ("no object known for %s\n", path); + return FALSE; } - } - if (!synchronously) { - /* Assume success */ - return TRUE; + obj = g_object_get_qdata (G_OBJECT (object), _nm_object_obj_nm_quark ()); + object_created (obj, path, odata); } - return *array && ((*array)->len == npaths); + return TRUE; } static void -handle_property_changed (NMObject *self, const char *dbus_name, - GVariant *value, gboolean synchronously) +handle_property_changed (NMObject *self, const char *dbus_name, GVariant *value) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); char *prop_name; @@ -1015,9 +712,9 @@ handle_property_changed (NMObject *self, const char *dbus_name, if (pspec && pi->object_type) { if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) - success = handle_object_property (self, pspec->name, value, pi, synchronously); + success = handle_object_property (self, pspec->name, value, pi); else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("ao"))) - success = handle_object_array_property (self, pspec->name, value, pi, synchronously); + success = handle_object_array_property (self, pspec->name, value, pi); else { g_warn_if_reached (); goto out; @@ -1037,31 +734,23 @@ out: } static void -process_properties_changed (NMObject *self, GVariant *properties, gboolean synchronously) +properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + GStrv invalidated_properties, + gpointer user_data) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + NMObject *self = NM_OBJECT (user_data); GVariantIter iter; const char *name; GVariant *value; - if (priv->suppress_property_updates) - return; - - g_variant_iter_init (&iter, properties); + g_variant_iter_init (&iter, changed_properties); while (g_variant_iter_next (&iter, "{&sv}", &name, &value)) { - handle_property_changed (self, name, value, synchronously); + handle_property_changed (self, name, value); g_variant_unref (value); } } -static void -properties_changed (GDBusProxy *proxy, - GVariant *properties, - gpointer user_data) -{ - process_properties_changed (NM_OBJECT (user_data), properties, FALSE); -} - #define HANDLE_TYPE(vtype, ctype, getter) \ G_STMT_START { \ if (g_variant_is_of_type (value, vtype)) { \ @@ -1240,10 +929,8 @@ _nm_object_register_properties (NMObject *object, } proxy = _nm_object_get_proxy (object, interface); - g_return_if_fail (proxy != NULL); - - _nm_dbus_signal_connect (proxy, "PropertiesChanged", G_VARIANT_TYPE ("(a{sv})"), - G_CALLBACK (properties_changed), object); + g_signal_connect (proxy, "g-properties-changed", + G_CALLBACK (properties_changed), object); instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->property_tables = g_slist_prepend (priv->property_tables, instance); @@ -1265,92 +952,6 @@ _nm_object_register_properties (NMObject *object, } } -static gboolean -_nm_object_reload_properties (NMObject *object, GError **error) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GVariant *ret, *props; - GHashTableIter iter; - const char *interface; - GDBusProxy *proxy; - - if (!g_hash_table_size (priv->proxies) || !priv->nm_running) - return TRUE; - - priv->reload_remaining++; - - g_hash_table_iter_init (&iter, priv->proxies); - while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) { - ret = _nm_dbus_proxy_call_sync (priv->properties_proxy, - "GetAll", - g_variant_new ("(s)", interface), - G_VARIANT_TYPE ("(a{sv})"), - G_DBUS_CALL_FLAGS_NONE, -1, - NULL, error); - if (!ret) { - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return FALSE; - } - - g_variant_get (ret, "(@a{sv})", &props); - process_properties_changed (object, props, TRUE); - g_variant_unref (props); - g_variant_unref (ret); - } - - if (--priv->reload_remaining == 0) - reload_complete (object, TRUE); - - return TRUE; -} - -void -_nm_object_suppress_property_updates (NMObject *object, gboolean suppress) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - - priv->suppress_property_updates = suppress; -} - - -void -_nm_object_reload_property (NMObject *object, - const char *interface, - const char *prop_name) -{ - GVariant *ret, *value; - GError *err = NULL; - - g_return_if_fail (NM_IS_OBJECT (object)); - g_return_if_fail (interface != NULL); - g_return_if_fail (prop_name != NULL); - - if (!NM_OBJECT_GET_PRIVATE (object)->nm_running) - return; - - ret = _nm_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, - "Get", - g_variant_new ("(ss)", interface, prop_name), - G_VARIANT_TYPE ("(v)"), - G_DBUS_CALL_FLAGS_NONE, 15000, - NULL, &err); - if (!ret) { - dbgmsg ("%s: Error getting '%s' for %s: %s\n", - __func__, - prop_name, - nm_object_get_path (object), - err->message); - g_clear_error (&err); - return; - } - - g_variant_get (ret, "(v)", &value); - handle_property_changed (object, prop_name, value, TRUE); - g_variant_unref (value); - g_variant_unref (ret); -} - void _nm_object_set_property (NMObject *object, const char *interface, @@ -1366,16 +967,13 @@ _nm_object_set_property (NMObject *object, g_return_if_fail (prop_name != NULL); g_return_if_fail (format_string != NULL); - if (!NM_OBJECT_GET_PRIVATE (object)->nm_running) - return; - va_start (ap, format_string); val = g_variant_new_va (format_string, NULL, &ap); va_end (ap); g_return_if_fail (val != NULL); - ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, - "Set", + ret = g_dbus_proxy_call_sync (_nm_object_get_proxy (object, interface), + DBUS_INTERFACE_PROPERTIES ".Set", g_variant_new ("(ssv)", interface, prop_name, val), G_DBUS_CALL_FLAGS_NONE, 2000, NULL, NULL); @@ -1418,139 +1016,40 @@ reload_complete (NMObject *object, gboolean emit_now) g_clear_error (&error); } -static void -reload_got_properties (GObject *proxy, - GAsyncResult *result, - gpointer user_data) -{ - NMObject *object = user_data; - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GVariant *ret, *props; - GError *error = NULL; - - ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, - G_VARIANT_TYPE ("(a{sv})"), - &error); - if (ret) { - g_variant_get (ret, "(@a{sv})", &props); - process_properties_changed (object, props, FALSE); - g_variant_unref (props); - g_variant_unref (ret); - } else { - g_dbus_error_strip_remote_error (error); - if (priv->reload_error) - g_error_free (error); - else - priv->reload_error = error; - } - - if (--priv->reload_remaining == 0) - reload_complete (object, FALSE); -} - -void -_nm_object_reload_properties_async (NMObject *object, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GSimpleAsyncResult *simple; - GHashTableIter iter; - const char *interface; - GDBusProxy *proxy; - - simple = g_simple_async_result_new (G_OBJECT (object), callback, - user_data, _nm_object_reload_properties_async); - - if (!g_hash_table_size (priv->proxies) || !priv->nm_running) { - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - return; - } - - priv->reload_results = g_slist_prepend (priv->reload_results, simple); - - /* If there was already a reload happening, we don't need to - * re-read the properties again, we just need to wait for the - * existing reload to finish. - */ - if (priv->reload_results->next) - return; - - g_hash_table_iter_init (&iter, priv->proxies); - while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) { - priv->reload_remaining++; - g_dbus_proxy_call (priv->properties_proxy, - "GetAll", - g_variant_new ("(s)", interface), - G_DBUS_CALL_FLAGS_NONE, -1, - cancellable, - reload_got_properties, object); - } -} - -gboolean -_nm_object_reload_properties_finish (NMObject *object, GAsyncResult *result, GError **error) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GSimpleAsyncResult *simple; - - g_return_val_if_fail (NM_IS_OBJECT (object), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (object), _nm_object_reload_properties_async), FALSE); - - /* NM might have disappeared meanwhile. That would cause a NoReply error to be emitted, - * but we don't care if property updates were disabled. */ - if (priv->suppress_property_updates) - return TRUE; - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - return g_simple_async_result_get_op_res_gboolean (simple); -} - -gboolean -_nm_object_get_nm_running (NMObject *self) +GDBusObjectManager * +_nm_object_get_dbus_object_manager (NMObject *self) { - return NM_OBJECT_GET_PRIVATE (self)->nm_running; + return NM_OBJECT_GET_PRIVATE (self)->object_manager; } /*****************************************************************************/ static void -on_name_owner_changed (GObject *proxy, - GParamSpec *pspec, - gpointer user_data) +init_dbus (NMObject *object) { - NMObject *self = NM_OBJECT (user_data); - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - gboolean now_running; - char *owner; - - now_running = ((owner = g_dbus_proxy_get_name_owner (priv->properties_proxy)) != NULL); - g_free (owner); - if (now_running != priv->nm_running) { - priv->nm_running = now_running; - g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING); - } } static void -init_dbus (NMObject *object) +init_if (GDBusInterface *interface, gpointer user_data) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - char *owner; - - if (_nm_dbus_is_connection_private (priv->connection)) - priv->nm_running = TRUE; - else { - priv->nm_running = ((owner = g_dbus_proxy_get_name_owner (priv->properties_proxy)) != NULL); - g_free (owner); - g_signal_connect (priv->properties_proxy, "notify::g-name-owner", - G_CALLBACK (on_name_owner_changed), object); + NMObject *self = NM_OBJECT (user_data); + GDBusProxy *proxy = G_DBUS_PROXY (interface); + gchar **props; + char **prop; + GVariant *val; + gchar *str; + + props = g_dbus_proxy_get_cached_property_names (proxy); + + for (prop = props; *prop; prop++) { + val = g_dbus_proxy_get_cached_property (proxy, *prop); + str = g_variant_print (val, TRUE); + handle_property_changed (self, *prop, val); + g_variant_unref (val); + g_free (str); } + + g_strfreev (props); } static gboolean @@ -1558,42 +1057,33 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { NMObject *self = NM_OBJECT (initable); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (self)); - GSList *iter; + GList *interfaces; - if (!priv->path) { - g_set_error_literal (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, - _("Caller did not specify D-Bus path for object")); - return FALSE; - } + g_assert (priv->object && priv->object_manager); - if (!priv->connection) - priv->connection = _nm_dbus_new_connection (cancellable, error); - if (!priv->connection) - return FALSE; + NM_OBJECT_GET_CLASS (self)->init_dbus (self); - /* Create proxies */ - for (iter = cpriv->interfaces; iter; iter = iter->next) { - const char *interface = iter->data; - GDBusProxy *proxy; + priv->reload_remaining++; - proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface, - cancellable, error); - if (!proxy) - return FALSE; - g_hash_table_insert (priv->proxies, (char *) interface, proxy); - } + interfaces = g_dbus_object_get_interfaces (priv->object); + g_list_foreach (interfaces, (GFunc) init_if, self); + g_list_free_full (interfaces, g_object_unref); - priv->properties_proxy = _nm_dbus_new_proxy_for_connection (priv->connection, - priv->path, - DBUS_INTERFACE_PROPERTIES, - cancellable, error); - if (!priv->properties_proxy) - return FALSE; + priv->inited = TRUE; - NM_OBJECT_GET_CLASS (self)->init_dbus (self); + if (--priv->reload_remaining == 0) + reload_complete (self, TRUE); + + /* There are some object properties whose creation couldn't proceed + * because it depended on this object. */ + while (priv->waiters) { + ObjectCreatedData *odata = priv->waiters->data; - return _nm_object_reload_properties (self, error); + priv->waiters = g_slist_remove (priv->waiters, odata); + object_property_maybe_complete (odata->self); + } + + return TRUE; } /*****************************************************************************/ @@ -1613,88 +1103,13 @@ init_async_complete (NMObjectInitData *init_data) g_simple_async_result_take_error (init_data->simple, init_data->error); else g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE); - g_simple_async_result_complete (init_data->simple); + g_simple_async_result_complete_in_idle (init_data->simple); g_object_unref (init_data->simple); g_clear_object (&init_data->cancellable); g_slice_free (NMObjectInitData, init_data); } static void -init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMObjectInitData *init_data = user_data; - - _nm_object_reload_properties_finish (NM_OBJECT (object), result, &init_data->error); - init_async_complete (init_data); -} - -static void -init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMObjectInitData *init_data = user_data; - NMObject *self = init_data->object; - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - GDBusProxy *proxy; - - if (!init_data->error) { - proxy = _nm_dbus_new_proxy_for_connection_finish (result, &init_data->error); - if (proxy) { - const char *interface = g_dbus_proxy_get_interface_name (proxy); - - if (!strcmp (interface, DBUS_INTERFACE_PROPERTIES)) - priv->properties_proxy = proxy; - else - g_hash_table_insert (priv->proxies, (char *) interface, proxy); - } - } - - init_data->proxies_pending--; - if (init_data->proxies_pending) - return; - - if (init_data->error) { - init_async_complete (init_data); - return; - } - - NM_OBJECT_GET_CLASS (self)->init_dbus (self); - - _nm_object_reload_properties_async (init_data->object, init_data->cancellable, init_async_got_properties, init_data); -} - -static void -init_async_got_bus (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMObjectInitData *init_data = user_data; - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (init_data->object); - NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (init_data->object)); - GSList *iter; - - priv->connection = _nm_dbus_new_connection_finish (result, &init_data->error); - if (!priv->connection) { - init_async_complete (init_data); - return; - } - - for (iter = cpriv->interfaces; iter; iter = iter->next) { - const char *interface = iter->data; - - _nm_dbus_new_proxy_for_connection_async (priv->connection, - priv->path, interface, - init_data->cancellable, - init_async_got_proxy, init_data); - init_data->proxies_pending++; - } - - _nm_dbus_new_proxy_for_connection_async (priv->connection, - priv->path, - DBUS_INTERFACE_PROPERTIES, - init_data->cancellable, - init_async_got_proxy, init_data); - init_data->proxies_pending++; -} - -static void init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1702,29 +1117,40 @@ init_async (GAsyncInitable *initable, int io_priority, NMObject *self = NM_OBJECT (initable); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectInitData *init_data; + GList *interfaces; - if (!priv->path) { - g_simple_async_report_error_in_idle (G_OBJECT (initable), - callback, user_data, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, - "%s", - _("Caller did not specify D-Bus path for object")); - return; - } + g_assert (priv->object && priv->object_manager); + + NM_OBJECT_GET_CLASS (self)->init_dbus (self); init_data = g_slice_new0 (NMObjectInitData); init_data->object = self; init_data->simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - _nm_dbus_new_connection_async (cancellable, init_async_got_bus, init_data); + interfaces = g_dbus_object_get_interfaces (priv->object); + g_list_foreach (interfaces, (GFunc) init_if, self); + g_list_free_full (interfaces, g_object_unref); + + init_async_complete (init_data); } static gboolean init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (initable); + + priv->inited = TRUE; + + /* There are some object properties whose creation couldn't proceed + * because it depended on this object. */ + while (priv->waiters) { + ObjectCreatedData *odata = priv->waiters->data; + + priv->waiters = g_slist_remove (priv->waiters, odata); + object_property_maybe_complete (odata->self); + } if (g_simple_async_result_propagate_error (simple, error)) return FALSE; @@ -1750,9 +1176,6 @@ nm_object_async_initable_iface_init (GAsyncInitableIface *iface) static void nm_object_init (NMObject *object) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - - priv->proxies = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); } static void @@ -1762,13 +1185,13 @@ set_property (GObject *object, guint prop_id, NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); switch (prop_id) { - case PROP_PATH: + case PROP_DBUS_OBJECT: /* Construct only */ - priv->path = g_value_dup_string (value); + priv->object = g_value_dup_object (value); break; - case PROP_DBUS_CONNECTION: + case PROP_DBUS_OBJECT_MANAGER: /* Construct only */ - priv->connection = g_value_dup_object (value); + priv->object_manager = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1784,13 +1207,16 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PATH: - g_value_set_string (value, priv->path); + g_value_set_string (value, nm_object_get_path (NM_OBJECT (object))); break; case PROP_DBUS_CONNECTION: - g_value_set_object (value, priv->connection); + g_value_set_object (value, g_dbus_object_manager_client_get_connection (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager))); break; - case PROP_NM_RUNNING: - g_value_set_boolean (value, priv->nm_running); + case PROP_DBUS_OBJECT: + g_value_set_object (value, priv->object); + break; + case PROP_DBUS_OBJECT_MANAGER: + g_value_set_object (value, priv->object_manager); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1809,10 +1235,9 @@ dispose (GObject *object) priv->notify_items = NULL; g_slist_free_full (priv->waiters, odata_free); - g_clear_pointer (&priv->proxies, g_hash_table_unref); - g_clear_object (&priv->properties_proxy); - g_clear_object (&priv->connection); + g_clear_object (&priv->object); + g_clear_object (&priv->object_manager); G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); } @@ -1823,7 +1248,6 @@ finalize (GObject *object) NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); g_slist_free_full (priv->property_tables, (GDestroyNotify) g_hash_table_destroy); - g_free (priv->path); G_OBJECT_CLASS (nm_object_parent_class)->finalize (object); } @@ -1846,7 +1270,7 @@ nm_object_class_init (NMObjectClass *nm_object_class) /* Properties */ /** - * NMObject:path: + * NMObject:path: (skip) * * The D-Bus object path. **/ @@ -1854,8 +1278,7 @@ nm_object_class_init (NMObjectClass *nm_object_class) (object_class, PROP_PATH, g_param_spec_string (NM_OBJECT_PATH, "", "", NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); /** @@ -1867,20 +1290,32 @@ nm_object_class_init (NMObjectClass *nm_object_class) (object_class, PROP_DBUS_CONNECTION, g_param_spec_object (NM_OBJECT_DBUS_CONNECTION, "", "", G_TYPE_DBUS_CONNECTION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + /** + * NMObject:dbus-object: (skip) + * + * The #GDBusObject of the object. + **/ + g_object_class_install_property + (object_class, PROP_DBUS_OBJECT, + g_param_spec_object (NM_OBJECT_DBUS_OBJECT, "", "", + G_TYPE_DBUS_OBJECT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** - * NMObject:manager-running: (skip) + * NMObject:dbus-object-manager: (skip) * - * Internal use only. - */ + * The #GDBusObjectManager of the object. + **/ 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)); + (object_class, PROP_DBUS_OBJECT_MANAGER, + g_param_spec_object (NM_OBJECT_DBUS_OBJECT_MANAGER, "", "", + G_TYPE_DBUS_OBJECT_MANAGER, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } - diff --git a/libnm/nm-object.h b/libnm/nm-object.h index fcfc718c22..bcf47ba6e1 100644 --- a/libnm/nm-object.h +++ b/libnm/nm-object.h @@ -39,6 +39,8 @@ G_BEGIN_DECLS #define NM_OBJECT_PATH "path" #define NM_OBJECT_DBUS_CONNECTION "dbus-connection" +#define NM_OBJECT_DBUS_OBJECT "dbus-object" +#define NM_OBJECT_DBUS_OBJECT_MANAGER "dbus-object-manager" /** * NMObject: diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c index 6ad5e5f506..d73f7764ef 100644 --- a/libnm/nm-remote-connection.c +++ b/libnm/nm-remote-connection.c @@ -628,15 +628,9 @@ init_dbus (NMObject *object) NM_OBJECT_CLASS (nm_remote_connection_parent_class)->init_dbus (object); - priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS_CONNECTION)); - g_assert (priv->proxy); - _nm_object_register_properties (object, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, property_info); - - g_signal_connect (priv->proxy, "updated", - G_CALLBACK (updated_cb), object); } static gboolean @@ -646,20 +640,20 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); GVariant *settings; - if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error)) - return FALSE; + priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (NM_OBJECT (initable), NM_DBUS_INTERFACE_SETTINGS_CONNECTION)); + g_signal_connect (priv->proxy, "updated", G_CALLBACK (updated_cb), initable); - if (!nmdbus_settings_connection_call_get_settings_sync (priv->proxy, - &settings, - cancellable, error)) { - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return FALSE; + if (nmdbus_settings_connection_call_get_settings_sync (priv->proxy, + &settings, + cancellable, + NULL)) { + priv->visible = TRUE; + replace_settings (self, settings); + g_variant_unref (settings); } - priv->visible = TRUE; - replace_settings (self, settings); - g_variant_unref (settings); + if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error)) + return FALSE; return TRUE; } @@ -668,6 +662,8 @@ typedef struct { NMRemoteConnection *connection; GCancellable *cancellable; GSimpleAsyncResult *result; + GAsyncInitable *initable; + int io_priority; } NMRemoteConnectionInitData; static void @@ -685,44 +681,35 @@ init_async_complete (NMRemoteConnectionInitData *init_data, GError *error) } static void -init_get_settings_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) +init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data) { NMRemoteConnectionInitData *init_data = user_data; - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); - GVariant *settings; GError *error = NULL; - if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &settings, - result, &error)) { - g_dbus_error_strip_remote_error (error); - init_async_complete (init_data, error); - return; - } - - priv->visible = TRUE; - replace_settings (init_data->connection, settings); - g_variant_unref (settings); - - init_async_complete (init_data, NULL); + init_async_complete (init_data, error); } static void -init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data) +init_get_settings_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { NMRemoteConnectionInitData *init_data = user_data; - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->initable); + GVariant *settings; GError *error = NULL; - if (!nm_remote_connection_parent_async_initable_iface->init_finish (G_ASYNC_INITABLE (source), result, &error)) { - init_async_complete (init_data, error); - return; + if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &settings, + result, &error)) { + g_error_free (error); + } else { + priv->visible = TRUE; + replace_settings (NM_REMOTE_CONNECTION (init_data->initable), settings); + g_variant_unref (settings); } - nmdbus_settings_connection_call_get_settings (priv->proxy, - init_data->cancellable, - init_get_settings_cb, init_data); + nm_remote_connection_parent_async_initable_iface-> + init_async (init_data->initable, init_data->io_priority, init_data->cancellable, init_async_parent_inited, init_data); } static void @@ -731,26 +718,24 @@ init_async (GAsyncInitable *initable, int io_priority, gpointer user_data) { NMRemoteConnectionInitData *init_data; + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); init_data = g_slice_new0 (NMRemoteConnectionInitData); - init_data->connection = NM_REMOTE_CONNECTION (initable); init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); + init_data->initable = initable; + init_data->io_priority = io_priority; - nm_remote_connection_parent_async_initable_iface-> - init_async (initable, io_priority, cancellable, init_async_parent_inited, init_data); -} + priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (NM_OBJECT (initable), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION)); -static gboolean -init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + g_signal_connect (priv->proxy, "updated", + G_CALLBACK (updated_cb), initable); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return TRUE; + nmdbus_settings_connection_call_get_settings (NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->initable)->proxy, + init_data->cancellable, + init_get_settings_cb, init_data); } static void @@ -790,10 +775,6 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) g_type_class_add_private (object_class, sizeof (NMRemoteConnectionPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_SETTINGS_CONNECTION); - _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - NMDBUS_TYPE_SETTINGS_CONNECTION_PROXY); - /* virtual methods */ object_class->constructed = constructed; object_class->get_property = get_property; @@ -852,5 +833,4 @@ nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface) nm_remote_connection_parent_async_initable_iface = g_type_interface_peek_parent (iface); iface->init_async = init_async; - iface->init_finish = init_finish; } diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index fa3a0f09f5..d8b275b835 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -33,7 +33,6 @@ #include "nm-remote-connection-private.h" #include "nm-object-private.h" #include "nm-dbus-helpers.h" -#include "nm-object-private.h" #include "nm-core-internal.h" #include "nmdbus-settings.h" @@ -46,7 +45,6 @@ typedef struct { NMDBusSettings *proxy; GPtrArray *all_connections; GPtrArray *visible_connections; - GCancellable *props_cancellable; /* AddConnectionInfo objects that are waiting for the connection to become initialized */ GSList *add_list; @@ -134,9 +132,6 @@ get_connection_by_string (NMRemoteSettings *settings, NMConnection *candidate; int i; - if (!_nm_object_get_nm_running (NM_OBJECT (settings))) - return NULL; - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); for (i = 0; i < priv->visible_connections->len; i++) { @@ -601,65 +596,6 @@ nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings, return g_simple_async_result_get_op_res_gboolean (simple); } -static void -updated_properties (GObject *object, GAsyncResult *result, gpointer user_data) -{ - GError *error = NULL; - - if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s: error reading NMRemoteSettings properties: %s", __func__, error->message); - g_error_free (error); - } -} - -static void -nm_running_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - NMRemoteSettings *self = NM_REMOTE_SETTINGS (object); - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - - g_object_freeze_notify (object); - - if (!_nm_object_get_nm_running (NM_OBJECT (self))) { - GPtrArray *connections; - int i; - - nm_clear_g_cancellable (&priv->props_cancellable); - - /* Clear connections */ - connections = priv->all_connections; - priv->all_connections = g_ptr_array_new (); - for (i = 0; i < connections->len; i++) - g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connections->pdata[i]); - g_ptr_array_unref (connections); - - /* Clear properties */ - if (priv->hostname) { - g_free (priv->hostname); - priv->hostname = NULL; - g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_HOSTNAME); - } - - if (priv->can_modify) { - priv->can_modify = FALSE; - g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_CAN_MODIFY); - } - - _nm_object_suppress_property_updates (NM_OBJECT (self), TRUE); - } else { - _nm_object_suppress_property_updates (NM_OBJECT (self), FALSE); - - nm_clear_g_cancellable (&priv->props_cancellable); - priv->props_cancellable = g_cancellable_new (); - _nm_object_reload_properties_async (NM_OBJECT (self), priv->props_cancellable, updated_properties, self); - } - - g_object_thaw_notify (object); -} - /*****************************************************************************/ static void @@ -688,9 +624,6 @@ init_dbus (NMObject *object) _nm_object_register_properties (object, NM_DBUS_INTERFACE_SETTINGS, property_info); - - g_signal_connect (object, "notify::" NM_OBJECT_NM_RUNNING, - G_CALLBACK (nm_running_changed), object); } static GObject * @@ -736,8 +669,6 @@ dispose (GObject *object) g_clear_pointer (&priv->all_connections, g_ptr_array_unref); } - g_signal_handlers_disconnect_by_func (object, G_CALLBACK (nm_running_changed), self); - g_clear_pointer (&priv->visible_connections, g_ptr_array_unref); g_clear_pointer (&priv->hostname, g_free); @@ -774,9 +705,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_SETTINGS); - _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_SETTINGS, NMDBUS_TYPE_SETTINGS_PROXY); - /* Virtual methods */ object_class->constructor = constructor; object_class->get_property = get_property; diff --git a/libnm/nm-vpn-connection.c b/libnm/nm-vpn-connection.c index 5780fb3a78..c7571d2926 100644 --- a/libnm/nm-vpn-connection.c +++ b/libnm/nm-vpn-connection.c @@ -185,10 +185,6 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class) g_type_class_add_private (connection_class, sizeof (NMVpnConnectionPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_VPN_CONNECTION); - _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_VPN_CONNECTION, - NMDBUS_TYPE_VPN_CONNECTION_PROXY); - /* virtual methods */ object_class->get_property = get_property; object_class->finalize = finalize; diff --git a/libnm/nm-wimax-nsp.c b/libnm/nm-wimax-nsp.c index c15fddd900..f8c8ca42b6 100644 --- a/libnm/nm-wimax-nsp.c +++ b/libnm/nm-wimax-nsp.c @@ -239,8 +239,6 @@ nm_wimax_nsp_class_init (NMWimaxNspClass *nsp_class) g_type_class_add_private (nsp_class, sizeof (NMWimaxNspPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_WIMAX_NSP); - /* virtual methods */ object_class->get_property = get_property; object_class->finalize = finalize; |