ptp4l: add pod parser to separate logic from scan_line

this patch extracts the pod parser from the scan_line function in order to
simplify the code for future patches

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
master
Jacob Keller 2012-08-20 10:57:06 -07:00 committed by Richard Cochran
parent 11a334b93e
commit 6157db9ac4
1 changed files with 55 additions and 34 deletions

View File

@ -22,11 +22,60 @@
#include "ether.h" #include "ether.h"
#include "print.h" #include "print.h"
static int scan_pod(const char *s, struct port_defaults *pod)
{
int val;
Integer8 i8;
UInteger8 u8;
if (1 == sscanf(s, " logAnnounceInterval %hhd", &i8)) {
pod->logAnnounceInterval = i8;
return 1;
} else if (1 == sscanf(s, " logSyncInterval %hhd", &i8)) {
pod->logSyncInterval = i8;
return 1;
} else if (1 == sscanf(s, " logMinDelayReqInterval %hhd", &i8)) {
pod->logMinDelayReqInterval = i8;
return 1;
} else if (1 == sscanf(s, " logMinPdelayReqInterval %hhd", &i8)) {
pod->logMinPdelayReqInterval = i8;
return 1;
} else if (1 == sscanf(s, " announceReceiptTimeout %hhu", &u8)) {
pod->announceReceiptTimeout = u8;
return 1;
} else if (1 == sscanf(s, " transportSpecific %hhx", &u8)) {
pod->transportSpecific = u8 << 4;
return 1;
} else if (1 == sscanf(s, " path_trace_enabled %u", &val)) {
pod->path_trace_enabled = val ? 1 : 0;
return 1;
} else if (1 == sscanf(s, " follow_up_info %u", &val)) {
pod->follow_up_info = val ? 1 : 0;
return 1;
}
return 0;
}
static void scan_line(char *s, struct config *cfg) static void scan_line(char *s, struct config *cfg)
{ {
double df; double df;
int i, val, cfg_ignore = cfg->cfg_ignore; int i, val, cfg_ignore = cfg->cfg_ignore;
Integer8 i8;
UInteger16 u16; UInteger16 u16;
UInteger8 u8; UInteger8 u8;
unsigned char mac[MAC_LEN]; unsigned char mac[MAC_LEN];
@ -35,7 +84,11 @@ static void scan_line(char *s, struct config *cfg)
struct defaultDS *dds = &cfg->dds; struct defaultDS *dds = &cfg->dds;
struct port_defaults *pod = &cfg->pod; struct port_defaults *pod = &cfg->pod;
if (1 == sscanf(s, " twoStepFlag %d", &val)) { if (scan_pod(s, pod)) {
/* nothing to do here */
} else if (1 == sscanf(s, " twoStepFlag %d", &val)) {
if (val) /* TODO - implement one step */ if (val) /* TODO - implement one step */
dds->twoStepFlag = val ? 1 : 0; dds->twoStepFlag = val ? 1 : 0;
@ -71,38 +124,6 @@ static void scan_line(char *s, struct config *cfg)
dds->clockQuality.offsetScaledLogVariance = u16; dds->clockQuality.offsetScaledLogVariance = u16;
} else if (1 == sscanf(s, " logAnnounceInterval %hhd", &i8)) {
pod->logAnnounceInterval = i8;
} else if (1 == sscanf(s, " logSyncInterval %hhd", &i8)) {
pod->logSyncInterval = i8;
} else if (1 == sscanf(s, " logMinDelayReqInterval %hhd", &i8)) {
pod->logMinDelayReqInterval = i8;
} else if (1 == sscanf(s, " logMinPdelayReqInterval %hhd", &i8)) {
pod->logMinPdelayReqInterval = i8;
} else if (1 == sscanf(s, " announceReceiptTimeout %hhu", &u8)) {
pod->announceReceiptTimeout = u8;
} else if (1 == sscanf(s, " transportSpecific %hhx", &u8)) {
pod->transportSpecific = u8 << 4;
} else if (1 == sscanf(s, " path_trace_enabled %u", &val)) {
pod->path_trace_enabled = val ? 1 : 0;
} else if (1 == sscanf(s, " follow_up_info %u", &val)) {
pod->follow_up_info = val ? 1 : 0;
} else if (1 == sscanf(s, " assume_two_step %u", &val)) { } else if (1 == sscanf(s, " assume_two_step %u", &val)) {
*cfg->assume_two_step = val ? 1 : 0; *cfg->assume_two_step = val ? 1 : 0;