mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
using singleton for printable path/node string
This commit is contained in:
parent
a1dff8c3bb
commit
b7e0edf5fa
6 changed files with 28 additions and 28 deletions
|
@ -29,7 +29,6 @@
|
|||
/* Helper macros for virtual node type */
|
||||
#define node_type(n) ((n)->_vt->type)
|
||||
#define node_parse(n, cfg) ((n)->_vt->parse(cfg, n))
|
||||
#define node_print(n) ((n)->_vt->print(n))
|
||||
|
||||
#define node_read(n, p, ps, f, c) ((n)->_vt->read(n, p, ps, f, c))
|
||||
#define node_write(n, p, ps, f, c) ((n)->_vt->write(n, p, ps, f, c))
|
||||
|
@ -163,6 +162,7 @@ struct node_type {
|
|||
struct node
|
||||
{
|
||||
const char *name; /**< A short identifier of the node, only used for configuration and logging */
|
||||
char *_print; /**< A string used to print to screen. */
|
||||
|
||||
int refcnt; /**< How many paths are sending / receiving from this node? */
|
||||
int combine; /**< Number of messages to send / recv at once (scatter / gather) */
|
||||
|
@ -206,13 +206,8 @@ int node_deinit();
|
|||
*/
|
||||
int node_start(struct node *n);
|
||||
|
||||
/** Deferred TCP connection setup
|
||||
*
|
||||
* @todo Dirty hack!
|
||||
* We should check the address of the connecting node!
|
||||
* We should preserve the original socket for proper shutdown.
|
||||
*/
|
||||
int node_start_defer(struct node *n);
|
||||
/** Return a pointer to a string which should be used to print this node */
|
||||
char * node_print(struct node *n);
|
||||
|
||||
/** Stops a node.
|
||||
*
|
||||
|
|
|
@ -53,6 +53,8 @@ struct path
|
|||
|
||||
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path */
|
||||
|
||||
char *_print; /**< A string which is used to print this path to screen. */
|
||||
|
||||
/** The following fields are mostly managed by hook_ functions @{ */
|
||||
|
||||
struct hist hist_owd; /**< Histogram for one-way-delay (OWD) of received messages */
|
||||
|
|
|
@ -186,9 +186,7 @@ int config_parse_path(config_setting_t *cfg,
|
|||
}
|
||||
}
|
||||
else {
|
||||
char *buf = path_print(p);
|
||||
warn("Path %s is not enabled", buf);
|
||||
free(buf);
|
||||
warn("Path %s is not enabled", path_print(p));
|
||||
|
||||
path_destroy(p);
|
||||
}
|
||||
|
|
|
@ -273,10 +273,8 @@ int hook_restart(struct path *p, struct hook *h, int when)
|
|||
{
|
||||
if (p->current->sequence == 0 &&
|
||||
p->previous->sequence <= UINT32_MAX - 32) {
|
||||
char *buf = path_print(p);
|
||||
warn("Simulation for path %s restarted (prev->seq=%u, current->seq=%u)",
|
||||
buf, p->previous->sequence, p->current->sequence);
|
||||
free(buf);
|
||||
path_print(p), p->previous->sequence, p->current->sequence);
|
||||
|
||||
p->sent =
|
||||
p->invalid =
|
||||
|
@ -378,6 +376,7 @@ int hook_stats(struct path *p, struct hook *h, int when)
|
|||
|
||||
if (p->received > 1)
|
||||
stats("%-40.40s|%10.2g|%10.2f|%10u|%10u|%10u|%10u|%10u|%10u|%10u|", buf,
|
||||
stats("%-40.40s|%10.2g|%10.2f|%10u|%10u|%10u|%10u|%10u|%10u|%10u|", path_print(p),
|
||||
p->hist_owd.last, 1 / p->hist_gap_msg.last,
|
||||
p->sent, p->received, p->dropped, p->skipped, p->invalid, p->overrun, list_length(p->current)
|
||||
);
|
||||
|
|
|
@ -65,9 +65,7 @@ int node_start(struct node *n)
|
|||
return -1;
|
||||
}
|
||||
|
||||
char *buf = node_print(n);
|
||||
debug(1, "Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, buf);
|
||||
free(buf);
|
||||
debug(1, "Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, node_print(n));
|
||||
|
||||
{ INDENT
|
||||
return node_open(n);
|
||||
|
@ -90,6 +88,14 @@ int node_stop(struct node *n)
|
|||
return ret;
|
||||
}
|
||||
|
||||
char * node_print(struct node *n)
|
||||
{
|
||||
if (!n->_print)
|
||||
n->_print = n->_vt->print(n);
|
||||
|
||||
return n->_print;
|
||||
}
|
||||
|
||||
void node_reverse(struct node *n)
|
||||
{
|
||||
switch (node_type(n)) {
|
||||
|
@ -131,6 +137,7 @@ void node_destroy(struct node *n)
|
|||
default: { }
|
||||
}
|
||||
|
||||
free(n->_print);
|
||||
free(n->socket);
|
||||
free(n);
|
||||
}
|
||||
|
|
|
@ -139,10 +139,8 @@ static void * path_run(void *arg)
|
|||
|
||||
int path_start(struct path *p)
|
||||
{ INDENT
|
||||
char *buf = path_print(p);
|
||||
info("Starting path: %s (poolsize=%u, msgsize=%u, #hooks=%zu, rate=%.1f)",
|
||||
buf, p->poolsize, p->msgsize, list_length(&p->hooks), p->rate);
|
||||
free(buf);
|
||||
path_print(p), p->poolsize, p->msgsize, list_length(&p->hooks), p->rate);
|
||||
|
||||
/* We sort the hooks according to their priority before starting the path */
|
||||
list_sort(&p->hooks, ({int cmp(const void *a, const void *b) {
|
||||
|
@ -174,9 +172,7 @@ int path_start(struct path *p)
|
|||
|
||||
int path_stop(struct path *p)
|
||||
{ INDENT
|
||||
char *buf = path_print(p);
|
||||
info("Stopping path: %s", buf);
|
||||
free(buf);
|
||||
info("Stopping path: %s", path_print(p));
|
||||
|
||||
pthread_cancel(p->recv_tid);
|
||||
pthread_join(p->recv_tid, NULL);
|
||||
|
@ -196,14 +192,16 @@ int path_stop(struct path *p)
|
|||
|
||||
char * path_print(struct path *p)
|
||||
{
|
||||
char *buf = alloc(32);
|
||||
if (!p->_print) {
|
||||
char *buf = alloc(64);
|
||||
|
||||
strcatf(&buf, "%s " MAG("=>"), p->in->name);
|
||||
strcatf(&buf, "%s " MAG("=>"), p->in->name);
|
||||
|
||||
list_foreach(struct node *n, &p->destinations)
|
||||
strcatf(&buf, " %s", n->name);
|
||||
list_foreach(struct node *n, &p->destinations)
|
||||
strcatf(&buf, " %s", n->name);
|
||||
}
|
||||
|
||||
return buf;
|
||||
return p->_print;
|
||||
}
|
||||
|
||||
struct path * path_create()
|
||||
|
@ -228,6 +226,7 @@ void path_destroy(struct path *p)
|
|||
list_destroy(&p->destinations);
|
||||
list_destroy(&p->hooks);
|
||||
|
||||
free(p->_print);
|
||||
free(p->pool);
|
||||
free(p);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue