From 8e196d03f0aa024e00d3930de31c96bfc19c2583 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 16 Nov 2015 10:41:29 +0100 Subject: [PATCH 1/2] added new members to represent state of nodes and paths --- server/include/node.h | 7 +++++++ server/include/path.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/server/include/node.h b/server/include/node.h index 6806236aa..58fe0938a 100644 --- a/server/include/node.h +++ b/server/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/server/include/path.h b/server/include/path.h index c7b81d60d..7abd5a9b8 100644 --- a/server/include/path.h +++ b/server/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) */ From 6be864ea75bf591924f56c8a4963d3700fbe2f21 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 16 Nov 2015 10:51:00 +0100 Subject: [PATCH 2/2] added state transitions --- server/src/node.c | 20 +++++++++++++++++--- server/src/path.c | 8 +++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/server/src/node.c b/server/src/node.c index cb16c041b..62480ca6e 100644 --- a/server/src/node.c +++ b/server/src/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/server/src/path.c b/server/src/path.c index 7658e621c..78ab92e42 100644 --- a/server/src/path.c +++ b/server/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; }