[Babel-users] Revised [PATCH 2/2] Coding Style alternative

Christof Schulze christof.schulze at gmx.net
Sun Aug 11 23:21:39 BST 2019


This implements an alternative coding style for the monitor change.
Squash this commit into the previous one if you prefer that style.
---
  local.c | 24 ++++++++++++------------
  local.h | 11 -----------
  2 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/local.c b/local.c
index 01122f9..bce104e 100644
--- a/local.c
+++ b/local.c
@@ -131,7 +131,7 @@ local_notify_interface(struct interface *ifp, int kind)
  {
      int i;
      for(i = 0; i < num_local_sockets; i++) {
-        if(get_flag(&local_sockets[i].monitor, MONITOR_INTERFACE))
+        if (local_sockets[i].monitor & (0x01 << MONITOR_INTERFACE))
              local_notify_interface_1(&local_sockets[i], ifp, kind);
      }
  }
@@ -186,7 +186,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
  {
      int i;
      for(i = 0; i < num_local_sockets; i++) {
-        if(get_flag(&local_sockets[i].monitor, MONITOR_NEIGHBOUR))
+        if (local_sockets[i].monitor & (0x01 << MONITOR_NEIGHBOUR))
              local_notify_neighbour_1(&local_sockets[i], neigh, kind);
      }
  }
@@ -223,7 +223,7 @@ local_notify_xroute(struct xroute *xroute, int kind)
  {
      int i;
      for(i = 0; i < num_local_sockets; i++) {
-        if(get_flag(&local_sockets[i].monitor, MONITOR_XROUTE))
+        if (local_sockets[i].monitor & (0x01 << MONITOR_XROUTE))
              local_notify_xroute_1(&local_sockets[i], xroute, kind);
      }
  }
@@ -268,7 +268,7 @@ local_notify_route(struct babel_route *route, int kind)
  {
      int i;
      for(i = 0; i < num_local_sockets; i++) {
-        if(get_flag(&local_sockets[i].monitor, MONITOR_ROUTE))
+        if (local_sockets[i].monitor & (0x01 << MONITOR_ROUTE))
              local_notify_route_1(&local_sockets[i], route, kind);
      }
  }
@@ -379,32 +379,32 @@ local_read(struct local_socket *s)
              local_notify_all_1(s);
              break;
          case CONFIG_ACTION_INTERFACE_MONITOR:
-	    set_flag(&s->monitor, MONITOR_INTERFACE);
+            s->monitor |= 0x01 << MONITOR_INTERFACE;
              local_notify_all_interface_1(s);
              break;
          case CONFIG_ACTION_INTERFACE_UNMONITOR:
-	    unset_flag(&s->monitor, MONITOR_INTERFACE);
+            s->monitor &= ~( 0x01 << MONITOR_INTERFACE );
              break;
          case CONFIG_ACTION_ROUTE_MONITOR:
-	    set_flag(&s->monitor, MONITOR_ROUTE);
+            s->monitor |= 0x01 << MONITOR_ROUTE;
              local_notify_all_route_1(s);
              break;
          case CONFIG_ACTION_ROUTE_UNMONITOR:
-	    unset_flag(&s->monitor, MONITOR_ROUTE);
+            s->monitor &= ~( 0x01 << MONITOR_ROUTE );
              break;
          case CONFIG_ACTION_XROUTE_MONITOR:
-	    set_flag(&s->monitor, MONITOR_XROUTE);
+            s->monitor |= 0x01 << MONITOR_XROUTE;
              local_notify_all_xroute_1(s);
              break;
          case CONFIG_ACTION_XROUTE_UNMONITOR:
-	    unset_flag(&s->monitor, MONITOR_XROUTE);
+            s->monitor &= ~( 0x01 << MONITOR_XROUTE );
              break;
          case CONFIG_ACTION_NEIGHBOUR_MONITOR:
-	    set_flag(&s->monitor, MONITOR_NEIGHBOUR);
+            s->monitor |= 0x01 << MONITOR_NEIGHBOUR;
              local_notify_all_neighbour_1(s);
              break;
          case CONFIG_ACTION_NEIGHBOUR_UNMONITOR:
-	    unset_flag(&s->monitor, MONITOR_NEIGHBOUR);
+            s->monitor &= ~( 0x01 << MONITOR_NEIGHBOUR );
              break;
          case CONFIG_ACTION_MONITOR:
              s->monitor = 0xff;
diff --git a/local.h b/local.h
index 6e5ecfc..18a88d1 100644
--- a/local.h
+++ b/local.h
@@ -46,17 +46,6 @@ struct local_socket {
  #define MONITOR_ROUTE 3
  #define MONITOR_XROUTE 4

-inline void set_flag(uint8_t *d, uint8_t flag) {
-    *d |= 0x01 << flag;
-}
-
-inline void unset_flag(uint8_t *d, uint8_t flag) {
-    *d &= ~( 0x01 << flag );
-}
-
-inline uint8_t get_flag(uint8_t *s, uint8_t flag) {
-    return *s & (0x01 << flag);
-}

  extern int local_server_socket;
  extern struct local_socket local_sockets[MAX_LOCAL_SOCKETS];
--
2.20.1




More information about the Babel-users mailing list