mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 09:30:16 +01:00
settings: add nm_connection_provider_get_connections() to connection provider interface
Will be used by some other stuff.
This commit is contained in:
parent
c3d3a3d16a
commit
a5df15d75a
3 changed files with 102 additions and 3 deletions
|
|
@ -23,10 +23,20 @@ nm_connection_provider_get_best_connections (NMConnectionProvider *self,
|
|||
NMConnectionFilterFunc func,
|
||||
gpointer func_data)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
|
||||
|
||||
if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections)
|
||||
return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections (self);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +45,45 @@ nm_connection_provider_get_best_connections (NMConnectionProvider *self,
|
|||
static void
|
||||
nm_connection_provider_init (gpointer g_iface)
|
||||
{
|
||||
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = TRUE;
|
||||
|
||||
/* Signals */
|
||||
g_signal_new (NM_CP_SIGNAL_CONNECTION_ADDED,
|
||||
iface_type,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMConnectionProvider, connection_added),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
||||
|
||||
g_signal_new (NM_CP_SIGNAL_CONNECTION_UPDATED,
|
||||
iface_type,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMConnectionProvider, connection_updated),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
||||
|
||||
g_signal_new (NM_CP_SIGNAL_CONNECTION_REMOVED,
|
||||
iface_type,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMConnectionProvider, connection_removed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
||||
|
||||
g_signal_new (NM_CP_SIGNAL_CONNECTIONS_LOADED,
|
||||
iface_type,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMConnectionProvider, connections_loaded),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
GType
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@
|
|||
|
||||
typedef struct _NMConnectionProvider NMConnectionProvider;
|
||||
|
||||
#define NM_CP_SIGNAL_CONNECTION_ADDED "cp-connection-added"
|
||||
#define NM_CP_SIGNAL_CONNECTION_UPDATED "cp-connection-updated"
|
||||
#define NM_CP_SIGNAL_CONNECTION_REMOVED "cp-connection-removed"
|
||||
#define NM_CP_SIGNAL_CONNECTIONS_LOADED "cp-connections-loaded"
|
||||
|
||||
|
||||
/**
|
||||
* NMConnectionFilterFunc:
|
||||
* @provider: The provider requesting the filtering
|
||||
|
|
@ -49,6 +55,17 @@ struct _NMConnectionProvider {
|
|||
const char *ctype2,
|
||||
NMConnectionFilterFunc func,
|
||||
gpointer func_data);
|
||||
|
||||
const GSList * (*get_connections) (NMConnectionProvider *self);
|
||||
|
||||
/* Signals */
|
||||
void (*connection_added) (NMConnectionProvider *self, NMConnection *connection);
|
||||
|
||||
void (*connection_updated) (NMConnectionProvider *self, NMConnection *connection);
|
||||
|
||||
void (*connection_removed) (NMConnectionProvider *self, NMConnection *connection);
|
||||
|
||||
void (*connections_loaded) (NMConnectionProvider *self);
|
||||
};
|
||||
|
||||
GType nm_connection_provider_get_type (void);
|
||||
|
|
@ -76,4 +93,14 @@ GSList *nm_connection_provider_get_best_connections (NMConnectionProvider *self,
|
|||
NMConnectionFilterFunc func,
|
||||
gpointer func_data);
|
||||
|
||||
/**
|
||||
* nm_connection_provider_get_connections:
|
||||
* @self: the #NMConnectionProvider
|
||||
*
|
||||
* Returns: a #GSList of #NMConnection objects representing all known
|
||||
* connections. Returned list is owned by the connection provider and must
|
||||
* not be freed.
|
||||
*/
|
||||
const GSList *nm_connection_provider_get_connections (NMConnectionProvider *self);
|
||||
|
||||
#endif /* NM_CONNECTION_PROVIDER_H */
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ load_connections (NMSettings *self)
|
|||
unmanaged_specs_changed (NULL, self);
|
||||
|
||||
g_signal_emit (self, signals[CONNECTIONS_LOADED], 0);
|
||||
g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTIONS_LOADED);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -679,6 +680,7 @@ connection_removed (NMSettingsConnection *obj, gpointer user_data)
|
|||
|
||||
/* Re-emit for listeners like NMPolicy */
|
||||
g_signal_emit (NM_SETTINGS (user_data), signals[CONNECTION_REMOVED], 0, connection);
|
||||
g_signal_emit_by_name (NM_SETTINGS (user_data), NM_CP_SIGNAL_CONNECTION_REMOVED, connection);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
|
@ -706,6 +708,7 @@ connection_updated (NMSettingsConnection *connection, gpointer user_data)
|
|||
signals[CONNECTION_UPDATED],
|
||||
0,
|
||||
connection);
|
||||
g_signal_emit_by_name (NM_SETTINGS (user_data), NM_CP_SIGNAL_CONNECTION_UPDATED, connection);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -854,6 +857,7 @@ claim_connection (NMSettings *self,
|
|||
if (priv->connections_loaded) {
|
||||
/* Internal added signal */
|
||||
g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection);
|
||||
g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_ADDED, connection);
|
||||
|
||||
/* Exported D-Bus signal */
|
||||
g_signal_emit (self, signals[NEW_CONNECTION], 0, connection);
|
||||
|
|
@ -1700,6 +1704,24 @@ get_best_connections (NMConnectionProvider *provider,
|
|||
return g_slist_reverse (sorted);
|
||||
}
|
||||
|
||||
static const GSList *
|
||||
get_connections (NMConnectionProvider *provider)
|
||||
{
|
||||
static GSList *list = NULL;
|
||||
NMSettings *self = NM_SETTINGS (provider);
|
||||
GHashTableIter iter;
|
||||
NMSettingsConnection *connection;
|
||||
|
||||
/* Lazily free the list with every call so we can keep it 'const' for callers */
|
||||
g_slist_free (list);
|
||||
list = NULL;
|
||||
|
||||
g_hash_table_iter_init (&iter, NM_SETTINGS_GET_PRIVATE (self)->connections);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection))
|
||||
list = g_slist_prepend (list, connection);
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
NMSettings *
|
||||
|
|
@ -1744,6 +1766,7 @@ static void
|
|||
connection_provider_init (NMConnectionProvider *cp_class)
|
||||
{
|
||||
cp_class->get_best_connections = get_best_connections;
|
||||
cp_class->get_connections = get_connections;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue