summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-03-29 08:52:45 +0200
committerThomas Haller <thaller@redhat.com>2018-03-29 11:24:32 +0200
commit497c415508c3d22c4cb6c412a8787752b3bc289c (patch)
treeb2f574d45d7304173502c0f365bd9dd3ea03f4df
parentbdbe1337dc756dc4699c0c00029852d1643e2c44 (diff)
downloadNetworkManager-497c415508c3d22c4cb6c412a8787752b3bc289c.tar.gz
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.
-rw-r--r--src/devices/wifi/nm-device-olpc-mesh.c5
-rw-r--r--src/devices/wifi/nm-iwd-manager.c14
-rw-r--r--src/nm-checkpoint-manager.c5
-rw-r--r--src/nm-checkpoint.c5
-rw-r--r--src/nm-manager.h15
-rw-r--r--src/nm-policy.c25
6 files changed, 36 insertions, 33 deletions
diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c
index d655406437..cd2c68af86 100644
--- a/src/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/devices/wifi/nm-device-olpc-mesh.c
@@ -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,
diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c
index ea903bc724..1cf91bbc53 100644
--- a/src/devices/wifi/nm-iwd-manager.c
+++ b/src/devices/wifi/nm-iwd-manager.c
@@ -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);
+ }
}
}
}
diff --git a/src/nm-checkpoint-manager.c b/src/nm-checkpoint-manager.c
index 7345f9a41d..2e4b2f1400 100644
--- a/src/nm-checkpoint-manager.c
+++ b/src/nm-checkpoint-manager.c
@@ -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));
diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c
index 631765c2af..c117ab9960 100644
--- a/src/nm-checkpoint.c
+++ b/src/nm-checkpoint.c
@@ -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);
diff --git a/src/nm-manager.h b/src/nm-manager.h
index 638ceed6ea..3d651c7f7d 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -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,
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 72351efe06..3984feb326 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -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;