diff --git a/include/node.h b/include/node.h index 6806236aa..58fe0938a 100644 --- a/include/node.h +++ b/include/node.h @@ -163,6 +163,13 @@ struct node int combine; /**< Number of messages to send / recv at once (scatter / gather) */ int affinity; /**< CPU Affinity of this node */ + enum node_state { + NODE_INVALID, /**< This node object is not in a valid state. */ + NODE_CREATED, /**< This node has been parsed from the configuration. */ + NODE_RUNNING, /**< This node has been started by calling node_open() */ + NODE_STOPPED /**< Node was running, but has been stopped by calling node_close() */ + } state; /**< Node state */ + struct node_type *_vt; /**< C++ like virtual function call table */ union { diff --git a/include/path.h b/include/path.h index c7b81d60d..7abd5a9b8 100644 --- a/include/path.h +++ b/include/path.h @@ -31,6 +31,13 @@ */ struct path { + enum { + PATH_INVALID, /**< */ + PATH_CREATED, /**< */ + PATH_RUNNING, /**< */ + PATH_STOPPED /**< */ + } state; /**< Path state */ + struct node *in; /**< Pointer to the incoming node */ struct node *out; /**< Pointer to the first outgoing node ( path::out == list_first(path::destinations) */ diff --git a/lib/node.c b/lib/node.c index cb16c041b..62480ca6e 100644 --- a/lib/node.c +++ b/lib/node.c @@ -70,20 +70,33 @@ int node_deinit() int node_start(struct node *n) { INDENT - info("Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, node_print(n)); + int ret; + info("Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, node_print(n)); { INDENT - return node_open(n); + ret = node_open(n); } + + if (ret == 0) + n->state = NODE_RUNNING; + + return ret; } int node_stop(struct node *n) { INDENT + int ret; + info("Stopping node '%s'", n->name); { INDENT - return node_close(n); + ret = node_close(n); } + + if (ret == 0) + n->state = NODE_STOPPED; + + return ret; } char * node_print(struct node *n) @@ -106,6 +119,7 @@ struct node * node_create(struct node_type *vt) list_push(&vt->instances, n); n->_vt = vt; + n->state = NODE_CREATED; return n; } diff --git a/src/path.c b/src/path.c index 7658e621c..78ab92e42 100644 --- a/src/path.c +++ b/src/path.c @@ -166,8 +166,10 @@ int path_start(struct path *p) pthread_create(&p->sent_tid, NULL, &path_run_async, p); } + + p->state = PATH_RUNNING; - return pthread_create(&p->recv_tid, NULL, &path_run, p); + return pthread_create(&p->recv_tid, NULL, &path_run, p); } int path_stop(struct path *p) @@ -183,6 +185,8 @@ int path_stop(struct path *p) close(p->tfd); } + + p->state = PATH_STOPPED; if (path_run_hook(p, HOOK_PATH_STOP)) return -1; @@ -215,6 +219,8 @@ struct path * path_create() if (h->type & HOOK_INTERNAL) list_push(&p->hooks, memdup(h, sizeof(*h))); } + + p->state = PATH_CREATED; return p; }