diff options
author | Dan Winship <danw@gnome.org> | 2014-10-22 12:32:46 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-10-28 17:17:17 -0400 |
commit | 6ae422485004485afd0a64f00e75c17fa5084b2e (patch) | |
tree | d364cd6dcd8f63e7aaba1666e3f8db41c2890378 /libnm | |
parent | 9e5c7d915b837e79a2f6d64a7d89bf2a2dec2f50 (diff) | |
download | NetworkManager-6ae422485004485afd0a64f00e75c17fa5084b2e.tar.gz |
libnm: change GSList to GPtrArray in libnm methods
libnm mostly used GPtrArrays in its APIs, except that arrays of
connections were usually GSLists. Fix this and make them GPtrArrays
too (and rename nm_client_list_connections() to
nm_client_get_connections() to match everything else).
Diffstat (limited to 'libnm')
-rw-r--r-- | libnm/libnm.ver | 2 | ||||
-rw-r--r-- | libnm/nm-access-point.c | 39 | ||||
-rw-r--r-- | libnm/nm-access-point.h | 4 | ||||
-rw-r--r-- | libnm/nm-client.c | 17 | ||||
-rw-r--r-- | libnm/nm-client.h | 2 | ||||
-rw-r--r-- | libnm/nm-device.c | 35 | ||||
-rw-r--r-- | libnm/nm-device.h | 4 | ||||
-rw-r--r-- | libnm/nm-remote-settings.c | 18 | ||||
-rw-r--r-- | libnm/nm-remote-settings.h | 10 | ||||
-rw-r--r-- | libnm/nm-wimax-nsp.c | 35 | ||||
-rw-r--r-- | libnm/nm-wimax-nsp.h | 4 | ||||
-rw-r--r-- | libnm/tests/test-remote-settings-client.c | 33 |
12 files changed, 94 insertions, 109 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver index bc08e7fd01..d735a30e38 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -54,6 +54,7 @@ global: nm_client_get_connection_by_id; nm_client_get_connection_by_path; nm_client_get_connection_by_uuid; + nm_client_get_connections; nm_client_get_connectivity; nm_client_get_device_by_iface; nm_client_get_device_by_path; @@ -66,7 +67,6 @@ 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; diff --git a/libnm/nm-access-point.c b/libnm/nm-access-point.c index 0bb2c21409..dfc7240192 100644 --- a/libnm/nm-access-point.c +++ b/libnm/nm-access-point.c @@ -323,39 +323,38 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection) /** * nm_access_point_filter_connections: * @ap: an #NMAccessPoint to filter connections for - * @connections: (element-type NMConnection): a list of - * #NMConnection objects to filter + * @connections: (element-type NMConnection): an array of #NMConnections to + * filter * - * Filters a given list of connections for a given #NMAccessPoint object and - * return connections which may be activated with the access point. Any + * Filters a given array of connections for a given #NMAccessPoint object and + * returns connections which may be activated with the access point. Any * returned connections will match the @ap's SSID and (if given) BSSID and * other attributes like security settings, channel, etc. * * To obtain the list of connections that are compatible with this access point, - * use nm_remote_settings_list_connections() and then filter the returned list - * for a given #NMDevice using nm_device_filter_connections() and finally - * filter that list with this function. + * use nm_client_get_connections() and then filter the returned list for a given + * #NMDevice using nm_device_filter_connections() and finally filter that list + * with this function. * - * Returns: (transfer container) (element-type NMConnection): a - * list of #NMConnection objects that could be activated with the given @ap. - * The elements of the list are owned by their creator and should not be freed - * by the caller, but the returned list itself is owned by the caller and should - * be freed with g_slist_free() when it is no longer required. + * Returns: (transfer container) (element-type NMConnection): an array of + * #NMConnections that could be activated with the given @ap. The array should + * be freed with g_ptr_array_unref() when it is no longer required. **/ -GSList * -nm_access_point_filter_connections (NMAccessPoint *ap, const GSList *connections) +GPtrArray * +nm_access_point_filter_connections (NMAccessPoint *ap, const GPtrArray *connections) { - GSList *filtered = NULL; - const GSList *iter; + GPtrArray *filtered; + int i; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + filtered = g_ptr_array_new_with_free_func (g_object_unref); + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = connections->pdata[i]; if (nm_access_point_connection_valid (ap, candidate)) - filtered = g_slist_prepend (filtered, candidate); + g_ptr_array_add (filtered, g_object_ref (candidate)); } - return g_slist_reverse (filtered); + return filtered; } /************************************************************/ diff --git a/libnm/nm-access-point.h b/libnm/nm-access-point.h index 53935e5fa9..6991c19ac6 100644 --- a/libnm/nm-access-point.h +++ b/libnm/nm-access-point.h @@ -74,8 +74,8 @@ NM80211Mode nm_access_point_get_mode (NMAccessPoint *ap); guint32 nm_access_point_get_max_bitrate (NMAccessPoint *ap); guint8 nm_access_point_get_strength (NMAccessPoint *ap); -GSList * nm_access_point_filter_connections (NMAccessPoint *ap, - const GSList *connections); +GPtrArray * nm_access_point_filter_connections (NMAccessPoint *ap, + const GPtrArray *connections); gboolean nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection); diff --git a/libnm/nm-client.c b/libnm/nm-client.c index dad101b00b..f6a2256709 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -1150,22 +1150,19 @@ nm_client_deactivate_connection_finish (NMClient *client, /****************************************************************/ /** - * nm_client_list_connections: + * nm_client_get_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. + * Returns: (transfer none) (element-type NMRemoteConnection): an array + * containing all connections provided by the remote settings service. The + * returned array is owned by the #NMClient object and should not be modified. **/ -GSList * -nm_client_list_connections (NMClient *client) +const GPtrArray * +nm_client_get_connections (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - return nm_remote_settings_list_connections (NM_CLIENT_GET_PRIVATE (client)->settings); + return nm_remote_settings_get_connections (NM_CLIENT_GET_PRIVATE (client)->settings); } /** diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 2f22289c1f..619ad8585f 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -294,7 +294,7 @@ gboolean nm_client_deactivate_connection_finish (NMClient *client, /* Connections */ -GSList *nm_client_list_connections (NMClient *client); +const GPtrArray *nm_client_get_connections (NMClient *client); NMRemoteConnection *nm_client_get_connection_by_id (NMClient *client, const char *id); NMRemoteConnection *nm_client_get_connection_by_path (NMClient *client, const char *path); diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 90df14035f..5999ed23d2 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -2168,38 +2168,37 @@ nm_device_connection_compatible (NMDevice *device, NMConnection *connection, GEr /** * nm_device_filter_connections: * @device: an #NMDevice to filter connections for - * @connections: (element-type NMConnection): a list of #NMConnection objects to filter + * @connections: (element-type NMConnection): an array of #NMConnections to filter * - * Filters a given list of connections for a given #NMDevice object and return + * Filters a given array of connections for a given #NMDevice object and returns * connections which may be activated with the device. For example if @device - * is a Wi-Fi device that supports only WEP encryption, the returned list will + * is a Wi-Fi device that supports only WEP encryption, the returned array will * contain any Wi-Fi connections in @connections that allow connection to - * unencrypted or WEP-enabled SSIDs. The returned list will not contain + * unencrypted or WEP-enabled SSIDs. The returned array will not contain * Ethernet, Bluetooth, Wi-Fi WPA connections, or any other connection that is * incompatible with the device. To get the full list of connections see - * nm_remote_settings_list_connections(). + * nm_client_get_connections(). * - * Returns: (transfer container) (element-type NMConnection): a - * list of #NMConnection objects that could be activated with the given @device. - * The elements of the list are owned by their creator and should not be freed - * by the caller, but the returned list itself is owned by the caller and should - * be freed with g_slist_free() when it is no longer required. + * Returns: (transfer container) (element-type NMConnection): an array of + * #NMConnections that could be activated with the given @device. The array + * should be freed with g_ptr_array_unref() when it is no longer required. **/ -GSList * -nm_device_filter_connections (NMDevice *device, const GSList *connections) +GPtrArray * +nm_device_filter_connections (NMDevice *device, const GPtrArray *connections) { - GSList *filtered = NULL; - const GSList *iter; + GPtrArray *filtered; + int i; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + filtered = g_ptr_array_new_with_free_func (g_object_unref); + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = connections->pdata[i]; /* Connection applies to this device */ if (nm_device_connection_valid (device, candidate)) - filtered = g_slist_prepend (filtered, candidate); + g_ptr_array_add (filtered, g_object_ref (candidate)); } - return g_slist_reverse (filtered); + return filtered; } /** diff --git a/libnm/nm-device.h b/libnm/nm-device.h index cbfe6d4309..412dff3f96 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -144,8 +144,8 @@ gboolean nm_device_delete_finish (NMDevice *device, GAsyncResult *result, GError **error); -GSList * nm_device_filter_connections (NMDevice *device, - const GSList *connections); +GPtrArray * nm_device_filter_connections (NMDevice *device, + const GPtrArray *connections); gboolean nm_device_connection_valid (NMDevice *device, NMConnection *connection); diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index 62a3853d69..351fbc1bd2 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -261,24 +261,12 @@ object_creation_failed (NMObject *object, const char *failed_path) } } -GSList * -nm_remote_settings_list_connections (NMRemoteSettings *settings) +const GPtrArray * +nm_remote_settings_get_connections (NMRemoteSettings *settings) { - NMRemoteSettingsPrivate *priv; - GSList *list = NULL; - int i; - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - if (_nm_object_get_nm_running (NM_OBJECT (settings))) { - for (i = 0; i < priv->visible_connections->len; i++) - list = g_slist_prepend (list, priv->visible_connections->pdata[i]); - list = g_slist_reverse (list); - } - - return list; + return NM_REMOTE_SETTINGS_GET_PRIVATE (settings)->visible_connections; } static void diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h index dbe39abe5e..1ffc0bf20b 100644 --- a/libnm/nm-remote-settings.h +++ b/libnm/nm-remote-settings.h @@ -62,13 +62,13 @@ struct _NMRemoteSettingsClass { GType nm_remote_settings_get_type (void); -GSList *nm_remote_settings_list_connections (NMRemoteSettings *settings); +const GPtrArray *nm_remote_settings_get_connections (NMRemoteSettings *settings); -NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, - const char *id); +NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, + const char *id); -NMRemoteConnection * nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, - const char *path); +NMRemoteConnection *nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, + const char *path); NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const char *uuid); diff --git a/libnm/nm-wimax-nsp.c b/libnm/nm-wimax-nsp.c index 2387000569..9532b17627 100644 --- a/libnm/nm-wimax-nsp.c +++ b/libnm/nm-wimax-nsp.c @@ -145,33 +145,32 @@ nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection) /** * nm_wimax_nsp_filter_connections: * @nsp: an #NMWimaxNsp to filter connections for - * @connections: (element-type NMConnection): a list of - * #NMConnection objects to filter + * @connections: (element-type NMConnection): an array of #NMConnections to + * filter * - * Filters a given list of connections for a given #NMWimaxNsp object and - * return connections which may be activated with the access point. Any - * returned connections will match the @nsp's network name and other attributes. + * Filters a given array of connections for a given #NMWimaxNsp object and + * return connections which may be activated with the NSP. Any returned + * connections will match the @nsp's network name and other attributes. * - * Returns: (transfer container) (element-type NMConnection): a - * list of #NMConnection objects that could be activated with the given @nsp. - * The elements of the list are owned by their creator and should not be freed - * by the caller, but the returned list itself is owned by the caller and should - * be freed with g_slist_free() when it is no longer required. + * Returns: (transfer container) (element-type NMConnection): an array of + * #NMConnections that could be activated with the given @nsp. The array should + * be freed with g_ptr_array_unref() when it is no longer required. **/ -GSList * -nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GSList *connections) +GPtrArray * +nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GPtrArray *connections) { - GSList *filtered = NULL; - const GSList *iter; + GPtrArray *filtered; + int i; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + filtered = g_ptr_array_new_with_free_func (g_object_unref); + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = connections->pdata[i]; if (nm_wimax_nsp_connection_valid (nsp, candidate)) - filtered = g_slist_prepend (filtered, candidate); + g_ptr_array_add (filtered, g_object_ref (candidate)); } - return g_slist_reverse (filtered); + return filtered; } /************************************************************/ diff --git a/libnm/nm-wimax-nsp.h b/libnm/nm-wimax-nsp.h index 710639e784..a8f9105268 100644 --- a/libnm/nm-wimax-nsp.h +++ b/libnm/nm-wimax-nsp.h @@ -65,8 +65,8 @@ const char * nm_wimax_nsp_get_name (NMWimaxNsp *nsp); guint32 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp); NMWimaxNspNetworkType nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp); -GSList * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, - const GSList *connections); +GPtrArray * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, + const GPtrArray *connections); gboolean nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection); diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index f521dbc1c0..d3af020526 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -133,7 +133,8 @@ static void test_make_invisible (void) { time_t start, now; - GSList *list, *iter; + const GPtrArray *conns; + int i; GDBusProxy *proxy; gboolean visible_changed = FALSE, connection_removed = FALSE; gboolean has_settings = FALSE; @@ -177,9 +178,9 @@ test_make_invisible (void) g_signal_handlers_disconnect_by_func (client, G_CALLBACK (connection_removed_cb), &connection_removed); /* 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); + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); g_assert ((gpointer) remote != (gpointer) candidate); g_assert (strcmp (path, nm_connection_get_path (candidate)) != 0); @@ -210,7 +211,8 @@ static void test_make_visible (void) { time_t start, now; - GSList *list, *iter; + const GPtrArray *conns; + int i; GDBusProxy *proxy; gboolean found = FALSE; char *path; @@ -255,9 +257,9 @@ test_make_visible (void) g_signal_handlers_disconnect_by_func (client, G_CALLBACK (vis_new_connection_cb), &new); /* 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); + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); if ((gpointer) remote == (gpointer) candidate) { g_assert_cmpstr (path, ==, nm_connection_get_path (candidate)); @@ -299,16 +301,17 @@ test_remove_connection (void) { NMRemoteConnection *connection; time_t start, now; - GSList *list, *iter; + const GPtrArray *conns; + int i; GDBusProxy *proxy; gboolean done = FALSE; char *path; /* Find a connection to delete */ - list = nm_client_list_connections (client); - g_assert_cmpint (g_slist_length (list), >, 0); + conns = nm_client_get_connections (client); + g_assert_cmpint (conns->len, >, 0); - connection = NM_REMOTE_CONNECTION (list->data); + connection = NM_REMOTE_CONNECTION (conns->pdata[0]); g_assert (connection); g_assert (remote == connection); path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); @@ -342,9 +345,9 @@ test_remove_connection (void) g_assert (!remote); /* 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); + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); g_assert ((gpointer) connection != (gpointer) candidate); g_assert_cmpstr (path, ==, nm_connection_get_path (candidate)); |