pmc: require a configuration for creating a PMC instance.

In the near future, the transports will need to consult the configuration
database in order to obtain various options.  This patch also introduces
the idea of a configuration file into the phc2sys and pmc programs.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-08-10 20:29:51 +02:00
parent b297f22a82
commit bbbc0cd451
4 changed files with 17 additions and 11 deletions

View File

@ -119,6 +119,8 @@ struct node {
struct clock *master;
};
static struct config phc2sys_config;
static int update_pmc(struct node *node, int subscribe);
static int clock_handle_leap(struct node *node, struct clock *clock,
int64_t offset, uint64_t ts);
@ -777,13 +779,13 @@ static void send_subscription(struct node *node)
pmc_send_set_action(node->pmc, TLV_SUBSCRIBE_EVENTS_NP, &sen, sizeof(sen));
}
static int init_pmc(struct node *node, int domain_number)
static int init_pmc(struct config *cfg, struct node *node, int domain_number)
{
char uds_local[MAX_IFNAME_SIZE + 1];
snprintf(uds_local, sizeof(uds_local), "/var/run/phc2sys.%d",
getpid());
node->pmc = pmc_create(TRANS_UDS, uds_local, 0, domain_number, 0, 1);
node->pmc = pmc_create(cfg, TRANS_UDS, uds_local, 0, domain_number, 0, 1);
if (!node->pmc) {
pr_err("failed to create pmc");
return -1;
@ -1395,7 +1397,7 @@ int main(int argc, char *argv[])
print_set_level(print_level);
if (autocfg) {
if (init_pmc(&node, domain_number))
if (init_pmc(&phc2sys_config, &node, domain_number))
return -1;
if (auto_init_ports(&node, rt) < 0)
return -1;
@ -1431,7 +1433,7 @@ int main(int argc, char *argv[])
r = -1;
if (wait_sync) {
if (init_pmc(&node, domain_number))
if (init_pmc(&phc2sys_config, &node, domain_number))
goto end;
while (is_running()) {

3
pmc.c
View File

@ -42,6 +42,7 @@
#define P41 ((double)(1ULL << 41))
static struct pmc *pmc;
static struct config pmc_config;
static void do_get_action(int action, int index, char *str);
static void do_set_action(int action, int index, char *str);
@ -816,7 +817,7 @@ int main(int argc, char *argv[])
print_set_syslog(1);
print_set_verbose(1);
pmc = pmc_create(transport_type, iface_name, boundary_hops,
pmc = pmc_create(&pmc_config, transport_type, iface_name, boundary_hops,
domain_number, transport_specific, zero_datalen);
if (!pmc) {
fprintf(stderr, "failed to create pmc\n");

View File

@ -61,9 +61,10 @@ struct pmc {
int zero_length_gets;
};
struct pmc *pmc_create(enum transport_type transport_type, const char *iface_name,
UInteger8 boundary_hops, UInteger8 domain_number,
UInteger8 transport_specific, int zero_datalen)
struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
const char *iface_name, UInteger8 boundary_hops,
UInteger8 domain_number, UInteger8 transport_specific,
int zero_datalen)
{
struct pmc *pmc;

View File

@ -21,14 +21,16 @@
#ifndef HAVE_PMC_COMMON_H
#define HAVE_PMC_COMMON_H
#include "config.h"
#include "msg.h"
#include "transport.h"
struct pmc;
struct pmc *pmc_create(enum transport_type transport_type, const char *iface_name,
UInteger8 boundary_hops, UInteger8 domain_number,
UInteger8 transport_specific, int zero_datalen);
struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
const char *iface_name, UInteger8 boundary_hops,
UInteger8 domain_number, UInteger8 transport_specific,
int zero_datalen);
void pmc_destroy(struct pmc *pmc);