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**.
This commit is contained in:
Dan Winship
2014-05-15 14:25:07 -04:00
parent 8ca2998d81
commit 258e74eb0c
44 changed files with 224 additions and 527 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;