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

add new functions to retrieve file descriptors from nodes, io formats and tasks

This commit is contained in:
Steffen Vogel 2017-08-30 00:22:58 +02:00
parent 544aa42723
commit f9324000fa
8 changed files with 48 additions and 2 deletions

View file

@ -86,6 +86,7 @@ void io_rewind(struct io *io);
int io_flush(struct io *io);
int io_fd(struct io *io);
int io_stream_open(struct io *io, const char *uri);
@ -95,4 +96,6 @@ int io_stream_eof(struct io *io);
void io_stream_rewind(struct io *io);
int io_stream_fd(struct io *io);
int io_stream_flush(struct io *io);

View file

@ -70,6 +70,9 @@ struct io_format {
* @see rewind()
*/
void (*rewind)(struct io *io);
/** Get a file descriptor which can be used with select / poll */
int (*fd)(struct io *io);
/** Flush buffered data to disk.
*

View file

@ -125,6 +125,8 @@ int node_read(struct node *n, struct sample *smps[], unsigned cnt);
int node_write(struct node *n, struct sample *smps[], unsigned cnt);
int node_fd(struct node *n);
/** Parse an array or single node and checks if they exist in the "nodes" section.
*
* Examples:

View file

@ -146,6 +146,9 @@ struct node_type {
* @param n A pointer to the node object.
*/
int (*reverse)(struct node *n);
/** Return a file descriptor which can be used by poll / select to detect the availability of new data. */
int (*fd)(struct node *n);
};
/** Initialize all registered node type subsystems.

View file

@ -68,4 +68,6 @@ uint64_t task_wait_until_next_period(struct task *t);
*
* @param until A pointer to a time in the future.
*/
int task_wait_until(struct task *t, const struct timespec *until);
int task_wait_until(struct task *t, const struct timespec *until);
int task_fd(struct task *t);

View file

@ -177,6 +177,19 @@ void io_stream_rewind(struct io *io)
}
}
int io_stream_fd(struct io *io)
{
switch (io->mode) {
case IO_MODE_ADVIO:
return afileno(io->advio.input);
case IO_MODE_STDIO:
return fileno(io->stdio.input);
case IO_MODE_CUSTOM:
return -1;
}
}
int io_open(struct io *io, const char *uri)
{
return io->_vt->open
@ -212,6 +225,13 @@ void io_rewind(struct io *io)
: io_stream_rewind(io);
}
int io_fd(struct io *io)
{
return io->_vt->fd
? io->_vt->fd(io)
: io_stream_fd(io);
}
int io_print(struct io *io, struct sample *smps[], unsigned cnt)
{
int ret;

View file

@ -288,6 +288,11 @@ int node_reverse(struct node *n)
return n->_vt->reverse ? n->_vt->reverse(n) : -1;
}
int node_fd(struct node *n)
{
return n->_vt->fd ? n->_vt->fd(n) : -1;
}
int node_parse_list(struct list *list, json_t *cfg, struct list *all)
{
struct node *node;

View file

@ -115,7 +115,6 @@ uint64_t task_wait_until_next_period(struct task *t)
return runs;
}
int task_wait_until(struct task *t, const struct timespec *until)
{
int ret;
@ -154,4 +153,13 @@ retry: ret = clock_nanosleep(t->clock, TIMER_ABSTIME, until, NULL);
#endif
return 0;
}
int task_fd(struct task *t)
{
#if PERIODIC_TASK_IMPL == TIMERFD
return t->fd;
#else
return -1;
#endif
}