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 <petrm@mellanox.com>
master
Petr Machata 2019-09-12 11:06:29 +00:00 committed by Richard Cochran
parent 48e605ef01
commit f9f00d8fe8
2 changed files with 25 additions and 0 deletions

18
util.c
View File

@ -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;

7
util.h
View File

@ -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.