Commit 258e74eb authored by Dan Winship's avatar Dan Winship

libnm: make the the use of GInitable mandatory

Remove _nm_object_ensure_inited(), etc; objects that implement
GInitable are now mandatory-to-init().

Remove constructor() implementations that sometimes return NULL; do
all the relevant checking in init() instead.

Make nm_client_new() and nm_remote_settings_new() take a GCancellable
and a GError**.
parent 8ca2998d
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
}
}
......
......@@ -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)"), "<timeout>"},
......@@ -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;
}
......
......@@ -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] */
......
......@@ -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 <glib.h>
......@@ -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;
}
......@@ -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;
}
......
......@@ -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 <glib.h>
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
......@@ -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;
......
......@@ -51,7 +51,7 @@ if __name__ == "__main__":
sys.exit('Usage: %s <interface>' % 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)
......
......@@ -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())
......
......@@ -124,7 +124,7 @@ if __name__ == "__main__":
sys.exit('Usage: %s <interface>' % 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)
......
......@@ -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:
......
......@@ -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;
......
......@@ -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));
......
......@@ -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));
......
......@@ -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));
......