mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
node: added support for pause/resume and restart node instances
This commit is contained in:
parent
b20ed40a59
commit
a088c116f0
4 changed files with 104 additions and 1 deletions
|
@ -40,7 +40,8 @@ enum state {
|
|||
STATE_UNLOADED = 5, /* alias for STATE_STARTED used by struct plugin */
|
||||
STATE_CLOSED = 5, /* alias for STATE_STARTED used by struct io */
|
||||
STATE_PENDING_CONNECT = 6,
|
||||
STATE_CONNECTED = 7
|
||||
STATE_CONNECTED = 7,
|
||||
STATE_PAUSED = 9
|
||||
};
|
||||
|
||||
/** Callback to destroy list elements.
|
||||
|
|
|
@ -125,6 +125,24 @@ int node_start(struct node *n);
|
|||
*/
|
||||
int node_stop(struct node *n);
|
||||
|
||||
/** Pauses operation of a node.
|
||||
*
|
||||
* @see node_type::close
|
||||
*/
|
||||
int node_pause(struct node *n);
|
||||
|
||||
/** Resumes operation of a node.
|
||||
*
|
||||
* @see node_type::close
|
||||
*/
|
||||
int node_resume(struct node *n);
|
||||
|
||||
/** Restarts operation of a node.
|
||||
*
|
||||
* @see node_type::close
|
||||
*/
|
||||
int node_restart(struct node *n);
|
||||
|
||||
/** Destroy node by freeing dynamically allocated memory.
|
||||
*
|
||||
* @see node_type::destroy
|
||||
|
|
|
@ -128,6 +128,14 @@ struct node_type {
|
|||
*/
|
||||
int (*start)(struct node *n);
|
||||
|
||||
/** Restart this node.
|
||||
*
|
||||
* @param n A pointer to the node object.
|
||||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int (*restart)(struct node *n);
|
||||
|
||||
/** Stop this node.
|
||||
*
|
||||
* @param n A pointer to the node object.
|
||||
|
@ -136,6 +144,22 @@ struct node_type {
|
|||
*/
|
||||
int (*stop)(struct node *n);
|
||||
|
||||
/** Pause this node.
|
||||
*
|
||||
* @param n A pointer to the node object.
|
||||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int (*pause)(struct node *n);
|
||||
|
||||
/** Resume this node.
|
||||
*
|
||||
* @param n A pointer to the node object.
|
||||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int (*resume)(struct node *n);
|
||||
|
||||
/** Receive multiple messages at once.
|
||||
*
|
||||
* Messages are received with a single recvmsg() syscall by
|
||||
|
|
60
lib/node.c
60
lib/node.c
|
@ -380,6 +380,66 @@ int node_stop(struct node *n)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int node_pause(struct node *n)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (n->state != STATE_STARTED)
|
||||
return -1;
|
||||
|
||||
info("Pausing node %s", node_name(n));
|
||||
|
||||
ret = node_type(n)->pause ? node_type(n)->pause(n) : 0;
|
||||
|
||||
if (ret == 0)
|
||||
n->state = STATE_PAUSED;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int node_resume(struct node *n)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (n->state != STATE_PAUSED)
|
||||
return -1;
|
||||
|
||||
info("Resuming node %s", node_name(n));
|
||||
|
||||
ret = node_type(n)->resume ? node_type(n)->resume(n) : 0;
|
||||
|
||||
if (ret == 0)
|
||||
n->state = STATE_STARTED;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int node_restart(struct node *n)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (n->state != STATE_STARTED)
|
||||
return -1;
|
||||
|
||||
info("Restarting node %s", node_name(n));
|
||||
|
||||
if (node_type(n)->restart) {
|
||||
ret = node_type(n)->restart(n);
|
||||
}
|
||||
else {
|
||||
ret = node_type(n)->stop ? node_type(n)->stop(n) : 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = node_type(n)->start ? node_type(n)->start(n) : 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int node_destroy(struct node *n)
|
||||
{
|
||||
int ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue