From f9f00d8fe8f04e896ee4c95d463be51497e1c788 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 12 Sep 2019 11:06:29 +0000 Subject: [PATCH] util: Add a function to render timestamp type TLV_PORT_PROPERTIES_NP carries, among other attributes, a timestamp type used for that port. In order to make it possible to format the value for user consumption, introduce a new function ts_str(). Signed-off-by: Petr Machata --- util.c | 18 ++++++++++++++++++ util.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/util.c b/util.c index 833f1a5..e64a93d 100644 --- a/util.c +++ b/util.c @@ -70,6 +70,24 @@ const char *ev_str[] = { "RS_PASSIVE", }; +const char *ts_str(enum timestamp_type ts) +{ + switch (ts) { + case TS_SOFTWARE: + return "SOFTWARE"; + case TS_HARDWARE: + return "HARDWARE"; + case TS_LEGACY_HW: + return "LEGACY_HW"; + case TS_ONESTEP: + return "ONESTEP"; + case TS_P2P1STEP: + return "P2P1STEP"; + } + + return "???"; +} + int addreq(enum transport_type type, struct address *a, struct address *b) { void *bufa, *bufb; diff --git a/util.h b/util.h index 9d3f227..60d28ac 100644 --- a/util.h +++ b/util.h @@ -41,6 +41,13 @@ extern const char *ps_str[]; */ extern const char *ev_str[]; +/** + * Gets a human-readable string for a given timestamp type. + * @param ts Timestamp type. + * @return Human-readable rendering if TS is valid, otherwise "???". + */ +const char *ts_str(enum timestamp_type ts); + /** * Compares two binary addresses for equality. * @param type One of the enumerated transport types.