Signed-off-by: Anders Selhammer <anders.selham...@est.tech>
---
 bmc.c          | 2 ++
 bmc.h          | 9 ++++++---
 clock.c        | 7 ++++++-
 clock.h        | 8 ++++++++
 port.c         | 5 +++--
 port_private.h | 1 -
 6 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/bmc.c b/bmc.c
index 857d22c..a2103b5 100644
--- a/bmc.c
+++ b/bmc.c
@@ -19,7 +19,9 @@
 #include <string.h>
 
 #include "bmc.h"
+#include "clock.h"
 #include "ds.h"
+#include "port.h"
 
 int dscmp2(struct dataset *a, struct dataset *b)
 {
diff --git a/bmc.h b/bmc.h
index e2fbf3b..b34818b 100644
--- a/bmc.h
+++ b/bmc.h
@@ -20,15 +20,18 @@
 #ifndef HAVE_BMC_H
 #define HAVE_BMC_H
 
-#include "clock.h"
-#include "port.h"
-#include "fsm.h"
+#include "ds.h"
 
 #define A_BETTER_TOPO  2
 #define A_BETTER       1
 #define B_BETTER      -1
 #define B_BETTER_TOPO -2
 
+typedef int (*dscmp_type)(struct dataset*, struct dataset*);
+
+struct clock; /*forward declaration*/
+struct port; /*forward declaration*/
+
 /**
  * BMC state decision algorithm.
  * @param c  The local clock.
diff --git a/clock.c b/clock.c
index afee960..1a863df 100644
--- a/clock.c
+++ b/clock.c
@@ -80,7 +80,7 @@ struct clock {
        clockid_t clkid;
        struct servo *servo;
        enum servo_type servo_type;
-       int (*dscmp)(struct dataset *a, struct dataset *b);
+       dscmp_type dscmp;
        struct defaultDS dds;
        struct dataset default_dataset;
        struct currentDS cur;
@@ -748,6 +748,11 @@ static int forwarding(struct clock *c, struct port *p)
 
 /* public methods */
 
+dscmp_type clock_dscmp(struct clock *c)
+{
+       return c->dscmp;
+}
+
 UInteger8 clock_class(struct clock *c)
 {
        return c->dds.clockQuality.clockClass;
diff --git a/clock.h b/clock.h
index 3fa026d..b2bdc3f 100644
--- a/clock.h
+++ b/clock.h
@@ -20,6 +20,7 @@
 #ifndef HAVE_CLOCK_H
 #define HAVE_CLOCK_H
 
+#include "bmc.h"
 #include "dm.h"
 #include "ds.h"
 #include "config.h"
@@ -59,6 +60,13 @@ struct dataset *clock_best_foreign(struct clock *c);
 struct port *clock_best_port(struct clock *c);
 
 /**
+ * Obtains the dscmp function used in bmca.
+ * @param c  The clock instance.
+ * @return   A pointer to the dscmp function.
+ */
+dscmp_type clock_dscmp(struct clock *c);
+
+/**
  * Obtain the clockClass attribute from a clock.
  * @param c  The clock instance.
  * @return   The value of the clock's class.
diff --git a/port.c b/port.c
index 1757dfe..593991f 100644
--- a/port.c
+++ b/port.c
@@ -2193,6 +2193,8 @@ struct foreign_clock *port_compute_best(struct port *p)
 {
        struct foreign_clock *fc;
        struct ptp_message *tmp;
+       dscmp_type dscmp = clock_dscmp(p->clock);
+
 
        p->best = NULL;
 
@@ -2210,7 +2212,7 @@ struct foreign_clock *port_compute_best(struct port *p)
 
                if (!p->best)
                        p->best = fc;
-               else if (p->dscmp(&fc->dataset, &p->best->dataset) > 0)
+               else if (dscmp(&fc->dataset, &p->best->dataset) > 0)
                        p->best = fc;
                else
                        fc_clear(fc);
@@ -2784,7 +2786,6 @@ struct port *port_open(int phc_index,
        }
 
        p->state_machine = clock_slave_only(clock) ? ptp_slave_fsm : ptp_fsm;
-       p->dscmp = dscmp;
        p->phc_index = phc_index;
        p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod");
        transport = config_get_int(cfg, interface->name, "network_transport");
diff --git a/port_private.h b/port_private.h
index 860a2bb..f8771c7 100644
--- a/port_private.h
+++ b/port_private.h
@@ -88,7 +88,6 @@ struct port {
        unsigned int multiple_pdr_detected;
        enum port_state (*state_machine)(enum port_state state,
                                         enum fsm_event event, int mdiff);
-       int (*dscmp)(struct dataset *a, struct dataset *b);
        /* portDS */
        struct PortIdentity portIdentity;
        enum port_state     state; /*portState*/
-- 
1.8.3.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to