| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-18 20:51:50 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-18 20:51:50 +0200 |
| commit | b1525c35503cafafd69aa63dedddf49bd00bac5f (patch) | |
| tree | 984e78e093629b4029b5aa2a549b081819691484 | |
| parent | 00990bdbc3f3e02a784352481ebdd567cea6ec0c (diff) | |
Starting to work on a timeout option.
| -rw-r--r-- | conf/space_navigator.conf | 1 | ||||
| -rw-r--r-- | src/config.c | 80 | ||||
| -rw-r--r-- | src/config.h | 2 |
3 files changed, 83 insertions, 0 deletions
diff --git a/conf/space_navigator.conf b/conf/space_navigator.conf index aa18480..788ee70 100644 --- a/conf/space_navigator.conf +++ b/conf/space_navigator.conf @@ -1,4 +1,5 @@ # 3DConnexion SpaceNavigator +timeout 100 # AXIS MIN MAX FUZZ FLAT RESOLUTION OPTIONS X -350 350 0 0 1 direct,real_fuzz Y -350 350 0 0 1 direct,real_fuzz diff --git a/src/config.c b/src/config.c index 44d463f..3b8eb0a 100644 --- a/src/config.c +++ b/src/config.c @@ -4,6 +4,8 @@ #include <stdlib.h> #include <limits.h> +#include <sys/time.h> + #include "error.h" #include "pervasive.h" #include "axis.h" @@ -242,6 +244,66 @@ static int read_axis_options return -1; } +static int parse_timeout_option +( + struct relabsd_config * const conf, + FILE * const f +) +{ + int valc, timeout_msec; + const int prev_errno = errno; + + conf->enable_timeout = 1; + + errno = 0; + + valc = fscanf(f, "%d", &timeout_msec); + + if (valc == EOF) + { + if (errno == 0) + { + RELABSD_S_FATAL + ( + "[CONFIG] Unexpected end of file while reading timeout option." + ); + } + else + { + RELABSD_FATAL + ( + "[CONFIG] An error occured while reading timeout option: %s.", + strerror(errno) + ); + } + + errno = prev_errno; + + return -1; + } + else if (valc < 1) + { + RELABSD_S_FATAL + ( + "[CONFIG] Invalid parameter count for timeout option (1 expected)." + ); + + errno = prev_errno; + + return -1; + } + + memset((void *) &(conf->timeout), 0, sizeof(struct timeval)); + + conf->timeout.tv_usec = + ( + ((suseconds_t) timeout_msec) + * ((suseconds_t) 1000) + ); + + return 0; +} + /* * Returns -1 on (fatal) error, * 0 on succes. @@ -260,6 +322,22 @@ static int parse_axis_configuration_line if (axis == RELABSD_UNKNOWN) { + if (RELABSD_STRING_EQUALS("timeout", buffer)) + { + if (parse_timeout_option(conf, f) < 0) + { + RELABSD_FATAL + ( + "[CONFIG] Issue while parsing timeout option '%s'.", + buffer + ); + + return -1; + } + + return 0; + } + RELABSD_FATAL ( "[CONFIG] Unknown axis '%s'.", @@ -390,6 +468,8 @@ static int read_config_file return -1; } + conf->enable_timeout = 0; + prev_errno = errno; errno = 0; diff --git a/src/config.h b/src/config.h index dde989d..3aa1a13 100644 --- a/src/config.h +++ b/src/config.h @@ -41,6 +41,8 @@ struct relabsd_config { const char * input_file; const char * device_name; + struct timeval timeout; + int enable_timeout; struct relabsd_config_axis axis[RELABSD_VALID_AXES_COUNT]; }; |


