diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 9c0597ca6..605de2e0c 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -8645,6 +8645,7 @@ do_connections (NmCli *nmc, int argc, char **argv) { int i = 0; gboolean real_cmd = FALSE; + GError *error = NULL; if (argc == 0) real_cmd = TRUE; @@ -8672,8 +8673,9 @@ do_connections (NmCli *nmc, int argc, char **argv) args_info.argv = argv; /* get system settings */ - if (!(nmc->system_settings = nm_remote_settings_new (NULL))) { - g_string_printf (nmc->return_text, _("Error: Could not get system settings.")); + if (!(nmc->system_settings = nm_remote_settings_new (NULL, &error))) { + g_string_printf (nmc->return_text, _("Error: Could not get system settings: %s."), error->message); + g_error_free (error); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; nmc->should_wait = FALSE; return nmc->return_value; diff --git a/clients/cli/network-manager.c b/clients/cli/network-manager.c index ed074c6de..dc55100ab 100644 --- a/clients/cli/network-manager.c +++ b/clients/cli/network-manager.c @@ -611,8 +611,9 @@ do_general (NmCli *nmc, int argc, char **argv) } /* get system settings */ - if (!(rem_settings = nm_remote_settings_new (NULL))) { - g_string_printf (nmc->return_text, _("Error: Could not get system settings.")); + if (!(rem_settings = nm_remote_settings_new (NULL, &error))) { + g_string_printf (nmc->return_text, _("Error: Could not get system settings: %s."), error->message); + g_clear_error (&error); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; goto finish; } diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index ffd2cdbbc..d5076a601 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -394,10 +394,13 @@ setup_signals (void) static NMClient * nmc_get_client (NmCli *nmc) { + GError *error = NULL; + if (!nmc->client) { - nmc->client = nm_client_new (); + nmc->client = nm_client_new (NULL, &error); if (!nmc->client) { - g_critical (_("Error: Could not create NMClient object.")); + g_critical (_("Error: Could not create NMClient object: %s."), error->message); + g_clear_error (&error); exit (NMC_RESULT_ERROR_UNKNOWN); } } diff --git a/clients/nm-online.c b/clients/nm-online.c index 3fcb9601b..234eac9b0 100644 --- a/clients/nm-online.c +++ b/clients/nm-online.c @@ -143,6 +143,7 @@ main (int argc, char *argv[]) NMState state = NM_STATE_UNKNOWN; GMainLoop *loop; gint64 remaining_ms; + GError *error = NULL; GOptionEntry options[] = { {"timeout", 't', 0, G_OPTION_ARG_INT, &t_secs, N_("Time to wait for a connection, in seconds (without the option, default value is 30)"), ""}, @@ -191,9 +192,10 @@ main (int argc, char *argv[]) g_type_init (); #endif - client = nm_client_new (); + client = nm_client_new (NULL, &error); if (!client) { - g_printerr (_("Error: Could not create NMClient object.")); + g_printerr (_("Error: Could not create NMClient object: %s."), error->message); + g_error_free (error); return 2; } diff --git a/clients/tui/nmtui.c b/clients/tui/nmtui.c index 7fcac445a..35f8ccb9a 100644 --- a/clients/tui/nmtui.c +++ b/clients/tui/nmtui.c @@ -246,13 +246,23 @@ main (int argc, char **argv) nm_editor_bindings_init (); - nm_client = nm_client_new (); + nm_client = nm_client_new (NULL, &error); + if (!nm_client) { + g_printerr (_("Could not contact NetworkManager: %s.\n"), error->message); + g_error_free (error); + exit (1); + } if (!nm_client_get_manager_running (nm_client)) { g_printerr ("%s\n", _("NetworkManager is not running.")); exit (1); } - nm_settings = nm_remote_settings_new (NULL); + nm_settings = nm_remote_settings_new (NULL, &error); + if (!nm_settings) { + g_printerr (_("Could not contact NetworkManager: %s.\n"), error->message); + g_error_free (error); + exit (1); + } g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ, G_CALLBACK (connections_read), &got_connections); /* coverity[loop_condition] */ diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c index 1b19b4fa9..5bddf9f21 100644 --- a/examples/C/glib/add-connection-libnm.c +++ b/examples/C/glib/add-connection-libnm.c @@ -24,7 +24,7 @@ * because libnm handles much of the low-level stuff for you. * * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm` add-connection-libnm.c -o add-connection-libnm + * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` add-connection-libnm.c -o add-connection-libnm */ #include @@ -106,9 +106,9 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam int main (int argc, char *argv[]) { - DBusGConnection *bus; NMRemoteSettings *settings; GMainLoop *loop; + GError *error = NULL; #if !GLIB_CHECK_VERSION (2, 35, 0) /* Initialize GType system */ @@ -117,11 +117,13 @@ int main (int argc, char *argv[]) loop = g_main_loop_new (NULL, FALSE); - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - /* Create our proxy for NetworkManager's settings service */ - settings = nm_remote_settings_new (bus); + settings = nm_remote_settings_new (NULL, &error); + if (!settings) { + g_message ("Error: Could not get system settings: %s.", error->message); + g_error_free (error); + return 1; + } /* Ask the settings service to add the new connection */ if (add_connection (settings, loop, "__Test connection__")) { @@ -132,7 +134,6 @@ int main (int argc, char *argv[]) /* Clean up */ g_object_unref (settings); - dbus_g_connection_unref (bus); return 0; } diff --git a/examples/C/glib/get-ap-info-libnm.c b/examples/C/glib/get-ap-info-libnm.c index 192181141..4c550ed6a 100644 --- a/examples/C/glib/get-ap-info-libnm.c +++ b/examples/C/glib/get-ap-info-libnm.c @@ -197,6 +197,7 @@ int main (int argc, char *argv[]) NMClient *client; const GPtrArray *devices; int i; + GError *error = NULL; #if !GLIB_CHECK_VERSION (2, 35, 0) /* Initialize GType system */ @@ -204,9 +205,10 @@ int main (int argc, char *argv[]) #endif /* Get NMClient object */ - client = nm_client_new (); + client = nm_client_new (NULL, &error); if (!client) { - g_message ("Error: Could not create NMClient."); + g_message ("Error: Could not create NMClient: %s.", error->message); + g_error_free (error); return EXIT_FAILURE; } diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c index 216cf06a2..a3ad2c5f1 100644 --- a/examples/C/glib/list-connections-libnm.c +++ b/examples/C/glib/list-connections-libnm.c @@ -21,11 +21,10 @@ * (that wraps direct D-Bus calls). * * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm` list-connections-libnm.c -o list-connections-libnm + * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` list-connections-libnm.c -o list-connections-libnm */ #include -#include #include #include #include @@ -119,13 +118,14 @@ get_connections_cb (NMRemoteSettings *settings, gpointer user_data) static gboolean list_connections (gpointer data) { - DBusGConnection *bus = (DBusGConnection *) data; NMRemoteSettings *settings; gboolean settings_running; + GError *error = NULL; /* Get system settings */ - if (!(settings = nm_remote_settings_new (bus))) { - g_message ("Error: Could not get system settings."); + if (!(settings = nm_remote_settings_new (NULL, &error))) { + g_message ("Error: Could not get system settings: %s.", error->message); + g_error_free (error); result = EXIT_FAILURE; g_main_loop_quit (loop); return FALSE; diff --git a/examples/python/gi/device-state-ip4config.py b/examples/python/gi/device-state-ip4config.py index faf0ef942..1a6f7dece 100755 --- a/examples/python/gi/device-state-ip4config.py +++ b/examples/python/gi/device-state-ip4config.py @@ -51,7 +51,7 @@ if __name__ == "__main__": sys.exit('Usage: %s ' % sys.argv[0]) dev_iface = sys.argv[1] - c = NM.Client.new() + c = NM.Client.new(None) dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) diff --git a/examples/python/gi/get-active-connections.py b/examples/python/gi/get-active-connections.py index a295be303..55ba2d81c 100755 --- a/examples/python/gi/get-active-connections.py +++ b/examples/python/gi/get-active-connections.py @@ -24,7 +24,7 @@ from gi.repository import GLib, NM if __name__ == "__main__": - client = NM.Client.new() + client = NM.Client.new(None) acons = client.get_active_connections() for ac in acons: print "%s (%s) - %s" % (ac.get_id(), ac.get_uuid(), ac.get_connection_type()) diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py index 9f1853f17..1d110bfd4 100755 --- a/examples/python/gi/get_ips.py +++ b/examples/python/gi/get_ips.py @@ -124,7 +124,7 @@ if __name__ == "__main__": sys.exit('Usage: %s ' % sys.argv[0]) dev_iface = sys.argv[1] - c = NM.Client.new() + c = NM.Client.new(None) dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py index 8f61cfcbe..c76d1c4cb 100755 --- a/examples/python/gi/show-wifi-networks.py +++ b/examples/python/gi/show-wifi-networks.py @@ -62,7 +62,7 @@ def print_ap_info(ap): print if __name__ == "__main__": - nmc = NM.Client.new() + nmc = NM.Client.new(None) devs = nmc.get_devices() for dev in devs: diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 447b97ae6..d21256c87 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1360,19 +1360,12 @@ nm_setting_init (NMSetting *setting) { } -static GObject* -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) +static void +constructed (GObject *object) { - GObject *object; - - object = G_OBJECT_CLASS (nm_setting_parent_class)->constructor (type, - n_construct_params, - construct_params); - _ensure_setting_info (object, NM_SETTING_GET_PRIVATE (object)); - return object; + + G_OBJECT_CLASS (nm_setting_parent_class)->constructed (object); } static void @@ -1399,7 +1392,7 @@ nm_setting_class_init (NMSettingClass *setting_class) g_type_class_add_private (setting_class, sizeof (NMSettingPrivate)); /* virtual methods */ - object_class->constructor = constructor; + object_class->constructed = constructed; object_class->get_property = get_property; setting_class->update_one_secret = update_one_secret; diff --git a/libnm/nm-access-point.c b/libnm/nm-access-point.c index 21dcc14da..c4b5bec56 100644 --- a/libnm/nm-access-point.c +++ b/libnm/nm-access-point.c @@ -83,7 +83,6 @@ nm_access_point_get_flags (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_FLAGS_NONE); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->flags; } @@ -100,7 +99,6 @@ nm_access_point_get_wpa_flags (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->wpa_flags; } @@ -118,7 +116,6 @@ nm_access_point_get_rsn_flags (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->rsn_flags; } @@ -136,7 +133,6 @@ nm_access_point_get_ssid (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->ssid; } @@ -153,7 +149,6 @@ nm_access_point_get_frequency (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->frequency; } @@ -171,7 +166,6 @@ nm_access_point_get_bssid (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid; } @@ -188,7 +182,6 @@ nm_access_point_get_mode (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->mode; } @@ -205,7 +198,6 @@ nm_access_point_get_max_bitrate (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->max_bitrate; } @@ -222,7 +214,6 @@ nm_access_point_get_strength (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); - _nm_object_ensure_inited (NM_OBJECT (ap)); return NM_ACCESS_POINT_GET_PRIVATE (ap)->strength; } @@ -410,8 +401,6 @@ get_property (GObject *object, { NMAccessPoint *ap = NM_ACCESS_POINT (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_FLAGS: g_value_set_uint (value, nm_access_point_get_flags (ap)); diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index 3f970f001..1f008b1c0 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -199,7 +199,6 @@ nm_active_connection_get_connection (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->connection; } @@ -217,7 +216,6 @@ nm_active_connection_get_id (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id; } @@ -235,7 +233,6 @@ nm_active_connection_get_uuid (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid; } @@ -253,7 +250,6 @@ nm_active_connection_get_connection_type (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type; } @@ -271,7 +267,6 @@ nm_active_connection_get_specific_object (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object; } @@ -289,7 +284,6 @@ nm_active_connection_get_devices (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return handle_ptr_array_return (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices); } @@ -306,7 +300,6 @@ nm_active_connection_get_state (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->state; } @@ -324,7 +317,6 @@ nm_active_connection_get_default (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default; } @@ -343,7 +335,6 @@ nm_active_connection_get_ip4_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip4_config; } @@ -363,7 +354,6 @@ nm_active_connection_get_dhcp4_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp4_config; } @@ -381,7 +371,6 @@ nm_active_connection_get_default6 (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default6; } @@ -400,7 +389,6 @@ nm_active_connection_get_ip6_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip6_config; } @@ -420,7 +408,6 @@ nm_active_connection_get_dhcp6_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp6_config; } @@ -437,7 +424,6 @@ nm_active_connection_get_vpn (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_vpn; } @@ -455,7 +441,6 @@ nm_active_connection_get_master (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - _nm_object_ensure_inited (NM_OBJECT (connection)); return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->master; } @@ -508,8 +493,6 @@ get_property (GObject *object, { NMActiveConnection *self = NM_ACTIVE_CONNECTION (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_CONNECTION: g_value_set_string (value, nm_active_connection_get_connection (self)); diff --git a/libnm/nm-client.c b/libnm/nm-client.c index d6919d999..97558fea4 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -402,8 +402,6 @@ nm_client_get_devices (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - _nm_object_ensure_inited (NM_OBJECT (client)); - return handle_ptr_array_return (NM_CLIENT_GET_PRIVATE (client)->devices); } @@ -823,8 +821,6 @@ nm_client_get_active_connections (NMClient *client) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - _nm_object_ensure_inited (NM_OBJECT (client)); - priv = NM_CLIENT_GET_PRIVATE (client); if (!priv->manager_running) return NULL; @@ -845,7 +841,6 @@ nm_client_wireless_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->wireless_enabled; } @@ -888,7 +883,6 @@ nm_client_wireless_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->wireless_hw_enabled; } @@ -905,7 +899,6 @@ nm_client_wwan_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->wwan_enabled; } @@ -948,7 +941,6 @@ nm_client_wwan_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->wwan_hw_enabled; } @@ -965,7 +957,6 @@ nm_client_wimax_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->wimax_enabled; } @@ -1008,7 +999,6 @@ nm_client_wimax_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->wimax_hw_enabled; } @@ -1029,8 +1019,6 @@ nm_client_get_version (NMClient *client) priv = NM_CLIENT_GET_PRIVATE (client); - _nm_object_ensure_inited (NM_OBJECT (client)); - return priv->manager_running ? priv->version : NULL; } @@ -1047,8 +1035,6 @@ nm_client_get_state (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (client)); - return NM_CLIENT_GET_PRIVATE (client)->state; } @@ -1066,8 +1052,6 @@ nm_client_get_startup (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (client)); - return NM_CLIENT_GET_PRIVATE (client)->startup; } @@ -1084,7 +1068,6 @@ nm_client_networking_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->networking_enabled; } @@ -1258,7 +1241,6 @@ nm_client_get_primary_connection (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->primary_connection; } @@ -1278,7 +1260,6 @@ nm_client_get_activating_connection (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - _nm_object_ensure_inited (NM_OBJECT (client)); return NM_CLIENT_GET_PRIVATE (client)->activating_connection; } @@ -1413,14 +1394,9 @@ proxy_name_owner_changed (DBusGProxy *proxy, NMConnectivityState nm_client_get_connectivity (NMClient *client) { - NMClientPrivate *priv; - g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN); - priv = NM_CLIENT_GET_PRIVATE (client); - _nm_object_ensure_inited (NM_OBJECT (client)); - - return priv->connectivity; + return NM_CLIENT_GET_PRIVATE (client)->connectivity; } /** @@ -1594,6 +1570,8 @@ nm_client_check_connectivity_finish (NMClient *client, /** * nm_client_new: + * @cancellable: a #GCancellable, or %NULL + * @error: location for a #GError, or %NULL * * Creates a new #NMClient. * @@ -1608,19 +1586,11 @@ nm_client_check_connectivity_finish (NMClient *client, * Returns: a new #NMClient or NULL on an error **/ NMClient * -nm_client_new (void) +nm_client_new (GCancellable *cancellable, + GError **error) { - NMClient *client; - - client = g_object_new (NM_TYPE_CLIENT, NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, NULL); - - /* NMObject's constructor() can fail on a D-Bus connection error. So we can - * get NULL here instead of a valid NMClient object. - */ - if (client) - _nm_object_ensure_inited (NM_OBJECT (client)); - - return client; + return g_initable_new (NM_TYPE_CLIENT, cancellable, error, + NULL); } static void @@ -1629,7 +1599,7 @@ client_inited (GObject *source, GAsyncResult *result, gpointer user_data) GSimpleAsyncResult *simple = user_data; GError *error = NULL; - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source), result, &error)) + if (!g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error)) g_simple_async_result_take_error (simple, error); else g_simple_async_result_set_op_res_gpointer (simple, source, g_object_unref); @@ -1657,21 +1627,13 @@ nm_client_new_async (GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - NMClient *client; GSimpleAsyncResult *simple; - client = g_object_new (NM_TYPE_CLIENT, NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, NULL); - /* When client is NULL, do no continue with initialization and run callback - * directly with result == NULL indicating NMClient creation failure. - */ - if (!client) { - callback (NULL, NULL, user_data); - return; - } - simple = g_simple_async_result_new (NULL, callback, user_data, nm_client_new_async); - g_async_initable_init_async (G_ASYNC_INITABLE (client), G_PRIORITY_DEFAULT, - cancellable, client_inited, simple); + + g_async_initable_new_async (NM_TYPE_CLIENT, G_PRIORITY_DEFAULT, + cancellable, client_inited, simple, + NULL); } /** @@ -1778,7 +1740,6 @@ constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { - GObject *object; guint i; const char *dbus_path; @@ -1798,24 +1759,14 @@ constructor (GType type, } } - object = G_OBJECT_CLASS (nm_client_parent_class)->constructor (type, - n_construct_params, - construct_params); - - return object; + return G_OBJECT_CLASS (nm_client_parent_class)->constructor (type, + n_construct_params, + construct_params); } static void constructed (GObject *object) { - GError *error = NULL; - - if (!nm_utils_init (&error)) { - g_warning ("Couldn't initilize nm-utils/crypto system: %d %s", - error->code, error->message); - g_clear_error (&error); - } - G_OBJECT_CLASS (nm_client_parent_class)->constructed (object); g_signal_connect (object, "notify::" NM_CLIENT_WIRELESS_ENABLED, @@ -1834,6 +1785,9 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) NMClient *client = NM_CLIENT (initable); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); + if (!nm_utils_init (error)) + return FALSE; + if (!nm_client_parent_initable_iface->init (initable, cancellable, error)) return FALSE; @@ -1948,6 +1902,13 @@ init_async (GAsyncInitable *initable, int io_priority, { NMClientInitData *init_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (initable); + GError *error = NULL; + + if (!nm_utils_init (&error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (initable), + callback, user_data, error); + return; + } init_data = g_slice_new0 (NMClientInitData); init_data->client = NM_CLIENT (initable); @@ -2067,8 +2028,6 @@ get_property (GObject *object, NMClient *self = NM_CLIENT (object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_VERSION: g_value_set_string (value, nm_client_get_version (self)); diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 9fa3203c1..438ace931 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -160,7 +160,8 @@ typedef struct { GType nm_client_get_type (void); -NMClient *nm_client_new (void); +NMClient *nm_client_new (GCancellable *cancellable, + GError **error); void nm_client_new_async (GCancellable *cancellable, GAsyncReadyCallback callback, diff --git a/libnm/nm-device-adsl.c b/libnm/nm-device-adsl.c index 08ccb65a4..3d99020a2 100644 --- a/libnm/nm-device-adsl.c +++ b/libnm/nm-device-adsl.c @@ -75,7 +75,6 @@ nm_device_adsl_get_carrier (NMDeviceAdsl *device) { g_return_val_if_fail (NM_IS_DEVICE_ADSL (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_ADSL_GET_PRIVATE (device)->carrier; } diff --git a/libnm/nm-device-bond.c b/libnm/nm-device-bond.c index 9d0bcb6f5..27d122baf 100644 --- a/libnm/nm-device-bond.c +++ b/libnm/nm-device-bond.c @@ -85,7 +85,6 @@ nm_device_bond_get_hw_address (NMDeviceBond *device) { g_return_val_if_fail (NM_IS_DEVICE_BOND (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BOND_GET_PRIVATE (device)->hw_address; } @@ -102,7 +101,6 @@ nm_device_bond_get_carrier (NMDeviceBond *device) { g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BOND_GET_PRIVATE (device)->carrier; } @@ -121,7 +119,6 @@ nm_device_bond_get_slaves (NMDeviceBond *device) { g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return handle_ptr_array_return (NM_DEVICE_BOND_GET_PRIVATE (device)->slaves); } @@ -235,8 +232,6 @@ get_property (GObject *object, { NMDeviceBond *device = NM_DEVICE_BOND (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_bond_get_hw_address (device)); diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c index 1ea605d03..6cd58b6b2 100644 --- a/libnm/nm-device-bridge.c +++ b/libnm/nm-device-bridge.c @@ -85,7 +85,6 @@ nm_device_bridge_get_hw_address (NMDeviceBridge *device) { g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address; } @@ -102,7 +101,6 @@ nm_device_bridge_get_carrier (NMDeviceBridge *device) { g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->carrier; } @@ -121,7 +119,6 @@ nm_device_bridge_get_slaves (NMDeviceBridge *device) { g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return handle_ptr_array_return (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves); } @@ -235,8 +232,6 @@ get_property (GObject *object, { NMDeviceBridge *device = NM_DEVICE_BRIDGE (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_bridge_get_hw_address (device)); diff --git a/libnm/nm-device-bt.c b/libnm/nm-device-bt.c index ab8212974..5daa015fc 100644 --- a/libnm/nm-device-bt.c +++ b/libnm/nm-device-bt.c @@ -84,7 +84,6 @@ nm_device_bt_get_hw_address (NMDeviceBt *device) { g_return_val_if_fail (NM_IS_DEVICE_BT (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BT_GET_PRIVATE (device)->hw_address; } @@ -101,7 +100,6 @@ nm_device_bt_get_name (NMDeviceBt *device) { g_return_val_if_fail (NM_IS_DEVICE_BT (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BT_GET_PRIVATE (device)->name; } @@ -118,7 +116,6 @@ nm_device_bt_get_capabilities (NMDeviceBt *device) { g_return_val_if_fail (NM_IS_DEVICE_BT (device), NM_BT_CAPABILITY_NONE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_BT_GET_PRIVATE (device)->bt_capabilities; } @@ -268,8 +265,6 @@ get_property (GObject *object, { NMDeviceBt *device = NM_DEVICE_BT (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_bt_get_hw_address (device)); diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index b022786a0..899006235 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -87,7 +87,6 @@ nm_device_ethernet_get_hw_address (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_address; } @@ -105,7 +104,6 @@ nm_device_ethernet_get_permanent_hw_address (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->perm_hw_address; } @@ -122,7 +120,6 @@ nm_device_ethernet_get_speed (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->speed; } @@ -139,7 +136,6 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->carrier; } @@ -268,8 +264,6 @@ get_property (GObject *object, { NMDeviceEthernet *device = NM_DEVICE_ETHERNET (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_ethernet_get_hw_address (device)); diff --git a/libnm/nm-device-generic.c b/libnm/nm-device-generic.c index 8bc08ac95..29cae7cd3 100644 --- a/libnm/nm-device-generic.c +++ b/libnm/nm-device-generic.c @@ -77,7 +77,6 @@ nm_device_generic_get_hw_address (NMDeviceGeneric *device) { g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address; } @@ -88,7 +87,6 @@ get_type_description (NMDevice *device) { NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device); - _nm_object_ensure_inited (NM_OBJECT (device)); return priv->type_description; } @@ -185,8 +183,6 @@ get_property (GObject *object, { NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, priv->hw_address); diff --git a/libnm/nm-device-infiniband.c b/libnm/nm-device-infiniband.c index 99eb0dbde..b3f7270b1 100644 --- a/libnm/nm-device-infiniband.c +++ b/libnm/nm-device-infiniband.c @@ -83,7 +83,6 @@ nm_device_infiniband_get_hw_address (NMDeviceInfiniband *device) { g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address; } @@ -100,7 +99,6 @@ nm_device_infiniband_get_carrier (NMDeviceInfiniband *device) { g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->carrier; } @@ -217,8 +215,6 @@ get_property (GObject *object, { NMDeviceInfiniband *device = NM_DEVICE_INFINIBAND (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_infiniband_get_hw_address (device)); diff --git a/libnm/nm-device-modem.c b/libnm/nm-device-modem.c index 400ef58cf..511f084bb 100644 --- a/libnm/nm-device-modem.c +++ b/libnm/nm-device-modem.c @@ -82,7 +82,6 @@ nm_device_modem_get_modem_capabilities (NMDeviceModem *self) { g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps; } @@ -102,7 +101,6 @@ nm_device_modem_get_current_capabilities (NMDeviceModem *self) { g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps; } @@ -211,8 +209,6 @@ get_property (GObject *object, { NMDeviceModem *self = NM_DEVICE_MODEM (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_MODEM_CAPS: g_value_set_uint (value, nm_device_modem_get_modem_capabilities (self)); diff --git a/libnm/nm-device-olpc-mesh.c b/libnm/nm-device-olpc-mesh.c index 2416e3810..b8c2c25cc 100644 --- a/libnm/nm-device-olpc-mesh.c +++ b/libnm/nm-device-olpc-mesh.c @@ -83,7 +83,6 @@ nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device) { g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address; } @@ -100,7 +99,6 @@ nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device) { g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion; } @@ -117,7 +115,6 @@ nm_device_olpc_mesh_get_active_channel (NMDeviceOlpcMesh *device) { g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->active_channel; } @@ -216,8 +213,6 @@ get_property (GObject *object, { NMDeviceOlpcMesh *device = NM_DEVICE_OLPC_MESH (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_olpc_mesh_get_hw_address (device)); diff --git a/libnm/nm-device-team.c b/libnm/nm-device-team.c index 3f45f1820..760117e10 100644 --- a/libnm/nm-device-team.c +++ b/libnm/nm-device-team.c @@ -85,7 +85,6 @@ nm_device_team_get_hw_address (NMDeviceTeam *device) { g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address; } @@ -102,7 +101,6 @@ nm_device_team_get_carrier (NMDeviceTeam *device) { g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_TEAM_GET_PRIVATE (device)->carrier; } @@ -121,7 +119,6 @@ nm_device_team_get_slaves (NMDeviceTeam *device) { g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return handle_ptr_array_return (NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves); } @@ -235,8 +232,6 @@ get_property (GObject *object, { NMDeviceTeam *device = NM_DEVICE_TEAM (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_team_get_hw_address (device)); diff --git a/libnm/nm-device-vlan.c b/libnm/nm-device-vlan.c index 8dd38dbdb..985d8b599 100644 --- a/libnm/nm-device-vlan.c +++ b/libnm/nm-device-vlan.c @@ -84,7 +84,6 @@ nm_device_vlan_get_hw_address (NMDeviceVlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address; } @@ -101,7 +100,6 @@ nm_device_vlan_get_carrier (NMDeviceVlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_VLAN_GET_PRIVATE (device)->carrier; } @@ -116,7 +114,6 @@ nm_device_vlan_get_vlan_id (NMDeviceVlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_VLAN_GET_PRIVATE (device)->vlan_id; } @@ -245,8 +242,6 @@ get_property (GObject *object, { NMDeviceVlan *device = NM_DEVICE_VLAN (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_vlan_get_hw_address (device)); diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c index 5a1055342..7abab9aa6 100644 --- a/libnm/nm-device-wifi.c +++ b/libnm/nm-device-wifi.c @@ -116,7 +116,6 @@ nm_device_wifi_get_hw_address (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_WIFI_GET_PRIVATE (device)->hw_address; } @@ -134,7 +133,6 @@ nm_device_wifi_get_permanent_hw_address (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_WIFI_GET_PRIVATE (device)->perm_hw_address; } @@ -151,7 +149,6 @@ nm_device_wifi_get_mode (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_WIFI_GET_PRIVATE (device)->mode; } @@ -182,7 +179,6 @@ nm_device_wifi_get_bitrate (NMDeviceWifi *device) return 0; } - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_WIFI_GET_PRIVATE (device)->rate; } @@ -199,7 +195,6 @@ nm_device_wifi_get_capabilities (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_WIFI_GET_PRIVATE (device)->wireless_caps; } @@ -234,7 +229,6 @@ nm_device_wifi_get_active_access_point (NMDeviceWifi *device) break; } - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_WIFI_GET_PRIVATE (device)->active_ap; } @@ -253,7 +247,6 @@ nm_device_wifi_get_access_points (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return handle_ptr_array_return (NM_DEVICE_WIFI_GET_PRIVATE (device)->aps); } @@ -528,8 +521,6 @@ get_property (GObject *object, { NMDeviceWifi *self = NM_DEVICE_WIFI (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_wifi_get_hw_address (self)); diff --git a/libnm/nm-device-wimax.c b/libnm/nm-device-wimax.c index a63ce1bf8..1459365f7 100644 --- a/libnm/nm-device-wimax.c +++ b/libnm/nm-device-wimax.c @@ -109,7 +109,6 @@ nm_device_wimax_get_hw_address (NMDeviceWimax *wimax) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); - _nm_object_ensure_inited (NM_OBJECT (wimax)); return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address; } @@ -144,7 +143,6 @@ nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax) break; } - _nm_object_ensure_inited (NM_OBJECT (wimax)); return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->active_nsp; } @@ -163,7 +161,6 @@ nm_device_wimax_get_nsps (NMDeviceWimax *wimax) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); - _nm_object_ensure_inited (NM_OBJECT (wimax)); return handle_ptr_array_return (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps); } @@ -245,7 +242,6 @@ nm_device_wimax_get_center_frequency (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->center_freq; } @@ -265,7 +261,6 @@ nm_device_wimax_get_rssi (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->rssi; } @@ -284,7 +279,6 @@ nm_device_wimax_get_cinr (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->cinr; } @@ -303,7 +297,6 @@ nm_device_wimax_get_tx_power (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->tx_power; } @@ -320,7 +313,6 @@ nm_device_wimax_get_bsid (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL); - _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid; } @@ -404,8 +396,6 @@ get_property (GObject *object, { NMDeviceWimax *self = NM_DEVICE_WIMAX (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_HW_ADDRESS: g_value_set_string (value, nm_device_wimax_get_hw_address (self)); diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 60a3b9bed..b06ba157e 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -420,8 +420,6 @@ get_property (GObject *object, NMDevice *device = NM_DEVICE (object); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_DEVICE_TYPE: g_value_set_uint (value, nm_device_get_device_type (device)); @@ -978,7 +976,6 @@ nm_device_get_iface (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->iface; } @@ -997,7 +994,6 @@ nm_device_get_ip_iface (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->ip_iface; } @@ -1032,7 +1028,6 @@ nm_device_get_udi (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->udi; } @@ -1050,7 +1045,6 @@ nm_device_get_driver (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->driver; } @@ -1068,7 +1062,6 @@ nm_device_get_driver_version (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->driver_version; } @@ -1086,7 +1079,6 @@ nm_device_get_firmware_version (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->firmware_version; } @@ -1158,7 +1150,6 @@ nm_device_get_capabilities (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->capabilities; } @@ -1175,7 +1166,6 @@ nm_device_get_managed (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->managed; } @@ -1192,7 +1182,6 @@ nm_device_get_autoconnect (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->autoconnect; } @@ -1237,7 +1226,6 @@ nm_device_get_firmware_missing (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->firmware_missing; } @@ -1258,7 +1246,6 @@ nm_device_get_ip4_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->ip4_config; } @@ -1280,7 +1267,6 @@ nm_device_get_dhcp4_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->dhcp4_config; } @@ -1301,7 +1287,6 @@ nm_device_get_ip6_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->ip6_config; } @@ -1323,7 +1308,6 @@ nm_device_get_dhcp6_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->dhcp6_config; } @@ -1340,7 +1324,6 @@ nm_device_get_state (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->state; } @@ -1359,7 +1342,6 @@ nm_device_get_state_reason (NMDevice *device, NMDeviceStateReason *reason) { g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (device)); if (reason) *reason = NM_DEVICE_GET_PRIVATE (device)->reason; return NM_DEVICE_GET_PRIVATE (device)->state; @@ -1379,7 +1361,6 @@ nm_device_get_active_connection (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->active_connection; } @@ -1399,7 +1380,6 @@ nm_device_get_available_connections (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - _nm_object_ensure_inited (NM_OBJECT (device)); return handle_ptr_array_return (NM_DEVICE_GET_PRIVATE (device)->available_connections); } @@ -1998,7 +1978,6 @@ nm_device_get_physical_port_id (NMDevice *device) priv = NM_DEVICE_GET_PRIVATE (device); - _nm_object_ensure_inited (NM_OBJECT (device)); if (priv->physical_port_id && *priv->physical_port_id) return priv->physical_port_id; else @@ -2018,7 +1997,6 @@ nm_device_get_mtu (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), 0); - _nm_object_ensure_inited (NM_OBJECT (device)); return NM_DEVICE_GET_PRIVATE (device)->mtu; } @@ -2035,7 +2013,6 @@ nm_device_is_software (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); - _nm_object_ensure_inited (NM_OBJECT (device)); return !!(NM_DEVICE_GET_PRIVATE (device)->capabilities & NM_DEVICE_CAP_IS_SOFTWARE); } diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c index b1b5e3240..1ca16b375 100644 --- a/libnm/nm-dhcp4-config.c +++ b/libnm/nm-dhcp4-config.c @@ -47,6 +47,9 @@ enum { static void nm_dhcp4_config_init (NMDhcp4Config *config) { + NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (config); + + priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); } static gboolean @@ -88,17 +91,6 @@ init_dbus (NMObject *object) property_info); } -static void -constructed (GObject *object) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - - G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->constructed (object); - - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - -} - static void finalize (GObject *object) { @@ -120,8 +112,6 @@ get_property (GObject *object, { NMDhcp4Config *self = NM_DHCP4_CONFIG (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_OPTIONS: g_value_set_boxed (value, nm_dhcp4_config_get_options (self)); @@ -141,7 +131,6 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate)); /* virtual methods */ - object_class->constructed = constructed; object_class->get_property = get_property; object_class->finalize = finalize; @@ -178,7 +167,6 @@ nm_dhcp4_config_get_options (NMDhcp4Config *config) { g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_DHCP4_CONFIG_GET_PRIVATE (config)->options; } diff --git a/libnm/nm-dhcp6-config.c b/libnm/nm-dhcp6-config.c index dc639d3ac..18cbb79b9 100644 --- a/libnm/nm-dhcp6-config.c +++ b/libnm/nm-dhcp6-config.c @@ -47,6 +47,9 @@ enum { static void nm_dhcp6_config_init (NMDhcp6Config *config) { + NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (config); + + priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); } static gboolean @@ -88,17 +91,6 @@ init_dbus (NMObject *object) property_info); } -static void -constructed (GObject *object) -{ - NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); - - G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->constructed (object); - - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - -} - static void finalize (GObject *object) { @@ -120,8 +112,6 @@ get_property (GObject *object, { NMDhcp6Config *self = NM_DHCP6_CONFIG (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_OPTIONS: g_value_set_boxed (value, nm_dhcp6_config_get_options (self)); @@ -141,7 +131,6 @@ nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class) g_type_class_add_private (config_class, sizeof (NMDhcp6ConfigPrivate)); /* virtual methods */ - object_class->constructed = constructed; object_class->get_property = get_property; object_class->finalize = finalize; @@ -178,7 +167,6 @@ nm_dhcp6_config_get_options (NMDhcp6Config *config) { g_return_val_if_fail (NM_IS_DHCP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_DHCP6_CONFIG_GET_PRIVATE (config)->options; } diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index 727e2a6b3..5635cbd9f 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -177,8 +177,6 @@ get_property (GObject *object, NMIP4Config *self = NM_IP4_CONFIG (object); NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_GATEWAY: g_value_set_string (value, nm_ip4_config_get_gateway (self)); @@ -319,7 +317,6 @@ nm_ip4_config_get_gateway (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP4_CONFIG_GET_PRIVATE (config)->gateway; } @@ -337,7 +334,6 @@ nm_ip4_config_get_addresses (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP4_CONFIG_GET_PRIVATE (config)->addresses; } @@ -356,7 +352,6 @@ nm_ip4_config_get_nameservers (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers; } @@ -374,7 +369,6 @@ nm_ip4_config_get_domains (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return handle_ptr_array_return (NM_IP4_CONFIG_GET_PRIVATE (config)->domains); } @@ -392,7 +386,6 @@ nm_ip4_config_get_searches (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return handle_ptr_array_return (NM_IP4_CONFIG_GET_PRIVATE (config)->searches); } @@ -411,7 +404,6 @@ nm_ip4_config_get_wins_servers (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP4_CONFIG_GET_PRIVATE (config)->wins; } @@ -430,6 +422,5 @@ nm_ip4_config_get_routes (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP4_CONFIG_GET_PRIVATE (config)->routes; } diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c index 29dc38a94..beb2b9cd7 100644 --- a/libnm/nm-ip6-config.c +++ b/libnm/nm-ip6-config.c @@ -150,7 +150,6 @@ nm_ip6_config_get_gateway (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP6_CONFIG_GET_PRIVATE (config)->gateway; } @@ -169,7 +168,6 @@ nm_ip6_config_get_addresses (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP6_CONFIG_GET_PRIVATE (config)->addresses; } @@ -186,7 +184,6 @@ nm_ip6_config_get_num_nameservers (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), 0); - _nm_object_ensure_inited (NM_OBJECT (config)); return g_slist_length (NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers); } @@ -209,7 +206,6 @@ nm_ip6_config_get_nameserver (NMIP6Config *config, guint32 idx) g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); priv = NM_IP6_CONFIG_GET_PRIVATE (config); for (item = priv->nameservers; item && i < idx; i++) @@ -235,7 +231,6 @@ nm_ip6_config_get_nameservers (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers; } @@ -253,7 +248,6 @@ nm_ip6_config_get_domains (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->domains); } @@ -271,7 +265,6 @@ nm_ip6_config_get_searches (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->searches); } @@ -290,7 +283,6 @@ nm_ip6_config_get_routes (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - _nm_object_ensure_inited (NM_OBJECT (config)); return NM_IP6_CONFIG_GET_PRIVATE (config)->routes; } @@ -329,8 +321,6 @@ get_property (GObject *object, NMIP6Config *self = NM_IP6_CONFIG (object); NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_GATEWAY: g_value_set_string (value, nm_ip6_config_get_gateway (self)); diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h index 75e63b2e7..6474dc751 100644 --- a/libnm/nm-object-private.h +++ b/libnm/nm-object-private.h @@ -24,8 +24,6 @@ #include #include "nm-object.h" -void _nm_object_ensure_inited (NMObject *object); - typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GValue *, gpointer); typedef GObject * (*NMObjectCreatorFunc) (DBusGConnection *, const char *); diff --git a/libnm/nm-object.c b/libnm/nm-object.c index 4482d24d4..390901f9a 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -73,7 +74,6 @@ typedef struct { GSList *notify_props; guint32 notify_id; - gboolean inited; GSList *reload_results; guint reload_remaining; @@ -139,38 +139,20 @@ nm_object_init (NMObject *object) { } -static GObject* -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) +static gboolean +init_common (NMObject *self, GError **error) { - GObject *object; - NMObjectPrivate *priv; + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - object = G_OBJECT_CLASS (nm_object_parent_class)->constructor (type, - n_construct_params, - construct_params); - - priv = NM_OBJECT_GET_PRIVATE (object); - - if (priv->connection == NULL || priv->path == NULL) { - g_warn_if_reached (); - g_object_unref (object); - return NULL; + if (!priv->path) { + g_set_error_literal (error, NM_OBJECT_ERROR, NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE, + _("Caller did not specify D-Bus path for object")); + return FALSE; } - return object; -} - -static void -constructed (GObject *object) -{ - NMObject *self = NM_OBJECT (object); - - if (G_OBJECT_CLASS (nm_object_parent_class)->constructed) - G_OBJECT_CLASS (nm_object_parent_class)->constructed (object); - NM_OBJECT_GET_CLASS (self)->init_dbus (self); + + return TRUE; } static void @@ -202,7 +184,16 @@ init_dbus (NMObject *object) static gboolean init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (initable); + NMObject *self = NM_OBJECT (initable); + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + + if (!priv->connection) { + priv->connection = _nm_dbus_new_connection (error); + if (!priv->connection) + return FALSE; + } + if (!init_common (self, error)) + return FALSE; if (priv->bus_proxy) { if (!dbus_g_proxy_call (priv->bus_proxy, @@ -214,8 +205,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) return FALSE; } - priv->inited = TRUE; - return _nm_object_reload_properties (NM_OBJECT (initable), error); + return _nm_object_reload_properties (self, error); } /* Takes ownership of @error */ @@ -236,7 +226,6 @@ init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_ GSimpleAsyncResult *simple = user_data; GError *error = NULL; - NM_OBJECT_GET_PRIVATE (object)->inited = TRUE; if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) g_assert (error); init_async_complete (simple, error); @@ -258,10 +247,9 @@ init_async_got_manager_running (DBusGProxy *proxy, DBusGProxyCall *call, G_TYPE_BOOLEAN, &priv->nm_running, G_TYPE_INVALID)) { init_async_complete (simple, error); - } else if (!priv->nm_running) { - priv->inited = TRUE; + } else if (!priv->nm_running) init_async_complete (simple, NULL); - } else + else _nm_object_reload_properties_async (self, init_async_got_properties, simple); /* g_async_result_get_source_object() adds a ref */ @@ -273,13 +261,31 @@ init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (initable); + NMObject *self = NM_OBJECT (initable); + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); GSimpleAsyncResult *simple; + GError *error = NULL; simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); - if (_nm_object_is_connection_private (NM_OBJECT (initable))) - _nm_object_reload_properties_async (NM_OBJECT (initable), init_async_got_properties, simple); + if (!priv->connection) { + priv->connection = _nm_dbus_new_connection (&error); + if (!priv->connection) { + g_simple_async_result_take_error (simple, error); + g_simple_async_result_complete_in_idle (simple); + g_object_unref (simple); + return; + } + } + if (!init_common (self, &error)) { + g_simple_async_result_take_error (simple, error); + g_simple_async_result_complete_in_idle (simple); + g_object_unref (simple); + return; + } + + if (_nm_object_is_connection_private (self)) + _nm_object_reload_properties_async (self, init_async_got_properties, simple); else { /* Check if NM is running */ dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner", @@ -349,8 +355,6 @@ set_property (GObject *object, guint prop_id, case PROP_DBUS_CONNECTION: /* Construct only */ priv->connection = g_value_dup_boxed (value); - if (!priv->connection) - priv->connection = _nm_dbus_new_connection (NULL); break; case PROP_DBUS_PATH: /* Construct only */ @@ -389,8 +393,6 @@ nm_object_class_init (NMObjectClass *nm_object_class) g_type_class_add_private (nm_object_class, sizeof (NMObjectPrivate)); /* virtual methods */ - object_class->constructor = constructor; - object_class->constructed = constructed; object_class->set_property = set_property; object_class->get_property = get_property; object_class->dispose = dispose; @@ -585,7 +587,6 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path) 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; @@ -620,10 +621,9 @@ nm_object_or_connection_get_path (gpointer instance) } static void -async_inited (GObject *source, GAsyncResult *result, gpointer user_data) +async_inited (GObject *object, GAsyncResult *result, gpointer user_data) { NMObjectTypeAsyncData *async_data = user_data; - GObject *object = G_OBJECT (source); GError *error = NULL; if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) { @@ -631,7 +631,7 @@ async_inited (GObject *source, GAsyncResult *result, gpointer user_data) nm_object_or_connection_get_path (object), error->message); g_error_free (error); - g_clear_object (&object); + object = NULL; } create_async_complete (object, async_data); @@ -664,7 +664,6 @@ async_got_type (GType type, gpointer user_data) NM_OBJECT_DBUS_CONNECTION, async_data->connection, NM_OBJECT_DBUS_PATH, async_data->path, NULL); - g_warn_if_fail (object != NULL); if (NM_IS_OBJECT (object)) _nm_object_cache_add (NM_OBJECT (object)); g_async_initable_init_async (G_ASYNC_INITABLE (object), G_PRIORITY_DEFAULT, @@ -1254,26 +1253,6 @@ _nm_object_suppress_property_updates (NMObject *object, gboolean suppress) } -void -_nm_object_ensure_inited (NMObject *object) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GError *error = NULL; - - if (!priv->inited) { - if (!g_initable_init (G_INITABLE (object), NULL, &error)) { - dbgmsg ("Could not initialize %s %s: %s", - G_OBJECT_TYPE_NAME (object), - priv->path, - error->message); - g_error_free (error); - - /* Only warn once */ - priv->inited = TRUE; - } - } -} - void _nm_object_reload_property (NMObject *object, const char *interface, diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c index 7498fff08..fbe3eef07 100644 --- a/libnm/nm-remote-connection.c +++ b/libnm/nm-remote-connection.c @@ -82,7 +82,6 @@ typedef struct { gboolean proxy_is_destroyed; GSList *calls; - gboolean inited; gboolean unsaved; gboolean visible; @@ -109,29 +108,6 @@ nm_remote_connection_error_quark (void) /****************************************************************/ -static void -_nm_remote_connection_ensure_inited (NMRemoteConnection *self) -{ - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - GError *error = NULL; - - if (!priv->inited) { - if (!g_initable_init (G_INITABLE (self), NULL, &error)) { - /* Don't warn when the call times out because the settings service can't - * be activated or whatever. - */ - if (!g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) { - g_warning ("%s: (NMRemoteConnection) error initializing: %s\n", - __func__, error->message); - } - g_error_free (error); - } - priv->inited = TRUE; - } -} - -/****************************************************************/ - static void remote_call_dbus_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data) { @@ -434,7 +410,6 @@ nm_remote_connection_get_unsaved (NMRemoteConnection *connection) { g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); - _nm_remote_connection_ensure_inited (connection); return NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->unsaved; } @@ -542,28 +517,26 @@ properties_changed_cb (DBusGProxy *proxy, /****************************************************************/ static void -constructed (GObject *object) +init_common (NMRemoteConnection *self) { - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object); - - G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructed (object); + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); g_assert (priv->bus); - g_assert (nm_connection_get_path (NM_CONNECTION (object))); + g_assert (nm_connection_get_path (NM_CONNECTION (self))); priv->proxy = _nm_dbus_new_proxy_for_connection (priv->bus, - nm_connection_get_path (NM_CONNECTION (object)), + nm_connection_get_path (NM_CONNECTION (self)), NM_DBUS_INTERFACE_SETTINGS_CONNECTION); g_assert (priv->proxy); dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT); dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), object, NULL); + dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), self, NULL); dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), object, NULL); + dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), self, NULL); - g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), object); + g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), self); /* Monitor properties */ dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, @@ -575,11 +548,11 @@ constructed (GObject *object) G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged", G_CALLBACK (properties_changed_cb), - object, + self, NULL); priv->props_proxy = _nm_dbus_new_proxy_for_connection (priv->bus, - nm_connection_get_path (NM_CONNECTION (object)), + nm_connection_get_path (NM_CONNECTION (self)), DBUS_INTERFACE_PROPERTIES); g_assert (priv->props_proxy); } @@ -587,16 +560,19 @@ constructed (GObject *object) static gboolean init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { + NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); GHashTable *hash; + init_common (self); + if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error, G_TYPE_INVALID, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash, G_TYPE_INVALID)) return FALSE; priv->visible = TRUE; - replace_settings (NM_REMOTE_CONNECTION (initable), hash); + replace_settings (self, hash); g_hash_table_destroy (hash); /* Get properties */ @@ -607,7 +583,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) DBUS_TYPE_G_MAP_OF_VARIANT, &hash, G_TYPE_INVALID)) return FALSE; - properties_changed_cb (priv->props_proxy, hash, NM_REMOTE_CONNECTION (initable)); + properties_changed_cb (priv->props_proxy, hash, self); g_hash_table_destroy (hash); return TRUE; @@ -623,10 +599,8 @@ init_async_complete (NMRemoteConnectionInitData *init_data, GError *error) { if (error) g_simple_async_result_take_error (init_data->result, error); - else { + else g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); - NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection)->inited = TRUE; - } g_simple_async_result_complete (init_data->result); g_object_unref (init_data->result); @@ -687,12 +661,13 @@ init_async (GAsyncInitable *initable, int io_priority, 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->result = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); + init_common (init_data->connection); + dbus_g_proxy_begin_call (priv->proxy, "GetSettings", init_get_settings_cb, init_data, NULL, G_TYPE_INVALID); @@ -755,8 +730,6 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - _nm_remote_connection_ensure_inited (NM_REMOTE_CONNECTION (object)); - switch (prop_id) { case PROP_UNSAVED: g_value_set_boolean (value, NM_REMOTE_CONNECTION_GET_PRIVATE (object)->unsaved); @@ -830,7 +803,6 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; - object_class->constructed = constructed; /* Properties */ /** diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index 5e35d1429..1fc80ef44 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -131,7 +131,6 @@ G_DEFINE_TYPE_WITH_CODE (NMRemoteSettings, nm_remote_settings, G_TYPE_OBJECT, typedef struct { DBusGConnection *bus; gboolean private_bus; - gboolean inited; DBusGProxy *proxy; GHashTable *connections; @@ -191,29 +190,6 @@ nm_remote_settings_error_quark (void) /**********************************************************************/ -static void -_nm_remote_settings_ensure_inited (NMRemoteSettings *self) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - GError *error = NULL; - - if (!priv->inited) { - if (!g_initable_init (G_INITABLE (self), NULL, &error)) { - /* Don't warn when the call times out because the settings service can't - * be activated or whatever. - */ - if (!g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) { - g_warning ("%s: (NMRemoteSettings) error initializing: %s\n", - __func__, error->message); - } - g_error_free (error); - } - priv->inited = TRUE; - } -} - -/**********************************************************************/ - typedef struct { NMRemoteSettings *self; NMRemoteSettingsAddConnectionFunc callback; @@ -278,8 +254,6 @@ nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (priv->service_running) { GHashTableIter iter; NMConnection *candidate; @@ -315,8 +289,6 @@ nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const cha priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - return priv->service_running ? g_hash_table_lookup (priv->connections, path) : NULL; } @@ -342,8 +314,6 @@ nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const cha priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (priv->service_running) { g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) { @@ -529,18 +499,17 @@ new_connection_cb (DBusGProxy *proxy, const char *path, gpointer user_data) NM_REMOTE_CONNECTION_BUS, priv->bus, NM_CONNECTION_PATH, path, NULL); - if (connection) { - g_async_initable_init_async (G_ASYNC_INITABLE (connection), - G_PRIORITY_DEFAULT, NULL, - connection_inited, self); + g_async_initable_init_async (G_ASYNC_INITABLE (connection), + G_PRIORITY_DEFAULT, NULL, + connection_inited, self); + + /* Add the connection to the pending table to wait for it to retrieve + * it's settings asynchronously over D-Bus. The connection isn't + * really valid until it has all its settings, so hide it until it does. + */ + move_connection (self, connection, NULL, priv->pending); + g_object_unref (connection); /* move_connection() takes a ref */ - /* Add the connection to the pending table to wait for it to retrieve - * it's settings asynchronously over D-Bus. The connection isn't - * really valid until it has all its settings, so hide it until it does. - */ - move_connection (self, connection, NULL, priv->pending); - g_object_unref (connection); /* move_connection() takes a ref */ - } return connection; } @@ -615,8 +584,6 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings) priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (priv->service_running) { g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, &value)) @@ -680,8 +647,6 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (!priv->service_running) return FALSE; @@ -735,8 +700,6 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (!priv->service_running) return FALSE; @@ -797,8 +760,6 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (!priv->service_running) { g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR, NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE, @@ -846,8 +807,6 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (!priv->service_running) { g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR, NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE, @@ -935,8 +894,6 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings, priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - _nm_remote_settings_ensure_inited (settings); - if (!priv->service_running) return FALSE; @@ -1046,7 +1003,8 @@ name_owner_changed (DBusGProxy *proxy, /** * nm_remote_settings_new: - * @bus: (allow-none): a valid and connected D-Bus connection + * @cancellable: a #GCancellable, or %NULL + * @error: location for a #GError, or %NULL * * Creates a new object representing the remote settings service. * @@ -1057,13 +1015,11 @@ name_owner_changed (DBusGProxy *proxy, * Returns: the new remote settings object on success, or %NULL on failure **/ NMRemoteSettings * -nm_remote_settings_new (DBusGConnection *bus) +nm_remote_settings_new (GCancellable *cancellable, + GError **error) { - NMRemoteSettings *self; - - self = g_object_new (NM_TYPE_REMOTE_SETTINGS, NM_REMOTE_SETTINGS_BUS, bus, NULL); - _nm_remote_settings_ensure_inited (self); - return self; + return g_initable_new (NM_TYPE_REMOTE_SETTINGS, cancellable, error, + NULL); } static void @@ -1072,7 +1028,7 @@ remote_settings_inited (GObject *source, GAsyncResult *result, gpointer user_dat GSimpleAsyncResult *simple = user_data; GError *error = NULL; - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source), result, &error)) + if (!g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error)) g_simple_async_result_take_error (simple, error); else g_simple_async_result_set_op_res_gpointer (simple, source, g_object_unref); @@ -1082,7 +1038,6 @@ remote_settings_inited (GObject *source, GAsyncResult *result, gpointer user_dat /** * nm_remote_settings_new_async: - * @bus: (allow-none): a valid and connected D-Bus connection * @cancellable: a #GCancellable, or %NULL * @callback: callback to call when the settings object is created * @user_data: data for @callback @@ -1093,19 +1048,16 @@ remote_settings_inited (GObject *source, GAsyncResult *result, gpointer user_dat * result. **/ void -nm_remote_settings_new_async (DBusGConnection *bus, GCancellable *cancellable, +nm_remote_settings_new_async (GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - NMRemoteSettings *self; GSimpleAsyncResult *simple; simple = g_simple_async_result_new (NULL, callback, user_data, nm_remote_settings_new_async); - self = g_object_new (NM_TYPE_REMOTE_SETTINGS, - NM_REMOTE_SETTINGS_BUS, bus, - NULL); - g_async_initable_init_async (G_ASYNC_INITABLE (self), G_PRIORITY_DEFAULT, - cancellable, remote_settings_inited, simple); + g_async_initable_new_async (NM_TYPE_REMOTE_SETTINGS, G_PRIORITY_DEFAULT, cancellable, + remote_settings_inited, simple, + NULL); } /** @@ -1153,11 +1105,9 @@ nm_remote_settings_init (NMRemoteSettings *self) } static void -constructed (GObject *object) +init_common (NMRemoteSettings *self) { - NMRemoteSettingsPrivate *priv; - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); + NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); if (priv->private_bus == FALSE) { /* D-Bus proxy for clearing connections on NameOwnerChanged */ @@ -1177,7 +1127,7 @@ constructed (GObject *object) dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged", G_CALLBACK (name_owner_changed), - object, NULL); + self, NULL); } priv->proxy = _nm_dbus_new_proxy_for_connection (priv->bus, @@ -1191,7 +1141,7 @@ constructed (GObject *object) G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "NewConnection", G_CALLBACK (new_connection_cb), - object, + self, NULL); /* D-Bus properties proxy */ @@ -1210,7 +1160,7 @@ constructed (GObject *object) G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged", G_CALLBACK (properties_changed_cb), - object, + self, NULL); } @@ -1221,6 +1171,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); GHashTable *props; + init_common (settings); + if (priv->private_bus == FALSE) { if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", error, G_TYPE_STRING, NM_DBUS_SERVICE, @@ -1264,10 +1216,6 @@ typedef struct { static void init_async_complete (NMRemoteSettingsInitData *init_data) { - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (init_data->settings); - - priv->inited = TRUE; - g_simple_async_result_complete (init_data->result); g_object_unref (init_data->result); g_slice_free (NMRemoteSettingsInitData, init_data); @@ -1358,6 +1306,8 @@ init_async (GAsyncInitable *initable, int io_priority, init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); + init_common (init_data->settings); + if (priv->private_bus) init_get_properties (init_data); else { @@ -1442,8 +1392,6 @@ get_property (GObject *object, guint prop_id, { NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); - _nm_remote_settings_ensure_inited (NM_REMOTE_SETTINGS (object)); - switch (prop_id) { case PROP_BUS: g_value_set_boxed (value, priv->bus); @@ -1471,7 +1419,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class) g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate)); /* 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-remote-settings.h b/libnm/nm-remote-settings.h index 12156d19f..9ce5e81ab 100644 --- a/libnm/nm-remote-settings.h +++ b/libnm/nm-remote-settings.h @@ -23,7 +23,6 @@ #define NM_REMOTE_SETTINGS_H #include -#include #include #include @@ -105,10 +104,10 @@ struct _NMRemoteSettingsClass { GType nm_remote_settings_get_type (void); -NMRemoteSettings *nm_remote_settings_new (DBusGConnection *bus); +NMRemoteSettings *nm_remote_settings_new (GCancellable *cancellable, + GError **error); -void nm_remote_settings_new_async (DBusGConnection *bus, - GCancellable *cancellable, +void nm_remote_settings_new_async (GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NMRemoteSettings *nm_remote_settings_new_finish (GAsyncResult *result, diff --git a/libnm/nm-vpn-connection.c b/libnm/nm-vpn-connection.c index d816dde6f..532592772 100644 --- a/libnm/nm-vpn-connection.c +++ b/libnm/nm-vpn-connection.c @@ -71,9 +71,6 @@ nm_vpn_connection_get_banner (NMVpnConnection *vpn) priv = NM_VPN_CONNECTION_GET_PRIVATE (vpn); - /* We need to update vpn_state first in case it's unknown. */ - _nm_object_ensure_inited (NM_OBJECT (vpn)); - if (priv->vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED) return NULL; @@ -93,7 +90,6 @@ nm_vpn_connection_get_vpn_state (NMVpnConnection *vpn) { g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_CONNECTION_STATE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (vpn)); return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->vpn_state; } @@ -171,8 +167,6 @@ get_property (GObject *object, { NMVpnConnection *self = NM_VPN_CONNECTION (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_VPN_STATE: g_value_set_uint (value, nm_vpn_connection_get_vpn_state (self)); diff --git a/libnm/nm-vpn-plugin.c b/libnm/nm-vpn-plugin.c index f9e85a891..289d27a0c 100644 --- a/libnm/nm-vpn-plugin.c +++ b/libnm/nm-vpn-plugin.c @@ -20,6 +20,10 @@ */ #include + +#include +#include + #include "nm-glib-compat.h" #include "nm-vpn-plugin.h" #include "nm-vpn-enum-types.h" @@ -68,7 +72,11 @@ static gboolean impl_vpn_plugin_set_failure (NMVpnPlugin *plugin, #define NM_VPN_PLUGIN_QUIT_TIMER 20 -G_DEFINE_ABSTRACT_TYPE (NMVpnPlugin, nm_vpn_plugin, G_TYPE_OBJECT) +static void nm_vpn_plugin_initable_iface_init (GInitableIface *iface); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMVpnPlugin, nm_vpn_plugin, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_vpn_plugin_initable_iface_init); + ) typedef struct { NMVpnServiceState state; @@ -729,71 +737,51 @@ nm_vpn_plugin_init (NMVpnPlugin *plugin) NULL); } -static GObject * -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) +static gboolean +init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { - GObject *object; + NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (initable); NMVpnPlugin *plugin; - NMVpnPluginPrivate *priv; DBusGConnection *connection; DBusGProxy *proxy; guint request_name_result; - GError *err = NULL; - object = G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->constructor (type, - n_construct_params, - construct_params); - if (!object) - return NULL; + if (!priv->dbus_service_name) { + g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, + _("No service name specified")); + return FALSE; + } - priv = NM_VPN_PLUGIN_GET_PRIVATE (object); - if (!priv->dbus_service_name) - goto err; - - connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); if (!connection) - goto err; + return FALSE; proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); - if (!dbus_g_proxy_call (proxy, "RequestName", &err, + if (!dbus_g_proxy_call (proxy, "RequestName", error, G_TYPE_STRING, priv->dbus_service_name, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_object_unref (proxy); - goto err; + return FALSE; } - g_object_unref (proxy); dbus_g_connection_register_g_object (connection, NM_VPN_DBUS_PLUGIN_PATH, - object); + G_OBJECT (initable)); - plugin = NM_VPN_PLUGIN (object); + plugin = NM_VPN_PLUGIN (initable); nm_vpn_plugin_set_connection (plugin, connection); nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_INIT); - return object; - - err: - if (err) { - g_warning ("Failed to initialize VPN plugin: %s", err->message); - g_error_free (err); - } - - if (object) - g_object_unref (object); - - return NULL; + return TRUE; } static void @@ -805,7 +793,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DBUS_SERVICE_NAME: /* Construct-only */ - priv->dbus_service_name = g_strdup (g_value_get_string (value)); + priv->dbus_service_name = g_value_dup_string (value); break; case PROP_STATE: nm_vpn_plugin_set_state (NM_VPN_PLUGIN (object), @@ -940,7 +928,6 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) &dbus_glib_nm_vpn_plugin_object_info); /* virtual methods */ - object_class->constructor = constructor; object_class->set_property = set_property; object_class->get_property = get_property; object_class->dispose = dispose; @@ -1062,3 +1049,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) setup_unix_signal_handler (); } + +static void +nm_vpn_plugin_initable_iface_init (GInitableIface *iface) +{ + iface->init = init_sync; +} diff --git a/libnm/nm-wimax-nsp.c b/libnm/nm-wimax-nsp.c index 168528f42..5d4d2e2c3 100644 --- a/libnm/nm-wimax-nsp.c +++ b/libnm/nm-wimax-nsp.c @@ -66,7 +66,6 @@ nm_wimax_nsp_get_name (NMWimaxNsp *nsp) { g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NULL); - _nm_object_ensure_inited (NM_OBJECT (nsp)); return NM_WIMAX_NSP_GET_PRIVATE (nsp)->name; } @@ -83,7 +82,6 @@ nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp) { g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), 0); - _nm_object_ensure_inited (NM_OBJECT (nsp)); return NM_WIMAX_NSP_GET_PRIVATE (nsp)->signal_quality; } @@ -100,7 +98,6 @@ nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp) { g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN); - _nm_object_ensure_inited (NM_OBJECT (nsp)); return NM_WIMAX_NSP_GET_PRIVATE (nsp)->network_type; } @@ -214,8 +211,6 @@ get_property (GObject *object, { NMWimaxNsp *nsp = NM_WIMAX_NSP (object); - _nm_object_ensure_inited (NM_OBJECT (object)); - switch (prop_id) { case PROP_NAME: g_value_set_string (value, nm_wimax_nsp_get_name (nsp)); diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 424aaa4f5..227fc627d 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -361,6 +361,7 @@ test_service_running (void) guint quit_id; int running_changed = 0; gboolean running; + GError *error = NULL; loop = g_main_loop_new (NULL, FALSE); @@ -372,7 +373,11 @@ test_service_running (void) /* Now kill the test service. */ nm_test_service_cleanup (sinfo); - settings2 = nm_remote_settings_new (bus); + settings2 = g_initable_new (NM_TYPE_REMOTE_SETTINGS, NULL, &error, + NM_REMOTE_SETTINGS_BUS, bus, + NULL); + g_assert_no_error (error); + g_assert (settings != NULL); /* settings2 should know that NM is running, but the previously-created * settings hasn't gotten the news yet. @@ -433,7 +438,10 @@ main (int argc, char **argv) sinfo = nm_test_service_init (); - settings = nm_remote_settings_new (bus); + settings = g_initable_new (NM_TYPE_REMOTE_SETTINGS, NULL, &error, + NM_REMOTE_SETTINGS_BUS, bus, + NULL); + g_assert_no_error (error); g_assert (settings != NULL); /* FIXME: these tests assume that they get run in order, but g_test_run()