mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 07:58:00 +02:00
core: add macro for iterating CList of devices of NMManager
I find it slightly nicer and explict. Also, the list elements are strictly speaking private, we should better not explicitly use them outside of NMManager/NMDevice. The macro hides this.
This commit is contained in:
parent
a399e2b8ff
commit
8de522fad0
6 changed files with 36 additions and 33 deletions
|
|
@ -387,7 +387,7 @@ static void
|
|||
find_companion (NMDeviceOlpcMesh *self)
|
||||
{
|
||||
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *candidate;
|
||||
|
||||
if (priv->companion)
|
||||
|
|
@ -396,8 +396,7 @@ find_companion (NMDeviceOlpcMesh *self)
|
|||
nm_device_add_pending_action (NM_DEVICE (self), NM_PENDING_ACTION_WAITING_FOR_COMPANION, TRUE);
|
||||
|
||||
/* Try to find the companion if it's already known to the NMManager */
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (candidate, all_devices, devices_lst) {
|
||||
nm_manager_for_each_device (priv->manager, candidate, tmp_lst) {
|
||||
if (check_companion (self, candidate)) {
|
||||
nm_device_queue_recheck_available (NM_DEVICE (self),
|
||||
NM_DEVICE_STATE_REASON_NONE,
|
||||
|
|
|
|||
|
|
@ -460,7 +460,7 @@ name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
|
|||
g_clear_object (&priv->object_manager);
|
||||
prepare_object_manager (self);
|
||||
} else {
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *device;
|
||||
|
||||
if (!priv->running)
|
||||
|
|
@ -468,13 +468,11 @@ name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
|
|||
|
||||
priv->running = false;
|
||||
|
||||
all_devices = nm_manager_get_devices (priv->nm_manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst) {
|
||||
if (!NM_IS_DEVICE_IWD (device))
|
||||
continue;
|
||||
|
||||
nm_device_iwd_set_dbus_object (NM_DEVICE_IWD (device),
|
||||
NULL);
|
||||
nm_manager_for_each_device (priv->nm_manager, device, tmp_lst) {
|
||||
if (NM_IS_DEVICE_IWD (device)) {
|
||||
nm_device_iwd_set_dbus_object (NM_DEVICE_IWD (device),
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,12 +174,11 @@ nm_checkpoint_manager_create (NMCheckpointManager *self,
|
|||
|
||||
if (!device_paths || !device_paths[0]) {
|
||||
const char *device_path;
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
GPtrArray *paths;
|
||||
|
||||
paths = g_ptr_array_new ();
|
||||
all_devices = nm_manager_get_devices (manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst) {
|
||||
nm_manager_for_each_device (manager, device, tmp_lst) {
|
||||
if (!nm_device_is_real (device))
|
||||
continue;
|
||||
device_path = nm_dbus_object_get_path (NM_DBUS_OBJECT (device));
|
||||
|
|
|
|||
|
|
@ -348,11 +348,10 @@ next_dev:
|
|||
}
|
||||
|
||||
if (NM_FLAGS_HAS (priv->flags, NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES)) {
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDeviceState state;
|
||||
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst) {
|
||||
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
||||
if (g_hash_table_contains (priv->devices, device))
|
||||
continue;
|
||||
state = nm_device_get_state (device);
|
||||
|
|
|
|||
|
|
@ -83,13 +83,14 @@ gboolean nm_manager_start (NMManager *manager,
|
|||
GError **error);
|
||||
void nm_manager_stop (NMManager *manager);
|
||||
NMState nm_manager_get_state (NMManager *manager);
|
||||
|
||||
const CList * nm_manager_get_active_connections (NMManager *manager);
|
||||
|
||||
#define nm_manager_for_each_active_connection(manager, iter, tmp_list) \
|
||||
for (tmp_list = nm_manager_get_active_connections (manager), \
|
||||
iter = c_list_entry (tmp_list->next, NMActiveConnection, active_connections_lst); \
|
||||
({ \
|
||||
gboolean _has_next = (&iter->active_connections_lst != tmp_list); \
|
||||
const gboolean _has_next = (&iter->active_connections_lst != tmp_list); \
|
||||
\
|
||||
if (!_has_next) \
|
||||
iter = NULL; \
|
||||
|
|
@ -107,6 +108,18 @@ void nm_manager_write_device_state (NMManager *manager);
|
|||
|
||||
const CList * nm_manager_get_devices (NMManager *manager);
|
||||
|
||||
#define nm_manager_for_each_device(manager, iter, tmp_list) \
|
||||
for (tmp_list = nm_manager_get_devices (manager), \
|
||||
iter = c_list_entry (tmp_list->next, NMDevice, devices_lst); \
|
||||
({ \
|
||||
const gboolean _has_next = (&iter->devices_lst != tmp_list); \
|
||||
\
|
||||
if (!_has_next) \
|
||||
iter = NULL; \
|
||||
_has_next; \
|
||||
}); \
|
||||
iter = c_list_entry (iter->devices_lst.next, NMDevice, devices_lst))
|
||||
|
||||
NMDevice * nm_manager_get_device_by_ifindex (NMManager *manager,
|
||||
int ifindex);
|
||||
NMDevice * nm_manager_get_device_by_path (NMManager *manager,
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ get_best_ip_device (NMPolicy *self,
|
|||
gboolean fully_activated)
|
||||
{
|
||||
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *device;
|
||||
NMDevice *best_device;
|
||||
NMDevice *prev_device;
|
||||
|
|
@ -401,8 +401,7 @@ get_best_ip_device (NMPolicy *self,
|
|||
? (fully_activated ? priv->default_device4 : priv->activating_device4)
|
||||
: (fully_activated ? priv->default_device6 : priv->activating_device6);
|
||||
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst) {
|
||||
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
||||
NMDeviceState state;
|
||||
const NMPObject *r;
|
||||
NMConnection *connection;
|
||||
|
|
@ -462,11 +461,10 @@ static gboolean
|
|||
all_devices_not_active (NMPolicy *self)
|
||||
{
|
||||
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *device;
|
||||
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst) {
|
||||
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
||||
NMDeviceState state;
|
||||
|
||||
state = nm_device_get_state (device);
|
||||
|
|
@ -2186,13 +2184,12 @@ schedule_activate_all_cb (gpointer user_data)
|
|||
{
|
||||
NMPolicy *self = user_data;
|
||||
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *device;
|
||||
|
||||
priv->schedule_activate_all_id = 0;
|
||||
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst)
|
||||
nm_manager_for_each_device (priv->manager, device, tmp_lst)
|
||||
schedule_activate_check (self, device);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
|
|
@ -2227,7 +2224,7 @@ firewall_state_changed (NMFirewallManager *manager,
|
|||
{
|
||||
NMPolicy *self = (NMPolicy *) user_data;
|
||||
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *device;
|
||||
|
||||
if (initialized_now) {
|
||||
|
|
@ -2241,8 +2238,7 @@ firewall_state_changed (NMFirewallManager *manager,
|
|||
return;
|
||||
|
||||
/* add interface of each device to correct zone */
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (device, all_devices, devices_lst)
|
||||
nm_manager_for_each_device (priv->manager, device, tmp_lst)
|
||||
nm_device_update_firewall_zone (device);
|
||||
}
|
||||
|
||||
|
|
@ -2288,14 +2284,13 @@ connection_updated (NMSettings *settings,
|
|||
{
|
||||
NMPolicyPrivate *priv = user_data;
|
||||
NMPolicy *self = _PRIV_TO_SELF (priv);
|
||||
const CList *all_devices;
|
||||
const CList *tmp_lst;
|
||||
NMDevice *device = NULL;
|
||||
NMDevice *dev;
|
||||
|
||||
if (by_user) {
|
||||
/* find device with given connection */
|
||||
all_devices = nm_manager_get_devices (priv->manager);
|
||||
c_list_for_each_entry (dev, all_devices, devices_lst) {
|
||||
nm_manager_for_each_device (priv->manager, dev, tmp_lst) {
|
||||
if (nm_device_get_settings_connection (dev) == connection) {
|
||||
device = dev;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue