clock: specify type at creation time.

Store the type in the clock object explicitly.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-10-18 16:26:49 +02:00
parent 63e530e297
commit 9c8fe6a94e
3 changed files with 20 additions and 7 deletions

20
clock.c
View File

@ -74,6 +74,7 @@ struct clock_subscriber {
};
struct clock {
enum clock_type type;
struct config *config;
clockid_t clkid;
struct servo *servo;
@ -799,7 +800,8 @@ static void clock_remove_port(struct clock *c, struct port *p)
port_close(p);
}
struct clock *clock_create(struct config *config, int phc_index)
struct clock *clock_create(enum clock_type type, struct config *config,
int phc_index)
{
enum timestamp_type timestamping =
config_get_int(config, NULL, "time_stamping");
@ -821,6 +823,17 @@ struct clock *clock_create(struct config *config, int phc_index)
if (c->nports)
clock_destroy(c);
switch (type) {
case CLOCK_TYPE_ORDINARY:
case CLOCK_TYPE_BOUNDARY:
c->type = type;
break;
case CLOCK_TYPE_P2P:
case CLOCK_TYPE_E2E:
case CLOCK_TYPE_MANAGEMENT:
return NULL;
}
/* Initialize the defaultDS. */
c->dds.clockQuality.clockClass =
config_get_int(config, NULL, "clockClass");
@ -1666,10 +1679,7 @@ struct clock_description *clock_description(struct clock *c)
enum clock_type clock_type(struct clock *c)
{
if (c->nports > 1) {
return CLOCK_TYPE_BOUNDARY;
}
return CLOCK_TYPE_ORDINARY;
return c->type;
}
void clock_check_ts(struct clock *c, struct timespec ts)

View File

@ -76,12 +76,14 @@ struct config *clock_config(struct clock *c);
* Create a clock instance. There can only be one clock in any system,
* so subsequent calls will destroy the previous clock instance.
*
* @param type Specifies which type of clock to create.
* @param config Pointer to the configuration database.
* @param phc_index PTP hardware clock device to use.
* Pass -1 to select CLOCK_REALTIME.
* @return A pointer to the single global clock instance.
*/
struct clock *clock_create(struct config *config, int phc_index);
struct clock *clock_create(enum clock_type type, struct config *config,
int phc_index);
/**
* Obtains a clock's default data set.

View File

@ -222,7 +222,8 @@ int main(int argc, char *argv[])
pr_info("selected /dev/ptp%d as PTP clock", phc_index);
}
clock = clock_create(cfg, phc_index);
clock = clock_create(cfg->n_interfaces > 1 ? CLOCK_TYPE_BOUNDARY :
CLOCK_TYPE_ORDINARY, cfg, phc_index);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
goto out;