libnm: merge NMRemoteSettings into NMClient

Make NMRemoteSettings internal and have NMClient wrap all of its APIs,
just like it does with NMManager.
This commit is contained in:
Dan Winship 2014-09-29 10:58:16 -04:00
parent c1f1e96181
commit 6f3d1f9526
26 changed files with 887 additions and 835 deletions

View file

@ -4894,7 +4894,7 @@ typedef struct {
} AddConnectionInfo;
static void
add_connection_cb (GObject *settings,
add_connection_cb (GObject *client,
GAsyncResult *result,
gpointer user_data)
{
@ -4903,8 +4903,7 @@ add_connection_cb (GObject *settings,
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
connection = nm_client_add_connection_finish (NM_CLIENT (client), result, &error);
if (error) {
g_dbus_error_strip_remote_error (error);
g_string_printf (nmc->return_text,
@ -4926,13 +4925,13 @@ add_connection_cb (GObject *settings,
static void
add_new_connection (gboolean persistent,
NMRemoteSettings *settings,
NMClient *client,
NMConnection *connection,
GAsyncReadyCallback callback,
gpointer user_data)
{
nm_remote_settings_add_connection_async (settings, connection, persistent,
NULL, callback, user_data);
nm_client_add_connection_async (client, connection, persistent,
NULL, callback, user_data);
}
static void
@ -5236,7 +5235,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
/* Tell the settings service to add the new connection */
add_new_connection (save_bool,
nmc->system_settings,
nmc->client,
connection,
add_connection_cb,
info);
@ -6335,15 +6334,14 @@ set_info_and_signal_editor_thread (GError *error, MonitorACInfo *monitor_ac_info
}
static void
add_connection_editor_cb (GObject *settings,
add_connection_editor_cb (GObject *client,
GAsyncResult *result,
gpointer user_data)
{
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
connection = nm_client_add_connection_finish (NM_CLIENT (client), result, &error);
set_info_and_signal_editor_thread (error, NULL);
g_clear_object (&connection);
@ -6958,8 +6956,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
menu_ctx.valid_props_str = NULL;
/* Get remote connection */
con_tmp = nm_remote_settings_get_connection_by_uuid (nmc->system_settings,
nm_connection_get_uuid (connection));
con_tmp = nm_client_get_connection_by_uuid (nmc->client,
nm_connection_get_uuid (connection));
g_weak_ref_init (&weak, con_tmp);
rem_con = g_weak_ref_get (&weak);
@ -7393,7 +7391,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
info->nmc = nmc;
info->con_name = g_strdup (nm_connection_get_id (connection));
add_new_connection (persistent,
nmc->system_settings,
nmc->client,
connection,
add_connection_editor_cb,
info);
@ -7423,8 +7421,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
nm_connection_get_id (connection),
nm_connection_get_uuid (connection));
con_tmp = nm_remote_settings_get_connection_by_uuid (nmc->system_settings,
nm_connection_get_uuid (connection));
con_tmp = nm_client_get_connection_by_uuid (nmc->client,
nm_connection_get_uuid (connection));
g_weak_ref_set (&weak, con_tmp);
refresh_remote_connection (&weak, &rem_con);
@ -8022,8 +8020,8 @@ do_connection_modify (NmCli *nmc,
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
goto finish;
}
rc = nm_remote_settings_get_connection_by_uuid (nmc->system_settings,
nm_connection_get_uuid (connection));
rc = nm_client_get_connection_by_uuid (nmc->client,
nm_connection_get_uuid (connection));
if (!rc) {
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), name);
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
@ -8289,7 +8287,7 @@ do_connection_reload (NmCli *nmc, int argc, char **argv)
return nmc->return_value;
}
if (!nm_remote_settings_reload_connections (nmc->system_settings, NULL, &error)) {
if (!nm_client_reload_connections (nmc->client, NULL, &error)) {
g_dbus_error_strip_remote_error (error);
g_string_printf (nmc->return_text, _("Error: failed to reload connections: %s."),
error->message);
@ -8327,7 +8325,7 @@ do_connection_load (NmCli *nmc, int argc, char **argv)
filenames[i] = argv[i];
filenames[i] = NULL;
nm_remote_settings_load_connections (nmc->system_settings, filenames, &failures, NULL, &error);
nm_client_load_connections (nmc->client, filenames, &failures, NULL, &error);
g_free (filenames);
if (error) {
g_dbus_error_strip_remote_error (error);
@ -8456,28 +8454,8 @@ do_connections (NmCli *nmc, int argc, char **argv)
if (!nmc_versions_match (nmc))
return nmc->return_value;
/* Get NMRemoteSettings object */
if (!(nmc->system_settings = nm_remote_settings_new (NULL, &error))) {
g_dbus_error_strip_remote_error (error);
g_string_printf (nmc->return_text, _("Error: could not get remote settings: %s."),
error->message);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->should_wait = FALSE;
return nmc->return_value;
}
/* Find out whether settings service is running */
g_object_get (nmc->system_settings, NM_REMOTE_SETTINGS_NM_RUNNING, &nmc->system_settings_running, NULL);
if (!nmc->system_settings_running) {
g_string_printf (nmc->return_text, _("Error: Can't obtain connections: settings service is not running."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->should_wait = FALSE;
return nmc->return_value;
}
/* Get the connection list */
nmc->connections = nm_remote_settings_list_connections (nmc->system_settings);
nmc->connections = nm_client_list_connections (nmc->client);
/* Now parse the command line and perform the required operation */
if (argc == 0) {

View file

@ -540,7 +540,7 @@ save_hostname_cb (GObject *object, GAsyncResult *result, gpointer user_data)
NmCli *nmc = (NmCli *) user_data;
GError *error = NULL;
nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error);
nm_client_save_hostname_finish (NM_CLIENT (object), result, &error);
if (error) {
g_dbus_error_strip_remote_error (error);
g_string_printf (nmc->return_text, _("Error: failed to set hostname: %s"),
@ -585,28 +585,16 @@ do_general (NmCli *nmc, int argc, char **argv)
show_nm_status (nmc, NULL, NULL);
}
else if (matches (*argv, "hostname") == 0) {
NMRemoteSettings *rem_settings;
if (nmc_arg_is_help (*(argv+1))) {
usage_general_hostname ();
goto finish;
}
/* get system settings */
if (!(rem_settings = nm_remote_settings_new (NULL, &error))) {
g_dbus_error_strip_remote_error (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;
}
if (next_arg (&argc, &argv) != 0) {
/* no arguments -> get hostname */
char *hostname = NULL;
g_object_get (rem_settings, NM_REMOTE_SETTINGS_HOSTNAME, &hostname, NULL);
g_object_get (nmc->client, NM_CLIENT_HOSTNAME, &hostname, NULL);
if (hostname)
g_print ("%s\n", hostname);
g_free (hostname);
@ -618,7 +606,7 @@ do_general (NmCli *nmc, int argc, char **argv)
g_print ("Warning: ignoring extra garbage after '%s' hostname\n", hostname);
nmc->should_wait = TRUE;
nm_remote_settings_save_hostname_async (rem_settings, hostname, NULL, save_hostname_cb, nmc);
nm_client_save_hostname_async (nmc->client, hostname, NULL, save_hostname_cb, nmc);
}
}
else if (matches (*argv, "permissions") == 0) {

View file

@ -498,8 +498,6 @@ nmc_init (NmCli *nmc)
nmc->timeout = -1;
nmc->system_settings = NULL;
nmc->system_settings_running = FALSE;
nmc->connections = NULL;
nmc->should_wait = FALSE;
@ -526,7 +524,6 @@ nmc_cleanup (NmCli *nmc)
g_string_free (nmc->return_text, TRUE);
if (nmc->system_settings) g_object_unref (nmc->system_settings);
g_slist_free (nmc->connections);
g_free (nmc->required_fields);

View file

@ -110,8 +110,6 @@ typedef struct _NmCli {
int timeout; /* Operation timeout */
NMRemoteSettings *system_settings; /* System settings */
gboolean system_settings_running; /* Is system settings service running? */
GSList *connections; /* List of connections */
gboolean should_wait; /* Indication that nmcli should not end yet */

View file

@ -254,14 +254,14 @@ nm_editor_utils_get_connection_type_list (void)
}
static char *
get_available_connection_name (const char *format,
NMRemoteSettings *settings)
get_available_connection_name (const char *format,
NMClient *client)
{
GSList *connections, *iter, *names = NULL;
char *cname = NULL;
int i = 0;
connections = nm_remote_settings_list_connections (settings);
connections = nm_client_list_connections (client);
for (iter = connections; iter; iter = iter->next) {
const char *id;
@ -297,7 +297,7 @@ get_available_connection_name (const char *format,
* nm_editor_utils_create_connection:
* @type: the type of the connection's primary #NMSetting
* @master: (allow-none): the connection's master, if any
* @settings: an #NMRemoteSettings
* @client: an #NMClient
*
* Creates a new #NMConnection of the given type, automatically
* creating a UUID and an appropriate not-currently-in-use connection
@ -309,9 +309,9 @@ get_available_connection_name (const char *format,
* Returns: a new #NMConnection
*/
NMConnection *
nm_editor_utils_create_connection (GType type,
NMConnection *master,
NMRemoteSettings *settings)
nm_editor_utils_create_connection (GType type,
NMConnection *master,
NMClient *client)
{
NMEditorConnectionTypeData **types;
NMEditorConnectionTypeDataReal *type_data = NULL;
@ -359,7 +359,7 @@ nm_editor_utils_create_connection (GType type,
}
uuid = nm_utils_uuid_generate ();
id = get_available_connection_name (type_data->id_format, settings);
id = get_available_connection_name (type_data->id_format, client);
g_object_set (s_con,
NM_SETTING_CONNECTION_UUID, uuid,

View file

@ -34,9 +34,9 @@ typedef struct {
NMEditorConnectionTypeData **nm_editor_utils_get_connection_type_list (void);
NMEditorConnectionTypeData *nm_editor_utils_get_connection_type_data (NMConnection *conn);
NMConnection *nm_editor_utils_create_connection (GType type,
NMConnection *master,
NMRemoteSettings *settings);
NMConnection *nm_editor_utils_create_connection (GType type,
NMConnection *master,
NMClient *client);
G_END_DECLS

View file

@ -480,7 +480,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
devices = nm_client_get_devices (nm_client);
acs = nm_client_get_active_connections (nm_client);
connections = nm_remote_settings_list_connections (nm_settings);
connections = nm_client_list_connections (nm_client);
nmt_devices = NULL;
@ -636,9 +636,9 @@ nmt_connect_connection_list_get_connection (NmtConnectConnectionList *list,
g_return_val_if_fail (identifier, FALSE);
if (nm_utils_is_uuid (identifier))
conn = NM_CONNECTION (nm_remote_settings_get_connection_by_uuid (nm_settings, identifier));
conn = NM_CONNECTION (nm_client_get_connection_by_uuid (nm_client, identifier));
if (!conn)
conn = NM_CONNECTION (nm_remote_settings_get_connection_by_id (nm_settings, identifier));
conn = NM_CONNECTION (nm_client_get_connection_by_id (nm_client, identifier));
for (diter = priv->nmt_devices; diter; diter = diter->next) {
nmtdev = diter->data;

View file

@ -191,7 +191,7 @@ nmt_edit_connection_list_rebuild (NmtEditConnectionList *list)
selected_conn = nmt_newt_listbox_get_active_key (priv->listbox);
free_connections (list);
priv->connections = nm_remote_settings_list_connections (nm_settings);
priv->connections = nm_client_list_connections (nm_client);
for (iter = priv->connections; iter; iter = next) {
conn = iter->data;
next = iter->next;
@ -293,7 +293,7 @@ nmt_edit_connection_list_constructed (GObject *object)
if (priv->extra)
nmt_newt_button_box_add_widget_end (priv->buttons, priv->extra);
g_signal_connect (nm_settings, "notify::" NM_REMOTE_SETTINGS_CONNECTIONS,
g_signal_connect (nm_client, "notify::" NM_CLIENT_CONNECTIONS,
G_CALLBACK (rebuild_on_connections_changed), list);
nmt_edit_connection_list_rebuild (list);

View file

@ -115,15 +115,14 @@ connection_updated (GObject *connection,
}
static void
connection_added (GObject *settings,
connection_added (GObject *client,
GAsyncResult *result,
gpointer op)
{
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
connection = nm_client_add_connection_finish (NM_CLIENT (client), result, &error);
nmt_sync_op_complete_boolean (op, error == NULL, error);
g_clear_object (&connection);
g_clear_error (&error);
@ -157,8 +156,8 @@ save_connection_and_exit (NmtNewtButton *button,
*/
nm_connection_clear_secrets (priv->orig_connection);
} else {
nm_remote_settings_add_connection_async (nm_settings, priv->orig_connection, TRUE,
NULL, connection_added, &op);
nm_client_add_connection_async (nm_client, priv->orig_connection, TRUE,
NULL, connection_added, &op);
if (!nmt_sync_op_wait_boolean (&op, &error)) {
nmt_newt_message_dialog (_("Unable to add new connection: %s"),
error->message);

View file

@ -87,7 +87,7 @@ edit_connection_list_filter (NmtEditConnectionList *list,
&& g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0)
return TRUE;
conns = nm_remote_settings_list_connections (nm_settings);
conns = nm_client_list_connections (nm_client);
for (iter = conns; iter; iter = iter->next) {
uuid = nm_connection_get_uuid (iter->data);
ifname = nm_connection_get_interface_name (iter->data);
@ -180,7 +180,7 @@ create_connection (NmtNewtWidget *widget, gpointer list)
GType type = (GType) GPOINTER_TO_SIZE (nmt_newt_listbox_get_active_key (priv->listbox));
NMConnection *connection;
connection = nm_editor_utils_create_connection (type, priv->master, nm_settings);
connection = nm_editor_utils_create_connection (type, priv->master, nm_client);
nmt_edit_connection (connection);
g_object_unref (connection);
@ -473,7 +473,7 @@ connection_deleted_callback (GObject *connection,
}
static void
connection_removed_signal (NMRemoteSettings *settings,
connection_removed_signal (NMClient *client,
NMRemoteConnection *connection,
gpointer user_data)
{
@ -496,7 +496,7 @@ remove_one_connection (NMRemoteConnection *connection)
nmt_sync_op_init (&data.op);
data.connection = connection;
g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTION_REMOVED,
g_signal_connect (nm_client, NM_CLIENT_CONNECTION_REMOVED,
G_CALLBACK (connection_removed_signal), &data);
nm_remote_connection_delete_async (connection, NULL, connection_deleted_callback, &data);
@ -507,7 +507,7 @@ remove_one_connection (NMRemoteConnection *connection)
g_error_free (error);
}
g_signal_handlers_disconnect_by_func (nm_settings, G_CALLBACK (connection_removed_signal), &data);
g_signal_handlers_disconnect_by_func (nm_client, G_CALLBACK (connection_removed_signal), &data);
}
void
@ -532,7 +532,7 @@ nmt_remove_connection (NMRemoteConnection *connection)
uuid = nm_connection_get_uuid (NM_CONNECTION (connection));
iface = nm_connection_get_interface_name (NM_CONNECTION (connection));
conns = nm_remote_settings_list_connections (nm_settings);
conns = nm_client_list_connections (nm_client);
for (iter = conns; iter; iter = iter->next) {
slave = iter->data;
s_con = nm_connection_get_setting_connection (NM_CONNECTION (slave));
@ -553,9 +553,9 @@ nmtui_edit (int argc, char **argv)
if (argc == 2) {
if (nm_utils_is_uuid (argv[1]))
conn = NM_CONNECTION (nm_remote_settings_get_connection_by_uuid (nm_settings, argv[1]));
conn = NM_CONNECTION (nm_client_get_connection_by_uuid (nm_client, argv[1]));
if (!conn)
conn = NM_CONNECTION (nm_remote_settings_get_connection_by_id (nm_settings, argv[1]));
conn = NM_CONNECTION (nm_client_get_connection_by_id (nm_client, argv[1]));
if (!conn) {
nmt_newt_message_dialog ("%s: no such connection '%s'\n", argv[0], argv[1]);

View file

@ -71,8 +71,8 @@ nmtui_hostname_run_dialog (void)
ok = nmt_newt_button_box_add_end (bbox, _("OK"));
nmt_newt_widget_set_exit_on_activate (ok, TRUE);
g_object_get (G_OBJECT (nm_settings),
NM_REMOTE_SETTINGS_HOSTNAME, &hostname,
g_object_get (G_OBJECT (nm_client),
NM_CLIENT_HOSTNAME, &hostname,
NULL);
nmt_newt_entry_set_text (entry, hostname);
g_free (hostname);
@ -92,7 +92,7 @@ hostname_set (GObject *object,
{
GError *error = NULL;
nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error);
nm_client_save_hostname_finish (NM_CLIENT (object), result, &error);
nmt_sync_op_complete_boolean (op, error == NULL, error);
g_clear_error (&error);
}
@ -112,7 +112,7 @@ nmtui_hostname (int argc, char **argv)
if (hostname) {
nmt_sync_op_init (&op);
nm_remote_settings_save_hostname_async (nm_settings, hostname, NULL, hostname_set, &op);
nm_client_save_hostname_async (nm_client, hostname, NULL, hostname_set, &op);
if (nmt_sync_op_wait_boolean (&op, &error)) {
/* Translators: this indicates the result. ie, "I have set the hostname to ..." */
nmt_newt_message_dialog (_("Set hostname to '%s'"), hostname);

View file

@ -44,7 +44,6 @@
#include "nmtui-hostname.h"
NMClient *nm_client;
NMRemoteSettings *nm_settings;
static GMainLoop *loop;
typedef NmtNewtForm * (*NmtuiSubprogram) (int argc, char **argv);
@ -244,13 +243,6 @@ main (int argc, char **argv)
exit (1);
}
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);
}
if (sleep_on_startup)
sleep (5);
@ -296,7 +288,6 @@ main (int argc, char **argv)
nmt_newt_finished ();
g_object_unref (nm_client);
g_object_unref (nm_settings);
return 0;
}

View file

@ -24,7 +24,6 @@
G_BEGIN_DECLS
extern NMClient *nm_client;
extern NMRemoteSettings *nm_settings;
void nmtui_quit (void);

View file

@ -34,10 +34,12 @@ IGNORE_HFILES= \
nm-dbus-helpers-private.h \
nm-core-internal.h \
nm-device-private.h \
nm-manager.h \
nm-object-cache.h \
nm-object-private.h \
nm-param-spec-dbus.h \
nm-remote-connection-private.h \
nm-remote-settings.h \
nm-setting-private.h \
nm-types-private.h \
nm-utils-private.h

View file

@ -66,7 +66,6 @@
<chapter>
<title>Client Object API Reference</title>
<xi:include href="xml/nm-client.xml"/>
<xi:include href="xml/nm-remote-settings.xml"/>
<xi:include href="xml/nm-secret-agent.xml"/>
<xi:include href="xml/nm-object.xml"/>
</chapter>

View file

@ -31,7 +31,7 @@
#include <NetworkManager.h>
static void
added_cb (GObject *settings,
added_cb (GObject *client,
GAsyncResult *result,
gpointer user_data)
{
@ -42,8 +42,7 @@ added_cb (GObject *settings,
/* NM responded to our request; either handle the resulting error or
* print out the object path of the connection we just added.
*/
remote = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
result, &error);
remote = nm_client_add_connection_finish (NM_CLIENT (client), result, &error);
if (error) {
g_print ("Error adding connection: %s", error->message);
@ -58,7 +57,7 @@ added_cb (GObject *settings,
}
static void
add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name)
add_connection (NMClient *client, GMainLoop *loop, const char *con_name)
{
NMConnection *connection;
NMSettingConnection *s_con;
@ -94,7 +93,7 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
/* Ask the settings service to add the new connection; we'll quit the
* mainloop and exit when the callback is called.
*/
nm_remote_settings_add_connection_async (settings, connection, TRUE, NULL, added_cb, loop);
nm_client_add_connection_async (client, connection, TRUE, NULL, added_cb, loop);
g_object_unref (connection);
}
@ -102,7 +101,7 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
int
main (int argc, char *argv[])
{
NMRemoteSettings *settings;
NMClient *client;
GMainLoop *loop;
GError *error = NULL;
@ -113,21 +112,21 @@ main (int argc, char *argv[])
loop = g_main_loop_new (NULL, FALSE);
/* Create our proxy for NetworkManager's settings service */
settings = nm_remote_settings_new (NULL, &error);
if (!settings) {
g_message ("Error: Could not get system settings: %s.", error->message);
/* Connect to NetworkManager */
client = nm_client_new (NULL, &error);
if (!client) {
g_message ("Error: Could not connect to NetworkManager: %s.", error->message);
g_error_free (error);
return 1;
}
/* Ask the settings service to add the new connection */
add_connection (settings, loop, "__Test connection__");
/* Ask NM to add the new connection */
add_connection (client, loop, "__Test connection__");
/* Wait for the connection to be added */
g_main_loop_run (loop);
/* Clean up */
g_object_unref (settings);
g_object_unref (client);
return 0;
}

View file

@ -18,9 +18,9 @@
*/
/*
* The example shows how to list connections from the System Settings service
* using libnm. Contrast this example with list-connections-gdbus.c, which is a
* bit lower level and talks directly to NM using GDBus.
* The example shows how to list connections. Contrast this example with
* list-connections-gdbus.c, which is a bit lower level and talks directly to NM
* using GDBus.
*
* Compile with:
* gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` list-connections-libnm.c -o list-connections-libnm
@ -65,8 +65,7 @@ show_connection (gpointer data, gpointer user_data)
int
main (int argc, char *argv[])
{
NMRemoteSettings *settings;
gboolean settings_running;
NMClient *client;
GError *error = NULL;
GSList *connections;
@ -75,30 +74,26 @@ main (int argc, char *argv[])
g_type_init ();
#endif
/* Get system settings */
if (!(settings = nm_remote_settings_new (NULL, &error))) {
g_message ("Error: Could not get system settings: %s.", error->message);
if (!(client = nm_client_new (NULL, &error))) {
g_message ("Error: Could not connect to NetworkManager: %s.", error->message);
g_error_free (error);
return EXIT_FAILURE;
}
/* Find out whether setting service is running */
g_object_get (settings, NM_REMOTE_SETTINGS_NM_RUNNING, &settings_running, NULL);
if (!settings_running) {
g_message ("Error: Can't obtain connections: settings service is not running.");
if (!nm_client_get_nm_running (client)) {
g_message ("Error: Can't obtain connections: NetworkManager is not running.");
return EXIT_FAILURE;
}
/* Now the connections can be listed. */
connections = nm_remote_settings_list_connections (settings);
connections = nm_client_list_connections (client);
printf ("Connections:\n===================\n");
g_slist_foreach (connections, show_connection, NULL);
g_slist_free (connections);
g_object_unref (settings);
g_object_unref (client);
return EXIT_SUCCESS;
}

View file

@ -50,7 +50,6 @@ libnminclude_HEADERS = \
nm-ip6-config.h \
nm-object.h \
nm-remote-connection.h \
nm-remote-settings.h \
nm-secret-agent.h \
nm-vpn-connection.h \
nm-vpn-plugin.h \
@ -64,7 +63,8 @@ libnm_la_private_headers = \
nm-manager.h \
nm-object-cache.h \
nm-object-private.h \
nm-remote-connection-private.h
nm-remote-connection-private.h \
nm-remote-settings.h
libnm_la_csources = \
nm-access-point.c \

View file

@ -50,7 +50,6 @@
#include <nm-ip6-config.h>
#include <nm-object.h>
#include <nm-remote-connection.h>
#include <nm-remote-settings.h>
#include <nm-secret-agent.h>
#include <nm-setting-8021x.h>
#include <nm-setting-adsl.h>

View file

@ -37,6 +37,8 @@ global:
nm_client_activate_connection_finish;
nm_client_add_and_activate_connection_async;
nm_client_add_and_activate_connection_finish;
nm_client_add_connection_async;
nm_client_add_connection_finish;
nm_client_check_connectivity;
nm_client_check_connectivity_async;
nm_client_check_connectivity_finish;
@ -47,6 +49,9 @@ global:
nm_client_error_quark;
nm_client_get_activating_connection;
nm_client_get_active_connections;
nm_client_get_connection_by_id;
nm_client_get_connection_by_path;
nm_client_get_connection_by_uuid;
nm_client_get_connectivity;
nm_client_get_device_by_iface;
nm_client_get_device_by_path;
@ -59,6 +64,10 @@ global:
nm_client_get_state;
nm_client_get_type;
nm_client_get_version;
nm_client_list_connections;
nm_client_load_connections;
nm_client_load_connections_async;
nm_client_load_connections_finish;
nm_client_networking_get_enabled;
nm_client_networking_set_enabled;
nm_client_new;
@ -66,6 +75,12 @@ global:
nm_client_new_finish;
nm_client_permission_get_type;
nm_client_permission_result_get_type;
nm_client_reload_connections;
nm_client_reload_connections_async;
nm_client_reload_connections_finish;
nm_client_save_hostname;
nm_client_save_hostname_async;
nm_client_save_hostname_finish;
nm_client_set_logging;
nm_client_wimax_get_enabled;
nm_client_wimax_hardware_get_enabled;
@ -363,27 +378,6 @@ global:
nm_remote_connection_save;
nm_remote_connection_save_async;
nm_remote_connection_save_finish;
nm_remote_settings_add_connection_async;
nm_remote_settings_add_connection_finish;
nm_remote_settings_error_get_type;
nm_remote_settings_error_quark;
nm_remote_settings_get_connection_by_id;
nm_remote_settings_get_connection_by_path;
nm_remote_settings_get_connection_by_uuid;
nm_remote_settings_get_type;
nm_remote_settings_list_connections;
nm_remote_settings_load_connections;
nm_remote_settings_load_connections_async;
nm_remote_settings_load_connections_finish;
nm_remote_settings_new;
nm_remote_settings_new_async;
nm_remote_settings_new_finish;
nm_remote_settings_reload_connections;
nm_remote_settings_reload_connections_async;
nm_remote_settings_reload_connections_finish;
nm_remote_settings_save_hostname;
nm_remote_settings_save_hostname_async;
nm_remote_settings_save_hostname_finish;
nm_secret_agent_capabilities_get_type;
nm_secret_agent_delete_secrets;
nm_secret_agent_error_get_type;

View file

@ -24,6 +24,7 @@
#include "nm-client.h"
#include "nm-manager.h"
#include "nm-remote-settings.h"
#include "nm-device-ethernet.h"
#include "nm-device-wifi.h"
#include "nm-device-private.h"
@ -50,6 +51,7 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT,
typedef struct {
NMManager *manager;
NMRemoteSettings *settings;
} NMClientPrivate;
enum {
@ -70,6 +72,9 @@ enum {
PROP_PRIMARY_CONNECTION,
PROP_ACTIVATING_CONNECTION,
PROP_DEVICES,
PROP_CONNECTIONS,
PROP_HOSTNAME,
PROP_CAN_MODIFY,
LAST_PROP
};
@ -78,6 +83,8 @@ enum {
DEVICE_ADDED,
DEVICE_REMOVED,
PERMISSION_CHANGED,
CONNECTION_ADDED,
CONNECTION_REMOVED,
LAST_SIGNAL
};
@ -579,6 +586,112 @@ nm_client_check_connectivity_finish (NMClient *client,
return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
}
/**
* nm_client_save_hostname:
* @client: the %NMClient
* @hostname: (allow-none): the new persistent hostname to set, or %NULL to
* clear any existing persistent hostname
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
*
* Returns: %TRUE if the request was successful, %FALSE if it failed
**/
gboolean
nm_client_save_hostname (NMClient *client,
const char *hostname,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
return nm_remote_settings_save_hostname (NM_CLIENT_GET_PRIVATE (client)->settings,
hostname, cancellable, error);
}
static void
save_hostname_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_client_save_hostname_async:
* @client: the %NMClient
* @hostname: (allow-none): the new persistent hostname to set, or %NULL to
* clear any existing persistent hostname
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
**/
void
nm_client_save_hostname_async (NMClient *client,
const char *hostname,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
if (!_nm_client_check_nm_running (client, &error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_save_hostname_async);
nm_remote_settings_save_hostname_async (NM_CLIENT_GET_PRIVATE (client)->settings,
hostname,
cancellable, save_hostname_cb, simple);
}
/**
* nm_client_save_hostname_finish:
* @client: the %NMClient
* @result: the result passed to the #GAsyncReadyCallback
* @error: return location for #GError
*
* Gets the result of an nm_client_save_hostname_async() call.
*
* Returns: %TRUE if the request was successful, %FALSE if it failed
**/
gboolean
nm_client_save_hostname_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
}
/****************************************************************/
/* Devices */
/****************************************************************/
@ -1033,6 +1146,419 @@ nm_client_deactivate_connection_finish (NMClient *client,
return g_simple_async_result_get_op_res_gboolean (simple);
}
/****************************************************************/
/* Connections */
/****************************************************************/
/**
* nm_client_list_connections:
* @client: the %NMClient
*
* Returns: (transfer container) (element-type NMRemoteConnection): a
* list containing all connections provided by the remote settings service.
* Each element of the returned list is a %NMRemoteConnection instance, which is
* owned by the %NMClient object and should not be freed by the caller.
* The returned list is, however, owned by the caller and should be freed
* using g_slist_free() when no longer required.
**/
GSList *
nm_client_list_connections (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
return nm_remote_settings_list_connections (NM_CLIENT_GET_PRIVATE (client)->settings);
}
/**
* nm_client_get_connection_by_id:
* @client: the %NMClient
* @id: the id of the remote connection
*
* Returns the first matching %NMRemoteConnection matching a given @id.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if no
* matching object was found.
**/
NMRemoteConnection *
nm_client_get_connection_by_id (NMClient *client, const char *id)
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (id != NULL, NULL);
return nm_remote_settings_get_connection_by_id (NM_CLIENT_GET_PRIVATE (client)->settings, id);
}
/**
* nm_client_get_connection_by_path:
* @client: the %NMClient
* @path: the D-Bus object path of the remote connection
*
* Returns the %NMRemoteConnection representing the connection at @path.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if the object was
* not known
**/
NMRemoteConnection *
nm_client_get_connection_by_path (NMClient *client, const char *path)
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (path != NULL, NULL);
return nm_remote_settings_get_connection_by_path (NM_CLIENT_GET_PRIVATE (client)->settings, path);
}
/**
* nm_client_get_connection_by_uuid:
* @client: the %NMClient
* @uuid: the UUID of the remote connection
*
* Returns the %NMRemoteConnection identified by @uuid.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if the object was
* not known
**/
NMRemoteConnection *
nm_client_get_connection_by_uuid (NMClient *client, const char *uuid)
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (uuid != NULL, NULL);
return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid);
}
static void
add_connection_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
NMRemoteConnection *conn;
GError *error = NULL;
conn = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object), result, &error);
if (conn)
g_simple_async_result_set_op_res_gpointer (simple, conn, g_object_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_client_add_connection_async:
* @client: the %NMClient
* @connection: the connection to add. Note that this object's settings will be
* added, not the object itself
* @save_to_disk: whether to immediately save the connection to disk
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the add operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service add the given settings to a new
* connection. If @save_to_disk is %TRUE, the connection is immediately written
* to disk; otherwise it is initially only stored in memory, but may be saved
* later by calling the connection's nm_remote_connection_commit_changes()
* method.
*
* @connection is untouched by this function and only serves as a template of
* the settings to add. The #NMRemoteConnection object that represents what
* NetworkManager actually added is returned to @callback when the addition
* operation is complete.
*
* Note that the #NMRemoteConnection returned in @callback may not contain
* identical settings to @connection as NetworkManager may perform automatic
* completion and/or normalization of connection properties.
**/
void
nm_client_add_connection_async (NMClient *client,
NMConnection *connection,
gboolean save_to_disk,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_CONNECTION (connection));
if (!_nm_client_check_nm_running (client, &error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_deactivate_connection_async);
nm_remote_settings_add_connection_async (NM_CLIENT_GET_PRIVATE (client)->settings,
connection, save_to_disk,
cancellable, add_connection_cb, simple);
}
/**
* nm_client_add_connection_finish:
* @client: an #NMClient
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_client_add_connection_async().
*
* Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on
* failure, in which case @error will be set.
**/
NMRemoteConnection *
nm_client_add_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
else
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
/**
* nm_client_load_connections:
* @client: the %NMClient
* @filenames: %NULL-terminated array of filenames to load
* @failures: (out) (transfer full): on return, a %NULL-terminated array of
* filenames that failed to load
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError
*
* Requests that the remote settings service load or reload the given files,
* adding or updating the connections described within.
*
* The changes to the indicated files will not yet be reflected in
* @client's connections array when the function returns.
*
* If all of the indicated files were successfully loaded, the
* function will return %TRUE, and @failures will be set to %NULL. If
* NetworkManager tried to load the files, but some (or all) failed,
* then @failures will be set to a %NULL-terminated array of the
* filenames that failed to load.
*
* Returns: %TRUE if NetworkManager at least tried to load @filenames,
* %FALSE if an error occurred (eg, permission denied).
**/
gboolean
nm_client_load_connections (NMClient *client,
char **filenames,
char ***failures,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (filenames != NULL, FALSE);
if (!_nm_client_check_nm_running (client, error))
return FALSE;
return nm_remote_settings_load_connections (NM_CLIENT_GET_PRIVATE (client)->settings,
filenames, failures,
cancellable, error);
}
static void
load_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
char **failures = NULL;
if (nm_remote_settings_load_connections_finish (NM_REMOTE_SETTINGS (object),
&failures, result, &error))
g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_client_load_connections_async:
* @client: the %NMClient
* @filenames: %NULL-terminated array of filenames to load
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service asynchronously load or reload the
* given files, adding or updating the connections described within.
*
* See nm_client_load_connections() for more details.
**/
void
nm_client_load_connections_async (NMClient *client,
char **filenames,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (filenames != NULL);
if (!_nm_client_check_nm_running (client, &error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_load_connections_async);
nm_remote_settings_load_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings,
filenames,
cancellable, load_connections_cb, simple);
}
/**
* nm_client_load_connections_finish:
* @client: the %NMClient
* @failures: (out) (transfer full): on return, a %NULL-terminated array of
* filenames that failed to load
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of an nm_client_load_connections_async() call.
* See nm_client_load_connections() for more details.
*
* Returns: %TRUE if NetworkManager at least tried to load @filenames,
* %FALSE if an error occurred (eg, permission denied).
**/
gboolean
nm_client_load_connections_finish (NMClient *client,
char ***failures,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else {
if (failures)
*failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple));
return TRUE;
}
}
/**
* nm_client_reload_connections:
* @client: the #NMClient
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError
*
* Requests that the remote settings service reload all connection
* files from disk, adding, updating, and removing connections until
* the in-memory state matches the on-disk state.
*
* Return value: %TRUE on success, %FALSE on failure
**/
gboolean
nm_client_reload_connections (NMClient *client,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
if (!_nm_client_check_nm_running (client, error))
return FALSE;
return nm_remote_settings_reload_connections (NM_CLIENT_GET_PRIVATE (client)->settings,
cancellable, error);
}
static void
reload_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nm_remote_settings_reload_connections_finish (NM_REMOTE_SETTINGS (object),
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_client_reload_connections_async:
* @client: the #NMClient
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the reload operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service begin reloading all connection
* files from disk, adding, updating, and removing connections until the
* in-memory state matches the on-disk state.
**/
void
nm_client_reload_connections_async (NMClient *client,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
if (!_nm_client_check_nm_running (client, &error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_reload_connections_async);
nm_remote_settings_reload_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings,
cancellable, reload_connections_cb, simple);
}
/**
* nm_client_reload_connections_finish:
* @client: the #NMClient
* @result: the result passed to the #GAsyncReadyCallback
* @error: return location for #GError
*
* Gets the result of an nm_client_reload_connections_async() call.
*
* Return value: %TRUE on success, %FALSE on failure
**/
gboolean
nm_client_reload_connections_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
}
/****************************************************************/
/**
@ -1046,10 +1572,6 @@ nm_client_deactivate_connection_finish (NMClient *client,
* client. You can use nm_client_new_async() if you want to avoid
* that.
*
* NOTE: #NMClient provides information about devices and a mechanism to
* control them. To access and modify network configuration data, use the
* #NMRemoteSettings object.
*
* Returns: a new #NMClient or NULL on an error
**/
NMClient *
@ -1084,10 +1606,6 @@ client_inited (GObject *source, GAsyncResult *result, gpointer user_data)
* @callback will be called when it is done; use
* nm_client_new_finish() to get the result. Note that on an error,
* the callback can be invoked with two first parameters as NULL.
*
* NOTE: #NMClient provides information about devices and a mechanism to
* control them. To access and modify network configuration data, use the
* #NMRemoteSettings object.
**/
void
nm_client_new_async (GCancellable *cancellable,
@ -1137,9 +1655,9 @@ nm_client_new_finish (GAsyncResult *result, GError **error)
}
static void
manager_notify (GObject *object,
GParamSpec *pspec,
gpointer client)
subobject_notify (GObject *object,
GParamSpec *pspec,
gpointer client)
{
if (!g_str_has_suffix (pspec->name, "-internal"))
g_object_notify (client, pspec->name);
@ -1169,6 +1687,21 @@ manager_permission_changed (NMManager *manager,
g_signal_emit (client, signals[PERMISSION_CHANGED], 0, permission, result);
}
static void
settings_connection_added (NMRemoteSettings *manager,
NMRemoteConnection *connection,
gpointer client)
{
g_signal_emit (client, signals[CONNECTION_ADDED], 0, connection);
}
static void
settings_connection_removed (NMRemoteSettings *manager,
NMRemoteConnection *connection,
gpointer client)
{
g_signal_emit (client, signals[CONNECTION_REMOVED], 0, connection);
}
static void
constructed (GObject *object)
{
@ -1178,9 +1711,8 @@ constructed (GObject *object)
priv->manager = g_object_new (NM_TYPE_MANAGER,
NM_OBJECT_PATH, NM_DBUS_PATH,
NULL);
g_signal_connect (priv->manager, "notify",
G_CALLBACK (manager_notify), client);
G_CALLBACK (subobject_notify), client);
g_signal_connect (priv->manager, "device-added",
G_CALLBACK (manager_device_added), client);
g_signal_connect (priv->manager, "device-removed",
@ -1188,6 +1720,16 @@ constructed (GObject *object)
g_signal_connect (priv->manager, "permission-changed",
G_CALLBACK (manager_permission_changed), client);
priv->settings = g_object_new (NM_TYPE_REMOTE_SETTINGS,
NM_OBJECT_PATH, NM_DBUS_PATH_SETTINGS,
NULL);
g_signal_connect (priv->settings, "notify",
G_CALLBACK (subobject_notify), client);
g_signal_connect (priv->settings, "connection-added",
G_CALLBACK (settings_connection_added), client);
g_signal_connect (priv->settings, "connection-removed",
G_CALLBACK (settings_connection_removed), client);
G_OBJECT_CLASS (nm_client_parent_class)->constructed (object);
}
@ -1199,6 +1741,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
if (!g_initable_init (G_INITABLE (priv->manager), cancellable, error))
return FALSE;
if (!g_initable_init (G_INITABLE (priv->settings), cancellable, error))
return FALSE;
return TRUE;
}
@ -1207,6 +1751,8 @@ typedef struct {
NMClient *client;
GCancellable *cancellable;
GSimpleAsyncResult *result;
gboolean manager_inited;
gboolean settings_inited;
} NMClientInitData;
static void
@ -1224,12 +1770,26 @@ init_async_inited_manager (GObject *object, GAsyncResult *result, gpointer user_
NMClientInitData *init_data = user_data;
GError *error = NULL;
if (g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error))
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
else
if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error))
g_simple_async_result_take_error (init_data->result, error);
init_async_complete (init_data);
init_data->manager_inited = TRUE;
if (init_data->settings_inited)
init_async_complete (init_data);
}
static void
init_async_inited_settings (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMClientInitData *init_data = user_data;
GError *error = NULL;
if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error))
g_simple_async_result_take_error (init_data->result, error);
init_data->settings_inited = TRUE;
if (init_data->manager_inited)
init_async_complete (init_data);
}
static void
@ -1248,6 +1808,9 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d
g_async_initable_init_async (G_ASYNC_INITABLE (priv->manager),
G_PRIORITY_DEFAULT, init_data->cancellable,
init_async_inited_manager, init_data);
g_async_initable_init_async (G_ASYNC_INITABLE (priv->settings),
G_PRIORITY_DEFAULT, init_data->cancellable,
init_async_inited_settings, init_data);
}
static void
@ -1292,6 +1855,7 @@ dispose (GObject *object)
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
g_clear_object (&priv->manager);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (nm_client_parent_class)->dispose (object);
}
@ -1338,6 +1902,12 @@ get_property (GObject *object, guint prop_id,
g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager),
pspec->name, value);
break;
case PROP_CONNECTIONS:
case PROP_HOSTNAME:
case PROP_CAN_MODIFY:
g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->settings),
pspec->name, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1559,6 +2129,48 @@ nm_client_class_init (NMClientClass *client_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMClient:connections:
*
* The list of configured connections that are available to the user. (Note
* that this differs from the underlying D-Bus property, which may also
* contain the object paths of connections that the user does not have
* permission to read the details of.)
*
* Element-type: NMRemoteConnection
*/
g_object_class_install_property
(object_class, PROP_CONNECTIONS,
g_param_spec_boxed (NM_CLIENT_CONNECTIONS, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMClient:hostname:
*
* The machine hostname stored in persistent configuration. This can be
* modified by calling nm_client_save_hostname().
*/
g_object_class_install_property
(object_class, PROP_HOSTNAME,
g_param_spec_string (NM_CLIENT_HOSTNAME, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMClient:can-modify:
*
* If %TRUE, adding and modifying connections is supported.
*/
g_object_class_install_property
(object_class, PROP_CAN_MODIFY,
g_param_spec_boolean (NM_CLIENT_CAN_MODIFY, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/* signals */
/**
@ -1569,7 +2181,7 @@ nm_client_class_init (NMClientClass *client_class)
* Notifies that a #NMDevice is added.
**/
signals[DEVICE_ADDED] =
g_signal_new ("device-added",
g_signal_new (NM_CLIENT_DEVICE_ADDED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, device_added),
@ -1585,7 +2197,7 @@ nm_client_class_init (NMClientClass *client_class)
* Notifies that a #NMDevice is removed.
**/
signals[DEVICE_REMOVED] =
g_signal_new ("device-removed",
g_signal_new (NM_CLIENT_DEVICE_REMOVED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, device_removed),
@ -1602,11 +2214,42 @@ nm_client_class_init (NMClientClass *client_class)
* Notifies that a permission has changed
**/
signals[PERMISSION_CHANGED] =
g_signal_new ("permission-changed",
g_signal_new (NM_CLIENT_PERMISSION_CHANGED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
/**
* NMClient::connection-added:
* @client: the settings object that received the signal
* @connection: the new connection
*
* Notifies that a #NMConnection has been added.
**/
signals[CONNECTION_ADDED] =
g_signal_new (NM_CLIENT_CONNECTION_ADDED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, connection_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
NM_TYPE_REMOTE_CONNECTION);
/**
* NMClient::connection-removed:
* @client: the settings object that received the signal
* @connection: the removed connection
*
* Notifies that a #NMConnection has been removed.
**/
signals[CONNECTION_REMOVED] =
g_signal_new (NM_CLIENT_CONNECTION_REMOVED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMClientClass, connection_removed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
NM_TYPE_REMOTE_CONNECTION);
}
static void

View file

@ -29,9 +29,11 @@
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <nm-dbus-interface.h>
#include "nm-device.h"
#include "nm-active-connection.h"
#include "nm-remote-connection.h"
#include "nm-vpn-connection.h"
G_BEGIN_DECLS
@ -59,6 +61,15 @@ G_BEGIN_DECLS
#define NM_CLIENT_PRIMARY_CONNECTION "primary-connection"
#define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection"
#define NM_CLIENT_DEVICES "devices"
#define NM_CLIENT_CONNECTIONS "connections"
#define NM_CLIENT_HOSTNAME "hostname"
#define NM_CLIENT_CAN_MODIFY "can-modify"
#define NM_CLIENT_DEVICE_ADDED "device-added"
#define NM_CLIENT_DEVICE_REMOVED "device-removed"
#define NM_CLIENT_PERMISSION_CHANGED "permission-changed"
#define NM_CLIENT_CONNECTION_ADDED "connection-added"
#define NM_CLIENT_CONNECTION_REMOVED "connection-removed"
/**
* NMClientPermission:
@ -131,12 +142,18 @@ typedef enum {
* @NM_CLIENT_ERROR_UNKNOWN: unknown or unclassified error
* @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager
* failed because NetworkManager is not running
* @NM_CLIENT_ERROR_CONNECTION_REMOVED: the #NMRemoteConnection object
* was removed before it was completely initialized
* @NM_CLIENT_ERROR_CONNECTION_UNAVAILABLE: the #NMRemoteConnection object
* is not visible or otherwise unreadable
*
* Describes errors that may result from operations involving a #NMClient.
**/
typedef enum {
NM_CLIENT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, /*< nick=ManagerNotRunning >*/
NM_CLIENT_ERROR_CONNECTION_REMOVED, /*< nick=ConnectionRemoved >*/
NM_CLIENT_ERROR_CONNECTION_UNAVAILABLE, /*< nick=ConnectionUnavailable >*/
} NMClientError;
#define NM_CLIENT_ERROR nm_client_error_quark ()
@ -155,6 +172,8 @@ typedef struct {
void (*permission_changed) (NMClient *client,
NMClientPermission permission,
NMClientPermissionResult result);
void (*connection_added) (NMClient *client, NMRemoteConnection *connection);
void (*connection_removed) (NMClient *client, NMRemoteConnection *connection);
/*< private >*/
gpointer padding[8];
@ -218,6 +237,19 @@ NMConnectivityState nm_client_check_connectivity_finish (NMClient *client,
GAsyncResult *result,
GError **error);
gboolean nm_client_save_hostname (NMClient *client,
const char *hostname,
GCancellable *cancellable,
GError **error);
void nm_client_save_hostname_async (NMClient *client,
const char *hostname,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_client_save_hostname_finish (NMClient *client,
GAsyncResult *result,
GError **error);
/* Devices */
const GPtrArray *nm_client_get_devices (NMClient *client);
@ -266,6 +298,50 @@ gboolean nm_client_deactivate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error);
/* Connections */
GSList *nm_client_list_connections (NMClient *client);
NMRemoteConnection *nm_client_get_connection_by_id (NMClient *client, const char *id);
NMRemoteConnection *nm_client_get_connection_by_path (NMClient *client, const char *path);
NMRemoteConnection *nm_client_get_connection_by_uuid (NMClient *client, const char *uuid);
void nm_client_add_connection_async (NMClient *client,
NMConnection *connection,
gboolean save_to_disk,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMRemoteConnection *nm_client_add_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error);
gboolean nm_client_load_connections (NMClient *client,
char **filenames,
char ***failures,
GCancellable *cancellable,
GError **error);
void nm_client_load_connections_async (NMClient *client,
char **filenames,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_client_load_connections_finish (NMClient *client,
char ***failures,
GAsyncResult *result,
GError **error);
gboolean nm_client_reload_connections (NMClient *client,
GCancellable *cancellable,
GError **error);
void nm_client_reload_connections_async (NMClient *client,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_client_reload_connections_finish (NMClient *client,
GAsyncResult *result,
GError **error);
G_END_DECLS
#endif /* __NM_CLIENT_H__ */

View file

@ -24,6 +24,7 @@
#include <nm-connection.h>
#include "nm-remote-settings.h"
#include "nm-client.h"
#include "nm-remote-connection-private.h"
#include "nm-object-private.h"
#include "nm-dbus-helpers.h"
@ -33,99 +34,6 @@
#include "nmdbus-settings.h"
/**
* SECTION:nm-remote-settings
* @Short_description: A helper for NetworkManager's settings API
* @Title: NMRemoteSettings
* @See_also:#NMRemoteConnection, #NMClient
*
* The #NMRemoteSettings object represents NetworkManager's "settings" service,
* which stores network configuration and allows authenticated clients to
* add, delete, and modify that configuration. The data required to connect
* to a specific network is called a "connection" and encapsulated by the
* #NMConnection object. Once a connection is known to NetworkManager, having
* either been added by a user or read from on-disk storage, the
* #NMRemoteSettings object creates a #NMRemoteConnection object which
* represents this stored connection. Use the #NMRemoteConnection object to
* perform any operations like modification or deletion.
*
* To add a new network connection to the NetworkManager settings service, first
* build up a template #NMConnection object. Since this connection is not yet
* added to NetworkManager, it is known only to your program and is not yet
* an #NMRemoteConnection. Then ask #NMRemoteSettings to add your connection.
* When the connection is added successfully, the supplied callback is called
* and returns to your program the new #NMRemoteConnection which represents
* the stored object known to NetworkManager.
*
* |[<!-- language="C" -->
* static void
* added_cb (GObject *object,
* GAsyncResult *result,
* gpointer user_data)
* {
* NMRemoteConnection *remote;
* GError *error = NULL;
*
* remote = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object),
* result, &error);
* if (error) {
* g_print ("Error adding connection: %s", error->message);
* g_clear_error (&error);
* } else {
* g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote)));
* /&ast; Use 'remote' with nm_remote_connection_commit_changes() to save
* * changes and nm_remote_connection_delete() to delete the connection &ast;/
* }
* }
*
* static gboolean
* add_wired_connection (const char *human_name)
* {
* NMConnection *connection;
* NMSettingConnection *s_con;
* NMSettingWired *s_wired;
* char *uuid;
* gboolean success;
*
* connection = nm_simple_connection_new ();
*
* /&ast; Build up the 'connection' setting &ast;/
* s_con = (NMSettingConnection *) nm_setting_connection_new ();
* uuid = nm_utils_uuid_generate ();
* g_object_set (G_OBJECT (s_con),
* NM_SETTING_CONNECTION_UUID, uuid,
* NM_SETTING_CONNECTION_ID, human_name,
* NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
* NULL);
* g_free (uuid);
* nm_connection_add_setting (connection, NM_SETTING (s_con));
*
* /&ast; Add the required 'wired' setting as this is a wired connection &ast;/
* nm_connection_add_setting (connection, nm_setting_wired_new ());
*
* /&ast; Add an 'ipv4' setting using AUTO configuration (eg DHCP) &ast;/
* s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
* g_object_set (G_OBJECT (s_ip4),
* NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
* NULL);
* nm_connection_add_setting (connection, NM_SETTING (s_ip4));
*
* /&ast; Ask NetworkManager to store the connection &ast;/
* success = nm_remote_settings_add_connection_async (settings, connection,
* NULL, added_cb, NULL);
*
* /&ast; Release the template connection; the actual stored connection will
* * be returned in added_cb() &ast;/
* g_object_unref (connection);
*
* /&ast; Let glib event loop run and added_cb() will be called when NetworkManager
* * is done adding the new connection. &ast;/
*
* return success;
* }
* ]|
*/
G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, NM_TYPE_OBJECT)
#define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate))
@ -144,7 +52,6 @@ typedef struct {
enum {
PROP_0,
PROP_NM_RUNNING,
PROP_CONNECTIONS,
PROP_HOSTNAME,
PROP_CAN_MODIFY,
@ -163,25 +70,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
/**********************************************************************/
/**
* nm_remote_settings_error_quark:
*
* Registers an error quark for #NMRemoteSettings if necessary.
*
* Returns: the error quark used for #NMRemoteSettings errors.
**/
GQuark
nm_remote_settings_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-remote-settings-error-quark");
return quark;
}
/**********************************************************************/
typedef struct {
NMRemoteSettings *self;
GSimpleAsyncResult *simple;
@ -255,16 +143,6 @@ get_connection_by_string (NMRemoteSettings *settings,
return NULL;
}
/**
* nm_remote_settings_get_connection_by_id:
* @settings: the %NMRemoteSettings
* @id: the id of the remote connection
*
* Returns the first matching %NMRemoteConnection matching a given @id.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if no
* matching object was found.
**/
NMRemoteConnection *
nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char *id)
{
@ -274,16 +152,6 @@ nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char
return get_connection_by_string (settings, id, nm_connection_get_id);
}
/**
* nm_remote_settings_get_connection_by_path:
* @settings: the %NMRemoteSettings
* @path: the D-Bus object path of the remote connection
*
* Returns the %NMRemoteConnection representing the connection at @path.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if the object was
* not known
**/
NMRemoteConnection *
nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const char *path)
{
@ -293,16 +161,6 @@ nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const cha
return get_connection_by_string (settings, path, nm_connection_get_path);
}
/**
* nm_remote_settings_get_connection_by_uuid:
* @settings: the %NMRemoteSettings
* @uuid: the UUID of the remote connection
*
* Returns the %NMRemoteConnection identified by @uuid.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if the object was
* not known
**/
NMRemoteConnection *
nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const char *uuid)
{
@ -393,25 +251,14 @@ object_creation_failed (NMObject *object, GError *error, char *failed_path)
addinfo = add_connection_info_find (self, failed_path);
if (addinfo) {
add_error = g_error_new_literal (NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED,
add_error = g_error_new_literal (NM_CLIENT_ERROR,
NM_CLIENT_ERROR_CONNECTION_REMOVED,
"Connection removed before it was initialized");
add_connection_info_complete (self, addinfo, NULL, add_error);
g_error_free (add_error);
}
}
/**
* nm_remote_settings_list_connections:
* @settings: the %NMRemoteSettings
*
* Returns: (transfer container) (element-type NMRemoteConnection): a
* list containing all connections provided by the remote settings service.
* Each element of the returned list is a %NMRemoteConnection instance, which is
* owned by the %NMRemoteSettings object and should not be freed by the caller.
* The returned list is, however, owned by the caller and should be freed
* using g_slist_free() when no longer required.
**/
GSList *
nm_remote_settings_list_connections (NMRemoteSettings *settings)
{
@ -432,18 +279,6 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings)
return list;
}
static gboolean
settings_service_is_running (NMRemoteSettings *settings, GError **error)
{
if (!_nm_object_get_nm_running (NM_OBJECT (settings))) {
g_set_error_literal (error, NM_REMOTE_SETTINGS_ERROR,
NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE,
"NetworkManager is not running.");
return FALSE;
} else
return TRUE;
}
static void
add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
@ -470,31 +305,6 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
*/
}
/**
* nm_remote_settings_add_connection_async:
* @settings: the %NMRemoteSettings
* @connection: the connection to add. Note that this object's settings will be
* added, not the object itself
* @save_to_disk: whether to immediately save the connection to disk
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the add operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service add the given settings to a new
* connection. If @save_to_disk is %TRUE, the connection is immediately written
* to disk; otherwise it is initially only stored in memory, but may be saved
* later by calling the connection's nm_remote_connection_commit_changes()
* method.
*
* @connection is untouched by this function and only serves as a template of
* the settings to add. The #NMRemoteConnection object that represents what
* NetworkManager actually added is returned to @callback when the addition
* operation is complete.
*
* Note that the #NMRemoteConnection returned in @callback may not contain
* identical settings to @connection as NetworkManager may perform automatic
* completion and/or normalization of connection properties.
**/
void
nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
NMConnection *connection,
@ -506,18 +316,12 @@ nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info;
GVariant *new_settings;
GError *error = NULL;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
g_return_if_fail (NM_IS_CONNECTION (connection));
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (settings), callback, user_data, error);
return;
}
info = g_slice_new0 (AddConnectionInfo);
info->self = settings;
info->simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
@ -541,17 +345,6 @@ nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
priv->add_list = g_slist_append (priv->add_list, info);
}
/**
* nm_remote_settings_add_connection_finish:
* @settings: an #NMRemoteSettings
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_remote_settings_add_connection_async().
*
* Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on
* failure, in which case @error will be set.
**/
NMRemoteConnection *
nm_remote_settings_add_connection_finish (NMRemoteSettings *settings,
GAsyncResult *result,
@ -568,30 +361,6 @@ nm_remote_settings_add_connection_finish (NMRemoteSettings *settings,
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
/**
* nm_remote_settings_load_connections:
* @settings: the %NMRemoteSettings
* @filenames: %NULL-terminated array of filenames to load
* @failures: (out) (transfer full): on return, a %NULL-terminated array of
* filenames that failed to load
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError
*
* Requests that the remote settings service load or reload the given files,
* adding or updating the connections described within.
*
* The changes to the indicated files will not yet be reflected in
* @settings's connections array when the function returns.
*
* If all of the indicated files were successfully loaded, the
* function will return %TRUE, and @failures will be set to %NULL. If
* NetworkManager tried to load the files, but some (or all) failed,
* then @failures will be set to a %NULL-terminated array of the
* filenames that failed to load.
*
* Returns: %TRUE if NetworkManager at least tried to load @filenames,
* %FALSE if an error occurred (eg, permission denied).
**/
gboolean
nm_remote_settings_load_connections (NMRemoteSettings *settings,
char **filenames,
@ -607,9 +376,6 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!settings_service_is_running (settings, error))
return FALSE;
if (!nmdbus_settings_call_load_connections_sync (priv->proxy,
(const char * const *) filenames,
&success,
@ -639,19 +405,6 @@ load_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
g_object_unref (simple);
}
/**
* nm_remote_settings_load_connections_async:
* @settings: the %NMRemoteSettings
* @filenames: %NULL-terminated array of filenames to load
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service asynchronously load or reload the
* given files, adding or updating the connections described within.
*
* See nm_remote_settings_load_connections() for more details.
**/
void
nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
char **filenames,
@ -661,7 +414,6 @@ nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
g_return_if_fail (filenames != NULL);
@ -671,33 +423,11 @@ nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_load_connections_async);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
nmdbus_settings_call_load_connections (priv->proxy,
(const char * const *) filenames,
cancellable, load_connections_cb, simple);
}
/**
* nm_remote_settings_load_connections_finish:
* @settings: the %NMRemoteSettings
* @failures: (out) (transfer full): on return, a %NULL-terminated array of
* filenames that failed to load
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of an nm_remote_settings_load_connections_async() call.
* See nm_remote_settings_load_connections() for more details.
*
* Returns: %TRUE if NetworkManager at least tried to load @filenames,
* %FALSE if an error occurred (eg, permission denied).
**/
gboolean
nm_remote_settings_load_connections_finish (NMRemoteSettings *settings,
char ***failures,
@ -717,18 +447,6 @@ nm_remote_settings_load_connections_finish (NMRemoteSettings *settings,
}
}
/**
* nm_remote_settings_reload_connections:
* @settings: the #NMRemoteSettings
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError
*
* Requests that the remote settings service reload all connection
* files from disk, adding, updating, and removing connections until
* the in-memory state matches the on-disk state.
*
* Return value: %TRUE on success, %FALSE on failure
**/
gboolean
nm_remote_settings_reload_connections (NMRemoteSettings *settings,
GCancellable *cancellable,
@ -741,9 +459,6 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings,
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!settings_service_is_running (settings, error))
return FALSE;
if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success,
cancellable, error))
success = FALSE;
@ -769,17 +484,6 @@ reload_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
g_object_unref (simple);
}
/**
* nm_remote_settings_reload_connections_async:
* @settings: the #NMRemoteSettings
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the reload operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the remote settings service begin reloading all connection
* files from disk, adding, updating, and removing connections until the
* in-memory state matches the on-disk state.
**/
void
nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
GCancellable *cancellable,
@ -788,7 +492,6 @@ nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
@ -797,27 +500,10 @@ nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_reload_connections_async);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
nmdbus_settings_call_reload_connections (priv->proxy, cancellable,
reload_connections_cb, simple);
}
/**
* nm_remote_settings_reload_connections_finish:
* @settings: the #NMRemoteSettings
* @result: the result passed to the #GAsyncReadyCallback
* @error: return location for #GError
*
* Gets the result of an nm_remote_settings_reload_connections_async() call.
*
* Return value: %TRUE on success, %FALSE on failure
**/
gboolean
nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings,
GAsyncResult *result,
@ -834,19 +520,6 @@ nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings,
return g_simple_async_result_get_op_res_gboolean (simple);
}
/**
* nm_remote_settings_save_hostname:
* @settings: the %NMRemoteSettings
* @hostname: (allow-none): the new persistent hostname to set, or %NULL to
* clear any existing persistent hostname
* @cancellable: a #GCancellable, or %NULL
* @error: return location for #GError
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
*
* Returns: %TRUE if the request was successful, %FALSE if it failed
**/
gboolean
nm_remote_settings_save_hostname (NMRemoteSettings *settings,
const char *hostname,
@ -859,9 +532,6 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings,
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!settings_service_is_running (settings, error))
return FALSE;
return nmdbus_settings_call_save_hostname_sync (priv->proxy,
hostname ? hostname : "",
cancellable, error);
@ -883,18 +553,6 @@ save_hostname_cb (GObject *proxy,
g_object_unref (simple);
}
/**
* nm_remote_settings_save_hostname_async:
* @settings: the %NMRemoteSettings
* @hostname: (allow-none): the new persistent hostname to set, or %NULL to
* clear any existing persistent hostname
* @cancellable: a #GCancellable, or %NULL
* @callback: (scope async): callback to be called when the operation completes
* @user_data: (closure): caller-specific data passed to @callback
*
* Requests that the machine's persistent hostname be set to the specified value
* or cleared.
**/
void
nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
const char *hostname,
@ -904,7 +562,6 @@ nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
@ -913,28 +570,11 @@ nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_save_hostname_async);
if (!settings_service_is_running (settings, &error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
nmdbus_settings_call_save_hostname (priv->proxy,
hostname ? hostname : "",
cancellable, save_hostname_cb, simple);
}
/**
* nm_remote_settings_save_hostname_finish:
* @settings: the %NMRemoteSettings
* @result: the result passed to the #GAsyncReadyCallback
* @error: return location for #GError
*
* Gets the result of an nm_remote_settings_save_hostname_async() call.
*
* Returns: %TRUE if the request was successful, %FALSE if it failed
**/
gboolean
nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings,
GAsyncResult *result,
@ -954,15 +594,12 @@ nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings,
static void
updated_properties (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
GError *error = NULL;
if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) {
g_warning ("%s: error reading NMRemoteSettings properties: %s", __func__, error->message);
g_error_free (error);
}
g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_NM_RUNNING);
}
static void
@ -999,7 +636,6 @@ nm_running_changed (GObject *object,
}
_nm_object_suppress_property_updates (NM_OBJECT (self), TRUE);
g_object_notify (G_OBJECT (self), NM_REMOTE_SETTINGS_NM_RUNNING);
} else {
_nm_object_suppress_property_updates (NM_OBJECT (self), FALSE);
_nm_object_reload_properties_async (NM_OBJECT (self), updated_properties, self);
@ -1010,70 +646,6 @@ nm_running_changed (GObject *object,
/****************************************************************/
/**
* nm_remote_settings_new:
* @cancellable: a #GCancellable, or %NULL
* @error: location for a #GError, or %NULL
*
* Creates a new object representing the remote settings service.
*
* Note that this will do blocking D-Bus calls to initialize the
* settings object. You can use nm_remote_settings_new_async() if you
* want to avoid that.
*
* Returns: the new remote settings object on success, or %NULL on failure
**/
NMRemoteSettings *
nm_remote_settings_new (GCancellable *cancellable,
GError **error)
{
return g_initable_new (NM_TYPE_REMOTE_SETTINGS, cancellable, error,
NULL);
}
/**
* nm_remote_settings_new_async:
* @cancellable: a #GCancellable, or %NULL
* @callback: callback to call when the settings object is created
* @user_data: data for @callback
*
* Creates a new object representing the remote settings service and
* begins asynchronously initializing it. @callback will be called
* when it is done; use nm_remote_settings_new_finish() to get the
* result.
**/
void
nm_remote_settings_new_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_async_initable_new_async (NM_TYPE_REMOTE_SETTINGS, G_PRIORITY_DEFAULT, cancellable,
callback, user_data,
NULL);
}
/**
* nm_remote_settings_new_finish:
* @result: a #GAsyncResult
* @error: location for a #GError, or %NULL
*
* Gets the result of an nm_remote_settings_new_async() call.
*
* Returns: a new #NMRemoteSettings object, or %NULL on error
**/
NMRemoteSettings *
nm_remote_settings_new_finish (GAsyncResult *result, GError **error)
{
GObject *source;
NMRemoteSettings *settings;
source = g_async_result_get_source_object (result);
settings = (NMRemoteSettings *) g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, error);
g_object_unref (source);
return settings;
}
static void
nm_remote_settings_init (NMRemoteSettings *self)
{
@ -1160,9 +732,6 @@ get_property (GObject *object, guint prop_id,
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NM_RUNNING:
g_value_set_boolean (value, _nm_object_get_nm_running (NM_OBJECT (object)));
break;
case PROP_CONNECTIONS:
g_value_take_boxed (value, _nm_utils_copy_object_array (priv->visible_connections));
break;
@ -1202,28 +771,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
/* Properties */
/**
* NMRemoteSettings:nm-running:
*
* Whether the NetworkManager settings service is running.
*/
g_object_class_install_property
(object_class, PROP_NM_RUNNING,
g_param_spec_boolean (NM_REMOTE_SETTINGS_NM_RUNNING, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMRemoteSettings:connections:
*
* The list of configured connections that are available to the user. (Note
* that this differs from the underlying D-Bus property, which may also
* contain the object paths of connections that the user does not have
* permission to read the details of.)
*
* Element-type: NMRemoteConnection
*/
g_object_class_install_property
(object_class, PROP_CONNECTIONS,
g_param_spec_boxed (NM_REMOTE_SETTINGS_CONNECTIONS, "", "",
@ -1231,12 +778,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMRemoteSettings:hostname:
*
* The machine hostname stored in persistent configuration. This can be
* modified by calling nm_remote_settings_save_hostname().
*/
g_object_class_install_property
(object_class, PROP_HOSTNAME,
g_param_spec_string (NM_REMOTE_SETTINGS_HOSTNAME, "", "",
@ -1244,11 +785,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMRemoteSettings:can-modify:
*
* If %TRUE, adding and modifying connections is supported.
*/
g_object_class_install_property
(object_class, PROP_CAN_MODIFY,
g_param_spec_boolean (NM_REMOTE_SETTINGS_CAN_MODIFY, "", "",
@ -1257,13 +793,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
G_PARAM_STATIC_STRINGS));
/* Signals */
/**
* NMRemoteSettings::connection-added:
* @settings: the settings object that received the signal
* @connection: the new connection
*
* Notifies that a #NMConnection has been added.
**/
signals[CONNECTION_ADDED] =
g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_ADDED,
G_OBJECT_CLASS_TYPE (object_class),
@ -1273,13 +802,6 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
G_TYPE_NONE, 1,
NM_TYPE_REMOTE_CONNECTION);
/**
* NMRemoteSettings::connection-removed:
* @settings: the settings object that received the signal
* @connection: the removed connection
*
* Notifies that a #NMConnection has been removed.
**/
signals[CONNECTION_REMOVED] =
g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_REMOVED,
G_OBJECT_CLASS_TYPE (object_class),

View file

@ -22,10 +22,6 @@
#ifndef __NM_REMOTE_SETTINGS_H__
#define __NM_REMOTE_SETTINGS_H__
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
#error "Only <NetworkManager.h> can be included directly."
#endif
#include <gio/gio.h>
#include <nm-object.h>
#include <nm-connection.h>
@ -40,30 +36,6 @@ G_BEGIN_DECLS
#define NM_IS_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_REMOTE_SETTINGS))
#define NM_REMOTE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass))
/**
* NMRemoteSettingsError:
* @NM_REMOTE_SETTINGS_ERROR_UNKNOWN: unknown or unclassified error
* @NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED: the #NMRemoteConnection object
* was removed before it was completely initialized
* @NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE: the #NMRemoteConnection object
* is not visible or otherwise unreadable
* @NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE: NetworkManager is not running.
*
* Describes errors that may result from operations involving a #NMRemoteSettings.
*
**/
typedef enum {
NM_REMOTE_SETTINGS_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED, /*< nick=ConnectionRemoved >*/
NM_REMOTE_SETTINGS_ERROR_CONNECTION_UNAVAILABLE, /*< nick=ConnectionUnavailable >*/
NM_REMOTE_SETTINGS_ERROR_SERVICE_UNAVAILABLE, /*< nick=ServiceUnavailable >*/
} NMRemoteSettingsError;
#define NM_REMOTE_SETTINGS_ERROR nm_remote_settings_error_quark ()
GQuark nm_remote_settings_error_quark (void);
#define NM_REMOTE_SETTINGS_NM_RUNNING "nm-running"
#define NM_REMOTE_SETTINGS_CONNECTIONS "connections"
#define NM_REMOTE_SETTINGS_HOSTNAME "hostname"
#define NM_REMOTE_SETTINGS_CAN_MODIFY "can-modify"
@ -93,15 +65,6 @@ struct _NMRemoteSettingsClass {
GType nm_remote_settings_get_type (void);
NMRemoteSettings *nm_remote_settings_new (GCancellable *cancellable,
GError **error);
void nm_remote_settings_new_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMRemoteSettings *nm_remote_settings_new_finish (GAsyncResult *result,
GError **error);
GSList *nm_remote_settings_list_connections (NMRemoteSettings *settings);
NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings,

View file

@ -30,7 +30,7 @@
#include "nm-test-utils.h"
static NMTestServiceInfo *sinfo;
static NMRemoteSettings *settings = NULL;
static NMClient *client = NULL;
GDBusConnection *bus = NULL;
NMRemoteConnection *remote = NULL;
@ -44,14 +44,14 @@ add_cb (GObject *s,
gboolean *done = user_data;
GError *error = NULL;
remote = nm_remote_settings_add_connection_finish (settings, result, &error);
remote = nm_client_add_connection_finish (client, result, &error);
g_assert_no_error (error);
*done = TRUE;
g_object_add_weak_pointer (G_OBJECT (remote), (void **) &remote);
/* nm_remote_settings_add_connection_finish() adds a ref to @remote, but we
* want the weak pointer to be cleared as soon as @settings drops its own ref.
/* nm_client_add_connection_finish() adds a ref to @remote, but we
* want the weak pointer to be cleared as soon as @client drops its own ref.
* So drop ours.
*/
g_object_unref (remote);
@ -68,12 +68,12 @@ test_add_connection (void)
connection = nmtst_create_minimal_connection (TEST_CON_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
nm_remote_settings_add_connection_async (settings,
connection,
TRUE,
NULL,
add_cb,
&done);
nm_client_add_connection_async (client,
connection,
TRUE,
NULL,
add_cb,
&done);
start = time (NULL);
do {
@ -113,7 +113,7 @@ visible_changed_cb (GObject *object, GParamSpec *pspec, gboolean *done)
}
static void
connection_removed_cb (NMRemoteSettings *s, NMRemoteConnection *connection, gboolean *done)
connection_removed_cb (NMClient *s, NMRemoteConnection *connection, gboolean *done)
{
if (connection == remote)
*done = TRUE;
@ -143,7 +143,7 @@ test_make_invisible (void)
/* Listen for the remove event when the connection becomes invisible */
g_signal_connect (remote, "notify::" NM_REMOTE_CONNECTION_VISIBLE, G_CALLBACK (visible_changed_cb), &visible_changed);
g_signal_connect (settings, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed);
g_signal_connect (client, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
proxy = g_dbus_proxy_new_sync (bus,
@ -156,7 +156,7 @@ test_make_invisible (void)
NULL);
g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
/* Bypass the NMClient object so we can test it independently */
g_dbus_proxy_call (proxy,
"SetVisible",
g_variant_new ("(b)", FALSE),
@ -174,10 +174,10 @@ test_make_invisible (void)
g_assert (connection_removed == TRUE);
g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (visible_changed_cb), &visible_changed);
g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (connection_removed_cb), &connection_removed);
g_signal_handlers_disconnect_by_func (client, G_CALLBACK (connection_removed_cb), &connection_removed);
/* Ensure NMRemoteSettings no longer has the connection */
list = nm_remote_settings_list_connections (settings);
/* Ensure NMClient no longer has the connection */
list = nm_client_list_connections (client);
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
@ -199,7 +199,7 @@ test_make_invisible (void)
/*******************************************************************/
static void
vis_new_connection_cb (NMRemoteSettings *foo,
vis_new_connection_cb (NMClient *foo,
NMRemoteConnection *connection,
NMRemoteConnection **new)
{
@ -219,7 +219,7 @@ test_make_visible (void)
g_assert (remote != NULL);
/* Wait for the new-connection signal when the connection is visible again */
g_signal_connect (settings, NM_REMOTE_SETTINGS_CONNECTION_ADDED,
g_signal_connect (client, NM_CLIENT_CONNECTION_ADDED,
G_CALLBACK (vis_new_connection_cb), &new);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
@ -233,7 +233,7 @@ test_make_visible (void)
NULL);
g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
/* Bypass the NMClient object so we can test it independently */
g_dbus_proxy_call (proxy,
"SetVisible",
g_variant_new ("(b)", TRUE),
@ -252,10 +252,10 @@ test_make_visible (void)
g_assert (new);
g_assert (new == remote);
g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (vis_new_connection_cb), &new);
g_signal_handlers_disconnect_by_func (client, G_CALLBACK (vis_new_connection_cb), &new);
/* Ensure NMRemoteSettings has the connection */
list = nm_remote_settings_list_connections (settings);
/* Ensure NMClient has the connection */
list = nm_client_list_connections (client);
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
@ -288,7 +288,7 @@ deleted_cb (GObject *proxy,
}
static void
removed_cb (NMRemoteSettings *s, NMRemoteConnection *connection, gboolean *done)
removed_cb (NMClient *s, NMRemoteConnection *connection, gboolean *done)
{
if (connection == remote)
*done = TRUE;
@ -305,14 +305,14 @@ test_remove_connection (void)
char *path;
/* Find a connection to delete */
list = nm_remote_settings_list_connections (settings);
list = nm_client_list_connections (client);
g_assert_cmpint (g_slist_length (list), >, 0);
connection = NM_REMOTE_CONNECTION (list->data);
g_assert (connection);
g_assert (remote == connection);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
g_signal_connect (settings, "connection-removed", G_CALLBACK (removed_cb), &done);
g_signal_connect (client, "connection-removed", G_CALLBACK (removed_cb), &done);
proxy = g_dbus_proxy_new_sync (bus,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
@ -324,7 +324,7 @@ test_remove_connection (void)
NULL);
g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
/* Bypass the NMClient object so we can test it independently */
g_dbus_proxy_call (proxy,
"Delete",
NULL,
@ -341,8 +341,8 @@ test_remove_connection (void)
g_assert (!remote);
/* Ensure NMRemoteSettings no longer has the connection */
list = nm_remote_settings_list_connections (settings);
/* Ensure NMClient no longer has the connection */
list = nm_client_list_connections (client);
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
@ -367,8 +367,8 @@ add_remove_cb (GObject *s,
gboolean *done = user_data;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (settings, result, &error);
g_assert_error (error, NM_REMOTE_SETTINGS_ERROR, NM_REMOTE_SETTINGS_ERROR_CONNECTION_REMOVED);
connection = nm_client_add_connection_finish (client, result, &error);
g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_CONNECTION_REMOVED);
g_assert (connection == NULL);
*done = TRUE;
@ -396,12 +396,12 @@ test_add_remove_connection (void)
g_variant_unref (ret);
connection = nmtst_create_minimal_connection (TEST_ADD_REMOVE_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
nm_remote_settings_add_connection_async (settings,
connection,
TRUE,
NULL,
add_remove_cb,
&done);
nm_client_add_connection_async (client,
connection,
TRUE,
NULL,
add_remove_cb,
&done);
start = time (NULL);
do {
@ -415,91 +415,6 @@ test_add_remove_connection (void)
/*******************************************************************/
static GMainLoop *loop;
static gboolean
loop_quit (gpointer user_data)
{
g_main_loop_quit (loop);
return G_SOURCE_REMOVE;
}
static void
settings_nm_running_changed (GObject *client,
GParamSpec *pspec,
gpointer user_data)
{
int *running_changed = user_data;
(*running_changed)++;
g_main_loop_quit (loop);
}
static void
test_nm_running (void)
{
NMRemoteSettings *settings2;
guint quit_id;
int running_changed = 0;
gboolean running;
GError *error = NULL;
loop = g_main_loop_new (NULL, FALSE);
g_object_get (G_OBJECT (settings),
NM_REMOTE_SETTINGS_NM_RUNNING, &running,
NULL);
g_assert (running == TRUE);
/* Now kill the test service. */
nm_test_service_cleanup (sinfo);
settings2 = nm_remote_settings_new (NULL, &error);
g_assert_no_error (error);
g_assert (settings2 != NULL);
/* settings2 should know that NM is running, but the previously-created
* settings hasn't gotten the news yet.
*/
g_object_get (G_OBJECT (settings2),
NM_REMOTE_SETTINGS_NM_RUNNING, &running,
NULL);
g_assert (running == FALSE);
g_object_get (G_OBJECT (settings),
NM_REMOTE_SETTINGS_NM_RUNNING, &running,
NULL);
g_assert (running == TRUE);
g_signal_connect (settings, "notify::" NM_REMOTE_SETTINGS_NM_RUNNING,
G_CALLBACK (settings_nm_running_changed), &running_changed);
quit_id = g_timeout_add_seconds (5, loop_quit, loop);
g_main_loop_run (loop);
g_assert_cmpint (running_changed, ==, 1);
g_source_remove (quit_id);
g_object_get (G_OBJECT (settings2),
NM_REMOTE_SETTINGS_NM_RUNNING, &running,
NULL);
g_assert (running == FALSE);
/* Now restart it */
sinfo = nm_test_service_init ();
quit_id = g_timeout_add_seconds (5, loop_quit, loop);
g_main_loop_run (loop);
g_assert_cmpint (running_changed, ==, 2);
g_source_remove (quit_id);
g_object_get (G_OBJECT (settings2),
NM_REMOTE_SETTINGS_NM_RUNNING, &running,
NULL);
g_assert (running == TRUE);
g_object_unref (settings2);
}
/*******************************************************************/
int
main (int argc, char **argv)
{
@ -519,24 +434,23 @@ main (int argc, char **argv)
sinfo = nm_test_service_init ();
settings = nm_remote_settings_new (NULL, &error);
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
g_assert (settings != NULL);
g_assert (client != NULL);
/* FIXME: these tests assume that they get run in order, but g_test_run()
* does not actually guarantee that!
*/
g_test_add_func ("/remote_settings/add_connection", test_add_connection);
g_test_add_func ("/remote_settings/make_invisible", test_make_invisible);
g_test_add_func ("/remote_settings/make_visible", test_make_visible);
g_test_add_func ("/remote_settings/remove_connection", test_remove_connection);
g_test_add_func ("/remote_settings/add_remove_connection", test_add_remove_connection);
g_test_add_func ("/remote_settings/nm_running", test_nm_running);
g_test_add_func ("/client/add_connection", test_add_connection);
g_test_add_func ("/client/make_invisible", test_make_invisible);
g_test_add_func ("/client/make_visible", test_make_visible);
g_test_add_func ("/client/remove_connection", test_remove_connection);
g_test_add_func ("/client/add_remove_connection", test_add_remove_connection);
ret = g_test_run ();
nm_test_service_cleanup (sinfo);
g_object_unref (settings);
g_object_unref (client);
g_object_unref (bus);
return ret;

View file

@ -182,7 +182,6 @@ test_secret_agent_new (void)
typedef struct {
NMTestServiceInfo *sinfo;
NMClient *client;
NMRemoteSettings *settings;
NMSecretAgent *agent;
NMDevice *device;
@ -227,7 +226,7 @@ connection_added_cb (GObject *s,
NMRemoteConnection *connection;
GError *error = NULL;
connection = nm_remote_settings_add_connection_finish (sadata->settings, result, &error);
connection = nm_client_add_connection_finish (sadata->client, result, &error);
g_assert_no_error (error);
g_assert_cmpstr (nm_connection_get_id (NM_CONNECTION (connection)), ==, sadata->con_id);
@ -268,8 +267,6 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
sadata->sinfo = nm_test_service_init ();
sadata->client = nm_client_new (NULL, &error);
g_assert_no_error (error);
sadata->settings = nm_remote_settings_new (NULL, &error);
g_assert_no_error (error);
sadata->loop = g_main_loop_new (NULL, FALSE);
sadata->timeout_id = g_timeout_add_seconds (5, timeout_assert, NULL);
@ -316,12 +313,12 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
NULL);
nm_connection_add_setting (connection, s_wsec);
nm_remote_settings_add_connection_async (sadata->settings,
connection,
TRUE,
NULL,
connection_added_cb,
sadata);
nm_client_add_connection_async (sadata->client,
connection,
TRUE,
NULL,
connection_added_cb,
sadata);
g_object_unref (connection);
g_main_loop_run (sadata->loop);
@ -358,7 +355,6 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data)
g_object_unref (sadata->connection);
g_object_unref (sadata->client);
g_object_unref (sadata->settings);
ret = g_dbus_proxy_call_sync (sadata->sinfo->proxy,
"RemoveDevice",