mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
call node_{init,deinit} per node type (similar to nodes and paths)
This commit is contained in:
parent
3a734eb80c
commit
6e8726a0be
5 changed files with 22 additions and 27 deletions
|
@ -185,13 +185,13 @@ struct node
|
|||
*
|
||||
* @see node_type::init
|
||||
*/
|
||||
int node_init(int argc, char *argv[], config_setting_t *cfg);
|
||||
int node_init(struct node_type *vt, int argc, char *argv[], config_setting_t *cfg);
|
||||
|
||||
/** De-initialize node type subsystems.
|
||||
*
|
||||
* @see node_type::deinit
|
||||
*/
|
||||
int node_deinit();
|
||||
int node_deinit(struct node_type *vt);
|
||||
|
||||
/** Create a node by allocating dynamic memory.
|
||||
*
|
||||
|
|
29
lib/node.c
29
lib/node.c
|
@ -30,33 +30,28 @@ int node_write(struct node *n, struct msg *p, int ps, int f, int c)
|
|||
return n->_vt->write ? n->_vt->write(n, p, ps, f, c) : -1;
|
||||
}
|
||||
|
||||
int node_init(int argc, char *argv[], config_setting_t *cfg)
|
||||
int node_init(struct node_type *vt, int argc, char *argv[], config_setting_t *cfg)
|
||||
{
|
||||
list_foreach(const struct node_type *vt, &node_types) {
|
||||
if (list_length(&vt->instances) > 0) {
|
||||
info("Initializing " YEL("%s") " node type", vt->name);
|
||||
if (list_length(&vt->instances) > 0) {
|
||||
info("Initializing " YEL("%s") " node type", vt->name);
|
||||
|
||||
if (vt->init) { INDENT
|
||||
vt->init(argc, argv, cfg);
|
||||
}
|
||||
if (vt->init) { INDENT
|
||||
vt->init(argc, argv, cfg);
|
||||
}
|
||||
else
|
||||
warn("No node is using the " YEL("%s") " node type. Skipping...", vt->name);
|
||||
}
|
||||
else
|
||||
warn("No node is using the " YEL("%s") " node type. Skipping...", vt->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int node_deinit()
|
||||
int node_deinit(struct node_type *vt)
|
||||
{
|
||||
/* De-initialize node types */
|
||||
list_foreach(const struct node_type *vt, &node_types) {
|
||||
if (list_length(&vt->instances) > 0) {
|
||||
info("De-initializing " YEL("%s") " node type", vt->name);
|
||||
if (list_length(&vt->instances) > 0) {
|
||||
info("De-initializing " YEL("%s") " node type", vt->name);
|
||||
|
||||
if (vt->deinit) { INDENT
|
||||
vt->deinit();
|
||||
}
|
||||
if (vt->deinit) { INDENT
|
||||
vt->deinit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
|||
pthread_join(send_thread, NULL);
|
||||
|
||||
node_stop(node);
|
||||
node_deinit();
|
||||
node_deinit(node->_vt);
|
||||
|
||||
free(recv_pool);
|
||||
free(send_pool);
|
||||
|
@ -158,7 +158,7 @@ int main(int argc, char *argv[])
|
|||
if (!node)
|
||||
error("Node '%s' does not exist!", argv[2]);
|
||||
|
||||
node_init(argc-optind, argv+optind, config_root_setting(&config));
|
||||
node_init(node->_vt, argc-optind, argv+optind, config_root_setting(&config));
|
||||
|
||||
recv_pool = alloc(sizeof(struct msg) * node->combine);
|
||||
send_pool = alloc(sizeof(struct msg) * node->combine);
|
||||
|
|
|
@ -42,8 +42,8 @@ static void quit()
|
|||
}
|
||||
|
||||
info("De-initializing node types");
|
||||
{ INDENT
|
||||
node_deinit();
|
||||
list_foreach(struct node_type *vt, &node_types) { INDENT
|
||||
node_deinit(vt);
|
||||
}
|
||||
|
||||
/* Freeing dynamically allocated memory */
|
||||
|
@ -161,8 +161,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
info("Initialize node types");
|
||||
{ INDENT
|
||||
node_init(argc, argv, config_root_setting(&config));
|
||||
list_foreach(struct node_type *vt, &node_types) { INDENT
|
||||
node_init(vt, argc, argv, config_root_setting(&config));
|
||||
}
|
||||
|
||||
info("Starting nodes");
|
||||
|
|
|
@ -92,7 +92,7 @@ int main(int argc, char *argv[])
|
|||
if (!node)
|
||||
error("There's no node with the name '%s'", argv[3]);
|
||||
|
||||
node_init(argc-3, argv+3, config_root_setting(&config));
|
||||
node_init(node->_vt, argc-3, argv+3, config_root_setting(&config));
|
||||
node_start(node);
|
||||
|
||||
/* Parse Arguments */
|
||||
|
@ -138,7 +138,7 @@ check:
|
|||
error("Unknown test: '%s'", argv[2]);
|
||||
|
||||
node_stop(node);
|
||||
node_deinit();
|
||||
node_deinit(node->_vt);
|
||||
config_destroy(&config);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue