The ts2phc program will introduce clock synchronization which is
orthogonal to the direction in which PPS is emitted (from the master
to the slave).

To have a more consistent terminology, we can avoid using the
ultra-generic term "master" and replace it with "PPS source", which
describes the role of the data structure in the new interpretation of
the program in a much clearer way.

Signed-off-by: Vladimir Oltean <olte...@gmail.com>
---
v4->v5: patch is new

 ts2phc.c                    |  56 +++++++++---------
 ts2phc_generic_pps_source.c |  32 +++++-----
 ts2phc_generic_pps_source.h |   8 +--
 ts2phc_nmea_pps_source.c    | 113 ++++++++++++++++++------------------
 ts2phc_nmea_pps_source.h    |   8 +--
 ts2phc_phc_pps_source.c     |  66 ++++++++++-----------
 ts2phc_phc_pps_source.h     |   8 +--
 ts2phc_pps_sink.c           |  10 ++--
 ts2phc_pps_sink.h           |   2 +-
 ts2phc_pps_source.c         |  30 +++++-----
 ts2phc_pps_source.h         |  36 ++++++------
 ts2phc_pps_source_private.h |  10 ++--
 12 files changed, 190 insertions(+), 189 deletions(-)

diff --git a/ts2phc.c b/ts2phc.c
index 812ac78b4875..6004e04effdd 100644
--- a/ts2phc.c
+++ b/ts2phc.c
@@ -19,11 +19,11 @@ struct interface {
        STAILQ_ENTRY(interface) list;
 };
 
-static void ts2phc_cleanup(struct config *cfg, struct ts2phc_master *master)
+static void ts2phc_cleanup(struct config *cfg, struct ts2phc_pps_source *src)
 {
        ts2phc_pps_sink_cleanup();
-       if (master) {
-               ts2phc_master_destroy(master);
+       if (src) {
+               ts2phc_pps_source_destroy(src);
        }
        if (cfg) {
                config_destroy(cfg);
@@ -56,8 +56,8 @@ static void usage(char *progname)
 int main(int argc, char *argv[])
 {
        int c, err = 0, have_sink = 0, index, print_level;
-       struct ts2phc_master *master = NULL;
-       enum ts2phc_master_type pps_type;
+       struct ts2phc_pps_source *src = NULL;
+       enum ts2phc_pps_source_type pps_type;
        char *config = NULL, *progname;
        const char *pps_source = NULL;
        struct config *cfg = NULL;
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
 
        cfg = config_create();
        if (!cfg) {
-               ts2phc_cleanup(cfg, master);
+               ts2phc_cleanup(cfg, src);
                return -1;
        }
 
@@ -81,14 +81,14 @@ int main(int argc, char *argv[])
                switch (c) {
                case 0:
                        if (config_parse_option(cfg, opts[index].name, optarg)) 
{
-                               ts2phc_cleanup(cfg, master);
+                               ts2phc_cleanup(cfg, src);
                                return -1;
                        }
                        break;
                case 'c':
                        if (!config_create_interface(optarg, cfg)) {
                                fprintf(stderr, "failed to add PPS sink\n");
-                               ts2phc_cleanup(cfg, master);
+                               ts2phc_cleanup(cfg, src);
                                return -1;
                        }
                        have_sink = 1;
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
                case 'l':
                        if (get_arg_val_i(c, optarg, &print_level,
                                          PRINT_LEVEL_MIN, PRINT_LEVEL_MAX)) {
-                               ts2phc_cleanup(cfg, master);
+                               ts2phc_cleanup(cfg, src);
                                return -1;
                        }
                        config_set_int(cfg, "logging_level", print_level);
@@ -116,29 +116,29 @@ int main(int argc, char *argv[])
                case 's':
                        if (pps_source) {
                                fprintf(stderr, "too many PPS sources\n");
-                               ts2phc_cleanup(cfg, master);
+                               ts2phc_cleanup(cfg, src);
                                return -1;
                        }
                        pps_source = optarg;
                        break;
                case 'v':
-                       ts2phc_cleanup(cfg, master);
+                       ts2phc_cleanup(cfg, src);
                        version_show(stdout);
                        return 0;
                case 'h':
-                       ts2phc_cleanup(cfg, master);
+                       ts2phc_cleanup(cfg, src);
                        usage(progname);
                        return -1;
                case '?':
                default:
-                       ts2phc_cleanup(cfg, master);
+                       ts2phc_cleanup(cfg, src);
                        usage(progname);
                        return -1;
                }
        }
        if (config && (c = config_read(config, cfg))) {
                fprintf(stderr, "failed to read config\n");
-               ts2phc_cleanup(cfg, master);
+               ts2phc_cleanup(cfg, src);
                return -1;
        }
        print_set_progname(progname);
@@ -151,14 +151,14 @@ int main(int argc, char *argv[])
                if (1 == config_get_int(cfg, interface_name(iface), 
"ts2phc.master")) {
                        if (pps_source) {
                                fprintf(stderr, "too many PPS sources\n");
-                               ts2phc_cleanup(cfg, master);
+                               ts2phc_cleanup(cfg, src);
                                return -1;
                        }
                        pps_source = interface_name(iface);
                } else {
                        if (ts2phc_pps_sink_add(cfg, interface_name(iface))) {
                                fprintf(stderr, "failed to add PPS sink\n");
-                               ts2phc_cleanup(cfg, master);
+                               ts2phc_cleanup(cfg, src);
                                return -1;
                        }
                        have_sink = 1;
@@ -166,44 +166,44 @@ int main(int argc, char *argv[])
        }
        if (!have_sink) {
                fprintf(stderr, "no PPS sinks specified\n");
-               ts2phc_cleanup(cfg, master);
+               ts2phc_cleanup(cfg, src);
                usage(progname);
                return -1;
        }
        if (!pps_source) {
                fprintf(stderr, "no PPS source specified\n");
-               ts2phc_cleanup(cfg, master);
+               ts2phc_cleanup(cfg, src);
                usage(progname);
                return -1;
        }
        if (ts2phc_pps_sink_arm()) {
                fprintf(stderr, "failed to arm PPS sinks\n");
-               ts2phc_cleanup(cfg, master);
+               ts2phc_cleanup(cfg, src);
                return -1;
        }
 
        if (!strcasecmp(pps_source, "generic")) {
-               pps_type = TS2PHC_MASTER_GENERIC;
+               pps_type = TS2PHC_PPS_SOURCE_GENERIC;
        } else if (!strcasecmp(pps_source, "nmea")) {
-               pps_type = TS2PHC_MASTER_NMEA;
+               pps_type = TS2PHC_PPS_SOURCE_NMEA;
        } else {
-               pps_type = TS2PHC_MASTER_PHC;
+               pps_type = TS2PHC_PPS_SOURCE_PHC;
        }
-       master = ts2phc_master_create(cfg, pps_source, pps_type);
-       if (!master) {
-               fprintf(stderr, "failed to create master\n");
-               ts2phc_cleanup(cfg, master);
+       src = ts2phc_pps_source_create(cfg, pps_source, pps_type);
+       if (!src) {
+               fprintf(stderr, "failed to create PPS source\n");
+               ts2phc_cleanup(cfg, src);
                return -1;
        }
 
        while (is_running()) {
-               err = ts2phc_pps_sink_poll(master);
+               err = ts2phc_pps_sink_poll(src);
                if (err) {
                        pr_err("poll failed");
                        break;
                }
        }
 
-       ts2phc_cleanup(cfg, master);
+       ts2phc_cleanup(cfg, src);
        return err;
 }
diff --git a/ts2phc_generic_pps_source.c b/ts2phc_generic_pps_source.c
index 0afea8ec1594..397031fe2521 100644
--- a/ts2phc_generic_pps_source.c
+++ b/ts2phc_generic_pps_source.c
@@ -1,5 +1,5 @@
 /**
- * @file ts2phc_generic_master.c
+ * @file ts2phc_generic_pps_source.c
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
@@ -12,14 +12,14 @@
 #include "ts2phc_pps_source_private.h"
 #include "util.h"
 
-struct ts2phc_generic_master {
-       struct ts2phc_master master;
+struct ts2phc_generic_pps_source {
+       struct ts2phc_pps_source pps_source;
 };
 
-static void ts2phc_generic_master_destroy(struct ts2phc_master *master)
+static void ts2phc_generic_pps_source_destroy(struct ts2phc_pps_source *src)
 {
-       struct ts2phc_generic_master *s =
-               container_of(master, struct ts2phc_generic_master, master);
+       struct ts2phc_generic_pps_source *s =
+               container_of(src, struct ts2phc_generic_pps_source, pps_source);
        free(s);
 }
 
@@ -28,8 +28,8 @@ static void ts2phc_generic_master_destroy(struct 
ts2phc_master *master)
  * PPS event was generated.  This implementation assumes that the
  * system time is approximately correct.
  */
-static int ts2phc_generic_master_getppstime(struct ts2phc_master *m,
-                                           struct timespec *ts)
+static int ts2phc_generic_pps_source_getppstime(struct ts2phc_pps_source *src,
+                                               struct timespec *ts)
 {
        struct timex ntx;
        int code;
@@ -47,17 +47,17 @@ static int ts2phc_generic_master_getppstime(struct 
ts2phc_master *m,
        return 0;
 }
 
-struct ts2phc_master *ts2phc_generic_master_create(struct config *cfg,
-                                                  const char *dev)
+struct ts2phc_pps_source *ts2phc_generic_pps_source_create(struct config *cfg,
+                                                          const char *dev)
 {
-       struct ts2phc_generic_master *master;
+       struct ts2phc_generic_pps_source *src;
 
-       master = calloc(1, sizeof(*master));
-       if (!master) {
+       src = calloc(1, sizeof(*src));
+       if (!src) {
                return NULL;
        }
-       master->master.destroy = ts2phc_generic_master_destroy;
-       master->master.getppstime = ts2phc_generic_master_getppstime;
+       src->pps_source.destroy = ts2phc_generic_pps_source_destroy;
+       src->pps_source.getppstime = ts2phc_generic_pps_source_getppstime;
 
-       return &master->master;
+       return &src->pps_source;
 }
diff --git a/ts2phc_generic_pps_source.h b/ts2phc_generic_pps_source.h
index 94ab29b30bcb..e169ab380ccf 100644
--- a/ts2phc_generic_pps_source.h
+++ b/ts2phc_generic_pps_source.h
@@ -3,12 +3,12 @@
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
-#ifndef HAVE_TS2PHC_GENERIC_MASTER_H
-#define HAVE_TS2PHC_GENERIC_MASTER_H
+#ifndef HAVE_TS2PHC_GENERIC_PPS_SOURCE_H
+#define HAVE_TS2PHC_GENERIC_PPS_SOURCE_H
 
 #include "ts2phc_pps_source.h"
 
-struct ts2phc_master *ts2phc_generic_master_create(struct config *cfg,
-                                                  const char *dev);
+struct ts2phc_pps_source *ts2phc_generic_pps_source_create(struct config *cfg,
+                                                          const char *dev);
 
 #endif
diff --git a/ts2phc_nmea_pps_source.c b/ts2phc_nmea_pps_source.c
index 17ba9883e724..52a96955f3ce 100644
--- a/ts2phc_nmea_pps_source.c
+++ b/ts2phc_nmea_pps_source.c
@@ -26,8 +26,8 @@
 #define MAX_RMC_AGE    5000000000ULL
 #define NMEA_TMO       2000 /*milliseconds*/
 
-struct ts2phc_nmea_master {
-       struct ts2phc_master master;
+struct ts2phc_nmea_pps_source {
+       struct ts2phc_pps_source pps_source;
        struct config *config;
        const char *leapfile;
        time_t lsfile_mtime;
@@ -67,7 +67,7 @@ static void *monitor_nmea_status(void *arg)
        struct nmea_parser *np = nmea_parser_create();
        struct pollfd pfd = { -1, POLLIN | POLLPRI };
        char *host, input[256], *port, *ptr, *uart;
-       struct ts2phc_nmea_master *master = arg;
+       struct ts2phc_nmea_pps_source *s = arg;
        struct timespec rxtime, tmo = { 2, 0 };
        int cnt, num, parsed, baud;
        struct nmea_rmc rmc;
@@ -77,10 +77,10 @@ static void *monitor_nmea_status(void *arg)
                pr_err("failed to create NMEA parser");
                return NULL;
        }
-       host = config_get_string(master->config, NULL, 
"ts2phc.nmea_remote_host");
-       port = config_get_string(master->config, NULL, 
"ts2phc.nmea_remote_port");
-       uart = config_get_string(master->config, NULL, 
"ts2phc.nmea_serialport");
-       baud = config_get_int(master->config, NULL, "ts2phc.nmea_baudrate");
+       host = config_get_string(s->config, NULL, "ts2phc.nmea_remote_host");
+       port = config_get_string(s->config, NULL, "ts2phc.nmea_remote_port");
+       uart = config_get_string(s->config, NULL, "ts2phc.nmea_serialport");
+       baud = config_get_int(s->config, NULL, "ts2phc.nmea_baudrate");
        memset(&ntx, 0, sizeof(ntx));
        ntx.modes = ADJ_NANO;
 
@@ -124,13 +124,13 @@ static void *monitor_nmea_status(void *arg)
                ptr = input;
                do {
                        if (!nmea_parse(np, ptr, cnt, &rmc, &parsed)) {
-                               pthread_mutex_lock(&master->mutex);
-                               master->local_monotime = rxtime;
-                               master->local_utctime.tv_sec = ntx.time.tv_sec;
-                               master->local_utctime.tv_nsec = 
ntx.time.tv_usec;
-                               master->rmc_utctime = rmc.ts;
-                               master->rmc_fix_valid = rmc.fix_valid;
-                               pthread_mutex_unlock(&master->mutex);
+                               pthread_mutex_lock(&s->mutex);
+                               s->local_monotime = rxtime;
+                               s->local_utctime.tv_sec = ntx.time.tv_sec;
+                               s->local_utctime.tv_nsec = ntx.time.tv_usec;
+                               s->rmc_utctime = rmc.ts;
+                               s->rmc_fix_valid = rmc.fix_valid;
+                               pthread_mutex_unlock(&s->mutex);
                        }
                        cnt -= parsed;
                        ptr += parsed;
@@ -144,49 +144,49 @@ static void *monitor_nmea_status(void *arg)
        return NULL;
 }
 
-static int update_leapsecond_table(struct ts2phc_nmea_master *master)
+static int update_leapsecond_table(struct ts2phc_nmea_pps_source *s)
 {
        struct stat statbuf;
        int err;
 
-       if (!master->leapfile) {
+       if (!s->leapfile) {
                return 0;
        }
-       err = stat(master->leapfile, &statbuf);
+       err = stat(s->leapfile, &statbuf);
        if (err) {
-               pr_err("nmea: file status failed on %s: %m", master->leapfile);
+               pr_err("nmea: file status failed on %s: %m", s->leapfile);
                return -1;
        }
-       if (master->lsfile_mtime == statbuf.st_mtim.tv_sec) {
+       if (s->lsfile_mtime == statbuf.st_mtim.tv_sec) {
                return 0;
        }
        pr_info("nmea: updating leap seconds file");
-       if (master->lstab) {
-               lstab_destroy(master->lstab);
+       if (s->lstab) {
+               lstab_destroy(s->lstab);
        }
-       master->lstab = lstab_create(master->leapfile);
-       if (!master->lstab) {
+       s->lstab = lstab_create(s->leapfile);
+       if (!s->lstab) {
                return -1;
        }
-       master->lsfile_mtime = statbuf.st_mtim.tv_sec;
+       s->lsfile_mtime = statbuf.st_mtim.tv_sec;
        return 0;
 }
 
-static void ts2phc_nmea_master_destroy(struct ts2phc_master *master)
+static void ts2phc_nmea_pps_source_destroy(struct ts2phc_pps_source *src)
 {
-       struct ts2phc_nmea_master *m =
-               container_of(master, struct ts2phc_nmea_master, master);
-       pthread_join(m->worker, NULL);
-       pthread_mutex_destroy(&m->mutex);
-       lstab_destroy(m->lstab);
-       free(m);
+       struct ts2phc_nmea_pps_source *s =
+               container_of(src, struct ts2phc_nmea_pps_source, pps_source);
+       pthread_join(s->worker, NULL);
+       pthread_mutex_destroy(&s->mutex);
+       lstab_destroy(s->lstab);
+       free(s);
 }
 
-static int ts2phc_nmea_master_getppstime(struct ts2phc_master *master,
-                                        struct timespec *ts)
+static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
+                                            struct timespec *ts)
 {
-       struct ts2phc_nmea_master *m =
-               container_of(master, struct ts2phc_nmea_master, master);
+       struct ts2phc_nmea_pps_source *m =
+               container_of(src, struct ts2phc_nmea_pps_source, pps_source);
        tmv_t delay_t1, delay_t2, duration_since_rmc, local_t1, local_t2, rmc;
        int lstab_error = 0, tai_offset = 0;
        enum lstab_result result;
@@ -249,42 +249,43 @@ static int ts2phc_nmea_master_getppstime(struct 
ts2phc_master *master,
        return lstab_error;
 }
 
-struct ts2phc_master *ts2phc_nmea_master_create(struct config *cfg, const char 
*dev)
+struct ts2phc_pps_source *ts2phc_nmea_pps_source_create(struct config *cfg,
+                                                       const char *dev)
 {
-       struct ts2phc_nmea_master *master;
+       struct ts2phc_nmea_pps_source *s;
        struct stat statbuf;
        int err;
 
-       master = calloc(1, sizeof(*master));
-       if (!master) {
+       s = calloc(1, sizeof(*s));
+       if (!s) {
                return NULL;
        }
-       master->leapfile = config_get_string(cfg, NULL, "leapfile");
-       master->lstab = lstab_create(master->leapfile);
-       if (!master->lstab) {
-               free(master);
+       s->leapfile = config_get_string(cfg, NULL, "leapfile");
+       s->lstab = lstab_create(s->leapfile);
+       if (!s->lstab) {
+               free(s);
                return NULL;
        }
-       if (master->leapfile) {
-               err = stat(master->leapfile, &statbuf);
+       if (s->leapfile) {
+               err = stat(s->leapfile, &statbuf);
                if (err) {
-                       lstab_destroy(master->lstab);
-                       free(master);
+                       lstab_destroy(s->lstab);
+                       free(s);
                        return NULL;
                }
-               master->lsfile_mtime = statbuf.st_mtim.tv_sec;
+               s->lsfile_mtime = statbuf.st_mtim.tv_sec;
        }
-       master->master.destroy = ts2phc_nmea_master_destroy;
-       master->master.getppstime = ts2phc_nmea_master_getppstime;
-       master->config = cfg;
-       pthread_mutex_init(&master->mutex, NULL);
-       err = pthread_create(&master->worker, NULL, monitor_nmea_status, 
master);
+       s->pps_source.destroy = ts2phc_nmea_pps_source_destroy;
+       s->pps_source.getppstime = ts2phc_nmea_pps_source_getppstime;
+       s->config = cfg;
+       pthread_mutex_init(&s->mutex, NULL);
+       err = pthread_create(&s->worker, NULL, monitor_nmea_status, s);
        if (err) {
                pr_err("failed to create worker thread: %s", strerror(err));
-               lstab_destroy(master->lstab);
-               free(master);
+               lstab_destroy(s->lstab);
+               free(s);
                return NULL;
        }
 
-       return &master->master;
+       return &s->pps_source;
 }
diff --git a/ts2phc_nmea_pps_source.h b/ts2phc_nmea_pps_source.h
index d05be1cc31a0..c14d8d741bb6 100644
--- a/ts2phc_nmea_pps_source.h
+++ b/ts2phc_nmea_pps_source.h
@@ -3,11 +3,11 @@
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
-#ifndef HAVE_TS2PHC_NMEA_MASTER_H
-#define HAVE_TS2PHC_NMEA_MASTER_H
+#ifndef HAVE_TS2PHC_NMEA_PPS_SOURCE_H
+#define HAVE_TS2PHC_NMEA_PPS_SOURCE_H
 
 #include "ts2phc_pps_source.h"
 
-struct ts2phc_master *ts2phc_nmea_master_create(struct config *cfg,
-                                               const char *dev);
+struct ts2phc_pps_source *ts2phc_nmea_pps_source_create(struct config *cfg,
+                                                       const char *dev);
 #endif
diff --git a/ts2phc_phc_pps_source.c b/ts2phc_phc_pps_source.c
index faf9bb779684..ffb96ef7299a 100644
--- a/ts2phc_phc_pps_source.c
+++ b/ts2phc_phc_pps_source.c
@@ -16,15 +16,15 @@
 #include "ts2phc_phc_pps_source.h"
 #include "util.h"
 
-struct ts2phc_phc_master {
-       struct ts2phc_master master;
+struct ts2phc_phc_pps_source {
+       struct ts2phc_pps_source pps_source;
        clockid_t clkid;
        int channel;
        int fd;
 };
 
-static int ts2phc_phc_master_activate(struct config *cfg, const char *dev,
-                                     struct ts2phc_phc_master *master)
+static int ts2phc_phc_pps_source_activate(struct config *cfg, const char *dev,
+                                         struct ts2phc_phc_pps_source *s)
 {
        struct ptp_perout_request perout_request;
        struct ptp_pin_desc desc;
@@ -32,37 +32,37 @@ static int ts2phc_phc_master_activate(struct config *cfg, 
const char *dev,
 
        memset(&desc, 0, sizeof(desc));
 
-       master->channel = config_get_int(cfg, dev, "ts2phc.channel");
+       s->channel = config_get_int(cfg, dev, "ts2phc.channel");
 
        desc.index = config_get_int(cfg, dev, "ts2phc.pin_index");
        desc.func = PTP_PF_PEROUT;
-       desc.chan = master->channel;
+       desc.chan = s->channel;
 
-       if (phc_pin_setfunc(master->clkid, &desc)) {
+       if (phc_pin_setfunc(s->clkid, &desc)) {
                pr_warning("Failed to set the pin. Continuing bravely on...");
        }
-       if (clock_gettime(master->clkid, &ts)) {
+       if (clock_gettime(s->clkid, &ts)) {
                perror("clock_gettime");
                return -1;
        }
        memset(&perout_request, 0, sizeof(perout_request));
-       perout_request.index = master->channel;
+       perout_request.index = s->channel;
        perout_request.start.sec = ts.tv_sec + 2;
        perout_request.start.nsec = 0;
        perout_request.period.sec = 1;
        perout_request.period.nsec = 0;
 
-       if (ioctl(master->fd, PTP_PEROUT_REQUEST2, &perout_request)) {
+       if (ioctl(s->fd, PTP_PEROUT_REQUEST2, &perout_request)) {
                pr_err(PTP_PEROUT_REQUEST_FAILED);
                return -1;
        }
        return 0;
 }
 
-static void ts2phc_phc_master_destroy(struct ts2phc_master *master)
+static void ts2phc_phc_pps_source_destroy(struct ts2phc_pps_source *src)
 {
-       struct ts2phc_phc_master *m =
-               container_of(master, struct ts2phc_phc_master, master);
+       struct ts2phc_phc_pps_source *m =
+               container_of(src, struct ts2phc_phc_pps_source, pps_source);
        struct ptp_perout_request perout_request;
 
        memset(&perout_request, 0, sizeof(perout_request));
@@ -74,40 +74,40 @@ static void ts2phc_phc_master_destroy(struct ts2phc_master 
*master)
        free(m);
 }
 
-static int ts2phc_phc_master_getppstime(struct ts2phc_master *m,
-                                       struct timespec *ts)
+static int ts2phc_phc_pps_source_getppstime(struct ts2phc_pps_source *src,
+                                           struct timespec *ts)
 {
-       struct ts2phc_phc_master *master =
-               container_of(m, struct ts2phc_phc_master, master);
-       return clock_gettime(master->clkid, ts);
+       struct ts2phc_phc_pps_source *s =
+               container_of(src, struct ts2phc_phc_pps_source, pps_source);
+       return clock_gettime(s->clkid, ts);
 }
 
-struct ts2phc_master *ts2phc_phc_master_create(struct config *cfg,
-                                              const char *dev)
+struct ts2phc_pps_source *ts2phc_phc_pps_source_create(struct config *cfg,
+                                                      const char *dev)
 {
-       struct ts2phc_phc_master *master;
+       struct ts2phc_phc_pps_source *s;
        int junk;
 
-       master = calloc(1, sizeof(*master));
-       if (!master) {
+       s = calloc(1, sizeof(*s));
+       if (!s) {
                return NULL;
        }
-       master->master.destroy = ts2phc_phc_master_destroy;
-       master->master.getppstime = ts2phc_phc_master_getppstime;
+       s->pps_source.destroy = ts2phc_phc_pps_source_destroy;
+       s->pps_source.getppstime = ts2phc_phc_pps_source_getppstime;
 
-       master->clkid = posix_clock_open(dev, &junk);
-       if (master->clkid == CLOCK_INVALID) {
-               free(master);
+       s->clkid = posix_clock_open(dev, &junk);
+       if (s->clkid == CLOCK_INVALID) {
+               free(s);
                return NULL;
        }
-       master->fd = CLOCKID_TO_FD(master->clkid);
+       s->fd = CLOCKID_TO_FD(s->clkid);
 
-       pr_debug("PHC master %s has ptp index %d", dev, junk);
+       pr_debug("PHC PPS source %s has ptp index %d", dev, junk);
 
-       if (ts2phc_phc_master_activate(cfg, dev, master)) {
-               ts2phc_phc_master_destroy(&master->master);
+       if (ts2phc_phc_pps_source_activate(cfg, dev, s)) {
+               ts2phc_phc_pps_source_destroy(&s->pps_source);
                return NULL;
        }
 
-       return &master->master;
+       return &s->pps_source;
 }
diff --git a/ts2phc_phc_pps_source.h b/ts2phc_phc_pps_source.h
index d0e130066068..c9ab54ecd259 100644
--- a/ts2phc_phc_pps_source.h
+++ b/ts2phc_phc_pps_source.h
@@ -3,12 +3,12 @@
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
-#ifndef HAVE_TS2PHC_PHC_MASTER_H
-#define HAVE_TS2PHC_PHC_MASTER_H
+#ifndef HAVE_TS2PHC_PHC_PPS_SOURCE_H
+#define HAVE_TS2PHC_PHC_PPS_SOURCE_H
 
 #include "ts2phc_pps_source.h"
 
-struct ts2phc_master *ts2phc_phc_master_create(struct config *cfg,
-                                              const char *dev);
+struct ts2phc_pps_source *ts2phc_phc_pps_source_create(struct config *cfg,
+                                                      const char *dev);
 
 #endif
diff --git a/ts2phc_pps_sink.c b/ts2phc_pps_sink.c
index 7da850c718eb..278c79e22d65 100644
--- a/ts2phc_pps_sink.c
+++ b/ts2phc_pps_sink.c
@@ -268,19 +268,19 @@ static int ts2phc_pps_sink_event(struct ts2phc_pps_sink 
*sink,
        }
 
        if (sink->no_adj) {
-               pr_info("%s master offset %10" PRId64, sink->name, offset);
+               pr_info("%s source offset %10" PRId64, sink->name, offset);
                return 0;
        }
 
        if (!source_ts.valid) {
-               pr_debug("%s ignoring invalid master time stamp", sink->name);
+               pr_debug("%s ignoring invalid source time stamp", sink->name);
                return 0;
        }
 
        adj = servo_sample(sink->servo, offset, extts_ts,
                           SAMPLE_WEIGHT, &sink->state);
 
-       pr_debug("%s master offset %10" PRId64 " s%d freq %+7.0f",
+       pr_debug("%s source offset %10" PRId64 " s%d freq %+7.0f",
                 sink->name, offset, sink->state, adj);
 
        switch (sink->state) {
@@ -402,7 +402,7 @@ void ts2phc_pps_sink_cleanup(void)
        }
 }
 
-int ts2phc_pps_sink_poll(struct ts2phc_master *master)
+int ts2phc_pps_sink_poll(struct ts2phc_pps_source *src)
 {
        struct ts2phc_source_timestamp source_ts;
        unsigned int i;
@@ -424,7 +424,7 @@ int ts2phc_pps_sink_poll(struct ts2phc_master *master)
                return 0;
        }
 
-       err = ts2phc_master_getppstime(master, &source_ts.ts);
+       err = ts2phc_pps_source_getppstime(src, &source_ts.ts);
        source_ts.valid = err ? false : true;
 
        for (i = 0; i < ts2phc_n_sinks; i++) {
diff --git a/ts2phc_pps_sink.h b/ts2phc_pps_sink.h
index 47afc2f04e34..e2518d726c29 100644
--- a/ts2phc_pps_sink.h
+++ b/ts2phc_pps_sink.h
@@ -15,6 +15,6 @@ int ts2phc_pps_sink_arm(void);
 
 void ts2phc_pps_sink_cleanup(void);
 
-int ts2phc_pps_sink_poll(struct ts2phc_master *master);
+int ts2phc_pps_sink_poll(struct ts2phc_pps_source *src);
 
 #endif
diff --git a/ts2phc_pps_source.c b/ts2phc_pps_source.c
index a2e8ed5ccd4b..ab8e899b962b 100644
--- a/ts2phc_pps_source.c
+++ b/ts2phc_pps_source.c
@@ -1,5 +1,5 @@
 /**
- * @file ts2phc_master.c
+ * @file ts2phc_pps_source.c
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
@@ -8,31 +8,31 @@
 #include "ts2phc_nmea_pps_source.h"
 #include "ts2phc_phc_pps_source.h"
 
-struct ts2phc_master *ts2phc_master_create(struct config *cfg, const char *dev,
-                                          enum ts2phc_master_type type)
+struct ts2phc_pps_source *ts2phc_pps_source_create(struct config *cfg, const 
char *dev,
+                                                  enum ts2phc_pps_source_type 
type)
 {
-       struct ts2phc_master *master = NULL;
+       struct ts2phc_pps_source *src = NULL;
 
        switch (type) {
-       case TS2PHC_MASTER_GENERIC:
-               master = ts2phc_generic_master_create(cfg, dev);
+       case TS2PHC_PPS_SOURCE_GENERIC:
+               src = ts2phc_generic_pps_source_create(cfg, dev);
                break;
-       case TS2PHC_MASTER_NMEA:
-               master = ts2phc_nmea_master_create(cfg, dev);
+       case TS2PHC_PPS_SOURCE_NMEA:
+               src = ts2phc_nmea_pps_source_create(cfg, dev);
                break;
-       case TS2PHC_MASTER_PHC:
-               master = ts2phc_phc_master_create(cfg, dev);
+       case TS2PHC_PPS_SOURCE_PHC:
+               src = ts2phc_phc_pps_source_create(cfg, dev);
                break;
        }
-       return master;
+       return src;
 }
 
-void ts2phc_master_destroy(struct ts2phc_master *master)
+void ts2phc_pps_source_destroy(struct ts2phc_pps_source *src)
 {
-       master->destroy(master);
+       src->destroy(src);
 }
 
-int ts2phc_master_getppstime(struct ts2phc_master *master, struct timespec *ts)
+int ts2phc_pps_source_getppstime(struct ts2phc_pps_source *src, struct 
timespec *ts)
 {
-       return master->getppstime(master, ts);
+       return src->getppstime(src, ts);
 }
diff --git a/ts2phc_pps_source.h b/ts2phc_pps_source.h
index 7a05df35e01b..1e1f46f70915 100644
--- a/ts2phc_pps_source.h
+++ b/ts2phc_pps_source.h
@@ -3,8 +3,8 @@
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
-#ifndef HAVE_TS2PHC_MASTER_H
-#define HAVE_TS2PHC_MASTER_H
+#ifndef HAVE_TS2PHC_PPS_SOURCE_H
+#define HAVE_TS2PHC_PPS_SOURCE_H
 
 #include <time.h>
 
@@ -13,40 +13,40 @@ struct config;
 /**
  * Opaque type
  */
-struct ts2phc_master;
+struct ts2phc_pps_source;
 
 /**
- * Defines the available PPS master clocks.
+ * Defines the available PPS sources.
  */
-enum ts2phc_master_type {
-       TS2PHC_MASTER_GENERIC,
-       TS2PHC_MASTER_NMEA,
-       TS2PHC_MASTER_PHC,
+enum ts2phc_pps_source_type {
+       TS2PHC_PPS_SOURCE_GENERIC,
+       TS2PHC_PPS_SOURCE_NMEA,
+       TS2PHC_PPS_SOURCE_PHC,
 };
 
 /**
- * Create a new instance of a PPS master clock.
+ * Create a new instance of a PPS source.
  * @param cfg  Pointer to a valid configuration.
- * @param dev   Name of the master clock or NULL.
+ * @param dev   Name of the source or NULL.
  * @param type The type of the clock to create.
- * @return     A pointer to a new PPS master clock on success, NULL otherwise.
+ * @return     A pointer to a new PPS source on success, NULL otherwise.
  */
-struct ts2phc_master *ts2phc_master_create(struct config *cfg, const char *dev,
-                                          enum ts2phc_master_type type);
+struct ts2phc_pps_source *ts2phc_pps_source_create(struct config *cfg, const 
char *dev,
+                                                  enum ts2phc_pps_source_type 
type);
 
 /**
- * Destroy an instance of a PPS master clock.
- * @param master Pointer to a master obtained via @ref ts2phc_master_create().
+ * Destroy an instance of a PPS source.
+ * @param src Pointer to a source obtained via @ref ts2phc_pps_source_create().
  */
-void ts2phc_master_destroy(struct ts2phc_master *master);
+void ts2phc_pps_source_destroy(struct ts2phc_pps_source *src);
 
 /**
  * Returns the time on the PPS source device at which the most recent
  * PPS event was generated.
- * @param master Pointer to a master obtained via @ref ts2phc_master_create().
+ * @param src    Pointer to a source obtained via @ref 
ts2phc_pps_source_create().
  * @param ts     Buffer to hold the time of the last PPS event.
  * @return       Zero if the reported time is valid, non-zero otherwise.
  */
-int ts2phc_master_getppstime(struct ts2phc_master *master, struct timespec 
*ts);
+int ts2phc_pps_source_getppstime(struct ts2phc_pps_source *src, struct 
timespec *ts);
 
 #endif
diff --git a/ts2phc_pps_source_private.h b/ts2phc_pps_source_private.h
index e98827ac2f6f..6472df6d5e0b 100644
--- a/ts2phc_pps_source_private.h
+++ b/ts2phc_pps_source_private.h
@@ -3,8 +3,8 @@
  * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com>
  * @note SPDX-License-Identifier: GPL-2.0+
  */
-#ifndef HAVE_TS2PHC_MASTER_PRIVATE_H
-#define HAVE_TS2PHC_MASTER_PRIVATE_H
+#ifndef HAVE_TS2PHC_PPS_SOURCE_PRIVATE_H
+#define HAVE_TS2PHC_PPS_SOURCE_PRIVATE_H
 
 #include <stdint.h>
 #include <time.h>
@@ -12,9 +12,9 @@
 #include "contain.h"
 #include "ts2phc_pps_source.h"
 
-struct ts2phc_master {
-       void (*destroy)(struct ts2phc_master *ts2phc_master);
-       int (*getppstime)(struct ts2phc_master *master, struct timespec *ts);
+struct ts2phc_pps_source {
+       void (*destroy)(struct ts2phc_pps_source *src);
+       int (*getppstime)(struct ts2phc_pps_source *src, struct timespec *ts);
 };
 
 #endif
-- 
2.25.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to