]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Remove many redundant #includes and do a clang format
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 19 Jun 2021 17:30:23 +0000 (18:30 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 19 Jun 2021 17:30:23 +0000 (18:30 +0100)
general-utilities.c
general-utilities.h
nqptp-clock-sources.c
nqptp-clock-sources.h
nqptp-message-handlers.c
nqptp-message-handlers.h
nqptp-shm-structures.h
nqptp-utilities.c
nqptp-utilities.h
nqptp.c
nqptp.h

index 6f024d5afe9b3c7ff9a8d82b5d6c18ad2cf004fc..87dc13d6c7a9e5353e0e1271f001e18490764c46 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "general-utilities.h"
 #include "debug.h"
-#include <arpa/inet.h>
-#include <string.h>
+#include <arpa/inet.h> // ntohl etc.
+#include <string.h>    // memcpy
 
 void hcton64(uint64_t num, uint8_t *p) {
   uint64_t numc = num;
index d8f180e29a572963d0e47b3efda6cb3a5f9cb723..071ab29796b08ce7f4a6ac3341319f711be9037f 100644 (file)
@@ -24,6 +24,7 @@
 // specialised stuff should go in the nqptp-utilities
 
 #include <inttypes.h>
+#include <sys/socket.h>
 #include <time.h>
 
 // struct sockaddr_in6 is bigger than struct sockaddr. derp
index 6a936d97f4aa5ab9a86272152bec8e73e57e80fe..b119aa73cea8974f6e43780ed7876cf4804cd8d2 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "nqptp-clock-sources.h"
 #include "debug.h"
-#include "nqptp-ptp-definitions.h"
 #include "general-utilities.h"
+#include "nqptp-ptp-definitions.h"
 #include <arpa/inet.h>
 #include <ifaddrs.h>
 #include <string.h>
@@ -165,7 +165,8 @@ void update_master() {
 
   int best_so_far = -1;
   int timing_peer_count = 0;
-  uint32_t acceptance_mask = (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid);
+  uint32_t acceptance_mask =
+      (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid);
   for (i = 0; i < MAX_CLOCKS; i++) {
     if ((clocks_private[i].flags & acceptance_mask) == acceptance_mask) {
       // found a possible clock candidate
@@ -210,11 +211,11 @@ void update_master() {
       debug(2, "No timing peer list found");
     else
       debug(1, "No master clock not found!");
-    } else {
-      // we found a master clock
-      clocks_private[best_so_far].flags |= (1 << clock_is_master);
+  } else {
+    // we found a master clock
+    clocks_private[best_so_far].flags |= (1 << clock_is_master);
 
-      if (old_master != best_so_far) {
+    if (old_master != best_so_far) {
       // clang-format off
       // Now we use the last few samples to calculate the best offset for the
       // new master clock.
@@ -299,7 +300,7 @@ void update_master() {
                                clocks_private[best_so_far].mastership_start_time);
       // clang-format on
 
-      clocks_private[best_so_far].previous_offset_time = 0;  // resync
+      clocks_private[best_so_far].previous_offset_time = 0; // resync
     }
   }
 
index b27e6e4519b2a8533dfb388597d4fd1c3fb45dd2..146b5d84bd28290fa1c7b7ee67f4435f8e7bcc9a 100644 (file)
@@ -34,9 +34,9 @@ typedef enum {
 
 // 8 samples per seconds
 #define MAX_TIMING_SAMPLES 47
- typedef struct {
-   uint64_t local_time, clock_time;
- } timing_samples;
+typedef struct {
+  uint64_t local_time, clock_time;
+} timing_samples;
 
 // information about each clock source
 typedef struct {
@@ -63,7 +63,6 @@ typedef struct {
   int next_sample_goes_here; // point to where in the timing samples array the next entries should
                              // go
 
-
   // these are for finding the best clock to use
   // See Figure 27 and 27 pp 89 -- 90 for the Data set comparison algorithm
 
index 3c76f7c63788b72eae77cfe734b8533b5040c7a7..1fcebd60ad8d623e896ac2899d5421f52339ff89 100644 (file)
  *
  * Commercial licensing is also available.
  */
-#include <arpa/inet.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
+#include <string.h> //strsep
 
 #include "debug.h"
 #include "general-utilities.h"
@@ -219,35 +216,34 @@ void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clo
 void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
                       clock_source_private_data *clock_private_info, uint64_t reception_time) {
 
-    clock_private_info->flags |= (1 << clock_is_valid); // valid because it has at least one follow_up
-    struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
+  clock_private_info->flags |= (1 << clock_is_valid); // valid because it has at least one follow_up
+  struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
 
-    uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
-    uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
-    uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
-    uint64_t preciseOriginTimestamp = seconds_hi;
-    preciseOriginTimestamp = preciseOriginTimestamp << 32;
-    preciseOriginTimestamp = preciseOriginTimestamp + seconds_low;
-    preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L;
-    preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
+  uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
+  uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
+  uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
+  uint64_t preciseOriginTimestamp = seconds_hi;
+  preciseOriginTimestamp = preciseOriginTimestamp << 32;
+  preciseOriginTimestamp = preciseOriginTimestamp + seconds_low;
+  preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L;
+  preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
 
-    // update our sample information
+  // update our sample information
 
-    clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time =
-        reception_time;
-    clock_private_info->samples[clock_private_info->next_sample_goes_here]
-        .clock_time = preciseOriginTimestamp;
+  clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time =
+      reception_time;
+  clock_private_info->samples[clock_private_info->next_sample_goes_here].clock_time =
+      preciseOriginTimestamp;
 
-    if (clock_private_info->vacant_samples > 0)
-      clock_private_info->vacant_samples--;
+  if (clock_private_info->vacant_samples > 0)
+    clock_private_info->vacant_samples--;
 
-    clock_private_info->next_sample_goes_here++;
-    // if we have need to wrap.
-    if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
-      clock_private_info->next_sample_goes_here = 0;
+  clock_private_info->next_sample_goes_here++;
+  // if we have need to wrap.
+  if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
+    clock_private_info->next_sample_goes_here = 0;
 
-
-//  if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
+  //  if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
   if (1) {
     debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id,
           &clock_private_info->ip);
@@ -308,7 +304,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
 
     uint32_t old_flags = clock_private_info->flags;
 
-    //if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
+    // if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
     //  debug(1, "clock %" PRIx64 " is now valid at: %s", packet_clock_id, clock_private_info->ip);
     //}
 
index f7daf75b3771b41cabae84ae0f5e34e645a33822..a0e28656c94de25939d4729dde390b8bb7c9a971 100644 (file)
@@ -20,9 +20,7 @@
 #ifndef NQPTP_MESSAGE_HANDLERS_H
 #define NQPTP_MESSAGE_HANDLERS_H
 
-#include "general-utilities.h"
 #include "nqptp-clock-sources.h"
-#include "nqptp-shm-structures.h"
 
 void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
                      uint64_t reception_time);
index 9704644e0c8834c09dd52361b1d83bcc61161efe..36c8a8131da355033f21c30a320fed7a0fd1fd16 100644 (file)
@@ -32,7 +32,6 @@
 // The IPs will become the new list of timing peers, replacing any previous
 
 #include <inttypes.h>
-#include <netinet/in.h>
 #include <pthread.h>
 
 struct shm_structure {
index 6a5904cfe537074168b98436d8648a86fdef9340..dec439ad97aa04204449d5091cbfc2fb8a1553fd 100644 (file)
  */
 
 #include "nqptp-utilities.h"
-#include "general-utilities.h"
-#include "nqptp-ptp-definitions.h"
 #include <errno.h>
-#include <fcntl.h>
-#include <ifaddrs.h>
-#include <linux/if_packet.h>
-#include <linux/net_tstamp.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/types.h>
+#include <fcntl.h>            // fcntl etc.
+#include <ifaddrs.h>          // getifaddrs
+#include <linux/if_packet.h>  // sockaddr_ll
+#include <linux/net_tstamp.h> // SOF_TIMESTAMPING_TX_HARDWARE and friends
+#include <netdb.h>            // getaddrinfo etc.
+#include <stdio.h>            // snprintf
+#include <stdlib.h>           // malloc, free
+#include <string.h>           // memset strcpy, etc.
 
 #include "debug.h"
 
index fb6d83d4ac2b406a7cfff2b655318dbf0a7527a1..66367a8be2d759c61b800ba62cd44cde75d51068 100644 (file)
 
 #ifndef NQPTP_UTILITIES_H
 #define NQPTP_UTILITIES_H
+
 #include "nqptp.h"
-#include <stddef.h>
+#include <inttypes.h>
+#include <pthread.h>
+
 // functions that are specific to NQPTP
 // general stuff should go in the general-utilities
 
diff --git a/nqptp.c b/nqptp.c
index 5dc66471b7c5d3a44bfdba2364b46226b4800d7f..a1d3f48189f99dbb2204a4b73db1ee4cd21ca753 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
 #include "gitversion.h"
 #endif
 
-#include <arpa/inet.h>
-#include <stdio.h>  //printf
-#include <stdlib.h> //malloc;
-#include <string.h> //memset
-#include <sys/socket.h>
-#include <unistd.h> // close
-
-#include <ifaddrs.h>
-#include <pthread.h>
-#include <sys/types.h>
+#include <arpa/inet.h> // inet_ntop
+#include <stdio.h>     // printf
+#include <stdlib.h>    // malloc;
+#include <string.h>    // memset
 
 #include <errno.h>
-#include <netdb.h>
-#include <time.h>
-
-#include <linux/if_packet.h>
-#include <net/ethernet.h> /* the L2 protocols */
-#include <sys/ioctl.h>
-
-#include <inttypes.h>
-
-#include <asm/types.h>
-#include <linux/errqueue.h>
-#include <linux/net_tstamp.h>
+#include <unistd.h> // close
 
-#include <fcntl.h> /* For O_* constants */
-#include <sys/mman.h>
-#include <sys/stat.h> /* For mode constants */
+#include <fcntl.h>    /* For O_* constants */
+#include <sys/mman.h> // for shared memory stuff
+#include <sys/stat.h> // umask
 
-#include <grp.h>
+#include <grp.h> // group stuff
 
-#include <signal.h>
+#include <signal.h> // SIGTERM and stuff like that
 #include <sys/epoll.h>
 
 #ifndef FIELD_SIZEOF
@@ -141,12 +124,12 @@ int main(int argc, char **argv) {
 #ifdef CONFIG_USE_GIT_VERSION_STRING
         if (git_version_string[0] != '\0')
           fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", git_version_string,
-                NQPTP_SHM_STRUCTURES_VERSION);
+                  NQPTP_SHM_STRUCTURES_VERSION);
         else
 #endif
 
-        fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION,
-                NQPTP_SHM_STRUCTURES_VERSION);
+          fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION,
+                  NQPTP_SHM_STRUCTURES_VERSION);
         exit(EXIT_SUCCESS);
       } else if (strcmp(argv[i] + 1, "vvv") == 0) {
         debug_level = 3;
diff --git a/nqptp.h b/nqptp.h
index 8d7d18a9dc7535095b75028b2ecd26db090f7039..327aba921add22eaf95cbdaf35125fda5fa93a8a 100644 (file)
--- a/nqptp.h
+++ b/nqptp.h
@@ -20,6 +20,9 @@
 #ifndef NQPTP_H
 #define NQPTP_H
 
+#include <inttypes.h>
+#include <pthread.h>
+
 #include "nqptp-shm-structures.h"
 
 #define MAX_OPEN_SOCKETS 16
@@ -35,4 +38,3 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t
                               uint64_t local_to_master_offset, uint64_t mastership_start_time);
 
 #endif
-