summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-10-10 13:09:43 -0400
committerDan Winship <danw@gnome.org>2014-10-10 13:09:43 -0400
commitdccaffe143410c9f5379f1d92e2a95d4de2072c0 (patch)
treebffa6c50529d46377f71da8907dcd734a8e7a366
parenta6b4d544996ad565cb0e175e78f0670618243d0c (diff)
parent6f3d1f95262abbf5101d6f88ecfa292d575e0d4f (diff)
downloadNetworkManager-dccaffe143410c9f5379f1d92e2a95d4de2072c0.tar.gz
libnm: merge NMRemoteSettings into NMClient (bgo #738103)
-rw-r--r--clients/cli/connections.c102
-rw-r--r--clients/cli/general.c18
-rw-r--r--clients/cli/nmcli.c7
-rw-r--r--clients/cli/nmcli.h4
-rw-r--r--clients/cli/settings.c4
-rw-r--r--clients/tui/nm-editor-utils.c16
-rw-r--r--clients/tui/nm-editor-utils.h6
-rw-r--r--clients/tui/nmt-connect-connection-list.c6
-rw-r--r--clients/tui/nmt-edit-connection-list.c4
-rw-r--r--clients/tui/nmt-editor.c9
-rw-r--r--clients/tui/nmtui-edit.c16
-rw-r--r--clients/tui/nmtui-hostname.c8
-rw-r--r--clients/tui/nmtui.c9
-rw-r--r--clients/tui/nmtui.h1
-rw-r--r--docs/libnm/Makefile.am2
-rw-r--r--docs/libnm/libnm-docs.xml1
-rw-r--r--examples/C/glib/add-connection-libnm.c25
-rw-r--r--examples/C/glib/list-connections-libnm.c25
-rw-r--r--libnm/Makefile.am6
-rw-r--r--libnm/NetworkManager.h1
-rw-r--r--libnm/libnm.ver36
-rw-r--r--libnm/nm-client.c2308
-rw-r--r--libnm/nm-client.h170
-rw-r--r--libnm/nm-manager.c1600
-rw-r--r--libnm/nm-manager.h168
-rw-r--r--libnm/nm-remote-settings.c484
-rw-r--r--libnm/nm-remote-settings.h37
-rw-r--r--libnm/tests/test-remote-settings-client.c174
-rw-r--r--libnm/tests/test-secret-agent.c18
29 files changed, 3182 insertions, 2083 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 5dc8b36815..cfaa669b06 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -820,7 +820,7 @@ fill_output_active_connection (NMActiveConnection *active,
GString *dev_str;
NMActiveConnectionState state;
int i;
- GSList *con_list = nmc->system_connections;
+ GSList *con_list = nmc->connections;
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
int idx_start = with_group ? 0 : 1;
@@ -1097,7 +1097,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
char **vpn_data_array = NULL;
guint32 items_num;
- con = get_connection_for_active (nmc->system_connections, acon);
+ con = get_connection_for_active (nmc->connections, acon);
s_con = nm_connection_get_setting_connection (con);
g_assert (s_con != NULL);
@@ -1307,7 +1307,7 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv)
g_ptr_array_add (nmc->output_data, arr);
/* Add values */
- for (iter = nmc->system_connections; iter; iter = g_slist_next (iter)) {
+ for (iter = nmc->connections; iter; iter = g_slist_next (iter)) {
NMConnection *con = NM_CONNECTION (iter->data);
fill_output_connection (con, nmc, active_only);
}
@@ -1346,11 +1346,11 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv)
}
/* Find connection by id, uuid, path or apath */
- con = nmc_find_connection (nmc->system_connections, selector, *argv, &pos);
+ con = nmc_find_connection (nmc->connections, selector, *argv, &pos);
if (!con) {
- acon = find_active_connection (active_cons, nmc->system_connections, selector, *argv, NULL);
+ acon = find_active_connection (active_cons, nmc->connections, selector, *argv, NULL);
if (acon)
- con = get_connection_for_active (nmc->system_connections, acon);
+ con = get_connection_for_active (nmc->connections, acon);
}
/* Print connection details */
@@ -1954,7 +1954,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
}
if (name)
- connection = nmc_find_connection (nmc->system_connections, selector, name, NULL);
+ connection = nmc_find_connection (nmc->connections, selector, name, NULL);
while (argc > 0) {
if (strcmp (*argv, "ifname") == 0) {
@@ -2063,7 +2063,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
}
}
- active = find_active_connection (active_cons, nmc->system_connections, selector, *arg_ptr, &idx);
+ active = find_active_connection (active_cons, nmc->connections, selector, *arg_ptr, &idx);
if (active) {
nm_client_deactivate_connection (nmc->client, active, NULL, NULL);
} else {
@@ -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
@@ -4996,14 +4995,14 @@ gen_func_master_ifnames (const char *text, int state)
NMSettingConnection *s_con;
const char *con_type, *ifname;
- if (!nm_cli.system_connections)
+ if (!nm_cli.connections)
return NULL;
/* Disable appending space after completion */
rl_completion_append_character = '\0';
ifnames = g_ptr_array_sized_new (20);
- for (iter = nm_cli.system_connections; iter; iter = g_slist_next (iter)) {
+ for (iter = nm_cli.connections; iter; iter = g_slist_next (iter)) {
con = NM_CONNECTION (iter->data);
s_con = nm_connection_get_setting_connection (con);
g_assert (s_con);
@@ -5201,7 +5200,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
char *try_name = ifname ?
g_strdup_printf ("%s-%s", get_name_alias (setting_name, nmc_valid_connection_types), ifname)
: g_strdup (get_name_alias (setting_name, nmc_valid_connection_types));
- default_name = unique_connection_name (nmc->system_connections, try_name);
+ default_name = unique_connection_name (nmc->connections, try_name);
g_free (try_name);
}
g_object_set (s_con,
@@ -5217,7 +5216,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv)
if (!complete_connection_by_type (connection,
setting_name,
- nmc->system_connections,
+ nmc->connections,
nmc->ask,
argc,
argv,
@@ -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);
@@ -5269,7 +5268,7 @@ uuid_display_hook (char **array, int len, int max_len)
const char *id;
for (i = 1; i <= len; i++) {
- con = nmc_find_connection (nmc_tab_completion.nmc->system_connections, "uuid", array[i], NULL);
+ con = nmc_find_connection (nmc_tab_completion.nmc->connections, "uuid", array[i], NULL);
id = con ? nm_connection_get_id (con) : NULL;
if (id) {
tmp = g_strdup_printf ("%s (%s)", array[i], id);
@@ -5522,12 +5521,12 @@ gen_vpn_uuids (const char *text, int state)
const char **uuids;
char *ret;
- len = g_slist_length (nmc_tab_completion.nmc->system_connections);
+ len = g_slist_length (nmc_tab_completion.nmc->connections);
if (len < 1)
return NULL;
uuids = g_new (const char *, len + 1);
- for (iter = nmc_tab_completion.nmc->system_connections; iter; iter = g_slist_next (iter)) {
+ for (iter = nmc_tab_completion.nmc->connections; iter; iter = g_slist_next (iter)) {
const char *type = nm_connection_get_connection_type (NM_CONNECTION (iter->data));
if (g_strcmp0 (type, NM_SETTING_VPN_SETTING_NAME) == 0)
@@ -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);
@@ -7831,7 +7829,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
/* Existing connection */
NMConnection *found_con;
- found_con = nmc_find_connection (nmc->system_connections, selector, con, NULL);
+ found_con = nmc_find_connection (nmc->connections, selector, con, NULL);
if (!found_con) {
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), con);
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
@@ -7886,7 +7884,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
if (con_name)
default_name = g_strdup (con_name);
else
- default_name = unique_connection_name (nmc->system_connections,
+ default_name = unique_connection_name (nmc->connections,
get_name_alias (connection_type, nmc_valid_connection_types));
g_object_set (s_con,
@@ -8016,14 +8014,14 @@ do_connection_modify (NmCli *nmc,
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto finish;
}
- connection = nmc_find_connection (nmc->system_connections, selector, name, NULL);
+ connection = nmc_find_connection (nmc->connections, selector, name, NULL);
if (!connection) {
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), name);
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;
@@ -8227,7 +8225,7 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
}
}
- connection = nmc_find_connection (nmc->system_connections, selector, *arg_ptr, &pos);
+ connection = nmc_find_connection (nmc->connections, selector, *arg_ptr, &pos);
if (!connection) {
if (nmc->print_output != NMC_PRINT_TERSE)
g_print (_("Error: unknown connection: %s\n"), *arg_ptr);
@@ -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);
@@ -8383,11 +8381,11 @@ gen_func_connection_names (const char *text, int state)
const char **connections;
char *ret;
- if (!nm_cli.system_connections)
+ if (!nm_cli.connections)
return NULL;
- connections = g_new (const char *, g_slist_length (nm_cli.system_connections) + 1);
- for (iter = nm_cli.system_connections; iter; iter = g_slist_next (iter)) {
+ connections = g_new (const char *, g_slist_length (nm_cli.connections) + 1);
+ for (iter = nm_cli.connections; iter; iter = g_slist_next (iter)) {
NMConnection *con = NM_CONNECTION (iter->data);
const char *id = nm_connection_get_id (con);
connections[i++] = id;
@@ -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->system_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) {
diff --git a/clients/cli/general.c b/clients/cli/general.c
index 381a330ca2..1da3803fc9 100644
--- a/clients/cli/general.c
+++ b/clients/cli/general.c
@@ -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) {
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c
index e89b150f6a..f6ca11e935 100644
--- a/clients/cli/nmcli.c
+++ b/clients/cli/nmcli.c
@@ -498,9 +498,7 @@ nmc_init (NmCli *nmc)
nmc->timeout = -1;
- nmc->system_settings = NULL;
- nmc->system_settings_running = FALSE;
- nmc->system_connections = NULL;
+ nmc->connections = NULL;
nmc->should_wait = FALSE;
nmc->nowait_flag = TRUE;
@@ -526,8 +524,7 @@ 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->system_connections);
+ g_slist_free (nmc->connections);
g_free (nmc->required_fields);
nmc_empty_output_fields (nmc);
diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h
index 5582b1d2ad..2d67320cbd 100644
--- a/clients/cli/nmcli.h
+++ b/clients/cli/nmcli.h
@@ -110,9 +110,7 @@ typedef struct _NmCli {
int timeout; /* Operation timeout */
- NMRemoteSettings *system_settings; /* System settings */
- gboolean system_settings_running; /* Is system settings service running? */
- GSList *system_connections; /* List of system connections */
+ GSList *connections; /* List of connections */
gboolean should_wait; /* Indication that nmcli should not end yet */
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index d64ca6b288..b7137560de 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -2507,7 +2507,7 @@ nmc_property_connection_set_secondaries (NMSetting *setting, const char *prop, c
continue;
if (nm_utils_is_uuid (*iter)) {
- con = nmc_find_connection (nm_cli.system_connections,
+ con = nmc_find_connection (nm_cli.connections,
"uuid", *iter, NULL);
if (!con)
g_print (_("Warning: %s is not an UUID of any existing connection profile\n"), *iter);
@@ -2520,7 +2520,7 @@ nmc_property_connection_set_secondaries (NMSetting *setting, const char *prop, c
}
}
} else {
- con = nmc_find_connection (nm_cli.system_connections,
+ con = nmc_find_connection (nm_cli.connections,
"id", *iter, NULL);
if (!con) {
g_set_error (error, 1, 0, _("'%s' is not a name of any exiting profile"), *iter);
diff --git a/clients/tui/nm-editor-utils.c b/clients/tui/nm-editor-utils.c
index 54efbf8ea1..e7b47e1a0d 100644
--- a/clients/tui/nm-editor-utils.c
+++ b/clients/tui/nm-editor-utils.c
@@ -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,
diff --git a/clients/tui/nm-editor-utils.h b/clients/tui/nm-editor-utils.h
index 8d61d7525a..5e402ce715 100644
--- a/clients/tui/nm-editor-utils.h
+++ b/clients/tui/nm-editor-utils.h
@@ -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
diff --git a/clients/tui/nmt-connect-connection-list.c b/clients/tui/nmt-connect-connection-list.c
index a596364533..f4dc0cf98e 100644
--- a/clients/tui/nmt-connect-connection-list.c
+++ b/clients/tui/nmt-connect-connection-list.c
@@ -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;
diff --git a/clients/tui/nmt-edit-connection-list.c b/clients/tui/nmt-edit-connection-list.c
index 508f204c39..9afe44164f 100644
--- a/clients/tui/nmt-edit-connection-list.c
+++ b/clients/tui/nmt-edit-connection-list.c
@@ -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);
diff --git a/clients/tui/nmt-editor.c b/clients/tui/nmt-editor.c
index 93e36d7919..bd1c77e339 100644
--- a/clients/tui/nmt-editor.c
+++ b/clients/tui/nmt-editor.c
@@ -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);
diff --git a/clients/tui/nmtui-edit.c b/clients/tui/nmtui-edit.c
index c0354784fe..d32da817cd 100644
--- a/clients/tui/nmtui-edit.c
+++ b/clients/tui/nmtui-edit.c
@@ -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]);
diff --git a/clients/tui/nmtui-hostname.c b/clients/tui/nmtui-hostname.c
index 92e493d92b..23de95b854 100644
--- a/clients/tui/nmtui-hostname.c
+++ b/clients/tui/nmtui-hostname.c
@@ -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);
diff --git a/clients/tui/nmtui.c b/clients/tui/nmtui.c
index ee63ccf280..0fac98ebc4 100644
--- a/clients/tui/nmtui.c
+++ b/clients/tui/nmtui.c
@@ -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;
}
diff --git a/clients/tui/nmtui.h b/clients/tui/nmtui.h
index 10b9c06ade..aada9719f7 100644
--- a/clients/tui/nmtui.h
+++ b/clients/tui/nmtui.h
@@ -24,7 +24,6 @@
G_BEGIN_DECLS
extern NMClient *nm_client;
-extern NMRemoteSettings *nm_settings;
void nmtui_quit (void);
diff --git a/docs/libnm/Makefile.am b/docs/libnm/Makefile.am
index 5556aadb97..1e1e9ae276 100644
--- a/docs/libnm/Makefile.am
+++ b/docs/libnm/Makefile.am
@@ -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
diff --git a/docs/libnm/libnm-docs.xml b/docs/libnm/libnm-docs.xml
index 3d1de81fe5..00eba8abb2 100644
--- a/docs/libnm/libnm-docs.xml
+++ b/docs/libnm/libnm-docs.xml
@@ -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>
diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c
index c680f420ff..1288e79c51 100644
--- a/examples/C/glib/add-connection-libnm.c
+++ b/examples/C/glib/add-connection-libnm.c
@@ -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;
}
diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c
index bebeeb8a23..f761bfd77f 100644
--- a/examples/C/glib/list-connections-libnm.c
+++ b/examples/C/glib/list-connections-libnm.c
@@ -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;
}
diff --git a/libnm/Makefile.am b/libnm/Makefile.am
index b15db447d7..e3945b88b6 100644
--- a/libnm/Makefile.am
+++ b/libnm/Makefile.am
@@ -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 \
@@ -61,9 +60,11 @@ libnminclude_HEADERS = \
libnm_la_private_headers = \
nm-dbus-helpers.h \
nm-device-private.h \
+ 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 \
@@ -89,6 +90,7 @@ libnm_la_csources = \
nm-enum-types.c \
nm-ip4-config.c \
nm-ip6-config.c \
+ nm-manager.c \
nm-object-cache.c \
nm-object.c \
nm-remote-connection.c \
diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h
index d7414101ce..ce7bec74c2 100644
--- a/libnm/NetworkManager.h
+++ b/libnm/NetworkManager.h
@@ -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>
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 08182f8c09..437cebf936 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -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;
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index 053f75ceae..9ecb77a1cf 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -23,19 +23,18 @@
#include <nm-utils.h>
#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"
#include "nm-core-internal.h"
-#include "nm-object-private.h"
#include "nm-active-connection.h"
#include "nm-vpn-connection.h"
#include "nm-object-cache.h"
#include "nm-glib-compat.h"
#include "nm-dbus-helpers.h"
-#include "nmdbus-manager.h"
-
void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
static void nm_client_initable_iface_init (GInitableIface *iface);
@@ -43,7 +42,7 @@ static void nm_client_async_initable_iface_init (GAsyncInitableIface *iface);
static GInitableIface *nm_client_parent_initable_iface;
static GAsyncInitableIface *nm_client_parent_async_initable_iface;
-G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, NM_TYPE_OBJECT,
+G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_client_initable_iface_init);
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_client_async_initable_iface_init);
)
@@ -51,33 +50,8 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, NM_TYPE_OBJECT,
#define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate))
typedef struct {
- NMDBusManager *manager_proxy;
- char *version;
- NMState state;
- gboolean startup;
- GPtrArray *devices;
- GPtrArray *active_connections;
- NMConnectivityState connectivity;
- NMActiveConnection *primary_connection;
- NMActiveConnection *activating_connection;
-
- GCancellable *perm_call_cancellable;
- GHashTable *permissions;
-
- /* Activations waiting for their NMActiveConnection
- * to appear and then their callback to be called.
- */
- GSList *pending_activations;
-
- gboolean networking_enabled;
- gboolean wireless_enabled;
- gboolean wireless_hw_enabled;
-
- gboolean wwan_enabled;
- gboolean wwan_hw_enabled;
-
- gboolean wimax_enabled;
- gboolean wimax_hw_enabled;
+ NMManager *manager;
+ NMRemoteSettings *settings;
} NMClientPrivate;
enum {
@@ -98,6 +72,9 @@ enum {
PROP_PRIMARY_CONNECTION,
PROP_ACTIVATING_CONNECTION,
PROP_DEVICES,
+ PROP_CONNECTIONS,
+ PROP_HOSTNAME,
+ PROP_CAN_MODIFY,
LAST_PROP
};
@@ -106,16 +83,14 @@ enum {
DEVICE_ADDED,
DEVICE_REMOVED,
PERMISSION_CHANGED,
+ CONNECTION_ADDED,
+ CONNECTION_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
-static void nm_running_changed_cb (GObject *object,
- GParamSpec *pspec,
- gpointer user_data);
-
/**********************************************************************/
/**
@@ -140,249 +115,588 @@ nm_client_error_quark (void)
static void
nm_client_init (NMClient *client)
{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
+}
- priv->state = NM_STATE_UNKNOWN;
+static gboolean
+_nm_client_check_nm_running (NMClient *client, GError **error)
+{
+ if (nm_client_get_nm_running (client))
+ return TRUE;
+ else {
+ g_set_error_literal (error,
+ NM_CLIENT_ERROR,
+ NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
+ "NetworkManager is not running");
+ return FALSE;
+ }
+}
+
+/**
+ * nm_client_get_version:
+ * @client: a #NMClient
+ *
+ * Gets NetworkManager version.
+ *
+ * Returns: string with the version (or %NULL if NetworkManager is not running)
+ **/
+const char *
+nm_client_get_version (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal);
+ return nm_manager_get_version (NM_CLIENT_GET_PRIVATE (client)->manager);
}
-static void
-poke_wireless_devices_with_rf_status (NMClient *client)
+/**
+ * nm_client_get_state:
+ * @client: a #NMClient
+ *
+ * Gets the current daemon state.
+ *
+ * Returns: the current %NMState
+ **/
+NMState
+nm_client_get_state (NMClient *client)
{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
- int i;
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
- for (i = 0; i < priv->devices->len; i++) {
- NMDevice *device = g_ptr_array_index (priv->devices, i);
+ return nm_manager_get_state (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
- if (NM_IS_DEVICE_WIFI (device))
- _nm_device_wifi_set_wireless_enabled (NM_DEVICE_WIFI (device), priv->wireless_enabled);
- }
+/**
+ * nm_client_get_startup:
+ * @client: a #NMClient
+ *
+ * Tests whether the daemon is still in the process of activating
+ * connections at startup.
+ *
+ * Returns: whether the daemon is still starting up
+ **/
+gboolean
+nm_client_get_startup (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
+
+ return nm_manager_get_startup (NM_CLIENT_GET_PRIVATE (client)->manager);
}
-static void
-wireless_enabled_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+/**
+ * nm_client_get_nm_running:
+ * @client: a #NMClient
+ *
+ * Determines whether the daemon is running.
+ *
+ * Returns: %TRUE if the daemon is running
+ **/
+gboolean
+nm_client_get_nm_running (NMClient *client)
{
- poke_wireless_devices_with_rf_status (NM_CLIENT (object));
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+
+ return nm_manager_get_nm_running (NM_CLIENT_GET_PRIVATE (client)->manager);
}
-static void client_recheck_permissions (NMDBusManager *proxy, gpointer user_data);
-static void active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data);
-static void object_creation_failed_cb (GObject *object, GError *error, char *failed_path);
+/**
+ * nm_client_networking_get_enabled:
+ * @client: a #NMClient
+ *
+ * Whether networking is enabled or disabled.
+ *
+ * Returns: %TRUE if networking is enabled, %FALSE if networking is disabled
+ **/
+gboolean
+nm_client_networking_get_enabled (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
-static void
-init_dbus (NMObject *object)
+ return nm_manager_networking_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_networking_set_enabled:
+ * @client: a #NMClient
+ * @enabled: %TRUE to set networking enabled, %FALSE to set networking disabled
+ * @error: (allow-none): return location for a #GError, or %NULL
+ *
+ * Enables or disables networking. When networking is disabled, all controlled
+ * interfaces are disconnected and deactivated. When networking is enabled,
+ * all controlled interfaces are available for activation.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise
+ **/
+gboolean
+nm_client_networking_set_enabled (NMClient *client, gboolean enable, GError **error)
{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
- const NMPropertiesInfo property_info[] = {
- { NM_CLIENT_VERSION, &priv->version },
- { NM_CLIENT_STATE, &priv->state },
- { NM_CLIENT_STARTUP, &priv->startup },
- { NM_CLIENT_NETWORKING_ENABLED, &priv->networking_enabled },
- { NM_CLIENT_WIRELESS_ENABLED, &priv->wireless_enabled },
- { NM_CLIENT_WIRELESS_HARDWARE_ENABLED, &priv->wireless_hw_enabled },
- { NM_CLIENT_WWAN_ENABLED, &priv->wwan_enabled },
- { NM_CLIENT_WWAN_HARDWARE_ENABLED, &priv->wwan_hw_enabled },
- { NM_CLIENT_WIMAX_ENABLED, &priv->wimax_enabled },
- { NM_CLIENT_WIMAX_HARDWARE_ENABLED, &priv->wimax_hw_enabled },
- { NM_CLIENT_ACTIVE_CONNECTIONS, &priv->active_connections, NULL, NM_TYPE_ACTIVE_CONNECTION },
- { NM_CLIENT_CONNECTIVITY, &priv->connectivity },
- { NM_CLIENT_PRIMARY_CONNECTION, &priv->primary_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
- { NM_CLIENT_ACTIVATING_CONNECTION, &priv->activating_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
- { NM_CLIENT_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE, "device" },
- { NULL },
- };
-
- NM_OBJECT_CLASS (nm_client_parent_class)->init_dbus (object);
-
- priv->manager_proxy = NMDBUS_MANAGER (_nm_object_get_proxy (object, NM_DBUS_INTERFACE));
- _nm_object_register_properties (object,
- NM_DBUS_INTERFACE,
- property_info);
-
- /* Permissions */
- g_signal_connect (priv->manager_proxy, "check-permissions",
- G_CALLBACK (client_recheck_permissions), object);
-}
-
-#define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network"
-#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI "org.freedesktop.NetworkManager.enable-disable-wifi"
-#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN "org.freedesktop.NetworkManager.enable-disable-wwan"
-#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX "org.freedesktop.NetworkManager.enable-disable-wimax"
-#define NM_AUTH_PERMISSION_SLEEP_WAKE "org.freedesktop.NetworkManager.sleep-wake"
-#define NM_AUTH_PERMISSION_NETWORK_CONTROL "org.freedesktop.NetworkManager.network-control"
-#define NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED "org.freedesktop.NetworkManager.wifi.share.protected"
-#define NM_AUTH_PERMISSION_WIFI_SHARE_OPEN "org.freedesktop.NetworkManager.wifi.share.open"
-#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM "org.freedesktop.NetworkManager.settings.modify.system"
-#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN "org.freedesktop.NetworkManager.settings.modify.own"
-#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME "org.freedesktop.NetworkManager.settings.modify.hostname"
-
-static NMClientPermission
-nm_permission_to_client (const char *nm)
-{
- if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK))
- return NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI))
- return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN))
- return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX))
- return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_SLEEP_WAKE))
- return NM_CLIENT_PERMISSION_SLEEP_WAKE;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_NETWORK_CONTROL))
- return NM_CLIENT_PERMISSION_NETWORK_CONTROL;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED))
- return NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN))
- return NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM))
- return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN))
- return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN;
- else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME))
- return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME;
-
- return NM_CLIENT_PERMISSION_NONE;
-}
-
-static NMClientPermissionResult
-nm_permission_result_to_client (const char *nm)
-{
- if (!strcmp (nm, "yes"))
- return NM_CLIENT_PERMISSION_RESULT_YES;
- else if (!strcmp (nm, "no"))
- return NM_CLIENT_PERMISSION_RESULT_NO;
- else if (!strcmp (nm, "auth"))
- return NM_CLIENT_PERMISSION_RESULT_AUTH;
- return NM_CLIENT_PERMISSION_RESULT_UNKNOWN;
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+
+ if (!_nm_client_check_nm_running (client, error))
+ return FALSE;
+
+ return nm_manager_networking_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager,
+ enable, error);
}
-static void
-update_permissions (NMClient *self, GVariant *permissions)
-{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
- GHashTableIter iter;
- gpointer key, value;
- NMClientPermission perm;
- NMClientPermissionResult perm_result;
- GList *keys, *keys_iter;
-
- /* get list of old permissions for change notification */
- keys = g_hash_table_get_keys (priv->permissions);
- g_hash_table_remove_all (priv->permissions);
-
- if (permissions) {
- GVariantIter viter;
- const char *pkey, *pvalue;
-
- /* Process new permissions */
- g_variant_iter_init (&viter, permissions);
- while (g_variant_iter_next (&viter, "{&s&s}", &pkey, &pvalue)) {
- perm = nm_permission_to_client (pkey);
- perm_result = nm_permission_result_to_client (pvalue);
- if (perm) {
- g_hash_table_insert (priv->permissions,
- GUINT_TO_POINTER (perm),
- GUINT_TO_POINTER (perm_result));
-
- /* Remove this permission from the list of previous permissions
- * we'll be sending NM_CLIENT_PERMISSION_RESULT_UNKNOWN for
- * in the change signal since it is still a known permission.
- */
- keys = g_list_remove (keys, GUINT_TO_POINTER (perm));
- }
- }
- }
+/**
+ * nm_client_wireless_get_enabled:
+ * @client: a #NMClient
+ *
+ * Determines whether the wireless is enabled.
+ *
+ * Returns: %TRUE if wireless is enabled
+ **/
+gboolean
+nm_client_wireless_get_enabled (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
- /* Signal changes in all updated permissions */
- g_hash_table_iter_init (&iter, priv->permissions);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- g_signal_emit (self, signals[PERMISSION_CHANGED], 0,
- GPOINTER_TO_UINT (key),
- GPOINTER_TO_UINT (value));
- }
+ return nm_manager_wireless_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
- /* And signal changes in all permissions that used to be valid but for
- * some reason weren't received in the last request (if any).
- */
- for (keys_iter = keys; keys_iter; keys_iter = g_list_next (keys_iter)) {
- g_signal_emit (self, signals[PERMISSION_CHANGED], 0,
- GPOINTER_TO_UINT (keys_iter->data),
- NM_CLIENT_PERMISSION_RESULT_UNKNOWN);
- }
- g_list_free (keys);
+/**
+ * nm_client_wireless_set_enabled:
+ * @client: a #NMClient
+ * @enabled: %TRUE to enable wireless
+ *
+ * Enables or disables wireless devices.
+ **/
+void
+nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
+{
+ g_return_if_fail (NM_IS_CLIENT (client));
+
+ if (!_nm_client_check_nm_running (client, NULL))
+ return;
+
+ nm_manager_wireless_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled);
}
-static gboolean
-get_permissions_sync (NMClient *self, GError **error)
+/**
+ * nm_client_wireless_hardware_get_enabled:
+ * @client: a #NMClient
+ *
+ * Determines whether the wireless hardware is enabled.
+ *
+ * Returns: %TRUE if the wireless hardware is enabled
+ **/
+gboolean
+nm_client_wireless_hardware_get_enabled (NMClient *client)
{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
- GVariant *permissions;
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
- if (nmdbus_manager_call_get_permissions_sync (priv->manager_proxy,
- &permissions,
- NULL, error)) {
- update_permissions (self, permissions);
- g_variant_unref (permissions);
- return TRUE;
- } else {
- update_permissions (self, NULL);
+ return nm_manager_wireless_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_wwan_get_enabled:
+ * @client: a #NMClient
+ *
+ * Determines whether WWAN is enabled.
+ *
+ * Returns: %TRUE if WWAN is enabled
+ **/
+gboolean
+nm_client_wwan_get_enabled (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+
+ return nm_manager_wwan_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_wwan_set_enabled:
+ * @client: a #NMClient
+ * @enabled: %TRUE to enable WWAN
+ *
+ * Enables or disables WWAN devices.
+ **/
+void
+nm_client_wwan_set_enabled (NMClient *client, gboolean enabled)
+{
+ g_return_if_fail (NM_IS_CLIENT (client));
+
+ if (!_nm_client_check_nm_running (client, NULL))
+ return;
+
+ nm_manager_wwan_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled);
+}
+
+/**
+ * nm_client_wwan_hardware_get_enabled:
+ * @client: a #NMClient
+ *
+ * Determines whether the WWAN hardware is enabled.
+ *
+ * Returns: %TRUE if the WWAN hardware is enabled
+ **/
+gboolean
+nm_client_wwan_hardware_get_enabled (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+
+ return nm_manager_wwan_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_wimax_get_enabled:
+ * @client: a #NMClient
+ *
+ * Determines whether WiMAX is enabled.
+ *
+ * Returns: %TRUE if WiMAX is enabled
+ **/
+gboolean
+nm_client_wimax_get_enabled (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+
+ return nm_manager_wimax_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_wimax_set_enabled:
+ * @client: a #NMClient
+ * @enabled: %TRUE to enable WiMAX
+ *
+ * Enables or disables WiMAX devices.
+ **/
+void
+nm_client_wimax_set_enabled (NMClient *client, gboolean enabled)
+{
+ g_return_if_fail (NM_IS_CLIENT (client));
+
+ if (!_nm_client_check_nm_running (client, NULL))
+ return;
+
+ nm_manager_wimax_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled);
+}
+
+/**
+ * nm_client_wimax_hardware_get_enabled:
+ * @client: a #NMClient
+ *
+ * Determines whether the WiMAX hardware is enabled.
+ *
+ * Returns: %TRUE if the WiMAX hardware is enabled
+ **/
+gboolean
+nm_client_wimax_hardware_get_enabled (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+
+ return nm_manager_wimax_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_get_logging:
+ * @client: a #NMClient
+ * @level: (allow-none): return location for logging level string
+ * @domains: (allow-none): return location for log domains string. The string is
+ * a list of domains separated by ","
+ * @error: (allow-none): return location for a #GError, or %NULL
+ *
+ * Gets NetworkManager current logging level and domains.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise
+ **/
+gboolean
+nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (level == NULL || *level == NULL, FALSE);
+ g_return_val_if_fail (domains == NULL || *domains == NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (!_nm_client_check_nm_running (client, error))
return FALSE;
- }
+
+ return nm_manager_get_logging (NM_CLIENT_GET_PRIVATE (client)->manager,
+ level, domains, error);
+}
+
+/**
+ * nm_client_set_logging:
+ * @client: a #NMClient
+ * @level: (allow-none): logging level to set (%NULL or an empty string for no change)
+ * @domains: (allow-none): logging domains to set. The string should be a list of log
+ * domains separated by ",". (%NULL or an empty string for no change)
+ * @error: (allow-none): return location for a #GError, or %NULL
+ *
+ * Sets NetworkManager logging level and/or domains.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise
+ **/
+gboolean
+nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (!_nm_client_check_nm_running (client, error))
+ return FALSE;
+
+ return nm_manager_set_logging (NM_CLIENT_GET_PRIVATE (client)->manager,
+ level, domains, error);
+}
+
+/**
+ * nm_client_get_permission_result:
+ * @client: a #NMClient
+ * @permission: the permission for which to return the result, one of #NMClientPermission
+ *
+ * Requests the result of a specific permission, which indicates whether the
+ * client can or cannot perform the action the permission represents
+ *
+ * Returns: the permission's result, one of #NMClientPermissionResult
+ **/
+NMClientPermissionResult
+nm_client_get_permission_result (NMClient *client, NMClientPermission permission)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_CLIENT_PERMISSION_RESULT_UNKNOWN);
+
+ return nm_manager_get_permission_result (NM_CLIENT_GET_PRIVATE (client)->manager, permission);
+}
+
+/**
+ * nm_client_get_connectivity:
+ * @client: an #NMClient
+ *
+ * Gets the current network connectivity state. Contrast
+ * nm_client_check_connectivity() and
+ * nm_client_check_connectivity_async(), which re-check the
+ * connectivity state first before returning any information.
+ *
+ * Returns: the current connectivity state
+ */
+NMConnectivityState
+nm_client_get_connectivity (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
+
+ return nm_manager_get_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager);
+}
+
+/**
+ * nm_client_check_connectivity:
+ * @client: an #NMClient
+ * @cancellable: a #GCancellable
+ * @error: return location for a #GError
+ *
+ * Updates the network connectivity state and returns the (new)
+ * current state. Contrast nm_client_get_connectivity(), which returns
+ * the most recent known state without re-checking.
+ *
+ * This is a blocking call; use nm_client_check_connectivity_async()
+ * if you do not want to block.
+ *
+ * Returns: the (new) current connectivity state
+ */
+NMConnectivityState
+nm_client_check_connectivity (NMClient *client,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
+
+ if (!_nm_client_check_nm_running (client, error))
+ return NM_CONNECTIVITY_UNKNOWN;
+
+ return nm_manager_check_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager,
+ cancellable, error);
}
static void
-get_permissions_reply (GObject *object,
+check_connectivity_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- NMClient *self;
- NMClientPrivate *priv;
- GVariant *permissions = NULL;
+ GSimpleAsyncResult *simple = user_data;
+ NMConnectivityState connectivity;
GError *error = NULL;
- /* WARNING: this may be called after the client is disposed, so we can't
- * look at self/priv until after we've determined that that isn't the case.
- */
+ connectivity = nm_manager_check_connectivity_finish (NM_MANAGER (object),
+ result, &error);
+ if (!error)
+ g_simple_async_result_set_op_res_gssize (simple, connectivity);
+ else
+ g_simple_async_result_take_error (simple, error);
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+/**
+ * nm_client_check_connectivity_async:
+ * @client: an #NMClient
+ * @cancellable: a #GCancellable
+ * @callback: callback to call with the result
+ * @user_data: data for @callback.
+ *
+ * Asynchronously updates the network connectivity state and invokes
+ * @callback when complete. Contrast nm_client_get_connectivity(),
+ * which (immediately) returns the most recent known state without
+ * re-checking, and nm_client_check_connectivity(), which blocks.
+ */
+void
+nm_client_check_connectivity_async (NMClient *client,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple;
+ GError *error = NULL;
+
+ g_return_if_fail (NM_IS_CLIENT (client));
- nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
- &permissions,
- result, &error);
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- /* @self has been disposed. */
- g_error_free (error);
+ if (!_nm_client_check_nm_running (client, &error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
- self = user_data;
- priv = NM_CLIENT_GET_PRIVATE (self);
+ simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
+ nm_client_check_connectivity_async);
+ nm_manager_check_connectivity_async (NM_CLIENT_GET_PRIVATE (client)->manager,
+ cancellable, check_connectivity_cb, simple);
+}
+
+/**
+ * nm_client_check_connectivity_finish:
+ * @client: an #NMClient
+ * @result: the #GAsyncResult
+ * @error: return location for a #GError
+ *
+ * Retrieves the result of an nm_client_check_connectivity_async()
+ * call.
+ *
+ * Returns: the (new) current connectivity state
+ */
+NMConnectivityState
+nm_client_check_connectivity_finish (NMClient *client,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NM_CONNECTIVITY_UNKNOWN);
- update_permissions (self, permissions);
+ simple = G_SIMPLE_ASYNC_RESULT (result);
- g_clear_pointer (&permissions, g_variant_unref);
- g_clear_error (&error);
- g_clear_object (&priv->perm_call_cancellable);
+ if (g_simple_async_result_propagate_error (simple, error))
+ return NM_CONNECTIVITY_UNKNOWN;
+ 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
-client_recheck_permissions (NMDBusManager *proxy, gpointer user_data)
+save_hostname_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- NMClient *self = NM_CLIENT (user_data);
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
+ 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);
+}
- if (priv->perm_call_cancellable)
+/**
+ * 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;
+ }
- priv->perm_call_cancellable = g_cancellable_new ();
- nmdbus_manager_call_get_permissions (priv->manager_proxy,
- priv->perm_call_cancellable,
- get_permissions_reply,
- self);
+ 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 */
+/****************************************************************/
+
+/**
* nm_client_get_devices:
* @client: a #NMClient
*
@@ -400,7 +714,7 @@ nm_client_get_devices (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- return NM_CLIENT_GET_PRIVATE (client)->devices;
+ return nm_manager_get_devices (NM_CLIENT_GET_PRIVATE (client)->manager);
}
/**
@@ -415,26 +729,10 @@ nm_client_get_devices (NMClient *client)
NMDevice *
nm_client_get_device_by_path (NMClient *client, const char *object_path)
{
- const GPtrArray *devices;
- int i;
- NMDevice *device = NULL;
-
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (object_path, NULL);
- devices = nm_client_get_devices (client);
- if (!devices)
- return NULL;
-
- for (i = 0; i < devices->len; i++) {
- NMDevice *candidate = g_ptr_array_index (devices, i);
- if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), object_path)) {
- device = candidate;
- break;
- }
- }
-
- return device;
+ return nm_manager_get_device_by_path (NM_CLIENT_GET_PRIVATE (client)->manager, object_path);
}
/**
@@ -449,128 +747,78 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path)
NMDevice *
nm_client_get_device_by_iface (NMClient *client, const char *iface)
{
- const GPtrArray *devices;
- int i;
- NMDevice *device = NULL;
-
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (iface, NULL);
- devices = nm_client_get_devices (client);
- if (!devices)
- return NULL;
-
- for (i = 0; i < devices->len; i++) {
- NMDevice *candidate = g_ptr_array_index (devices, i);
- if (!strcmp (nm_device_get_iface (candidate), iface)) {
- device = candidate;
- break;
- }
- }
-
- return device;
+ return nm_manager_get_device_by_iface (NM_CLIENT_GET_PRIVATE (client)->manager, iface);
}
-typedef struct {
- NMClient *client;
- GSimpleAsyncResult *simple;
- GCancellable *cancellable;
- gulong cancelled_id;
- char *active_path;
- char *new_connection_path;
-} ActivateInfo;
+/****************************************************************/
+/* Active Connections */
+/****************************************************************/
-static void
-activate_info_complete (ActivateInfo *info,
- NMActiveConnection *active,
- GError *error)
+/**
+ * nm_client_get_active_connections:
+ * @client: a #NMClient
+ *
+ * Gets the active connections.
+ *
+ * Returns: (transfer none) (element-type NMActiveConnection): a #GPtrArray
+ * containing all the active #NMActiveConnections.
+ * The returned array is owned by the client and should not be modified.
+ **/
+const GPtrArray *
+nm_client_get_active_connections (NMClient *client)
{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (info->client);
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- if (active)
- g_simple_async_result_set_op_res_gpointer (info->simple, g_object_ref (active), g_object_unref);
- else
- g_simple_async_result_set_from_error (info->simple, error);
- g_simple_async_result_complete (info->simple);
-
- priv->pending_activations = g_slist_remove (priv->pending_activations, info);
-
- g_free (info->active_path);
- g_free (info->new_connection_path);
- g_object_unref (info->simple);
- if (info->cancellable) {
- if (info->cancelled_id)
- g_signal_handler_disconnect (info->cancellable, info->cancelled_id);
- g_object_unref (info->cancellable);
- }
- g_slice_free (ActivateInfo, info);
+ return nm_manager_get_active_connections (NM_CLIENT_GET_PRIVATE (client)->manager);
}
-static void
-recheck_pending_activations (NMClient *self, const char *failed_path, GError *error)
-{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
- GSList *iter, *next;
- const GPtrArray *active_connections;
- gboolean found_in_active = FALSE;
- gboolean found_in_pending = FALSE;
- ActivateInfo *ainfo = NULL;
- int i;
-
- active_connections = nm_client_get_active_connections (self);
-
- /* For each pending activation, look for a active connection that has
- * the pending activation's object path, and call pending connection's
- * callback.
- * If the connection to activate doesn't make it to active_connections,
- * due to an error, we have to call the callback for failed_path.
- */
- for (iter = priv->pending_activations; iter; iter = next) {
- ActivateInfo *info = iter->data;
-
- next = g_slist_next (iter);
-
- if (!found_in_pending && failed_path && g_strcmp0 (failed_path, info->active_path) == 0) {
- found_in_pending = TRUE;
- ainfo = info;
- }
-
- for (i = 0; i < active_connections->len; i++) {
- NMActiveConnection *active = g_ptr_array_index (active_connections, i);
- const char *active_path = nm_object_get_path (NM_OBJECT (active));
-
- if (!found_in_active && failed_path && g_strcmp0 (failed_path, active_path) == 0)
- found_in_active = TRUE;
-
- if (g_strcmp0 (info->active_path, active_path) == 0) {
- /* Call the pending activation's callback and it all up */
- activate_info_complete (info, active, NULL);
- break;
- }
- }
- }
+/**
+ * nm_client_get_primary_connection:
+ * @client: an #NMClient
+ *
+ * Gets the #NMActiveConnection corresponding to the primary active
+ * network device.
+ *
+ * In particular, when there is no VPN active, or the VPN does not
+ * have the default route, this returns the active connection that has
+ * the default route. If there is a VPN active with the default route,
+ * then this function returns the active connection that contains the
+ * route to the VPN endpoint.
+ *
+ * If there is no default route, or the default route is over a
+ * non-NetworkManager-recognized device, this will return %NULL.
+ *
+ * Returns: (transfer none): the appropriate #NMActiveConnection, if
+ * any
+ */
+NMActiveConnection *
+nm_client_get_primary_connection (NMClient *client)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- if (!found_in_active && found_in_pending) {
- /* A newly activated connection failed due to some immediate error
- * and disappeared from active connection list. Make sure the
- * callback gets called.
- */
- activate_info_complete (ainfo, NULL, error);
- }
+ return nm_manager_get_primary_connection (NM_CLIENT_GET_PRIVATE (client)->manager);
}
-static void
-activation_cancelled (GCancellable *cancellable,
- gpointer user_data)
+/**
+ * nm_client_get_activating_connection:
+ * @client: an #NMClient
+ *
+ * Gets the #NMActiveConnection corresponding to a
+ * currently-activating connection that is expected to become the new
+ * #NMClient:primary-connection upon successful activation.
+ *
+ * Returns: (transfer none): the appropriate #NMActiveConnection, if
+ * any.
+ */
+NMActiveConnection *
+nm_client_get_activating_connection (NMClient *client)
{
- ActivateInfo *info = user_data;
- GError *error = NULL;
-
- if (!g_cancellable_set_error_if_cancelled (cancellable, &error))
- return;
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- activate_info_complete (info, NULL, error);
- g_clear_error (&error);
+ return nm_manager_get_activating_connection (NM_CLIENT_GET_PRIVATE (client)->manager);
}
static void
@@ -578,22 +826,18 @@ activate_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- ActivateInfo *info = user_data;
+ GSimpleAsyncResult *simple = user_data;
+ NMActiveConnection *ac;
GError *error = NULL;
- if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object),
- &info->active_path,
- result, &error)) {
- if (info->cancellable) {
- info->cancelled_id = g_signal_connect (info->cancellable, "cancelled",
- G_CALLBACK (activation_cancelled), info);
- }
-
- recheck_pending_activations (info->client, NULL, NULL);
- } else {
- activate_info_complete (info, NULL, error);
- g_clear_error (&error);
- }
+ ac = nm_manager_activate_connection_finish (NM_MANAGER (object), result, &error);
+ if (ac)
+ g_simple_async_result_set_op_res_gpointer (simple, ac, g_object_unref);
+ else
+ g_simple_async_result_take_error (simple, error);
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
}
/**
@@ -638,8 +882,8 @@ nm_client_activate_connection_async (NMClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- NMClientPrivate *priv;
- ActivateInfo *info;
+ GSimpleAsyncResult *simple;
+ GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
if (device)
@@ -647,29 +891,16 @@ nm_client_activate_connection_async (NMClient *client,
if (connection)
g_return_if_fail (NM_IS_CONNECTION (connection));
- if (!nm_client_get_nm_running (client)) {
- g_simple_async_report_error_in_idle (G_OBJECT (client), callback, user_data,
- NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
- "NetworkManager is not running");
+ if (!_nm_client_check_nm_running (client, &error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
- info = g_slice_new0 (ActivateInfo);
- info->client = client;
- info->simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
- nm_client_activate_connection_async);
- info->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
-
- priv = NM_CLIENT_GET_PRIVATE (client);
- priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
-
- nmdbus_manager_call_activate_connection (priv->manager_proxy,
- connection ? nm_connection_get_path (connection) : "/",
- device ? nm_object_get_path (NM_OBJECT (device)) : "/",
- specific_object ? specific_object : "/",
- cancellable,
- activate_cb, info);
+ simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
+ nm_client_activate_connection_async);
+ nm_manager_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager,
+ connection, device, specific_object,
+ cancellable, activate_cb, simple);
}
/**
@@ -690,7 +921,8 @@ nm_client_activate_connection_finish (NMClient *client,
{
GSimpleAsyncResult *simple;
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_activate_connection_async), NULL);
+ 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))
@@ -704,23 +936,18 @@ add_activate_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- ActivateInfo *info = user_data;
+ GSimpleAsyncResult *simple = user_data;
+ NMActiveConnection *ac;
GError *error = NULL;
- if (nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object),
- NULL,
- &info->active_path,
- result, &error)) {
- if (info->cancellable) {
- info->cancelled_id = g_signal_connect (info->cancellable, "cancelled",
- G_CALLBACK (activation_cancelled), info);
- }
-
- recheck_pending_activations (info->client, NULL, NULL);
- } else {
- activate_info_complete (info, NULL, error);
- g_clear_error (&error);
- }
+ ac = nm_manager_add_and_activate_connection_finish (NM_MANAGER (object), result, &error);
+ if (ac)
+ g_simple_async_result_set_op_res_gpointer (simple, ac, g_object_unref);
+ else
+ g_simple_async_result_take_error (simple, error);
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
}
/**
@@ -761,43 +988,24 @@ nm_client_add_and_activate_connection_async (NMClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- NMClientPrivate *priv;
- GVariant *dict = NULL;
- ActivateInfo *info;
+ GSimpleAsyncResult *simple;
+ GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_DEVICE (device));
if (partial)
g_return_if_fail (NM_IS_CONNECTION (partial));
- if (!nm_client_get_nm_running (client)) {
- g_simple_async_report_error_in_idle (G_OBJECT (client), callback, user_data,
- NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
- "NetworkManager is not running");
+ if (!_nm_client_check_nm_running (client, &error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
- info = g_slice_new0 (ActivateInfo);
- info->client = client;
- info->simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
- nm_client_add_and_activate_connection_async);
- info->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
-
- priv = NM_CLIENT_GET_PRIVATE (client);
- priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
-
- if (partial)
- dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL);
- if (!dict)
- dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
-
- nmdbus_manager_call_add_and_activate_connection (priv->manager_proxy,
- dict,
- nm_object_get_path (NM_OBJECT (device)),
- specific_object ? specific_object : "/",
- cancellable,
- add_activate_cb, info);
+ simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
+ nm_client_add_and_activate_connection_async);
+ nm_manager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager,
+ partial, device, specific_object,
+ cancellable, add_activate_cb, simple);
}
/**
@@ -821,7 +1029,8 @@ nm_client_add_and_activate_connection_finish (NMClient *client,
{
GSimpleAsyncResult *simple;
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_add_and_activate_connection_async), NULL);
+ 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))
@@ -830,19 +1039,6 @@ nm_client_add_and_activate_connection_finish (NMClient *client,
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
-static void
-active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
-{
- recheck_pending_activations (NM_CLIENT (object), NULL, NULL);
-}
-
-static void
-object_creation_failed_cb (GObject *object, GError *error, char *failed_path)
-{
- if (error)
- recheck_pending_activations (NM_CLIENT (object), failed_path, error);
-}
-
/**
* nm_client_deactivate_connection:
* @client: a #NMClient
@@ -860,20 +1056,14 @@ nm_client_deactivate_connection (NMClient *client,
GCancellable *cancellable,
GError **error)
{
- NMClientPrivate *priv;
- const char *path;
-
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE);
- priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_client_get_nm_running (client))
+ if (!_nm_client_check_nm_running (client, NULL))
return TRUE;
- path = nm_object_get_path (NM_OBJECT (active));
- return nmdbus_manager_call_deactivate_connection_sync (priv->manager_proxy,
- path,
- cancellable, error);
+ return nm_manager_deactivate_connection (NM_CLIENT_GET_PRIVATE (client)->manager,
+ active, cancellable, error);
}
static void
@@ -884,8 +1074,7 @@ deactivated_cb (GObject *object,
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
- if (nmdbus_manager_call_deactivate_connection_finish (NMDBUS_MANAGER (object),
- result, &error))
+ if (nm_manager_deactivate_connection_finish (NM_MANAGER (object), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else
g_simple_async_result_take_error (simple, error);
@@ -910,8 +1099,6 @@ nm_client_deactivate_connection_async (NMClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- NMClientPrivate *priv;
- const char *path;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_CLIENT (client));
@@ -920,19 +1107,16 @@ nm_client_deactivate_connection_async (NMClient *client,
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_deactivate_connection_async);
- priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_client_get_nm_running (client)) {
+ if (!_nm_client_check_nm_running (client, NULL)) {
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
- path = nm_object_get_path (NM_OBJECT (active));
- nmdbus_manager_call_deactivate_connection (priv->manager_proxy,
- path,
- cancellable,
- deactivated_cb, simple);
+ nm_manager_deactivate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager,
+ active,
+ cancellable, deactivated_cb, simple);
}
/**
@@ -952,7 +1136,8 @@ nm_client_deactivate_connection_finish (NMClient *client,
{
GSimpleAsyncResult *simple;
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_deactivate_connection_async), FALSE);
+ 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))
@@ -961,625 +1146,352 @@ nm_client_deactivate_connection_finish (NMClient *client,
return g_simple_async_result_get_op_res_gboolean (simple);
}
+/****************************************************************/
+/* Connections */
+/****************************************************************/
+
/**
- * nm_client_get_active_connections:
- * @client: a #NMClient
- *
- * Gets the active connections.
- *
- * Returns: (transfer none) (element-type NMActiveConnection): a #GPtrArray
- * containing all the active #NMActiveConnections.
- * The returned array is owned by the client and should not be modified.
+ * 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.
**/
-const GPtrArray *
-nm_client_get_active_connections (NMClient *client)
+GSList *
+nm_client_list_connections (NMClient *client)
{
- NMClientPrivate *priv;
-
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_client_get_nm_running (client))
- return NULL;
-
- return priv->active_connections;
+ return nm_remote_settings_list_connections (NM_CLIENT_GET_PRIVATE (client)->settings);
}
/**
- * nm_client_wireless_get_enabled:
- * @client: a #NMClient
+ * nm_client_get_connection_by_id:
+ * @client: the %NMClient
+ * @id: the id of the remote connection
*
- * Determines whether the wireless is enabled.
+ * Returns the first matching %NMRemoteConnection matching a given @id.
*
- * Returns: %TRUE if wireless is enabled
- **/
-gboolean
-nm_client_wireless_get_enabled (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
-
- return NM_CLIENT_GET_PRIVATE (client)->wireless_enabled;
-}
-
-/**
- * nm_client_wireless_set_enabled:
- * @client: a #NMClient
- * @enabled: %TRUE to enable wireless
- *
- * Enables or disables wireless devices.
+ * Returns: (transfer none): the remote connection object on success, or %NULL if no
+ * matching object was found.
**/
-void
-nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
+NMRemoteConnection *
+nm_client_get_connection_by_id (NMClient *client, const char *id)
{
- g_return_if_fail (NM_IS_CLIENT (client));
-
- if (!nm_client_get_nm_running (client))
- return;
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (id != NULL, NULL);
- _nm_object_set_property (NM_OBJECT (client),
- NM_DBUS_INTERFACE,
- "WirelessEnabled",
- "b", enabled);
+ return nm_remote_settings_get_connection_by_id (NM_CLIENT_GET_PRIVATE (client)->settings, id);
}
/**
- * nm_client_wireless_hardware_get_enabled:
- * @client: a #NMClient
+ * nm_client_get_connection_by_path:
+ * @client: the %NMClient
+ * @path: the D-Bus object path of the remote connection
*
- * Determines whether the wireless hardware is enabled.
+ * Returns the %NMRemoteConnection representing the connection at @path.
*
- * Returns: %TRUE if the wireless hardware is enabled
+ * Returns: (transfer none): the remote connection object on success, or %NULL if the object was
+ * not known
**/
-gboolean
-nm_client_wireless_hardware_get_enabled (NMClient *client)
+NMRemoteConnection *
+nm_client_get_connection_by_path (NMClient *client, const char *path)
{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (path != NULL, NULL);
- return NM_CLIENT_GET_PRIVATE (client)->wireless_hw_enabled;
+ return nm_remote_settings_get_connection_by_path (NM_CLIENT_GET_PRIVATE (client)->settings, path);
}
/**
- * nm_client_wwan_get_enabled:
- * @client: a #NMClient
+ * nm_client_get_connection_by_uuid:
+ * @client: the %NMClient
+ * @uuid: the UUID of the remote connection
*
- * Determines whether WWAN is enabled.
+ * Returns the %NMRemoteConnection identified by @uuid.
*
- * Returns: %TRUE if WWAN is enabled
+ * Returns: (transfer none): the remote connection object on success, or %NULL if the object was
+ * not known
**/
-gboolean
-nm_client_wwan_get_enabled (NMClient *client)
+NMRemoteConnection *
+nm_client_get_connection_by_uuid (NMClient *client, const char *uuid)
{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
-
- return NM_CLIENT_GET_PRIVATE (client)->wwan_enabled;
-}
-
-/**
- * nm_client_wwan_set_enabled:
- * @client: a #NMClient
- * @enabled: %TRUE to enable WWAN
- *
- * Enables or disables WWAN devices.
- **/
-void
-nm_client_wwan_set_enabled (NMClient *client, gboolean enabled)
-{
- g_return_if_fail (NM_IS_CLIENT (client));
-
- if (!nm_client_get_nm_running (client))
- return;
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (uuid != NULL, NULL);
- _nm_object_set_property (NM_OBJECT (client),
- NM_DBUS_INTERFACE,
- "WwanEnabled",
- "b", enabled);
+ return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid);
}
-/**
- * nm_client_wwan_hardware_get_enabled:
- * @client: a #NMClient
- *
- * Determines whether the WWAN hardware is enabled.
- *
- * Returns: %TRUE if the WWAN hardware is enabled
- **/
-gboolean
-nm_client_wwan_hardware_get_enabled (NMClient *client)
+static void
+add_connection_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
-
- return NM_CLIENT_GET_PRIVATE (client)->wwan_hw_enabled;
-}
+ GSimpleAsyncResult *simple = user_data;
+ NMRemoteConnection *conn;
+ GError *error = NULL;
-/**
- * nm_client_wimax_get_enabled:
- * @client: a #NMClient
- *
- * Determines whether WiMAX is enabled.
- *
- * Returns: %TRUE if WiMAX is enabled
- **/
-gboolean
-nm_client_wimax_get_enabled (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+ 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);
- return NM_CLIENT_GET_PRIVATE (client)->wimax_enabled;
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
}
/**
- * nm_client_wimax_set_enabled:
- * @client: a #NMClient
- * @enabled: %TRUE to enable WiMAX
- *
- * Enables or disables WiMAX devices.
+ * 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_wimax_set_enabled (NMClient *client, gboolean enabled)
+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_get_nm_running (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;
+ }
- _nm_object_set_property (NM_OBJECT (client),
- NM_DBUS_INTERFACE,
- "WimaxEnabled",
- "b", enabled);
+ 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_wimax_hardware_get_enabled:
- * @client: a #NMClient
+ * nm_client_add_connection_finish:
+ * @client: an #NMClient
+ * @result: the result passed to the #GAsyncReadyCallback
+ * @error: location for a #GError, or %NULL
*
- * Determines whether the WiMAX hardware is enabled.
+ * Gets the result of a call to nm_client_add_connection_async().
*
- * Returns: %TRUE if the WiMAX hardware is enabled
+ * Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on
+ * failure, in which case @error will be set.
**/
-gboolean
-nm_client_wimax_hardware_get_enabled (NMClient *client)
+NMRemoteConnection *
+nm_client_add_connection_finish (NMClient *client,
+ GAsyncResult *result,
+ GError **error)
{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
-
- return NM_CLIENT_GET_PRIVATE (client)->wimax_hw_enabled;
-}
+ GSimpleAsyncResult *simple;
-/**
- * nm_client_get_version:
- * @client: a #NMClient
- *
- * Gets NetworkManager version.
- *
- * Returns: string with the version
- **/
-const char *
-nm_client_get_version (NMClient *client)
-{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
- if (!nm_client_get_nm_running (client))
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+ if (g_simple_async_result_propagate_error (simple, error))
return NULL;
-
- return NM_CLIENT_GET_PRIVATE (client)->version;
-}
-
-/**
- * nm_client_get_state:
- * @client: a #NMClient
- *
- * Gets the current daemon state.
- *
- * Returns: the current %NMState
- **/
-NMState
-nm_client_get_state (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
-
- return NM_CLIENT_GET_PRIVATE (client)->state;
-}
-
-/**
- * nm_client_get_startup:
- * @client: a #NMClient
- *
- * Tests whether the daemon is still in the process of activating
- * connections at startup.
- *
- * Returns: whether the daemon is still starting up
- **/
-gboolean
-nm_client_get_startup (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
-
- return NM_CLIENT_GET_PRIVATE (client)->startup;
+ else
+ return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
/**
- * nm_client_networking_get_enabled:
- * @client: a #NMClient
+ * 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
*
- * Whether networking is enabled or disabled.
+ * Requests that the remote settings service load or reload the given files,
+ * adding or updating the connections described within.
*
- * Returns: %TRUE if networking is enabled, %FALSE if networking is disabled
- **/
-gboolean
-nm_client_networking_get_enabled (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
-
- return NM_CLIENT_GET_PRIVATE (client)->networking_enabled;
-}
-
-/**
- * nm_client_networking_set_enabled:
- * @client: a #NMClient
- * @enabled: %TRUE to set networking enabled, %FALSE to set networking disabled
- * @error: (allow-none): return location for a #GError, or %NULL
+ * The changes to the indicated files will not yet be reflected in
+ * @client's connections array when the function returns.
*
- * Enables or disables networking. When networking is disabled, all controlled
- * interfaces are disconnected and deactivated. When networking is enabled,
- * all controlled interfaces are available for activation.
+ * 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 on success, %FALSE otherwise
+ * Returns: %TRUE if NetworkManager at least tried to load @filenames,
+ * %FALSE if an error occurred (eg, permission denied).
**/
gboolean
-nm_client_networking_set_enabled (NMClient *client, gboolean enable, GError **error)
+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_get_nm_running (client)) {
- g_set_error_literal (error,
- NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
- "NetworkManager is not running");
+ if (!_nm_client_check_nm_running (client, error))
return FALSE;
- }
-
- return nmdbus_manager_call_enable_sync (NM_CLIENT_GET_PRIVATE (client)->manager_proxy,
- enable,
- NULL, error);
-}
-
-/**
- * nm_client_get_nm_running:
- * @client: a #NMClient
- *
- * Determines whether the daemon is running.
- *
- * Returns: %TRUE if the daemon is running
- **/
-gboolean
-nm_client_get_nm_running (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
- return _nm_object_get_nm_running (NM_OBJECT (client));
+ return nm_remote_settings_load_connections (NM_CLIENT_GET_PRIVATE (client)->settings,
+ filenames, failures,
+ cancellable, error);
}
-/**
- * nm_client_get_permission_result:
- * @client: a #NMClient
- * @permission: the permission for which to return the result, one of #NMClientPermission
- *
- * Requests the result of a specific permission, which indicates whether the
- * client can or cannot perform the action the permission represents
- *
- * Returns: the permission's result, one of #NMClientPermissionResult
- **/
-NMClientPermissionResult
-nm_client_get_permission_result (NMClient *client, NMClientPermission permission)
+static void
+load_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{
- gpointer result;
+ GSimpleAsyncResult *simple = user_data;
+ GError *error = NULL;
+ char **failures = NULL;
- g_return_val_if_fail (NM_IS_CLIENT (client), NM_CLIENT_PERMISSION_RESULT_UNKNOWN);
+ 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);
- result = g_hash_table_lookup (NM_CLIENT_GET_PRIVATE (client)->permissions,
- GUINT_TO_POINTER (permission));
- return GPOINTER_TO_UINT (result);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
}
/**
- * nm_client_get_logging:
- * @client: a #NMClient
- * @level: (allow-none): return location for logging level string
- * @domains: (allow-none): return location for log domains string. The string is
- * a list of domains separated by ","
- * @error: (allow-none): return location for a #GError, or %NULL
+ * 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
*
- * Gets NetworkManager current logging level and domains.
+ * Requests that the remote settings service asynchronously load or reload the
+ * given files, adding or updating the connections described within.
*
- * Returns: %TRUE on success, %FALSE otherwise
+ * See nm_client_load_connections() for more details.
**/
-gboolean
-nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error)
+void
+nm_client_load_connections_async (NMClient *client,
+ char **filenames,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- NMClientPrivate *priv;
+ GSimpleAsyncResult *simple;
+ GError *error = NULL;
- g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
- g_return_val_if_fail (level == NULL || *level == NULL, FALSE);
- g_return_val_if_fail (domains == NULL || *domains == NULL, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_if_fail (NM_IS_CLIENT (client));
+ g_return_if_fail (filenames != NULL);
- priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_client_get_nm_running (client)) {
- g_set_error_literal (error,
- NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
- "NetworkManager is not running");
- return FALSE;
+ if (!_nm_client_check_nm_running (client, &error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
+ return;
}
- if (!level && !domains)
- return TRUE;
-
- return nmdbus_manager_call_get_logging_sync (priv->manager_proxy,
- level, domains,
- NULL, error);
+ 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_set_logging:
- * @client: a #NMClient
- * @level: (allow-none): logging level to set (%NULL or an empty string for no change)
- * @domains: (allow-none): logging domains to set. The string should be a list of log
- * domains separated by ",". (%NULL or an empty string for no change)
- * @error: (allow-none): return location for a #GError, or %NULL
+ * 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
*
- * Sets NetworkManager logging level and/or domains.
+ * Gets the result of an nm_client_load_connections_async() call.
+
+ * See nm_client_load_connections() for more details.
*
- * Returns: %TRUE on success, %FALSE otherwise
+ * Returns: %TRUE if NetworkManager at least tried to load @filenames,
+ * %FALSE if an error occurred (eg, permission denied).
**/
gboolean
-nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error)
+nm_client_load_connections_finish (NMClient *client,
+ char ***failures,
+ GAsyncResult *result,
+ GError **error)
{
- NMClientPrivate *priv;
+ GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
- priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_client_get_nm_running (client)) {
- g_set_error_literal (error,
- NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
- "NetworkManager is not running");
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+ if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
- }
-
- if (!level && !domains)
- return TRUE;
-
- if (!level)
- level = "";
- if (!domains)
- domains = "";
-
- return nmdbus_manager_call_set_logging_sync (priv->manager_proxy,
- level, domains,
- NULL, error);
-}
-
-/**
- * nm_client_get_primary_connection:
- * @client: an #NMClient
- *
- * Gets the #NMActiveConnection corresponding to the primary active
- * network device.
- *
- * In particular, when there is no VPN active, or the VPN does not
- * have the default route, this returns the active connection that has
- * the default route. If there is a VPN active with the default route,
- * then this function returns the active connection that contains the
- * route to the VPN endpoint.
- *
- * If there is no default route, or the default route is over a
- * non-NetworkManager-recognized device, this will return %NULL.
- *
- * Returns: (transfer none): the appropriate #NMActiveConnection, if
- * any
- */
-NMActiveConnection *
-nm_client_get_primary_connection (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
-
- return NM_CLIENT_GET_PRIVATE (client)->primary_connection;
-}
-
-/**
- * nm_client_get_activating_connection:
- * @client: an #NMClient
- *
- * Gets the #NMActiveConnection corresponding to a
- * currently-activating connection that is expected to become the new
- * #NMClient:primary-connection upon successful activation.
- *
- * Returns: (transfer none): the appropriate #NMActiveConnection, if
- * any.
- */
-NMActiveConnection *
-nm_client_get_activating_connection (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
-
- return NM_CLIENT_GET_PRIVATE (client)->activating_connection;
-}
-
-/****************************************************************/
-
-static void
-free_devices (NMClient *client, gboolean in_dispose)
-{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
- GPtrArray *devices;
- NMDevice *device;
- int i;
-
- if (!priv->devices)
- return;
-
- devices = priv->devices;
-
- if (in_dispose)
- priv->devices = NULL;
else {
- priv->devices = g_ptr_array_new ();
-
- for (i = 0; i < devices->len; i++) {
- device = devices->pdata[i];
- g_signal_emit (client, signals[DEVICE_REMOVED], 0, device);
- }
- }
-
- g_ptr_array_unref (devices);
-}
-
-static void
-free_active_connections (NMClient *client, gboolean in_dispose)
-{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
- GPtrArray *active_connections;
- NMActiveConnection *active_connection;
- int i;
-
- if (!priv->active_connections)
- return;
-
- active_connections = priv->active_connections;
- priv->active_connections = NULL;
-
- for (i = 0; i < active_connections->len; i++) {
- active_connection = active_connections->pdata[i];
- /* Break circular refs */
- g_object_run_dispose (G_OBJECT (active_connection));
- }
- g_ptr_array_unref (active_connections);
-
- if (!in_dispose) {
- priv->active_connections = g_ptr_array_new ();
- g_object_notify (G_OBJECT (client), NM_CLIENT_ACTIVE_CONNECTIONS);
- }
-}
-
-static void
-updated_properties (GObject *object, GAsyncResult *result, gpointer user_data)
-{
- NMClient *client = NM_CLIENT (user_data);
- GError *error = NULL;
-
- if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) {
- g_warning ("%s: error reading NMClient properties: %s", __func__, error->message);
- g_error_free (error);
- }
-
- _nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_NM_RUNNING);
-}
-
-static void
-nm_running_changed_cb (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- NMClient *client = NM_CLIENT (object);
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
-
- if (!nm_client_get_nm_running (client)) {
- priv->state = NM_STATE_UNKNOWN;
- priv->startup = FALSE;
- _nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_NM_RUNNING);
- _nm_object_suppress_property_updates (NM_OBJECT (client), TRUE);
- poke_wireless_devices_with_rf_status (client);
- free_devices (client, FALSE);
- free_active_connections (client, FALSE);
- update_permissions (client, NULL);
- priv->wireless_enabled = FALSE;
- priv->wireless_hw_enabled = FALSE;
- priv->wwan_enabled = FALSE;
- priv->wwan_hw_enabled = FALSE;
- priv->wimax_enabled = FALSE;
- priv->wimax_hw_enabled = FALSE;
- g_free (priv->version);
- priv->version = NULL;
-
- /* Clear object cache to ensure bad refcounting by clients doesn't
- * keep objects in the cache.
- */
- _nm_object_cache_clear ();
- } else {
- _nm_object_suppress_property_updates (NM_OBJECT (client), FALSE);
- _nm_object_reload_properties_async (NM_OBJECT (client), updated_properties, client);
- client_recheck_permissions (priv->manager_proxy, client);
+ if (failures)
+ *failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple));
+ return TRUE;
}
}
/**
- * nm_client_get_connectivity:
- * @client: an #NMClient
- *
- * Gets the current network connectivity state. Contrast
- * nm_client_check_connectivity() and
- * nm_client_check_connectivity_async(), which re-check the
- * connectivity state first before returning any information.
- *
- * Returns: the current connectivity state
- */
-NMConnectivityState
-nm_client_get_connectivity (NMClient *client)
-{
- g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
-
- return NM_CLIENT_GET_PRIVATE (client)->connectivity;
-}
-
-/**
- * nm_client_check_connectivity:
- * @client: an #NMClient
- * @cancellable: a #GCancellable
- * @error: return location for a #GError
- *
- * Updates the network connectivity state and returns the (new)
- * current state. Contrast nm_client_get_connectivity(), which returns
- * the most recent known state without re-checking.
+ * nm_client_reload_connections:
+ * @client: the #NMClient
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: return location for #GError
*
- * This is a blocking call; use nm_client_check_connectivity_async()
- * if you do not want to block.
+ * 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.
*
- * Returns: the (new) current connectivity state
- */
-NMConnectivityState
-nm_client_check_connectivity (NMClient *client,
+ * Return value: %TRUE on success, %FALSE on failure
+ **/
+gboolean
+nm_client_reload_connections (NMClient *client,
GCancellable *cancellable,
GError **error)
{
- NMClientPrivate *priv;
- guint32 connectivity;
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
- g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
- priv = NM_CLIENT_GET_PRIVATE (client);
+ if (!_nm_client_check_nm_running (client, error))
+ return FALSE;
- if (nmdbus_manager_call_check_connectivity_sync (priv->manager_proxy,
- &connectivity,
- cancellable, error))
- return connectivity;
- else
- return NM_CONNECTIVITY_UNKNOWN;
+ return nm_remote_settings_reload_connections (NM_CLIENT_GET_PRIVATE (client)->settings,
+ cancellable, error);
}
static void
-check_connectivity_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+reload_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
- guint32 connectivity;
GError *error = NULL;
- if (nmdbus_manager_call_check_connectivity_finish (NMDBUS_MANAGER (object),
- &connectivity,
- result, &error))
- g_simple_async_result_set_op_res_gssize (simple, connectivity);
+ 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);
@@ -1588,61 +1500,63 @@ check_connectivity_cb (GObject *object,
}
/**
- * nm_client_check_connectivity_async:
- * @client: an #NMClient
- * @cancellable: a #GCancellable
- * @callback: callback to call with the result
- * @user_data: data for @callback.
+ * 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
*
- * Asynchronously updates the network connectivity state and invokes
- * @callback when complete. Contrast nm_client_get_connectivity(),
- * which (immediately) returns the most recent known state without
- * re-checking, and nm_client_check_connectivity(), which blocks.
- */
+ * 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_check_connectivity_async (NMClient *client,
+nm_client_reload_connections_async (NMClient *client,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- NMClientPrivate *priv;
GSimpleAsyncResult *simple;
+ GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
- priv = NM_CLIENT_GET_PRIVATE (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_check_connectivity_async);
- nmdbus_manager_call_check_connectivity (priv->manager_proxy,
- cancellable,
- check_connectivity_cb, simple);
+ nm_client_reload_connections_async);
+ nm_remote_settings_reload_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings,
+ cancellable, reload_connections_cb, simple);
}
/**
- * nm_client_check_connectivity_finish:
- * @client: an #NMClient
- * @result: the #GAsyncResult
- * @error: return location for a #GError
+ * nm_client_reload_connections_finish:
+ * @client: the #NMClient
+ * @result: the result passed to the #GAsyncReadyCallback
+ * @error: return location for #GError
*
- * Retrieves the result of an nm_client_check_connectivity_async()
- * call.
+ * Gets the result of an nm_client_reload_connections_async() call.
*
- * Returns: the (new) current connectivity state
- */
-NMConnectivityState
-nm_client_check_connectivity_finish (NMClient *client,
+ * 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 (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN);
+ 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 NM_CONNECTIVITY_UNKNOWN;
- return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
+ return FALSE;
+ else
+ return g_simple_async_result_get_op_res_gboolean (simple);
}
/****************************************************************/
@@ -1658,10 +1572,6 @@ nm_client_check_connectivity_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 *
@@ -1696,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,
@@ -1748,88 +1654,94 @@ nm_client_new_finish (GAsyncResult *result, GError **error)
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
-/*
- * constructor() shouldn't be overriden in most cases, rather constructed()
- * method is preferred and more useful.
- * But, this serves as a workaround for bindings (use) calling the constructor()
- * directly instead of nm_client_new() function, and neither providing
- * construction properties. So, we fill "dbus-path" here if it was not specified
- * (was set to default value (NULL)).
- *
- * It allows this python code:
- * from gi.repository import NM
- * nmclient = NM.Client()
- * print nmclient.get_active_connections()
- *
- * instead of proper
- * nmclient = NM.Client().new()
- *
- * Note:
- * A nice overview of GObject construction is here:
- * http://blogs.gnome.org/desrt/2012/02/26/a-gentle-introduction-to-gobject-construction
- * It is much better explanation than the official docs
- * http://developer.gnome.org/gobject/unstable/chapter-gobject.html#gobject-instantiation
- */
-static GObject*
-constructor (GType type,
- guint n_construct_params,
- GObjectConstructParam *construct_params)
-{
- guint i;
- const char *dbus_path;
-
- for (i = 0; i < n_construct_params; i++) {
- if (strcmp (construct_params[i].pspec->name, NM_OBJECT_PATH) == 0) {
- dbus_path = g_value_get_string (construct_params[i].value);
- if (dbus_path == NULL) {
- g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH);
- } else {
- if (!g_variant_is_object_path (dbus_path)) {
- g_warning ("Passed D-Bus object path '%s' is invalid; using default '%s' instead",
- dbus_path, NM_DBUS_PATH);
- g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH);
- }
- }
- break;
- }
- }
+static void
+subobject_notify (GObject *object,
+ GParamSpec *pspec,
+ gpointer client)
+{
+ if (!g_str_has_suffix (pspec->name, "-internal"))
+ g_object_notify (client, pspec->name);
+}
- return G_OBJECT_CLASS (nm_client_parent_class)->constructor (type,
- n_construct_params,
- construct_params);
+static void
+manager_device_added (NMManager *manager,
+ NMDevice *device,
+ gpointer client)
+{
+ g_signal_emit (client, signals[DEVICE_ADDED], 0, device);
+}
+static void
+manager_device_removed (NMManager *manager,
+ NMDevice *device,
+ gpointer client)
+{
+ g_signal_emit (client, signals[DEVICE_REMOVED], 0, device);
}
static void
-constructed (GObject *object)
+manager_permission_changed (NMManager *manager,
+ NMClientPermission permission,
+ NMClientPermissionResult result,
+ gpointer client)
{
- G_OBJECT_CLASS (nm_client_parent_class)->constructed (object);
+ g_signal_emit (client, signals[PERMISSION_CHANGED], 0, permission, result);
+}
- g_signal_connect (object, "notify::" NM_OBJECT_NM_RUNNING,
- G_CALLBACK (nm_running_changed_cb), NULL);
+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);
+}
- g_signal_connect (object, "notify::" NM_CLIENT_WIRELESS_ENABLED,
- G_CALLBACK (wireless_enabled_cb), NULL);
+static void
+constructed (GObject *object)
+{
+ NMClient *client = NM_CLIENT (object);
+ NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
- g_signal_connect (object, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
- G_CALLBACK (active_connections_changed_cb), NULL);
+ priv->manager = g_object_new (NM_TYPE_MANAGER,
+ NM_OBJECT_PATH, NM_DBUS_PATH,
+ NULL);
+ g_signal_connect (priv->manager, "notify",
+ G_CALLBACK (subobject_notify), client);
+ g_signal_connect (priv->manager, "device-added",
+ G_CALLBACK (manager_device_added), client);
+ g_signal_connect (priv->manager, "device-removed",
+ G_CALLBACK (manager_device_removed), client);
+ 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_signal_connect (object, "object-creation-failed",
- G_CALLBACK (object_creation_failed_cb), NULL);
+ G_OBJECT_CLASS (nm_client_parent_class)->constructed (object);
}
static gboolean
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{
NMClient *client = NM_CLIENT (initable);
+ NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_utils_init (error))
+ if (!g_initable_init (G_INITABLE (priv->manager), cancellable, error))
return FALSE;
-
- if (!nm_client_parent_initable_iface->init (initable, cancellable, error))
- return FALSE;
-
- if ( nm_client_get_nm_running (client)
- && !get_permissions_sync (client, error))
+ if (!g_initable_init (G_INITABLE (priv->settings), cancellable, error))
return FALSE;
return TRUE;
@@ -1839,6 +1751,8 @@ typedef struct {
NMClient *client;
GCancellable *cancellable;
GSimpleAsyncResult *result;
+ gboolean manager_inited;
+ gboolean settings_inited;
} NMClientInitData;
static void
@@ -1851,20 +1765,31 @@ init_async_complete (NMClientInitData *init_data)
}
static void
-init_async_got_permissions (GObject *object, GAsyncResult *result, gpointer user_data)
+init_async_inited_manager (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMClientInitData *init_data = user_data;
- GVariant *permissions;
+ GError *error = NULL;
- if (nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
- &permissions,
- result, NULL)) {
- update_permissions (init_data->client, permissions);
- g_variant_unref (permissions);
- } else
- update_permissions (init_data->client, NULL);
+ 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
@@ -1880,14 +1805,12 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d
return;
}
- if (!nm_client_get_nm_running (init_data->client)) {
- init_async_complete (init_data);
- return;
- }
-
- nmdbus_manager_call_get_permissions (priv->manager_proxy,
- init_data->cancellable,
- init_async_got_permissions, init_data);
+ 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
@@ -1929,75 +1852,25 @@ init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error)
static void
dispose (GObject *object)
{
- NMClient *client = NM_CLIENT (object);
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
- if (priv->perm_call_cancellable) {
- g_cancellable_cancel (priv->perm_call_cancellable);
- g_clear_object (&priv->perm_call_cancellable);
- }
-
- free_devices (client, TRUE);
- free_active_connections (client, TRUE);
- g_clear_object (&priv->primary_connection);
- g_clear_object (&priv->activating_connection);
-
- /* Each activation should hold a ref on @client, so if we're being disposed,
- * there shouldn't be any pending.
- */
- g_warn_if_fail (priv->pending_activations == NULL);
-
- g_hash_table_destroy (priv->permissions);
- priv->permissions = NULL;
+ g_clear_object (&priv->manager);
+ g_clear_object (&priv->settings);
G_OBJECT_CLASS (nm_client_parent_class)->dispose (object);
}
static void
-finalize (GObject *object)
-{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
-
- g_free (priv->version);
-
- G_OBJECT_CLASS (nm_client_parent_class)->finalize (object);
-}
-
-static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
- gboolean b;
-
switch (prop_id) {
case PROP_NETWORKING_ENABLED:
- b = g_value_get_boolean (value);
- if (priv->networking_enabled != b) {
- nm_client_networking_set_enabled (NM_CLIENT (object), b, NULL);
- /* Let the property value flip when we get the change signal from NM */
- }
- break;
case PROP_WIRELESS_ENABLED:
- b = g_value_get_boolean (value);
- if (priv->wireless_enabled != b) {
- nm_client_wireless_set_enabled (NM_CLIENT (object), b);
- /* Let the property value flip when we get the change signal from NM */
- }
- break;
case PROP_WWAN_ENABLED:
- b = g_value_get_boolean (value);
- if (priv->wwan_enabled != b) {
- nm_client_wwan_set_enabled (NM_CLIENT (object), b);
- /* Let the property value flip when we get the change signal from NM */
- }
- break;
case PROP_WIMAX_ENABLED:
- b = g_value_get_boolean (value);
- if (priv->wimax_enabled != b) {
- nm_client_wimax_set_enabled (NM_CLIENT (object), b);
- /* Let the property value flip when we get the change signal from NM */
- }
+ g_object_set_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager),
+ pspec->name, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -2006,62 +1879,34 @@ set_property (GObject *object, guint prop_id,
}
static void
-get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
{
- NMClient *self = NM_CLIENT (object);
- NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
-
switch (prop_id) {
case PROP_VERSION:
- g_value_set_string (value, nm_client_get_version (self));
- break;
case PROP_STATE:
- g_value_set_enum (value, nm_client_get_state (self));
- break;
case PROP_STARTUP:
- g_value_set_boolean (value, nm_client_get_startup (self));
- break;
case PROP_NM_RUNNING:
- g_value_set_boolean (value, nm_client_get_nm_running (self));
- break;
case PROP_NETWORKING_ENABLED:
- g_value_set_boolean (value, nm_client_networking_get_enabled (self));
- break;
case PROP_WIRELESS_ENABLED:
- g_value_set_boolean (value, priv->wireless_enabled);
- break;
case PROP_WIRELESS_HARDWARE_ENABLED:
- g_value_set_boolean (value, priv->wireless_hw_enabled);
- break;
case PROP_WWAN_ENABLED:
- g_value_set_boolean (value, priv->wwan_enabled);
- break;
case PROP_WWAN_HARDWARE_ENABLED:
- g_value_set_boolean (value, priv->wwan_hw_enabled);
- break;
case PROP_WIMAX_ENABLED:
- g_value_set_boolean (value, priv->wimax_enabled);
- break;
case PROP_WIMAX_HARDWARE_ENABLED:
- g_value_set_boolean (value, priv->wimax_hw_enabled);
- break;
case PROP_ACTIVE_CONNECTIONS:
- g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_active_connections (self)));
- break;
case PROP_CONNECTIVITY:
- g_value_set_enum (value, priv->connectivity);
- break;
case PROP_PRIMARY_CONNECTION:
- g_value_set_object (value, priv->primary_connection);
- break;
case PROP_ACTIVATING_CONNECTION:
- g_value_set_object (value, priv->activating_connection);
- break;
case PROP_DEVICES:
- g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_devices (self)));
+ 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);
@@ -2073,22 +1918,14 @@ static void
nm_client_class_init (NMClientClass *client_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (client_class);
- NMObjectClass *nm_object_class = NM_OBJECT_CLASS (client_class);
g_type_class_add_private (client_class, sizeof (NMClientPrivate));
- _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE);
- _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE, NMDBUS_TYPE_MANAGER_PROXY);
-
/* virtual methods */
- object_class->constructor = constructor;
object_class->constructed = constructed;
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->dispose = dispose;
- object_class->finalize = finalize;
-
- nm_object_class->init_dbus = init_dbus;
/* properties */
@@ -2292,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 */
/**
@@ -2302,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),
@@ -2318,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),
@@ -2335,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
diff --git a/libnm/nm-client.h b/libnm/nm-client.h
index ccd7a6db95..99de7e003a 100644
--- a/libnm/nm-client.h
+++ b/libnm/nm-client.h
@@ -29,10 +29,11 @@
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
+
#include <nm-dbus-interface.h>
-#include "nm-object.h"
#include "nm-device.h"
#include "nm-active-connection.h"
+#include "nm-remote-connection.h"
#include "nm-vpn-connection.h"
G_BEGIN_DECLS
@@ -60,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:
@@ -132,23 +142,29 @@ 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 ()
GQuark nm_client_error_quark (void);
typedef struct {
- NMObject parent;
+ GObject parent;
} NMClient;
typedef struct {
- NMObjectClass parent;
+ GObjectClass parent;
/* Signals */
void (*device_added) (NMClient *client, NMDevice *device);
@@ -156,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];
@@ -172,10 +190,79 @@ void nm_client_new_async (GCancellable *cancellable,
NMClient *nm_client_new_finish (GAsyncResult *result,
GError **error);
+const char *nm_client_get_version (NMClient *client);
+NMState nm_client_get_state (NMClient *client);
+gboolean nm_client_get_startup (NMClient *client);
+gboolean nm_client_get_nm_running (NMClient *client);
+
+gboolean nm_client_networking_get_enabled (NMClient *client);
+gboolean nm_client_networking_set_enabled (NMClient *client,
+ gboolean enabled,
+ GError **error);
+
+gboolean nm_client_wireless_get_enabled (NMClient *client);
+void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
+gboolean nm_client_wireless_hardware_get_enabled (NMClient *client);
+
+gboolean nm_client_wwan_get_enabled (NMClient *client);
+void nm_client_wwan_set_enabled (NMClient *client, gboolean enabled);
+gboolean nm_client_wwan_hardware_get_enabled (NMClient *client);
+
+gboolean nm_client_wimax_get_enabled (NMClient *client);
+void nm_client_wimax_set_enabled (NMClient *client, gboolean enabled);
+gboolean nm_client_wimax_hardware_get_enabled (NMClient *client);
+
+gboolean nm_client_get_logging (NMClient *client,
+ char **level,
+ char **domains,
+ GError **error);
+gboolean nm_client_set_logging (NMClient *client,
+ const char *level,
+ const char *domains,
+ GError **error);
+
+NMClientPermissionResult nm_client_get_permission_result (NMClient *client,
+ NMClientPermission permission);
+
+NMConnectivityState nm_client_get_connectivity (NMClient *client);
+
+NMConnectivityState nm_client_check_connectivity (NMClient *client,
+ GCancellable *cancellable,
+ GError **error);
+void nm_client_check_connectivity_async (NMClient *client,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+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);
NMDevice *nm_client_get_device_by_path (NMClient *client, const char *object_path);
NMDevice *nm_client_get_device_by_iface (NMClient *client, const char *iface);
+/* Active Connections */
+
+const GPtrArray *nm_client_get_active_connections (NMClient *client);
+
+NMActiveConnection *nm_client_get_primary_connection (NMClient *client);
+NMActiveConnection *nm_client_get_activating_connection (NMClient *client);
+
void nm_client_activate_connection_async (NMClient *client,
NMConnection *connection,
NMDevice *device,
@@ -211,50 +298,49 @@ gboolean nm_client_deactivate_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error);
-gboolean nm_client_networking_get_enabled (NMClient *client);
-gboolean nm_client_networking_set_enabled (NMClient *client,
- gboolean enabled,
- GError **error);
-
-gboolean nm_client_wireless_get_enabled (NMClient *client);
-void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
-gboolean nm_client_wireless_hardware_get_enabled (NMClient *client);
-
-gboolean nm_client_wwan_get_enabled (NMClient *client);
-void nm_client_wwan_set_enabled (NMClient *client, gboolean enabled);
-gboolean nm_client_wwan_hardware_get_enabled (NMClient *client);
-
-gboolean nm_client_wimax_get_enabled (NMClient *client);
-void nm_client_wimax_set_enabled (NMClient *client, gboolean enabled);
-gboolean nm_client_wimax_hardware_get_enabled (NMClient *client);
-
-const char *nm_client_get_version (NMClient *client);
-NMState nm_client_get_state (NMClient *client);
-gboolean nm_client_get_startup (NMClient *client);
-gboolean nm_client_get_nm_running (NMClient *client);
-const GPtrArray *nm_client_get_active_connections (NMClient *client);
+/* Connections */
-NMClientPermissionResult nm_client_get_permission_result (NMClient *client,
- NMClientPermission permission);
+GSList *nm_client_list_connections (NMClient *client);
-gboolean nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error);
-gboolean nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error);
+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);
-NMConnectivityState nm_client_get_connectivity (NMClient *client);
+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);
-NMConnectivityState nm_client_check_connectivity (NMClient *client,
- GCancellable *cancellable,
- GError **error);
-void nm_client_check_connectivity_async (NMClient *client,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-NMConnectivityState nm_client_check_connectivity_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);
-NMActiveConnection *nm_client_get_primary_connection (NMClient *client);
-NMActiveConnection *nm_client_get_activating_connection (NMClient *client);
+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
diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c
new file mode 100644
index 0000000000..7bfab68a86
--- /dev/null
+++ b/libnm/nm-manager.c
@@ -0,0 +1,1600 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2008 Novell, Inc.
+ * Copyright 2007 - 2014 Red Hat, Inc.
+ */
+
+#include <string.h>
+#include <nm-utils.h>
+
+#include "nm-manager.h"
+#include "nm-device-ethernet.h"
+#include "nm-device-wifi.h"
+#include "nm-device-private.h"
+#include "nm-core-internal.h"
+#include "nm-object-private.h"
+#include "nm-active-connection.h"
+#include "nm-vpn-connection.h"
+#include "nm-object-cache.h"
+#include "nm-glib-compat.h"
+#include "nm-dbus-helpers.h"
+
+#include "nmdbus-manager.h"
+
+void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
+
+static void nm_manager_initable_iface_init (GInitableIface *iface);
+static void nm_manager_async_initable_iface_init (GAsyncInitableIface *iface);
+static GInitableIface *nm_manager_parent_initable_iface;
+static GAsyncInitableIface *nm_manager_parent_async_initable_iface;
+
+G_DEFINE_TYPE_WITH_CODE (NMManager, nm_manager, NM_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_manager_initable_iface_init);
+ G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_manager_async_initable_iface_init);
+ )
+
+#define NM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MANAGER, NMManagerPrivate))
+
+typedef struct {
+ NMDBusManager *manager_proxy;
+ char *version;
+ NMState state;
+ gboolean startup;
+ GPtrArray *devices;
+ GPtrArray *active_connections;
+ NMConnectivityState connectivity;
+ NMActiveConnection *primary_connection;
+ NMActiveConnection *activating_connection;
+
+ GCancellable *perm_call_cancellable;
+ GHashTable *permissions;
+
+ /* Activations waiting for their NMActiveConnection
+ * to appear and then their callback to be called.
+ */
+ GSList *pending_activations;
+
+ gboolean networking_enabled;
+ gboolean wireless_enabled;
+ gboolean wireless_hw_enabled;
+
+ gboolean wwan_enabled;
+ gboolean wwan_hw_enabled;
+
+ gboolean wimax_enabled;
+ gboolean wimax_hw_enabled;
+} NMManagerPrivate;
+
+enum {
+ PROP_0,
+ PROP_VERSION,
+ PROP_STATE,
+ PROP_STARTUP,
+ PROP_NM_RUNNING,
+ PROP_NETWORKING_ENABLED,
+ PROP_WIRELESS_ENABLED,
+ PROP_WIRELESS_HARDWARE_ENABLED,
+ PROP_WWAN_ENABLED,
+ PROP_WWAN_HARDWARE_ENABLED,
+ PROP_WIMAX_ENABLED,
+ PROP_WIMAX_HARDWARE_ENABLED,
+ PROP_ACTIVE_CONNECTIONS,
+ PROP_CONNECTIVITY,
+ PROP_PRIMARY_CONNECTION,
+ PROP_ACTIVATING_CONNECTION,
+ PROP_DEVICES,
+
+ LAST_PROP
+};
+
+enum {
+ DEVICE_ADDED,
+ DEVICE_REMOVED,
+ PERMISSION_CHANGED,
+
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void nm_running_changed_cb (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data);
+
+/**********************************************************************/
+
+static void
+nm_manager_init (NMManager *manager)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
+
+ priv->state = NM_STATE_UNKNOWN;
+ priv->connectivity = NM_CONNECTIVITY_UNKNOWN;
+
+ priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal);
+}
+
+static void
+poke_wireless_devices_with_rf_status (NMManager *manager)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
+ int i;
+
+ for (i = 0; i < priv->devices->len; i++) {
+ NMDevice *device = g_ptr_array_index (priv->devices, i);
+
+ if (NM_IS_DEVICE_WIFI (device))
+ _nm_device_wifi_set_wireless_enabled (NM_DEVICE_WIFI (device), priv->wireless_enabled);
+ }
+}
+
+static void
+wireless_enabled_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+ poke_wireless_devices_with_rf_status (NM_MANAGER (object));
+}
+
+static void manager_recheck_permissions (NMDBusManager *proxy, gpointer user_data);
+static void active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data);
+static void object_creation_failed_cb (GObject *object, GError *error, char *failed_path);
+
+static void
+init_dbus (NMObject *object)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
+ const NMPropertiesInfo property_info[] = {
+ { NM_MANAGER_VERSION, &priv->version },
+ { NM_MANAGER_STATE, &priv->state },
+ { NM_MANAGER_STARTUP, &priv->startup },
+ { NM_MANAGER_NETWORKING_ENABLED, &priv->networking_enabled },
+ { NM_MANAGER_WIRELESS_ENABLED, &priv->wireless_enabled },
+ { NM_MANAGER_WIRELESS_HARDWARE_ENABLED, &priv->wireless_hw_enabled },
+ { NM_MANAGER_WWAN_ENABLED, &priv->wwan_enabled },
+ { NM_MANAGER_WWAN_HARDWARE_ENABLED, &priv->wwan_hw_enabled },
+ { NM_MANAGER_WIMAX_ENABLED, &priv->wimax_enabled },
+ { NM_MANAGER_WIMAX_HARDWARE_ENABLED, &priv->wimax_hw_enabled },
+ { NM_MANAGER_ACTIVE_CONNECTIONS, &priv->active_connections, NULL, NM_TYPE_ACTIVE_CONNECTION },
+ { NM_MANAGER_CONNECTIVITY, &priv->connectivity },
+ { NM_MANAGER_PRIMARY_CONNECTION, &priv->primary_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
+ { NM_MANAGER_ACTIVATING_CONNECTION, &priv->activating_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
+ { NM_MANAGER_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE, "device" },
+ { NULL },
+ };
+
+ NM_OBJECT_CLASS (nm_manager_parent_class)->init_dbus (object);
+
+ priv->manager_proxy = NMDBUS_MANAGER (_nm_object_get_proxy (object, NM_DBUS_INTERFACE));
+ _nm_object_register_properties (object,
+ NM_DBUS_INTERFACE,
+ property_info);
+
+ /* Permissions */
+ g_signal_connect (priv->manager_proxy, "check-permissions",
+ G_CALLBACK (manager_recheck_permissions), object);
+}
+
+#define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network"
+#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI "org.freedesktop.NetworkManager.enable-disable-wifi"
+#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN "org.freedesktop.NetworkManager.enable-disable-wwan"
+#define NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX "org.freedesktop.NetworkManager.enable-disable-wimax"
+#define NM_AUTH_PERMISSION_SLEEP_WAKE "org.freedesktop.NetworkManager.sleep-wake"
+#define NM_AUTH_PERMISSION_NETWORK_CONTROL "org.freedesktop.NetworkManager.network-control"
+#define NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED "org.freedesktop.NetworkManager.wifi.share.protected"
+#define NM_AUTH_PERMISSION_WIFI_SHARE_OPEN "org.freedesktop.NetworkManager.wifi.share.open"
+#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM "org.freedesktop.NetworkManager.settings.modify.system"
+#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN "org.freedesktop.NetworkManager.settings.modify.own"
+#define NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME "org.freedesktop.NetworkManager.settings.modify.hostname"
+
+static NMClientPermission
+nm_permission_to_client (const char *nm)
+{
+ if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK))
+ return NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI))
+ return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN))
+ return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX))
+ return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_SLEEP_WAKE))
+ return NM_CLIENT_PERMISSION_SLEEP_WAKE;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_NETWORK_CONTROL))
+ return NM_CLIENT_PERMISSION_NETWORK_CONTROL;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED))
+ return NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN))
+ return NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM))
+ return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN))
+ return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN;
+ else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME))
+ return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME;
+
+ return NM_CLIENT_PERMISSION_NONE;
+}
+
+static NMClientPermissionResult
+nm_permission_result_to_client (const char *nm)
+{
+ if (!strcmp (nm, "yes"))
+ return NM_CLIENT_PERMISSION_RESULT_YES;
+ else if (!strcmp (nm, "no"))
+ return NM_CLIENT_PERMISSION_RESULT_NO;
+ else if (!strcmp (nm, "auth"))
+ return NM_CLIENT_PERMISSION_RESULT_AUTH;
+ return NM_CLIENT_PERMISSION_RESULT_UNKNOWN;
+}
+
+static void
+update_permissions (NMManager *self, GVariant *permissions)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+ GHashTableIter iter;
+ gpointer key, value;
+ NMClientPermission perm;
+ NMClientPermissionResult perm_result;
+ GList *keys, *keys_iter;
+
+ /* get list of old permissions for change notification */
+ keys = g_hash_table_get_keys (priv->permissions);
+ g_hash_table_remove_all (priv->permissions);
+
+ if (permissions) {
+ GVariantIter viter;
+ const char *pkey, *pvalue;
+
+ /* Process new permissions */
+ g_variant_iter_init (&viter, permissions);
+ while (g_variant_iter_next (&viter, "{&s&s}", &pkey, &pvalue)) {
+ perm = nm_permission_to_client (pkey);
+ perm_result = nm_permission_result_to_client (pvalue);
+ if (perm) {
+ g_hash_table_insert (priv->permissions,
+ GUINT_TO_POINTER (perm),
+ GUINT_TO_POINTER (perm_result));
+
+ /* Remove this permission from the list of previous permissions
+ * we'll be sending NM_CLIENT_PERMISSION_RESULT_UNKNOWN for
+ * in the change signal since it is still a known permission.
+ */
+ keys = g_list_remove (keys, GUINT_TO_POINTER (perm));
+ }
+ }
+ }
+
+ /* Signal changes in all updated permissions */
+ g_hash_table_iter_init (&iter, priv->permissions);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ g_signal_emit (self, signals[PERMISSION_CHANGED], 0,
+ GPOINTER_TO_UINT (key),
+ GPOINTER_TO_UINT (value));
+ }
+
+ /* And signal changes in all permissions that used to be valid but for
+ * some reason weren't received in the last request (if any).
+ */
+ for (keys_iter = keys; keys_iter; keys_iter = g_list_next (keys_iter)) {
+ g_signal_emit (self, signals[PERMISSION_CHANGED], 0,
+ GPOINTER_TO_UINT (keys_iter->data),
+ NM_CLIENT_PERMISSION_RESULT_UNKNOWN);
+ }
+ g_list_free (keys);
+}
+
+static gboolean
+get_permissions_sync (NMManager *self, GError **error)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+ GVariant *permissions;
+
+ if (nmdbus_manager_call_get_permissions_sync (priv->manager_proxy,
+ &permissions,
+ NULL, error)) {
+ update_permissions (self, permissions);
+ g_variant_unref (permissions);
+ return TRUE;
+ } else {
+ update_permissions (self, NULL);
+ return FALSE;
+ }
+}
+
+static void
+get_permissions_reply (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ NMManager *self;
+ NMManagerPrivate *priv;
+ GVariant *permissions = NULL;
+ GError *error = NULL;
+
+ /* WARNING: this may be called after the manager is disposed, so we can't
+ * look at self/priv until after we've determined that that isn't the case.
+ */
+
+ nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
+ &permissions,
+ result, &error);
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ /* @self has been disposed. */
+ g_error_free (error);
+ return;
+ }
+
+ self = user_data;
+ priv = NM_MANAGER_GET_PRIVATE (self);
+
+ update_permissions (self, permissions);
+
+ g_clear_pointer (&permissions, g_variant_unref);
+ g_clear_error (&error);
+ g_clear_object (&priv->perm_call_cancellable);
+}
+
+static void
+manager_recheck_permissions (NMDBusManager *proxy, gpointer user_data)
+{
+ NMManager *self = NM_MANAGER (user_data);
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+
+ if (priv->perm_call_cancellable)
+ return;
+
+ priv->perm_call_cancellable = g_cancellable_new ();
+ nmdbus_manager_call_get_permissions (priv->manager_proxy,
+ priv->perm_call_cancellable,
+ get_permissions_reply,
+ self);
+}
+
+const char *
+nm_manager_get_version (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->version;
+}
+
+NMState
+nm_manager_get_state (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NM_STATE_UNKNOWN);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->state;
+}
+
+gboolean
+nm_manager_get_startup (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NM_STATE_UNKNOWN);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->startup;
+}
+
+gboolean
+nm_manager_get_nm_running (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return _nm_object_get_nm_running (NM_OBJECT (manager));
+}
+
+gboolean
+nm_manager_networking_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->networking_enabled;
+}
+
+gboolean
+nm_manager_networking_set_enabled (NMManager *manager, gboolean enable, GError **error)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return nmdbus_manager_call_enable_sync (NM_MANAGER_GET_PRIVATE (manager)->manager_proxy,
+ enable,
+ NULL, error);
+}
+
+gboolean
+nm_manager_wireless_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->wireless_enabled;
+}
+
+void
+nm_manager_wireless_set_enabled (NMManager *manager, gboolean enabled)
+{
+ g_return_if_fail (NM_IS_MANAGER (manager));
+
+ _nm_object_set_property (NM_OBJECT (manager),
+ NM_DBUS_INTERFACE,
+ "WirelessEnabled",
+ "b", enabled);
+}
+
+gboolean
+nm_manager_wireless_hardware_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->wireless_hw_enabled;
+}
+
+gboolean
+nm_manager_wwan_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->wwan_enabled;
+}
+
+void
+nm_manager_wwan_set_enabled (NMManager *manager, gboolean enabled)
+{
+ g_return_if_fail (NM_IS_MANAGER (manager));
+
+ _nm_object_set_property (NM_OBJECT (manager),
+ NM_DBUS_INTERFACE,
+ "WwanEnabled",
+ "b", enabled);
+}
+
+gboolean
+nm_manager_wwan_hardware_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->wwan_hw_enabled;
+}
+
+gboolean
+nm_manager_wimax_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->wimax_enabled;
+}
+
+void
+nm_manager_wimax_set_enabled (NMManager *manager, gboolean enabled)
+{
+ g_return_if_fail (NM_IS_MANAGER (manager));
+
+ _nm_object_set_property (NM_OBJECT (manager),
+ NM_DBUS_INTERFACE,
+ "WimaxEnabled",
+ "b", enabled);
+}
+
+gboolean
+nm_manager_wimax_hardware_get_enabled (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->wimax_hw_enabled;
+}
+
+gboolean
+nm_manager_get_logging (NMManager *manager, char **level, char **domains, GError **error)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+ g_return_val_if_fail (level == NULL || *level == NULL, FALSE);
+ g_return_val_if_fail (domains == NULL || *domains == NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (!level && !domains)
+ return TRUE;
+
+ return nmdbus_manager_call_get_logging_sync (NM_MANAGER_GET_PRIVATE (manager)->manager_proxy,
+ level, domains,
+ NULL, error);
+}
+
+gboolean
+nm_manager_set_logging (NMManager *manager, const char *level, const char *domains, GError **error)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (!level && !domains)
+ return TRUE;
+
+ if (!level)
+ level = "";
+ if (!domains)
+ domains = "";
+
+ return nmdbus_manager_call_set_logging_sync (NM_MANAGER_GET_PRIVATE (manager)->manager_proxy,
+ level, domains,
+ NULL, error);
+}
+
+NMClientPermissionResult
+nm_manager_get_permission_result (NMManager *manager, NMClientPermission permission)
+{
+ gpointer result;
+
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NM_CLIENT_PERMISSION_RESULT_UNKNOWN);
+
+ result = g_hash_table_lookup (NM_MANAGER_GET_PRIVATE (manager)->permissions,
+ GUINT_TO_POINTER (permission));
+ return GPOINTER_TO_UINT (result);
+}
+
+NMConnectivityState
+nm_manager_get_connectivity (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NM_STATE_UNKNOWN);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->connectivity;
+}
+
+NMConnectivityState
+nm_manager_check_connectivity (NMManager *manager,
+ GCancellable *cancellable,
+ GError **error)
+{
+ NMManagerPrivate *priv;
+ guint32 connectivity;
+
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NM_CONNECTIVITY_UNKNOWN);
+ priv = NM_MANAGER_GET_PRIVATE (manager);
+
+ if (nmdbus_manager_call_check_connectivity_sync (priv->manager_proxy,
+ &connectivity,
+ cancellable, error))
+ return connectivity;
+ else
+ return NM_CONNECTIVITY_UNKNOWN;
+}
+
+static void
+check_connectivity_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple = user_data;
+ guint32 connectivity;
+ GError *error = NULL;
+
+ if (nmdbus_manager_call_check_connectivity_finish (NMDBUS_MANAGER (object),
+ &connectivity,
+ result, &error))
+ g_simple_async_result_set_op_res_gssize (simple, connectivity);
+ else
+ g_simple_async_result_take_error (simple, error);
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+void
+nm_manager_check_connectivity_async (NMManager *manager,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMManagerPrivate *priv;
+ GSimpleAsyncResult *simple;
+
+ g_return_if_fail (NM_IS_MANAGER (manager));
+ priv = NM_MANAGER_GET_PRIVATE (manager);
+
+ simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data,
+ nm_manager_check_connectivity_async);
+ nmdbus_manager_call_check_connectivity (priv->manager_proxy,
+ cancellable,
+ check_connectivity_cb, simple);
+}
+
+NMConnectivityState
+nm_manager_check_connectivity_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN);
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return NM_CONNECTIVITY_UNKNOWN;
+ return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
+}
+
+/****************************************************************/
+/* Devices */
+/****************************************************************/
+
+const GPtrArray *
+nm_manager_get_devices (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->devices;
+}
+
+NMDevice *
+nm_manager_get_device_by_path (NMManager *manager, const char *object_path)
+{
+ const GPtrArray *devices;
+ int i;
+ NMDevice *device = NULL;
+
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+ g_return_val_if_fail (object_path, NULL);
+
+ devices = nm_manager_get_devices (manager);
+ if (!devices)
+ return NULL;
+
+ for (i = 0; i < devices->len; i++) {
+ NMDevice *candidate = g_ptr_array_index (devices, i);
+ if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), object_path)) {
+ device = candidate;
+ break;
+ }
+ }
+
+ return device;
+}
+
+NMDevice *
+nm_manager_get_device_by_iface (NMManager *manager, const char *iface)
+{
+ const GPtrArray *devices;
+ int i;
+ NMDevice *device = NULL;
+
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+ g_return_val_if_fail (iface, NULL);
+
+ devices = nm_manager_get_devices (manager);
+ if (!devices)
+ return NULL;
+
+ for (i = 0; i < devices->len; i++) {
+ NMDevice *candidate = g_ptr_array_index (devices, i);
+ if (!strcmp (nm_device_get_iface (candidate), iface)) {
+ device = candidate;
+ break;
+ }
+ }
+
+ return device;
+}
+
+/****************************************************************/
+/* Active Connections */
+/****************************************************************/
+
+const GPtrArray *
+nm_manager_get_active_connections (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->active_connections;
+}
+
+NMActiveConnection *
+nm_manager_get_primary_connection (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->primary_connection;
+}
+
+NMActiveConnection *
+nm_manager_get_activating_connection (NMManager *manager)
+{
+ g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+
+ return NM_MANAGER_GET_PRIVATE (manager)->activating_connection;
+}
+
+typedef struct {
+ NMManager *manager;
+ GSimpleAsyncResult *simple;
+ GCancellable *cancellable;
+ gulong cancelled_id;
+ char *active_path;
+ char *new_connection_path;
+} ActivateInfo;
+
+static void
+activate_info_complete (ActivateInfo *info,
+ NMActiveConnection *active,
+ GError *error)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (info->manager);
+
+ if (active)
+ g_simple_async_result_set_op_res_gpointer (info->simple, g_object_ref (active), g_object_unref);
+ else
+ g_simple_async_result_set_from_error (info->simple, error);
+ g_simple_async_result_complete (info->simple);
+
+ priv->pending_activations = g_slist_remove (priv->pending_activations, info);
+
+ g_free (info->active_path);
+ g_free (info->new_connection_path);
+ g_object_unref (info->simple);
+ if (info->cancellable) {
+ if (info->cancelled_id)
+ g_signal_handler_disconnect (info->cancellable, info->cancelled_id);
+ g_object_unref (info->cancellable);
+ }
+ g_slice_free (ActivateInfo, info);
+}
+
+static void
+recheck_pending_activations (NMManager *self, const char *failed_path, GError *error)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+ GSList *iter, *next;
+ const GPtrArray *active_connections;
+ gboolean found_in_active = FALSE;
+ gboolean found_in_pending = FALSE;
+ ActivateInfo *ainfo = NULL;
+ int i;
+
+ active_connections = nm_manager_get_active_connections (self);
+
+ /* For each pending activation, look for a active connection that has
+ * the pending activation's object path, and call pending connection's
+ * callback.
+ * If the connection to activate doesn't make it to active_connections,
+ * due to an error, we have to call the callback for failed_path.
+ */
+ for (iter = priv->pending_activations; iter; iter = next) {
+ ActivateInfo *info = iter->data;
+
+ next = g_slist_next (iter);
+
+ if (!found_in_pending && failed_path && g_strcmp0 (failed_path, info->active_path) == 0) {
+ found_in_pending = TRUE;
+ ainfo = info;
+ }
+
+ for (i = 0; i < active_connections->len; i++) {
+ NMActiveConnection *active = g_ptr_array_index (active_connections, i);
+ const char *active_path = nm_object_get_path (NM_OBJECT (active));
+
+ if (!found_in_active && failed_path && g_strcmp0 (failed_path, active_path) == 0)
+ found_in_active = TRUE;
+
+ if (g_strcmp0 (info->active_path, active_path) == 0) {
+ /* Call the pending activation's callback and it all up */
+ activate_info_complete (info, active, NULL);
+ break;
+ }
+ }
+ }
+
+ if (!found_in_active && found_in_pending) {
+ /* A newly activated connection failed due to some immediate error
+ * and disappeared from active connection list. Make sure the
+ * callback gets called.
+ */
+ activate_info_complete (ainfo, NULL, error);
+ }
+}
+
+static void
+activation_cancelled (GCancellable *cancellable,
+ gpointer user_data)
+{
+ ActivateInfo *info = user_data;
+ GError *error = NULL;
+
+ if (!g_cancellable_set_error_if_cancelled (cancellable, &error))
+ return;
+
+ activate_info_complete (info, NULL, error);
+ g_clear_error (&error);
+}
+
+static void
+activate_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ActivateInfo *info = user_data;
+ GError *error = NULL;
+
+ if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object),
+ &info->active_path,
+ result, &error)) {
+ if (info->cancellable) {
+ info->cancelled_id = g_signal_connect (info->cancellable, "cancelled",
+ G_CALLBACK (activation_cancelled), info);
+ }
+
+ recheck_pending_activations (info->manager, NULL, NULL);
+ } else {
+ activate_info_complete (info, NULL, error);
+ g_clear_error (&error);
+ }
+}
+
+void
+nm_manager_activate_connection_async (NMManager *manager,
+ NMConnection *connection,
+ NMDevice *device,
+ const char *specific_object,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMManagerPrivate *priv;
+ ActivateInfo *info;
+
+ g_return_if_fail (NM_IS_MANAGER (manager));
+ if (device)
+ g_return_if_fail (NM_IS_DEVICE (device));
+ if (connection)
+ g_return_if_fail (NM_IS_CONNECTION (connection));
+
+ info = g_slice_new0 (ActivateInfo);
+ info->manager = manager;
+ info->simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data,
+ nm_manager_activate_connection_async);
+ info->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
+
+ priv = NM_MANAGER_GET_PRIVATE (manager);
+ priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
+
+ nmdbus_manager_call_activate_connection (priv->manager_proxy,
+ connection ? nm_connection_get_path (connection) : "/",
+ device ? nm_object_get_path (NM_OBJECT (device)) : "/",
+ specific_object ? specific_object : "/",
+ cancellable,
+ activate_cb, info);
+}
+
+NMActiveConnection *
+nm_manager_activate_connection_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_activate_connection_async), 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));
+}
+
+static void
+add_activate_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ActivateInfo *info = user_data;
+ GError *error = NULL;
+
+ if (nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object),
+ NULL,
+ &info->active_path,
+ result, &error)) {
+ if (info->cancellable) {
+ info->cancelled_id = g_signal_connect (info->cancellable, "cancelled",
+ G_CALLBACK (activation_cancelled), info);
+ }
+
+ recheck_pending_activations (info->manager, NULL, NULL);
+ } else {
+ activate_info_complete (info, NULL, error);
+ g_clear_error (&error);
+ }
+}
+
+void
+nm_manager_add_and_activate_connection_async (NMManager *manager,
+ NMConnection *partial,
+ NMDevice *device,
+ const char *specific_object,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMManagerPrivate *priv;
+ GVariant *dict = NULL;
+ ActivateInfo *info;
+
+ g_return_if_fail (NM_IS_MANAGER (manager));
+ g_return_if_fail (NM_IS_DEVICE (device));
+ if (partial)
+ g_return_if_fail (NM_IS_CONNECTION (partial));
+
+ info = g_slice_new0 (ActivateInfo);
+ info->manager = manager;
+ info->simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data,
+ nm_manager_add_and_activate_connection_async);
+ info->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
+
+ priv = NM_MANAGER_GET_PRIVATE (manager);
+ priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
+
+ if (partial)
+ dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL);
+ if (!dict)
+ dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
+
+ nmdbus_manager_call_add_and_activate_connection (priv->manager_proxy,
+ dict,
+ nm_object_get_path (NM_OBJECT (device)),
+ specific_object ? specific_object : "/",
+ cancellable,
+ add_activate_cb, info);
+}
+
+NMActiveConnection *
+nm_manager_add_and_activate_connection_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_add_and_activate_connection_async), 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));
+}
+
+static void
+active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+ recheck_pending_activations (NM_MANAGER (object), NULL, NULL);
+}
+
+static void
+object_creation_failed_cb (GObject *object, GError *error, char *failed_path)
+{
+ if (error)
+ recheck_pending_activations (NM_MANAGER (object), failed_path, error);
+}
+
+gboolean
+nm_manager_deactivate_connection (NMManager *manager,
+ NMActiveConnection *active,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const char *path;
+
+ g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE);
+ g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE);
+
+ path = nm_object_get_path (NM_OBJECT (active));
+ return nmdbus_manager_call_deactivate_connection_sync (NM_MANAGER_GET_PRIVATE (manager)->manager_proxy,
+ path,
+ cancellable, error);
+}
+
+static void
+deactivated_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple = user_data;
+ GError *error = NULL;
+
+ if (nmdbus_manager_call_deactivate_connection_finish (NMDBUS_MANAGER (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);
+}
+
+void
+nm_manager_deactivate_connection_async (NMManager *manager,
+ NMActiveConnection *active,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ const char *path;
+ GSimpleAsyncResult *simple;
+
+ g_return_if_fail (NM_IS_MANAGER (manager));
+ g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active));
+
+ simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data,
+ nm_manager_deactivate_connection_async);
+
+ path = nm_object_get_path (NM_OBJECT (active));
+ nmdbus_manager_call_deactivate_connection (NM_MANAGER_GET_PRIVATE (manager)->manager_proxy,
+ path,
+ cancellable,
+ deactivated_cb, simple);
+}
+
+gboolean
+nm_manager_deactivate_connection_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_deactivate_connection_async), 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);
+}
+
+/****************************************************************/
+
+static void
+free_devices (NMManager *manager, gboolean in_dispose)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
+ GPtrArray *devices;
+ NMDevice *device;
+ int i;
+
+ if (!priv->devices)
+ return;
+
+ devices = priv->devices;
+
+ if (in_dispose)
+ priv->devices = NULL;
+ else {
+ priv->devices = g_ptr_array_new ();
+
+ for (i = 0; i < devices->len; i++) {
+ device = devices->pdata[i];
+ g_signal_emit (manager, signals[DEVICE_REMOVED], 0, device);
+ }
+ }
+
+ g_ptr_array_unref (devices);
+}
+
+static void
+free_active_connections (NMManager *manager, gboolean in_dispose)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
+ GPtrArray *active_connections;
+ NMActiveConnection *active_connection;
+ int i;
+
+ if (!priv->active_connections)
+ return;
+
+ active_connections = priv->active_connections;
+ priv->active_connections = NULL;
+
+ for (i = 0; i < active_connections->len; i++) {
+ active_connection = active_connections->pdata[i];
+ /* Break circular refs */
+ g_object_run_dispose (G_OBJECT (active_connection));
+ }
+ g_ptr_array_unref (active_connections);
+
+ if (!in_dispose) {
+ priv->active_connections = g_ptr_array_new ();
+ g_object_notify (G_OBJECT (manager), NM_MANAGER_ACTIVE_CONNECTIONS);
+ }
+}
+
+static void
+updated_properties (GObject *object, GAsyncResult *result, gpointer user_data)
+{
+ NMManager *manager = NM_MANAGER (user_data);
+ GError *error = NULL;
+
+ if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) {
+ g_warning ("%s: error reading NMManager properties: %s", __func__, error->message);
+ g_error_free (error);
+ }
+
+ _nm_object_queue_notify (NM_OBJECT (manager), NM_MANAGER_NM_RUNNING);
+}
+
+static void
+nm_running_changed_cb (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ NMManager *manager = NM_MANAGER (object);
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
+
+ if (!nm_manager_get_nm_running (manager)) {
+ priv->state = NM_STATE_UNKNOWN;
+ priv->startup = FALSE;
+ _nm_object_queue_notify (NM_OBJECT (manager), NM_MANAGER_NM_RUNNING);
+ _nm_object_suppress_property_updates (NM_OBJECT (manager), TRUE);
+ poke_wireless_devices_with_rf_status (manager);
+ free_devices (manager, FALSE);
+ free_active_connections (manager, FALSE);
+ update_permissions (manager, NULL);
+ priv->wireless_enabled = FALSE;
+ priv->wireless_hw_enabled = FALSE;
+ priv->wwan_enabled = FALSE;
+ priv->wwan_hw_enabled = FALSE;
+ priv->wimax_enabled = FALSE;
+ priv->wimax_hw_enabled = FALSE;
+ g_free (priv->version);
+ priv->version = NULL;
+
+ /* Clear object cache to ensure bad refcounting by managers doesn't
+ * keep objects in the cache.
+ */
+ _nm_object_cache_clear ();
+ } else {
+ _nm_object_suppress_property_updates (NM_OBJECT (manager), FALSE);
+ _nm_object_reload_properties_async (NM_OBJECT (manager), updated_properties, manager);
+ manager_recheck_permissions (priv->manager_proxy, manager);
+ }
+}
+
+/****************************************************************/
+
+static void
+constructed (GObject *object)
+{
+ G_OBJECT_CLASS (nm_manager_parent_class)->constructed (object);
+
+ g_signal_connect (object, "notify::" NM_OBJECT_NM_RUNNING,
+ G_CALLBACK (nm_running_changed_cb), NULL);
+
+ g_signal_connect (object, "notify::" NM_MANAGER_WIRELESS_ENABLED,
+ G_CALLBACK (wireless_enabled_cb), NULL);
+
+ g_signal_connect (object, "notify::" NM_MANAGER_ACTIVE_CONNECTIONS,
+ G_CALLBACK (active_connections_changed_cb), NULL);
+
+ g_signal_connect (object, "object-creation-failed",
+ G_CALLBACK (object_creation_failed_cb), NULL);
+}
+
+static gboolean
+init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
+{
+ NMManager *manager = NM_MANAGER (initable);
+
+ if (!nm_utils_init (error))
+ return FALSE;
+
+ if (!nm_manager_parent_initable_iface->init (initable, cancellable, error))
+ return FALSE;
+
+ if ( nm_manager_get_nm_running (manager)
+ && !get_permissions_sync (manager, error))
+ return FALSE;
+
+ return TRUE;
+}
+
+typedef struct {
+ NMManager *manager;
+ GCancellable *cancellable;
+ GSimpleAsyncResult *result;
+} NMManagerInitData;
+
+static void
+init_async_complete (NMManagerInitData *init_data)
+{
+ g_simple_async_result_complete (init_data->result);
+ g_object_unref (init_data->result);
+ g_clear_object (&init_data->cancellable);
+ g_slice_free (NMManagerInitData, init_data);
+}
+
+static void
+init_async_got_permissions (GObject *object, GAsyncResult *result, gpointer user_data)
+{
+ NMManagerInitData *init_data = user_data;
+ GVariant *permissions;
+
+ if (nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
+ &permissions,
+ result, NULL)) {
+ update_permissions (init_data->manager, permissions);
+ g_variant_unref (permissions);
+ } else
+ update_permissions (init_data->manager, NULL);
+
+ init_async_complete (init_data);
+}
+
+static void
+init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data)
+{
+ NMManagerInitData *init_data = user_data;
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (init_data->manager);
+ GError *error = NULL;
+
+ if (!nm_manager_parent_async_initable_iface->init_finish (G_ASYNC_INITABLE (source), result, &error)) {
+ g_simple_async_result_take_error (init_data->result, error);
+ init_async_complete (init_data);
+ return;
+ }
+
+ if (!nm_manager_get_nm_running (init_data->manager)) {
+ init_async_complete (init_data);
+ return;
+ }
+
+ nmdbus_manager_call_get_permissions (priv->manager_proxy,
+ init_data->cancellable,
+ init_async_got_permissions, init_data);
+}
+
+static void
+init_async (GAsyncInitable *initable, int io_priority,
+ GCancellable *cancellable, GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMManagerInitData *init_data;
+ GError *error = NULL;
+
+ if (!nm_utils_init (&error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (initable),
+ callback, user_data, error);
+ return;
+ }
+
+ init_data = g_slice_new0 (NMManagerInitData);
+ init_data->manager = NM_MANAGER (initable);
+ init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
+ init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
+ user_data, init_async);
+ g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
+
+ nm_manager_parent_async_initable_iface->init_async (initable, io_priority, cancellable,
+ init_async_parent_inited, init_data);
+}
+
+static gboolean
+init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+ else
+ return TRUE;
+}
+
+static void
+dispose (GObject *object)
+{
+ NMManager *manager = NM_MANAGER (object);
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
+
+ if (priv->perm_call_cancellable) {
+ g_cancellable_cancel (priv->perm_call_cancellable);
+ g_clear_object (&priv->perm_call_cancellable);
+ }
+
+ free_devices (manager, TRUE);
+ free_active_connections (manager, TRUE);
+ g_clear_object (&priv->primary_connection);
+ g_clear_object (&priv->activating_connection);
+
+ /* Each activation should hold a ref on @manager, so if we're being disposed,
+ * there shouldn't be any pending.
+ */
+ g_warn_if_fail (priv->pending_activations == NULL);
+
+ g_hash_table_destroy (priv->permissions);
+ priv->permissions = NULL;
+
+ G_OBJECT_CLASS (nm_manager_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
+
+ g_free (priv->version);
+
+ G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
+ gboolean b;
+
+ switch (prop_id) {
+ case PROP_NETWORKING_ENABLED:
+ b = g_value_get_boolean (value);
+ if (priv->networking_enabled != b) {
+ nm_manager_networking_set_enabled (NM_MANAGER (object), b, NULL);
+ /* Let the property value flip when we get the change signal from NM */
+ }
+ break;
+ case PROP_WIRELESS_ENABLED:
+ b = g_value_get_boolean (value);
+ if (priv->wireless_enabled != b) {
+ nm_manager_wireless_set_enabled (NM_MANAGER (object), b);
+ /* Let the property value flip when we get the change signal from NM */
+ }
+ break;
+ case PROP_WWAN_ENABLED:
+ b = g_value_get_boolean (value);
+ if (priv->wwan_enabled != b) {
+ nm_manager_wwan_set_enabled (NM_MANAGER (object), b);
+ /* Let the property value flip when we get the change signal from NM */
+ }
+ break;
+ case PROP_WIMAX_ENABLED:
+ b = g_value_get_boolean (value);
+ if (priv->wimax_enabled != b) {
+ nm_manager_wimax_set_enabled (NM_MANAGER (object), b);
+ /* Let the property value flip when we get the change signal from NM */
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NMManager *self = NM_MANAGER (object);
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+
+ switch (prop_id) {
+ case PROP_VERSION:
+ g_value_set_string (value, nm_manager_get_version (self));
+ break;
+ case PROP_STATE:
+ g_value_set_enum (value, nm_manager_get_state (self));
+ break;
+ case PROP_STARTUP:
+ g_value_set_boolean (value, nm_manager_get_startup (self));
+ break;
+ case PROP_NM_RUNNING:
+ g_value_set_boolean (value, nm_manager_get_nm_running (self));
+ break;
+ case PROP_NETWORKING_ENABLED:
+ g_value_set_boolean (value, nm_manager_networking_get_enabled (self));
+ break;
+ case PROP_WIRELESS_ENABLED:
+ g_value_set_boolean (value, priv->wireless_enabled);
+ break;
+ case PROP_WIRELESS_HARDWARE_ENABLED:
+ g_value_set_boolean (value, priv->wireless_hw_enabled);
+ break;
+ case PROP_WWAN_ENABLED:
+ g_value_set_boolean (value, priv->wwan_enabled);
+ break;
+ case PROP_WWAN_HARDWARE_ENABLED:
+ g_value_set_boolean (value, priv->wwan_hw_enabled);
+ break;
+ case PROP_WIMAX_ENABLED:
+ g_value_set_boolean (value, priv->wimax_enabled);
+ break;
+ case PROP_WIMAX_HARDWARE_ENABLED:
+ g_value_set_boolean (value, priv->wimax_hw_enabled);
+ break;
+ case PROP_ACTIVE_CONNECTIONS:
+ g_value_take_boxed (value, _nm_utils_copy_object_array (nm_manager_get_active_connections (self)));
+ break;
+ case PROP_CONNECTIVITY:
+ g_value_set_enum (value, priv->connectivity);
+ break;
+ case PROP_PRIMARY_CONNECTION:
+ g_value_set_object (value, priv->primary_connection);
+ break;
+ case PROP_ACTIVATING_CONNECTION:
+ g_value_set_object (value, priv->activating_connection);
+ break;
+ case PROP_DEVICES:
+ g_value_take_boxed (value, _nm_utils_copy_object_array (nm_manager_get_devices (self)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_manager_class_init (NMManagerClass *manager_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (manager_class);
+ NMObjectClass *nm_object_class = NM_OBJECT_CLASS (manager_class);
+
+ g_type_class_add_private (manager_class, sizeof (NMManagerPrivate));
+
+ _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE);
+ _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE, NMDBUS_TYPE_MANAGER_PROXY);
+
+ /* virtual methods */
+ object_class->constructed = constructed;
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+
+ nm_object_class->init_dbus = init_dbus;
+
+ /* properties */
+
+ g_object_class_install_property
+ (object_class, PROP_VERSION,
+ g_param_spec_string (NM_MANAGER_VERSION, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_STATE,
+ g_param_spec_enum (NM_CLIENT_STATE, "", "",
+ NM_TYPE_STATE,
+ NM_STATE_UNKNOWN,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_STARTUP,
+ g_param_spec_boolean (NM_MANAGER_STARTUP, "", "",
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_NM_RUNNING,
+ g_param_spec_boolean (NM_MANAGER_NM_RUNNING, "", "",
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_NETWORKING_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_NETWORKING_ENABLED, "", "",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_WIRELESS_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_WIRELESS_ENABLED, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_WIRELESS_HARDWARE_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_WIRELESS_HARDWARE_ENABLED, "", "",
+ TRUE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_WWAN_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_WWAN_ENABLED, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_WWAN_HARDWARE_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_WWAN_HARDWARE_ENABLED, "", "",
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_WIMAX_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_WIMAX_ENABLED, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_WIMAX_HARDWARE_ENABLED,
+ g_param_spec_boolean (NM_MANAGER_WIMAX_HARDWARE_ENABLED, "", "",
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_ACTIVE_CONNECTIONS,
+ g_param_spec_boxed (NM_MANAGER_ACTIVE_CONNECTIONS, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_CONNECTIVITY,
+ g_param_spec_enum (NM_CLIENT_CONNECTIVITY, "", "",
+ NM_TYPE_CONNECTIVITY_STATE,
+ NM_CONNECTIVITY_UNKNOWN,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_PRIMARY_CONNECTION,
+ g_param_spec_object (NM_MANAGER_PRIMARY_CONNECTION, "", "",
+ NM_TYPE_ACTIVE_CONNECTION,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_ACTIVATING_CONNECTION,
+ g_param_spec_object (NM_MANAGER_ACTIVATING_CONNECTION, "", "",
+ NM_TYPE_ACTIVE_CONNECTION,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_DEVICES,
+ g_param_spec_boxed (NM_MANAGER_DEVICES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /* signals */
+
+ signals[DEVICE_ADDED] =
+ g_signal_new ("device-added",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NMManagerClass, device_added),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
+ signals[DEVICE_REMOVED] =
+ g_signal_new ("device-removed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NMManagerClass, device_removed),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
+ signals[PERMISSION_CHANGED] =
+ g_signal_new ("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);
+}
+
+static void
+nm_manager_initable_iface_init (GInitableIface *iface)
+{
+ nm_manager_parent_initable_iface = g_type_interface_peek_parent (iface);
+
+ iface->init = init_sync;
+}
+
+static void
+nm_manager_async_initable_iface_init (GAsyncInitableIface *iface)
+{
+ nm_manager_parent_async_initable_iface = g_type_interface_peek_parent (iface);
+
+ iface->init_async = init_async;
+ iface->init_finish = init_finish;
+}
diff --git a/libnm/nm-manager.h b/libnm/nm-manager.h
new file mode 100644
index 0000000000..6b74b44483
--- /dev/null
+++ b/libnm/nm-manager.h
@@ -0,0 +1,168 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2008 Novell, Inc.
+ * Copyright 2007 - 2014 Red Hat, Inc.
+ */
+
+#ifndef __NM_MANAGER_H__
+#define __NM_MANAGER_H__
+
+#include "nm-client.h"
+#include "nm-object.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_MANAGER (nm_manager_get_type ())
+#define NM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MANAGER, NMManager))
+#define NM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MANAGER, NMManagerClass))
+#define NM_IS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MANAGER))
+#define NM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MANAGER))
+#define NM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MANAGER, NMManagerClass))
+
+#define NM_MANAGER_VERSION "version"
+#define NM_MANAGER_STATE "state"
+#define NM_MANAGER_STARTUP "startup"
+#define NM_MANAGER_NM_RUNNING "nm-running"
+#define NM_MANAGER_NETWORKING_ENABLED "networking-enabled"
+#define NM_MANAGER_WIRELESS_ENABLED "wireless-enabled"
+#define NM_MANAGER_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
+#define NM_MANAGER_WWAN_ENABLED "wwan-enabled"
+#define NM_MANAGER_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
+#define NM_MANAGER_WIMAX_ENABLED "wimax-enabled"
+#define NM_MANAGER_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled"
+#define NM_MANAGER_ACTIVE_CONNECTIONS "active-connections"
+#define NM_MANAGER_CONNECTIVITY "connectivity"
+#define NM_MANAGER_PRIMARY_CONNECTION "primary-connection"
+#define NM_MANAGER_ACTIVATING_CONNECTION "activating-connection"
+#define NM_MANAGER_DEVICES "devices"
+
+typedef struct {
+ NMObject parent;
+} NMManager;
+
+typedef struct {
+ NMObjectClass parent;
+
+ /* Signals */
+ void (*device_added) (NMManager *manager, NMDevice *device);
+ void (*device_removed) (NMManager *manager, NMDevice *device);
+ void (*permission_changed) (NMManager *manager,
+ NMClientPermission permission,
+ NMClientPermissionResult result);
+} NMManagerClass;
+
+GType nm_manager_get_type (void);
+
+const char *nm_manager_get_version (NMManager *manager);
+NMState nm_manager_get_state (NMManager *manager);
+gboolean nm_manager_get_startup (NMManager *manager);
+gboolean nm_manager_get_nm_running (NMManager *manager);
+
+gboolean nm_manager_networking_get_enabled (NMManager *manager);
+gboolean nm_manager_networking_set_enabled (NMManager *manager,
+ gboolean enabled,
+ GError **error);
+
+gboolean nm_manager_wireless_get_enabled (NMManager *manager);
+void nm_manager_wireless_set_enabled (NMManager *manager, gboolean enabled);
+gboolean nm_manager_wireless_hardware_get_enabled (NMManager *manager);
+
+gboolean nm_manager_wwan_get_enabled (NMManager *manager);
+void nm_manager_wwan_set_enabled (NMManager *manager, gboolean enabled);
+gboolean nm_manager_wwan_hardware_get_enabled (NMManager *manager);
+
+gboolean nm_manager_wimax_get_enabled (NMManager *manager);
+void nm_manager_wimax_set_enabled (NMManager *manager, gboolean enabled);
+gboolean nm_manager_wimax_hardware_get_enabled (NMManager *manager);
+
+gboolean nm_manager_get_logging (NMManager *manager,
+ char **level,
+ char **domains,
+ GError **error);
+gboolean nm_manager_set_logging (NMManager *manager,
+ const char *level,
+ const char *domains,
+ GError **error);
+
+NMClientPermissionResult nm_manager_get_permission_result (NMManager *manager,
+ NMClientPermission permission);
+
+NMConnectivityState nm_manager_get_connectivity (NMManager *manager);
+
+NMConnectivityState nm_manager_check_connectivity (NMManager *manager,
+ GCancellable *cancellable,
+ GError **error);
+void nm_manager_check_connectivity_async (NMManager *manager,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+NMConnectivityState nm_manager_check_connectivity_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error);
+
+/* Devices */
+
+const GPtrArray *nm_manager_get_devices (NMManager *manager);
+NMDevice *nm_manager_get_device_by_path (NMManager *manager, const char *object_path);
+NMDevice *nm_manager_get_device_by_iface (NMManager *manager, const char *iface);
+
+/* Active Connections */
+
+const GPtrArray *nm_manager_get_active_connections (NMManager *manager);
+
+NMActiveConnection *nm_manager_get_primary_connection (NMManager *manager);
+NMActiveConnection *nm_manager_get_activating_connection (NMManager *manager);
+
+void nm_manager_activate_connection_async (NMManager *manager,
+ NMConnection *connection,
+ NMDevice *device,
+ const char *specific_object,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+NMActiveConnection *nm_manager_activate_connection_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error);
+
+void nm_manager_add_and_activate_connection_async (NMManager *manager,
+ NMConnection *partial,
+ NMDevice *device,
+ const char *specific_object,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+NMActiveConnection *nm_manager_add_and_activate_connection_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error);
+
+gboolean nm_manager_deactivate_connection (NMManager *manager,
+ NMActiveConnection *active,
+ GCancellable *cancellable,
+ GError **error);
+void nm_manager_deactivate_connection_async (NMManager *manager,
+ NMActiveConnection *active,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean nm_manager_deactivate_connection_finish (NMManager *manager,
+ GAsyncResult *result,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __NM_MANAGER_H__ */
diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c
index 5ed6d03949..12e5450375 100644
--- a/libnm/nm-remote-settings.c
+++ b/libnm/nm-remote-settings.c
@@ -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),
diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h
index 1ada9a21dd..bed6a495e4 100644
--- a/libnm/nm-remote-settings.h
+++ b/libnm/nm-remote-settings.h
@@ -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,
diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c
index 1561ef9e42..ca0f03f6d4 100644
--- a/libnm/tests/test-remote-settings-client.c
+++ b/libnm/tests/test-remote-settings-client.c
@@ -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;
diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c
index c4eafd7a40..de49893c75 100644
--- a/libnm/tests/test-secret-agent.c
+++ b/libnm/tests/test-secret-agent.c
@@ -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",