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

refactored dtor_cb_t to return an integer

This commit is contained in:
Steffen Vogel 2017-02-18 10:43:01 -05:00
parent bc634ebccc
commit 30e0ecf544
10 changed files with 39 additions and 25 deletions

View file

@ -44,7 +44,7 @@ struct hist {
void hist_create(struct hist *h, double start, double end, double resolution);
/** Free the dynamically allocated memory. */
void hist_destroy(struct hist *h);
int hist_destroy(struct hist *h);
/** Reset all counters and values back to zero. */
void hist_reset(struct hist *h);

View file

@ -40,7 +40,7 @@
*
* @param data A pointer to the data which should be freed.
*/
typedef void (*dtor_cb_t)(void *);
typedef int (*dtor_cb_t)(void *);
/** Callback to search or sort a list. */
typedef int (*cmp_cb_t)(const void *, const void *);
@ -65,7 +65,7 @@ void list_init(struct list *l);
* @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed.
* @param l A pointer to the list data structure.
*/
void list_destroy(struct list *l, dtor_cb_t dtor, bool free);
int list_destroy(struct list *l, dtor_cb_t dtor, bool free);
/** Append an element to the end of the list */
void list_push(struct list *l, void *p);

View file

@ -198,7 +198,7 @@ struct node * node_create(struct node_type *vt);
*
* @see node_type::destroy
*/
void node_destroy(struct node *n);
int node_destroy(struct node *n);
/** Start operation of a node.
*

View file

@ -85,7 +85,7 @@ void path_init(struct path *p);
*
* @param i A pointer to the path structure.
*/
void path_destroy(struct path *p);
int path_destroy(struct path *p);
/** Initialize pool queue and hooks.
*

View file

@ -30,9 +30,11 @@ void hist_create(struct hist *h, double low, double high, double resolution)
hist_reset(h);
}
void hist_destroy(struct hist *h)
int hist_destroy(struct hist *h)
{
free(h->data);
return 0;
}
void hist_put(struct hist *h, double value)

View file

@ -42,7 +42,7 @@ void list_init(struct list *l)
l->array = NULL;
}
void list_destroy(struct list *l, dtor_cb_t destructor, bool release)
int list_destroy(struct list *l, dtor_cb_t destructor, bool release)
{
pthread_mutex_lock(&l->lock);
@ -62,6 +62,8 @@ void list_destroy(struct list *l, dtor_cb_t destructor, bool release)
pthread_mutex_unlock(&l->lock);
pthread_mutex_destroy(&l->lock);
return 0;
}
void list_push(struct list *l, void *p)

View file

@ -193,7 +193,7 @@ struct node * node_create(struct node_type *vt)
return n;
}
void node_destroy(struct node *n)
int node_destroy(struct node *n)
{
if (n->_vt->destroy)
n->_vt->destroy(n);
@ -203,4 +203,6 @@ void node_destroy(struct node *n)
free(n->_vd);
free(n->_name);
free(n);
return 0;
}

View file

@ -429,26 +429,30 @@ char * ngsi_print(struct node *n)
i->endpoint, i->timeout, list_length(&i->mapping));
}
static void ngsi_destroy_metadata(struct ngsi_metadata *meta)
static int ngsi_metadata_destroy(struct ngsi_metadata *meta)
{
free(meta->value);
free(meta->name);
free(meta->type);
return 0;
}
static void ngsi_destroy_attribute(struct ngsi_attribute *attr)
static int ngsi_attribute_destroy(struct ngsi_attribute *attr)
{
free(attr->name);
free(attr->type);
list_destroy(&attr->metadata, (dtor_cb_t) ngsi_destroy_metadata, true);
list_destroy(&attr->metadata, (dtor_cb_t) ngsi_metadata_destroy, true);
return 0;
}
int ngsi_destroy(struct node *n)
{
struct ngsi *i = n->_vd;
list_destroy(&i->mapping, (dtor_cb_t) ngsi_destroy_attribute, true);
list_destroy(&i->mapping, (dtor_cb_t) ngsi_attribute_destroy, true);
return 0;
}

View file

@ -197,6 +197,21 @@ void path_init(struct path *p)
p->state = PATH_CREATED;
}
int path_destroy(struct path *p)
{
hook_run(p, NULL, 0, HOOK_DEINIT); /* Release memory */
list_destroy(&p->destinations, NULL, false);
list_destroy(&p->hooks, NULL, true);
queue_destroy(&p->queue);
pool_destroy(&p->pool);
free(p->_name);
return 0;
}
int path_prepare(struct path *p)
{
int ret;
@ -226,19 +241,6 @@ int path_prepare(struct path *p)
return 0;
}
void path_destroy(struct path *p)
{
hook_run(p, NULL, 0, HOOK_DEINIT); /* Release memory */
list_destroy(&p->destinations, NULL, false);
list_destroy(&p->hooks, NULL, true);
queue_destroy(&p->queue);
pool_destroy(&p->pool);
free(p->_name);
}
int path_uses_node(struct path *p, struct node *n) {
return (p->in == n) || list_contains(&p->destinations, n) ? 0 : 1;
}

View file

@ -43,4 +43,6 @@ int pool_destroy(struct pool *p)
queue_destroy(&p->queue);
return memory_free(p->mem, p->buffer, p->len);
return 0;
}