From 6fdaaf2ecd3dfddfdc40353a3c3fef825bcd4643 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Grondin?= Date: Mon, 3 Jul 2017 15:15:11 -0400 Subject: [PATCH] Add files via upload --- src/asource/asrc_hops.c | 81 +++++++++++++++++++++++++++++++++++++++++ src/asource/asrc_hops.h | 28 ++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/asource/asrc_hops.c create mode 100644 src/asource/asrc_hops.h diff --git a/src/asource/asrc_hops.c b/src/asource/asrc_hops.c new file mode 100644 index 0000000..753f3ef --- /dev/null +++ b/src/asource/asrc_hops.c @@ -0,0 +1,81 @@ + + #include "asrc_hops.h" + + asrc_hops_obj * asrc_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config) { + + asrc_hops_obj * obj; + + obj = (asrc_hops_obj *) malloc(sizeof(asrc_hops_obj)); + + obj->src_hops = src_hops_construct(src_hops_config, msg_hops_config); + obj->out = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&asrc_hops_thread, (void *) obj); + + return obj; + + } + + void asrc_hops_destroy(asrc_hops_obj * obj) { + + src_hops_destroy(obj->src_hops); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asrc_hops_connect(asrc_hops_obj * obj, amsg_hops_obj * out) { + + obj->out = out; + + } + + void asrc_hops_disconnect(asrc_hops_obj * obj) { + + obj->out = (amsg_hops_obj *) NULL; + + } + + void * asrc_hops_thread(void * ptr) { + + asrc_hops_obj * obj; + msg_hops_obj * msg_hops_out; + int rtnValue; + + obj = (asrc_hops_obj *) ptr; + + // Open the source + src_hops_open(obj->src_hops); + + while(1) { + + // Pop a message, process, and push back + msg_hops_out = amsg_hops_empty_pop(obj->out); + src_hops_connect(obj->src_hops, msg_hops_out); + rtnValue = src_hops_process(obj->src_hops); + src_hops_disconnect(obj->src_hops); + amsg_hops_filled_push(obj->out, msg_hops_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + // Some other process may ask to stop the thread + if (thread_askedToStop(obj->thread) == 1) { + break; + } + + } + + // Close the source + src_hops_close(obj->src_hops); + + // Send the "0" message, that kills all connected threads + // that will consume this message + msg_hops_out = amsg_hops_empty_pop(obj->out); + msg_hops_zero(msg_hops_out); + amsg_hops_filled_push(obj->out, msg_hops_out); + + } \ No newline at end of file diff --git a/src/asource/asrc_hops.h b/src/asource/asrc_hops.h new file mode 100644 index 0000000..050fc24 --- /dev/null +++ b/src/asource/asrc_hops.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASOURCE_HOPS +#define __ODAS_ASOURCE_HOPS + + #include "../amessage/amsg_hops.h" + #include "../source/src_hops.h" + #include "../general/thread.h" + + #include + + typedef struct asrc_hops_obj { + + src_hops_obj * src_hops; + amsg_hops_obj * out; + thread_obj * thread; + + } asrc_hops_obj; + + asrc_hops_obj * asrc_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config); + + void asrc_hops_destroy(asrc_hops_obj * obj); + + void asrc_hops_connect(asrc_hops_obj * obj, amsg_hops_obj * out); + + void asrc_hops_disconnect(asrc_hops_obj * obj); + + void * asrc_hops_thread(void * ptr); + +#endif \ No newline at end of file -- 2.34.1