diff --git a/include/villas/node_type.h b/include/villas/node_type.h index dee935d32..29666b8ab 100644 --- a/include/villas/node_type.h +++ b/include/villas/node_type.h @@ -50,23 +50,25 @@ struct node_type { enum state state; - /** Global initialization per node type. - * - * This callback is invoked once per node-type. - * - * @retval 0 Success. Everything went well. - * @retval <0 Error. Something went wrong. - */ - int (*init)(struct super_node *sn); + struct { + /** Global initialization per node type. + * + * This callback is invoked once per node-type. + * + * @retval 0 Success. Everything went well. + * @retval <0 Error. Something went wrong. + */ + int (*start)(struct super_node *sn); - /** Global de-initialization per node type. - * - * This callback is invoked once per node-type. - * - * @retval 0 Success. Everything went well. - * @retval <0 Error. Something went wrong. - */ - int (*deinit)(); + /** Global de-initialization per node type. + * + * This callback is invoked once per node-type. + * + * @retval 0 Success. Everything went well. + * @retval <0 Error. Something went wrong. + */ + int (*stop)(); + } type; /** Allocate memory for an instance of this type. * @@ -74,6 +76,13 @@ struct node_type { */ void * (*create)(); + /** Initialize a new node instance. + * + * @retval 0 Success. Everything went well. + * @retval <0 Error. Something went wrong. + */ + int (*init)(); + /** Free memory of an instance of this type. * * @param n A pointer to the node object. diff --git a/include/villas/nodes/iec61850.h b/include/villas/nodes/iec61850.h index 349549ffa..08ee86900 100644 --- a/include/villas/nodes/iec61850.h +++ b/include/villas/nodes/iec61850.h @@ -99,9 +99,11 @@ struct iec61850_receiver { }; }; -int iec61850_init(struct super_node *sn); +/** @see node_type::type_start */ +int iec61850_type_start(struct super_node *sn); -int iec61850_deinit(); +/** @see node_type::type_stop */ +int iec61850_type_stop(); const struct iec61850_type_descriptor * iec61850_lookup_type(const char *name, char fmt); diff --git a/include/villas/nodes/iec61850_sv.h b/include/villas/nodes/iec61850_sv.h index 7213c20fb..597b03134 100644 --- a/include/villas/nodes/iec61850_sv.h +++ b/include/villas/nodes/iec61850_sv.h @@ -81,24 +81,34 @@ struct iec61850_sv { } publisher; }; -int iec61850_sv_init(struct super_node *sn); +/** @see node_type::type_start */ +int iec61850_sv_type_start(struct super_node *sn); -int iec61850_sv_deinit(); +/** @see node_type::type_stop */ +int iec61850_sv_type_stop(); +/** @see node_type::parse */ int iec61850_sv_parse(struct node *n, json_t *json); +/** @see node_type::print */ char * iec61850_sv_print(struct node *n); +/** @see node_type::start */ int iec61850_sv_start(struct node *n); +/** @see node_type::stop */ int iec61850_sv_stop(struct node *n); +/** @see node_type::destroy */ int iec61850_sv_destroy(struct node *n); -int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt); +/** @see node_type::read */ +int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release); -int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt); +/** @see node_type::write */ +int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release); +/** @see node_type::fd */ int iec61850_sv_fd(struct node *n); #ifdef __cplusplus diff --git a/include/villas/nodes/infiniband.h b/include/villas/nodes/infiniband.h index 7a5058f71..4555af1ae 100644 --- a/include/villas/nodes/infiniband.h +++ b/include/villas/nodes/infiniband.h @@ -105,11 +105,11 @@ int ib_destroy(struct node *n); /** @see node_type::close */ int ib_stop(struct node *n); -/** @see node_type::init */ -int ib_init(struct super_node *n); +/** @see node_type::type_start */ +int ib_type_start(struct super_node *n); -/** @see node_type::deinit */ -int ib_deinit(); +/** @see node_type::type_stop */ +int ib_type_stop(); /** @see node_type::read */ int ib_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release); diff --git a/include/villas/nodes/mqtt.h b/include/villas/nodes/mqtt.h index fb4b96563..05fe624c1 100644 --- a/include/villas/nodes/mqtt.h +++ b/include/villas/nodes/mqtt.h @@ -88,11 +88,11 @@ int mqtt_destroy(struct node *n); /** @see node_type::close */ int mqtt_stop(struct node *n); -/** @see node_type::init */ -int mqtt_init(); +/** @see node_type::type_start */ +int mqtt_type_start(); -/** @see node_type::deinit */ -int mqtt_deinit(); +/** @see node_type::type_stop */ +int mqtt_type_stop(); /** @see node_type::read */ int mqtt_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release); diff --git a/include/villas/nodes/ngsi.h b/include/villas/nodes/ngsi.h index b417317ca..090a446f7 100644 --- a/include/villas/nodes/ngsi.h +++ b/include/villas/nodes/ngsi.h @@ -70,15 +70,15 @@ struct ngsi { /** Initialize global NGSI settings and maps shared memory regions. * - * @see node_type::init + * @see node_type::type_start */ -int ngsi_init(struct super_node *sn); +int ngsi_type_start(struct super_node *sn); /** Free global NGSI settings and unmaps shared memory regions. * - * @see node_type::deinit + * @see node_type::type_stop */ -int ngsi_deinit(); +int ngsi_type_stop(); /** @see node_type::parse */ int ngsi_parse(struct node *n, json_t *cfg); diff --git a/include/villas/nodes/opal.h b/include/villas/nodes/opal.h index 10d96e514..f2dfdf5e6 100644 --- a/include/villas/nodes/opal.h +++ b/include/villas/nodes/opal.h @@ -58,15 +58,15 @@ struct opal { /** Initialize global OPAL settings and maps shared memory regions. * - * @see node_type::init + * @see node_type::type_start */ -int opal_init(struct super_node *sn); +int opal_type_start(struct super_node *sn); /** Free global OPAL settings and unmaps shared memory regions. * - * @see node_type::deinit + * @see node_type::type_stop */ -int opal_deinit(); +int opal_type_stop(); /** @see node_type::parse */ int opal_parse(struct node *n, json_t *cfg); diff --git a/include/villas/nodes/socket.h b/include/villas/nodes/socket.h index 5db551339..184b1e9b8 100644 --- a/include/villas/nodes/socket.h +++ b/include/villas/nodes/socket.h @@ -106,11 +106,11 @@ struct socket { }; -/** @see node_vtable::init */ -int socket_init(struct super_node *sn); +/** @see node_vtable::type_start */ +int socket_type_start(struct super_node *sn); -/** @see node_type::deinit */ -int socket_deinit(); +/** @see node_type::type_stop */ +int socket_type_stop(); /** @see node_type::open */ int socket_start(struct node *n); diff --git a/include/villas/nodes/stats.h b/include/villas/nodes/stats.h index cc50d9148..2f111d409 100644 --- a/include/villas/nodes/stats.h +++ b/include/villas/nodes/stats.h @@ -52,7 +52,7 @@ struct stats_node { }; /** @see node_type::print */ -int stats_node_init(struct super_node *sn); +int stats_node_type_start(struct super_node *sn); /** @see node_type::print */ char *stats_node_print(struct node *n); diff --git a/include/villas/nodes/websocket.h b/include/villas/nodes/websocket.h index 232bcc04d..dd8d770b3 100644 --- a/include/villas/nodes/websocket.h +++ b/include/villas/nodes/websocket.h @@ -96,11 +96,11 @@ struct websocket_destination { int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len); -/** @see node_vtable::init */ -int websocket_init(struct super_node *sn); +/** @see node_type::type_start */ +int websocket_type_start(struct super_node *sn); -/** @see node_type::deinit */ -int websocket_deinit(); +/** @see node_type::type_stop */ +int websocket_type_stop(); /** @see node_type::open */ int websocket_start(struct node *n); diff --git a/include/villas/nodes/zeromq.h b/include/villas/nodes/zeromq.h index c5d62c4b2..5dc4c8d26 100644 --- a/include/villas/nodes/zeromq.h +++ b/include/villas/nodes/zeromq.h @@ -89,11 +89,11 @@ char * zeromq_print(struct node *n); /** @see node_type::parse */ int zeromq_parse(struct node *n, json_t *cfg); -/** @see node_type::init */ -int zeromq_init(); +/** @see node_type::type_start */ +int zeromq_type_start(); -/** @see node_type::deinit */ -int zeromq_deinit(); +/** @see node_type::type_stop */ +int zeromq_type_stop(); /** @see node_type::open */ int zeromq_start(struct node *n); diff --git a/lib/node_type.c b/lib/node_type.c index f962ab1f6..b1ff6eb6e 100644 --- a/lib/node_type.c +++ b/lib/node_type.c @@ -38,7 +38,7 @@ int node_type_start(struct node_type *vt, struct super_node *sn) info("Initializing " CLR_YEL("%s") " node type which is used by %zu nodes", node_type_name(vt), list_length(&vt->instances)); { INDENT - ret = vt->init ? vt->init(sn) : 0; + ret = vt->type.start ? vt->type.start(sn) : 0; } if (ret == 0) @@ -56,7 +56,7 @@ int node_type_stop(struct node_type *vt) info("De-initializing " CLR_YEL("%s") " node type", node_type_name(vt)); { INDENT - ret = vt->deinit ? vt->deinit() : 0; + ret = vt->type.stop ? vt->type.stop() : 0; } if (ret == 0) diff --git a/lib/nodes/iec61850.c b/lib/nodes/iec61850.c index b6aae1706..6c01ea446 100644 --- a/lib/nodes/iec61850.c +++ b/lib/nodes/iec61850.c @@ -145,7 +145,7 @@ int iec61850_parse_mapping(json_t *json_mapping, struct list *mapping) return total_size; } -int iec61850_init(struct super_node *sn) +int iec61850_type_start(struct super_node *sn) { int ret; @@ -162,7 +162,7 @@ int iec61850_init(struct super_node *sn) return 0; } -int iec61850_deinit() +int iec61850_type_stop() { int ret; diff --git a/lib/nodes/iec61850_sv.c b/lib/nodes/iec61850_sv.c index c4050dfb8..acda79c81 100644 --- a/lib/nodes/iec61850_sv.c +++ b/lib/nodes/iec61850_sv.c @@ -344,7 +344,7 @@ int iec61850_sv_destroy(struct node *n) return 0; } -int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt) +int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) { int pulled; struct iec61850_sv *i = (struct iec61850_sv *) n->_vd; @@ -361,7 +361,7 @@ int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt) return pulled; } -int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt) +int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) { struct iec61850_sv *i = (struct iec61850_sv *) n->_vd; @@ -429,8 +429,8 @@ static struct plugin p = { .node = { .vectorize = 0, .size = sizeof(struct iec61850_sv), - .init = iec61850_init, - .deinit = iec61850_deinit, + .type.start = iec61850_type_start, + .type.stop = iec61850_type_stop, .parse = iec61850_sv_parse, .print = iec61850_sv_print, .start = iec61850_sv_start, diff --git a/lib/nodes/infiniband.c b/lib/nodes/infiniband.c index ff13b2ebf..277b89590 100644 --- a/lib/nodes/infiniband.c +++ b/lib/nodes/infiniband.c @@ -670,16 +670,6 @@ int ib_stop(struct node *n) return 0; } -int ib_init(struct super_node *n) -{ - return 0; -} - -int ib_deinit() -{ - return 0; -} - int ib_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) { struct infiniband *ib = (struct infiniband *) n->_vd; @@ -909,8 +899,6 @@ static struct plugin p = { .start = ib_start, .destroy = ib_destroy, .stop = ib_stop, - .init = ib_init, - .deinit = ib_deinit, .read = ib_read, .write = ib_write, .fd = ib_fd, diff --git a/lib/nodes/mqtt.c b/lib/nodes/mqtt.c index c0045ee90..a17d31f0c 100644 --- a/lib/nodes/mqtt.c +++ b/lib/nodes/mqtt.c @@ -342,7 +342,7 @@ int mqtt_stop(struct node *n) return 0; } -int mqtt_init() +int mqtt_type_start() { int ret; @@ -353,7 +353,7 @@ int mqtt_init() return 0; } -int mqtt_deinit() +int mqtt_type_stop() { int ret; @@ -420,14 +420,14 @@ static struct plugin p = { .node = { .vectorize = 0, .size = sizeof(struct mqtt), + .type.start = mqtt_type_start, + .type.stop = mqtt_type_stop, .reverse = mqtt_reverse, .parse = mqtt_parse, .print = mqtt_print, .start = mqtt_start, .destroy = mqtt_destroy, .stop = mqtt_stop, - .init = mqtt_init, - .deinit = mqtt_deinit, .read = mqtt_read, .write = mqtt_write, .fd = mqtt_fd diff --git a/lib/nodes/nanomsg.c b/lib/nodes/nanomsg.c index 0ce59c31c..57a0e76c2 100644 --- a/lib/nodes/nanomsg.c +++ b/lib/nodes/nanomsg.c @@ -221,7 +221,7 @@ int nanomsg_destroy(struct node *n) return 0; } -int nanomsg_deinit() +int nanomsg_type_stop() { nn_term(); @@ -284,13 +284,13 @@ static struct plugin p = { .node = { .vectorize = 0, .size = sizeof(struct nanomsg), + .type.start = nanomsg_type_stop, .reverse = nanomsg_reverse, .parse = nanomsg_parse, .print = nanomsg_print, .start = nanomsg_start, .stop = nanomsg_stop, .destroy = nanomsg_destroy, - .deinit = nanomsg_deinit, .read = nanomsg_read, .write = nanomsg_write, .fd = nanomsg_fd diff --git a/lib/nodes/ngsi.c b/lib/nodes/ngsi.c index 59a8588e9..a4d8d896a 100644 --- a/lib/nodes/ngsi.c +++ b/lib/nodes/ngsi.c @@ -389,12 +389,12 @@ out: json_decref(request); return ret; } -int ngsi_init(struct super_node *sn) +int ngsi_type_start(struct super_node *sn) { return curl_global_init(CURL_GLOBAL_ALL); } -int ngsi_deinit() +int ngsi_type_stop() { free(name); @@ -586,14 +586,14 @@ static struct plugin p = { .node = { .vectorize = 0, /* unlimited */ .size = sizeof(struct ngsi), + .type.start = ngsi_type_start, + .type.stop = ngsi_type_stop, .parse = ngsi_parse, .print = ngsi_print, .start = ngsi_start, .stop = ngsi_stop, .read = ngsi_read, .write = ngsi_write, - .init = ngsi_init, - .deinit = ngsi_deinit, .fd = ngsi_fd } }; diff --git a/lib/nodes/opal.c b/lib/nodes/opal.c index af378ffa9..28c96c75b 100644 --- a/lib/nodes/opal.c +++ b/lib/nodes/opal.c @@ -309,14 +309,14 @@ static struct plugin p = { .node = { .vectoroize = 1, .size = sizeof(struct opal), + .type.start = opal_type_start, + .type.stop = opal_type_stop, .parse = opal_parse, .print = opal_print, .start = opal_start, .stop = opal_stop, .read = opal_read, - .write = opal_write, - .init = opal_init, - .deinit = opal_deinit + .write = opal_write } }; diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index ec8d58bac..a76f26ccd 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -52,7 +52,7 @@ static struct plugin p; /* Private static storage */ struct list interfaces = { .state = STATE_DESTROYED }; -int socket_init(struct super_node *sn) +int socket_type_start(struct super_node *sn) { #ifdef WITH_NETEM int ret; @@ -111,7 +111,7 @@ found: list_push(&i->sockets, s); return 0; } -int socket_deinit() +int socket_type_stop() { #ifdef WITH_NETEM for (size_t j = 0; j < list_length(&interfaces); j++) { @@ -789,6 +789,8 @@ static struct plugin p = { .node = { .vectorize = 0, .size = sizeof(struct socket), + .type.start = socket_type_start, + .type.stop = socket_type_stop, .destroy = socket_destroy, .reverse = socket_reverse, .parse = socket_parse, @@ -797,8 +799,6 @@ static struct plugin p = { .stop = socket_stop, .read = socket_read, .write = socket_write, - .init = socket_init, - .deinit = socket_deinit, .fd = socket_fd } }; diff --git a/lib/nodes/stats.c b/lib/nodes/stats.c index 57dcfa2ab..ec22f494b 100644 --- a/lib/nodes/stats.c +++ b/lib/nodes/stats.c @@ -38,7 +38,7 @@ static struct list *nodes; /** The global list of nodes */ -int stats_node_init(struct super_node *sn) +int stats_node_type_start(struct super_node *sn) { if (!sn) return -1; @@ -161,16 +161,16 @@ static struct plugin p = { .description = "Send statistics to another node", .type = PLUGIN_TYPE_NODE, .node = { - .vectorize = 1, - .size = sizeof(struct stats_node), - .init = stats_node_init, - .parse = stats_node_parse, - .destroy= stats_node_destroy, - .print = stats_node_print, - .start = stats_node_start, - .stop = stats_node_stop, - .read = stats_node_read, - .fd = stats_node_fd + .vectorize = 1, + .size = sizeof(struct stats_node), + .type.start = stats_node_type_start, + .parse = stats_node_parse, + .destroy = stats_node_destroy, + .print = stats_node_print, + .start = stats_node_start, + .stop = stats_node_stop, + .read = stats_node_read, + .fd = stats_node_fd } }; diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index 008dbfe11..2f2faf8cf 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -358,7 +358,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi return 0; } -int websocket_init(struct super_node *sn) +int websocket_type_start(struct super_node *sn) { list_init(&connections); @@ -370,7 +370,7 @@ int websocket_init(struct super_node *sn) return 0; } -int websocket_deinit() +int websocket_type_stop() { int ret; @@ -598,8 +598,8 @@ static struct plugin p = { .node = { .vectorize = 0, /* unlimited */ .size = sizeof(struct websocket), - .init = websocket_init, - .deinit = websocket_deinit, + .type.start = websocket_type_start, + .type.stop = websocket_type_stop, .start = websocket_start, .stop = websocket_stop, .destroy = websocket_destroy, diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index db27d6f6b..55c019867 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -232,14 +232,14 @@ char * zeromq_print(struct node *n) return buf; } -int zeromq_init(struct super_node *sn) +int zeromq_type_start(struct super_node *sn) { context = zmq_ctx_new(); return context == NULL; } -int zeromq_deinit() +int zeromq_type_stop() { return zmq_ctx_term(context); } @@ -527,14 +527,14 @@ static struct plugin p = { .node = { .vectorize = 0, .size = sizeof(struct zeromq), + .type.start = zeromq_type_start, + .type.stop = zeromq_type_stop, .reverse = zeromq_reverse, .parse = zeromq_parse, .print = zeromq_print, .start = zeromq_start, .stop = zeromq_stop, .destroy = zeromq_destroy, - .init = zeromq_init, - .deinit = zeromq_deinit, .read = zeromq_read, .write = zeromq_write, .fd = zeromq_fd