1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

improve naming of struct node_type function pointers (closes #150)

This commit is contained in:
Steffen Vogel 2018-07-16 08:08:17 +02:00
parent d9080fa1db
commit 60f55ec178
23 changed files with 116 additions and 107 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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)

View file

@ -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;

View file

@ -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,

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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
}
};

View file

@ -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
}
};

View file

@ -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
}
};

View file

@ -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
}
};

View file

@ -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,

View file

@ -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