core: drop interface function nm_connection_provider_get_best_connections()

... in favor of nm_settings_get_best_connections().
This commit is contained in:
Thomas Haller 2016-05-16 19:10:17 +02:00
parent 8e1443457d
commit f20341a1fd
5 changed files with 58 additions and 80 deletions

View file

@ -47,7 +47,6 @@
#include "nm-auth-utils.h"
#include "nm-settings-connection.h"
#include "nm-settings.h"
#include "nm-connection-provider.h"
#include "nm-enum-types.h"
#include "nm-core-internal.h"
#include "nm-config.h"
@ -1199,7 +1198,7 @@ check_scanning_allowed (NMDeviceWifi *self)
}
static gboolean
hidden_filter_func (NMConnectionProvider *provider,
hidden_filter_func (NMSettings *settings,
NMConnection *connection,
gpointer user_data)
{
@ -1226,12 +1225,12 @@ build_hidden_probe_list (NMDeviceWifi *self)
if (G_UNLIKELY (nullssid == NULL))
nullssid = g_byte_array_new ();
connections = nm_connection_provider_get_best_connections ((NMConnectionProvider *) nm_device_get_settings ((NMDevice *) self),
max_scan_ssids - 1,
NM_SETTING_WIRELESS_SETTING_NAME,
NULL,
hidden_filter_func,
NULL);
connections = nm_settings_get_best_connections (nm_device_get_settings ((NMDevice *) self),
max_scan_ssids - 1,
NM_SETTING_WIRELESS_SETTING_NAME,
NULL,
hidden_filter_func,
NULL);
if (connections && connections->data) {
ssids = g_ptr_array_new_full (max_scan_ssids - 1, (GDestroyNotify) g_byte_array_unref);
g_ptr_array_add (ssids, g_byte_array_ref (nullssid)); /* Add wildcard SSID */

View file

@ -21,21 +21,6 @@
G_DEFINE_INTERFACE (NMConnectionProvider, nm_connection_provider, G_TYPE_OBJECT)
GSList *
nm_connection_provider_get_best_connections (NMConnectionProvider *self,
guint max_requested,
const char *ctype1,
const char *ctype2,
NMConnectionFilterFunc func,
gpointer func_data)
{
g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_best_connections)
return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_best_connections (self, max_requested, ctype1, ctype2, func, func_data);
return NULL;
}
const GSList *
nm_connection_provider_get_connections (NMConnectionProvider *self)
{

View file

@ -28,30 +28,10 @@
#define NM_CP_SIGNAL_CONNECTION_REMOVED "cp-connection-removed"
/**
* NMConnectionFilterFunc:
* @provider: The provider requesting the filtering
* @connection: the connection to be filtered
* @func_data: the caller-provided data pointer
*
* Returns: %TRUE to allow the connection, %FALSE to ignore it
*/
typedef gboolean (*NMConnectionFilterFunc) (NMConnectionProvider *provider,
NMConnection *connection,
gpointer func_data);
typedef struct {
GTypeInterface g_iface;
/* Methods */
GSList * (*get_best_connections) (NMConnectionProvider *self,
guint max_requested,
const char *ctype1,
const char *ctype2,
NMConnectionFilterFunc func,
gpointer func_data);
const GSList * (*get_connections) (NMConnectionProvider *self);
NMConnection * (*add_connection) (NMConnectionProvider *self,
@ -74,29 +54,6 @@ GType nm_connection_provider_get_type (void);
*/
NMConnectionProvider *nm_connection_provider_get (void);
/**
* nm_connection_provider_get_best_connections:
* @self: the #NMConnectionProvider
* @max_requested: if non-zero, the maximum number of connections to return
* @ctype1: an #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) to
* filter connections against
* @ctype2: a second #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME)
* to filter connections against
* @func: caller-supplied function for filtering connections
* @func_data: caller-supplied data passed to @func
*
* Returns: a #GSList of #NMConnection objects in sorted order representing the
* "best" or highest-priority connections filtered by @ctype1 and/or @ctype2,
* and/or @func. Caller is responsible for freeing the returned #GSList, but
* the contained values do not need to be unreffed.
*/
GSList *nm_connection_provider_get_best_connections (NMConnectionProvider *self,
guint max_requested,
const char *ctype1,
const char *ctype2,
NMConnectionFilterFunc func,
gpointer func_data);
/**
* nm_connection_provider_get_connections:
* @self: the #NMConnectionProvider

View file

@ -2130,22 +2130,41 @@ nm_settings_sort_connections (gconstpointer a, gconstpointer b)
return 0;
}
static GSList *
get_best_connections (NMConnectionProvider *provider,
guint max_requested,
const char *ctype1,
const char *ctype2,
NMConnectionFilterFunc func,
gpointer func_data)
/**
* nm_settings_get_best_connections:
* @self: the #NMSetting
* @max_requested: if non-zero, the maximum number of connections to return
* @ctype1: an #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) to
* filter connections against
* @ctype2: a second #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME)
* to filter connections against
* @func: caller-supplied function for filtering connections
* @func_data: caller-supplied data passed to @func
*
* Returns: a #GSList of #NMConnection objects in sorted order representing the
* "best" or highest-priority connections filtered by @ctype1 and/or @ctype2,
* and/or @func. Caller is responsible for freeing the returned #GSList, but
* the contained values do not need to be unreffed.
*/
GSList *
nm_settings_get_best_connections (NMSettings *self,
guint max_requested,
const char *ctype1,
const char *ctype2,
NMConnectionFilterFunc func,
gpointer func_data)
{
NMSettings *self = NM_SETTINGS (provider);
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
NMSettingsPrivate *priv;
GSList *sorted = NULL;
GHashTableIter iter;
NMSettingsConnection *connection;
guint added = 0;
guint64 oldest = 0;
g_return_val_if_fail (NM_IS_SETTINGS (self), NULL);
priv = NM_SETTINGS_GET_PRIVATE (self);
g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) {
guint64 cur_ts = 0;
@ -2154,7 +2173,7 @@ get_best_connections (NMConnectionProvider *provider,
continue;
if (ctype2 && !nm_connection_is_type (NM_CONNECTION (connection), ctype2))
continue;
if (func && !func (provider, NM_CONNECTION (connection), func_data))
if (func && !func (self, NM_CONNECTION (connection), func_data))
continue;
/* Don't bother with a connection that's older than the oldest one in the list */
@ -2370,10 +2389,9 @@ nm_settings_start (NMSettings *self, GError **error)
static void
connection_provider_iface_init (NMConnectionProviderInterface *cp_iface)
{
cp_iface->get_best_connections = get_best_connections;
cp_iface->get_connections = get_connections;
cp_iface->add_connection = _nm_connection_provider_add_connection;
cp_iface->get_connection_by_uuid = cp_get_connection_by_uuid;
cp_iface->get_connections = get_connections;
cp_iface->add_connection = _nm_connection_provider_add_connection;
cp_iface->get_connection_by_uuid = cp_get_connection_by_uuid;
cp_iface->get_unmanaged_specs = cp_get_unmanaged_specs;
}

View file

@ -49,6 +49,18 @@
#define NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED "connection-visibility-changed"
#define NM_SETTINGS_SIGNAL_AGENT_REGISTERED "agent-registered"
/**
* NMConnectionFilterFunc:
* @settings: The #NMSettings requesting the filtering
* @connection: the connection to be filtered
* @func_data: the caller-provided data pointer
*
* Returns: %TRUE to allow the connection, %FALSE to ignore it
*/
typedef gboolean (*NMConnectionFilterFunc) (NMSettings *settings,
NMConnection *connection,
gpointer func_data);
struct _NMSettings {
NMExportedObject parent_instance;
};
@ -93,6 +105,13 @@ NMSettingsConnection *const* nm_settings_get_connections (NMSettings *settings,
GSList *nm_settings_get_connections_sorted (NMSettings *settings);
GSList *nm_settings_get_best_connections (NMSettings *self,
guint max_requested,
const char *ctype1,
const char *ctype2,
NMConnectionFilterFunc func,
gpointer func_data);
NMSettingsConnection *nm_settings_add_connection (NMSettings *settings,
NMConnection *connection,
gboolean save_to_disk,