| summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/communication_thread.c | 1 | ||||
| -rw-r--r-- | src/server/conversion_main_loop.c | 129 | ||||
| -rw-r--r-- | src/server/interruption.c | 23 |
3 files changed, 97 insertions, 56 deletions
diff --git a/src/server/communication_thread.c b/src/server/communication_thread.c index 2ed1aae..2da54d2 100644 --- a/src/server/communication_thread.c +++ b/src/server/communication_thread.c @@ -23,7 +23,6 @@ void * posix_main_loop (void * params) /******************************************************************************/ /**** EXPORTED FUNCTIONS ******************************************************/ /******************************************************************************/ - int relabsd_server_create_communication_thread ( struct relabsd_server server [const static 1] diff --git a/src/server/conversion_main_loop.c b/src/server/conversion_main_loop.c index 0180e80..b5b97db 100644 --- a/src/server/conversion_main_loop.c +++ b/src/server/conversion_main_loop.c @@ -10,15 +10,6 @@ #include "input.h" #include "relabsd_device.h" -static int RELABSD_RUN = 1; - -static void interrupt (int unused_mandatory_parameter) -{ - RELABSD_RUN = 0; - - RELABSD_S_WARNING("Interrupted, will exit at the next input device event."); -} - static void handle_relative_axis_event ( struct relabsd_config * const conf, @@ -108,66 +99,94 @@ static void convert_input } } -static int set_signal_handlers () +int relabsd_server_conversion_loop +( + struct relabsd_server server [const static 1] +) { - RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Setting signal handlers."); - - if (signal(SIGINT, interrupt) == SIG_ERR) - { - RELABSD_S_FATAL("Unable to set the SIGINT signal handler."); - - return -1; - } - return 0; } -/* -int main (int argc, char ** argv) -{ - struct relabsd_config conf; - struct relabsd_input input; - struct relabsd_device dev; - - RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "relabsd started."); - if (set_signal_handlers() < 0) +int wait_for_next_event +( + const struct relabsd_physical_device * const input, + const struct relabsd_config * const config +) +{ + int ready_fds; + const int old_errno = errno; + fd_set ready_to_read; + struct timeval curr_timeout; + + FD_ZERO(&ready_to_read); + FD_SET(input->fd, &ready_to_read); + + /* call to select may alter timeout */ + memcpy + ( + (void *) &(curr_timeout), + (const void *) &(config->timeout), + sizeof(struct timeval) + ); + + errno = 0; + + RELABSD_S_ERROR + ( + "Waiting for input to be ready..." + ); + + ready_fds = select + ( + (input->fd + 1), + &ready_to_read, + (fd_set *) NULL, + (fd_set *) NULL, + (input->timed_out) ? NULL : &(curr_timeout) + ); + + if (errno != 0) { - return -1; - } + RELABSD_ERROR + ( + "Unable to wait for timeout: %s (errno: %d).", + strerror(errno), + errno + ); + + if (errno == EINTR) + { + /* Signal interruption? */ + } + else + { + /* TODO: error message */ + } - if (relabsd_config_parse(&conf, argc, argv) < 0) - { - return -2; - } + errno = old_errno; - if (relabsd_input_open(&input, &conf) < 0) - { - return -3; + return -1; } - if (relabsd_device_create(&dev, &conf) < 0) + if (ready_fds == -1) { - return -4; - } - - convert_input(&conf, &input, &dev); + /* TODO: error message */ - RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Terminating..."); + RELABSD_S_ERROR + ( + "Unable to wait for timeout, yet errno was not set to anything." + ); - relabsd_device_destroy(&dev); - relabsd_input_close(&input); + errno = old_errno; - RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Done."); + return -1; + } - return 0; -} -*/ + RELABSD_ERROR + ( + "Input is ready, ready_fds = %d", ready_fds + ); -int relabsd_server_conversion_loop -( - struct relabsd_server server [const static 1] -) -{ - return 0; + return ready_fds; } diff --git a/src/server/interruption.c b/src/server/interruption.c new file mode 100644 index 0000000..6eb7827 --- /dev/null +++ b/src/server/interruption.c @@ -0,0 +1,23 @@ +static int RELABSD_RUN = 1; + +static void interrupt (int unused_mandatory_parameter) +{ + RELABSD_RUN = 0; + + RELABSD_S_WARNING("Interrupted, will exit at the next input device event."); +} + +static int set_signal_handlers () +{ + RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Setting signal handlers."); + + if (signal(SIGINT, interrupt) == SIG_ERR) + { + RELABSD_S_FATAL("Unable to set the SIGINT signal handler."); + + return -1; + } + + return 0; +} + |


