2 * @file frescan_acceptor_threads.c
4 * @brief FRESCAN acceptor threads
6 * This module contains the acceptor threads, with an operation to create them.
12 * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
17 #include "fosa_threads_and_signals.h" // fosa_thread_attr_init...
18 #include "frescan_acceptor_threads.h"
19 #include "frescan_config.h"
20 #include "frescan_debug.h"
21 #include "frescan_data.h"
22 #include "frescan_negotiation_messages.h"
24 static void *frescan_acceptor_thread(void *arg);
27 * frescan_acceptor_thread_create()
30 int frescan_acceptor_thread_create(frescan_network_t net)
33 fosa_thread_attr_t attr;
35 ret = fosa_thread_attr_init(&attr);
37 ERROR("could not init thread attributes\n");
41 ret = fosa_thread_attr_set_prio(&attr, FRESCAN_ACCEPTOR_THREAD_PRIO);
43 ERROR("could not set acceptor thread prio %d\n",
44 FRESCAN_ACCEPTOR_THREAD_PRIO);
48 ret = fosa_thread_create(&the_networks[net].neg_thread_id,
50 frescan_acceptor_thread,
51 (void *)(uint32_t)net);
54 ERROR("could not create the negotiator thread\n");
58 ret = fosa_thread_attr_destroy(&attr);
60 ERROR("could not destroy thread attributes\n");
68 * frescan_acceptor_thread()
70 * a loop waiting for negotiation requests on the network. When it receives
71 * a request it acts like a normal thread requesting a negotiation to the
72 * negotiator thread. Once it gets the results it sends them back to the
73 * node that asked the negotiation.
76 static void *frescan_acceptor_thread(void *arg)
79 frescan_recv_params_t params;
85 DEBUG(FRESCAN_ACCEPTOR_THREAD_ENABLE_DEBUG,
86 "master acceptor thread starts\n");
88 params.net = (frescan_network_t)(uint32_t)arg;
89 params.channel = FRESCAN_NEG_CHANNEL;
90 params.flags = FRESCAN_SYNC;
93 DEBUG(FRESCAN_ACCEPTOR_THREAD_ENABLE_DEBUG,
94 "waiting for msg, net:%u chan:%u flags:%u\n",
95 params.net, params.channel, params.flags);
97 ret = frescan_recv(¶ms, msg, 200,
98 &recv_bytes, &from, &prio);
101 DEBUG(FRESCAN_ACCEPTOR_THREAD_ENABLE_DEBUG,
102 "msg received, from:%u size:%u prio:%u\n",
103 from, recv_bytes, prio);
105 ret = frescan_message_parse(params.net, msg, recv_bytes, from);