| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | include/relabsd/config/parameters.h | 22 | ||||
| -rw-r--r-- | include/relabsd/device/axis.h | 17 | ||||
| -rw-r--r-- | include/relabsd/device/physical_device.h | 2 | ||||
| -rw-r--r-- | include/relabsd/device/physical_device_types.h | 2 | ||||
| -rw-r--r-- | include/relabsd/device/virtual_device.h | 33 | ||||
| -rw-r--r-- | include/relabsd/device/virtual_device_types.h | 6 | ||||
| -rw-r--r-- | src/config/parameters/compatibility.c | 50 | ||||
| -rw-r--r-- | src/config/parameters/parameters_accessors.c | 10 | ||||
| -rw-r--r-- | src/device/axis/axis.c | 8 | ||||
| -rw-r--r-- | src/device/physical/physical_device.c | 68 | ||||
| -rw-r--r-- | src/device/virtual/virtual_device.c | 71 | 
11 files changed, 180 insertions, 109 deletions
| diff --git a/include/relabsd/config/parameters.h b/include/relabsd/config/parameters.h index e1c67a4..8a5df32 100644 --- a/include/relabsd/config/parameters.h +++ b/include/relabsd/config/parameters.h @@ -1,7 +1,17 @@  #pragma once +/**** LIBEVDEV ****************************************************************/ +#include <libevdev/libevdev.h> + +/**** RELABSD *****************************************************************/  #include <relabsd/config/parameters_types.h> +#include <relabsd/device/axis.h> + +/******************************************************************************/ +/**** EXPORTED FUNCTIONS ******************************************************/ +/******************************************************************************/ +  /**** Utility *****************************************************************/  int relabsd_parameters_parse_execution_mode  ( @@ -25,6 +35,12 @@ int relabsd_parameters_argument_count_for  void relabsd_parameters_print_usage (const char exec [const restrict static 1]); +int relabsd_parameters_are_compatible_with +( +   const struct libevdev * const restrict libevdev/*[const restrict static 1]*/, +   const struct relabsd_parameters parameters [const restrict static 1] +); +  /**** Accessors ***************************************************************/  void relabsd_parameters_initialize_options  ( @@ -55,3 +71,9 @@ enum relabsd_parameters_run_mode relabsd_parameters_get_execution_mode  (     const struct relabsd_parameters parameters [const restrict static 1]  ); + +struct relabsd_axis * relabsd_parameters_get_axis +( +   const enum relabsd_axis_name i, +   const struct relabsd_parameters parameters [const restrict static 1] +); diff --git a/include/relabsd/device/axis.h b/include/relabsd/device/axis.h index 815bbb8..792a1cd 100644 --- a/include/relabsd/device/axis.h +++ b/include/relabsd/device/axis.h @@ -1,7 +1,14 @@  #pragma once +/**** LIBEVDEV ****************************************************************/ +#include <libevdev/libevdev.h> + +/**** RELABSD *****************************************************************/  #include <relabsd/device/axis_types.h> +/******************************************************************************/ +/**** EXPORTED FUNCTIONS ******************************************************/ +/******************************************************************************/  /*   * Gives the relabsd_axis and EV_ABS event code equivalent to an EV_REL event   * code. @@ -65,3 +72,13 @@ int relabsd_axis_enable_option_from_name  );  void relabsd_axis_enable (struct relabsd_axis axis [const restrict static 1]); +int relabsd_axis_is_enabled +( +   const struct relabsd_axis axis [const restrict static 1] +); + +void relabsd_axis_to_absinfo +( +   struct relabsd_axis axis [const restrict static 1], +   struct input_absinfo absinfo [const restrict static 1] +); diff --git a/include/relabsd/device/physical_device.h b/include/relabsd/device/physical_device.h index 3e55823..910d46f 100644 --- a/include/relabsd/device/physical_device.h +++ b/include/relabsd/device/physical_device.h @@ -31,7 +31,7 @@ void relabsd_physical_device_close   */  int relabsd_physical_device_read  ( -   const struct relabsd_physical_device device [const restrict static 1], +   struct relabsd_physical_device device [const restrict static 1],     unsigned int input_type [const restrict static 1],     unsigned int input_code [const restrict static 1],     int input_value [const restrict static 1] diff --git a/include/relabsd/device/physical_device_types.h b/include/relabsd/device/physical_device_types.h index 0c2cec7..fc15cc7 100644 --- a/include/relabsd/device/physical_device_types.h +++ b/include/relabsd/device/physical_device_types.h @@ -6,5 +6,5 @@ struct relabsd_physical_device  {     struct libevdev * libevdev;     int file; -   int timed_out; +   int is_late;  }; diff --git a/include/relabsd/device/virtual_device.h b/include/relabsd/device/virtual_device.h index 646422a..5ffd1c9 100644 --- a/include/relabsd/device/virtual_device.h +++ b/include/relabsd/device/virtual_device.h @@ -1,40 +1,45 @@  #pragma once +#include <relabsd/config/parameters.h> +  #include <relabsd/device/virtual_device_types.h>  /*   * - Clones the (real) input device.   * - Adds ABS event support to the clone. - * - Adds the ABS axis described in 'config' to the clone (overwriting if + * - Adds the ABS axis described in 'parameters' to the clone (overwriting if   *   needed).   * - Disables the associated REL events from the clone.   *   * Returns -1 on (fatal) error,   *         0  on success.   * - * 'dev' does not need to be initialized, as the function will to that for you - * (on success). - * On success, 'dev' will need to be closed. + * 'device' does not need to be initialized, as the function will to that for + * you (on success). + * On success, 'device' will need to be closed.   * This opens the (real) input device in read only mode to copy its properties.   */ -int relabsd_device_create +int relabsd_virtual_device_create_from  ( -   struct relabsd_device * const dev, -   const struct relabsd_config * const config +   const struct relabsd_parameters parameters [const restrict static 1], +   struct relabsd_virtual_device device [const restrict static 1]  ); -void relabsd_device_destroy (const struct relabsd_device * const dev); +void relabsd_virtual_device_destroy +( +   const struct relabsd_virtual_device device [const restrict static 1] +);  /* - * Write an event to 'dev'. At this time, every event written to 'dev' is + * Write an event to 'device'. At this time, every event written to 'device' is   * followed by an EV_SYN event.   *   * Returns 0 if both the event and the EV_SYN were successful,   *         -1 if either failed.   */ -int relabsd_device_write_evdev_event +int relabsd_virtual_device_write_evdev_event  ( -   const struct relabsd_device * const dev, +   const struct relabsd_virtual_device device [const restrict static 1],     unsigned int const type,     unsigned int const code,     int const value @@ -44,8 +49,8 @@ int relabsd_device_write_evdev_event   * Send an event for each enabled axis, setting it to zero.   * An EV_SYN event is sent afterwards.   */ -void relabsd_device_set_axes_to_zero +void relabsd_virtual_device_set_axes_to_zero  ( -   const struct relabsd_device * const dev, -   const struct relabsd_config * const config +   const struct relabsd_parameters parameters [const restrict static 1], +   const struct relabsd_virtual_device device [const restrict static 1]  ); diff --git a/include/relabsd/device/virtual_device_types.h b/include/relabsd/device/virtual_device_types.h index d20fafe..7c0c05a 100644 --- a/include/relabsd/device/virtual_device_types.h +++ b/include/relabsd/device/virtual_device_types.h @@ -16,8 +16,8 @@     #define RELABSD_UINPUT_OPEN_MANAGED LIBEVDEV_UINPUT_OPEN_MANAGED  #endif -struct relabsd_device +struct relabsd_virtual_device  { -   struct libevdev * dev; -   struct libevdev_uinput * uidev; +   struct libevdev * libevdev; +   struct libevdev_uinput * uinput_device;  }; diff --git a/src/config/parameters/compatibility.c b/src/config/parameters/compatibility.c new file mode 100644 index 0000000..cc65c7f --- /dev/null +++ b/src/config/parameters/compatibility.c @@ -0,0 +1,50 @@ +/**** LIBEVDEV ****************************************************************/ +#include <libevdev/libevdev.h> + +/**** RELABSD *****************************************************************/ +#include <relabsd/debug.h> + +#include <relabsd/config/parameters.h> + +#include <relabsd/device/axis.h> + +/******************************************************************************/ +/**** LOCAL FUNCTIONS *********************************************************/ +/******************************************************************************/ + +/******************************************************************************/ +/**** EXPORTED FUNCTIONS ******************************************************/ +/******************************************************************************/ +int relabsd_parameters_are_compatible_with +( +   const struct libevdev * const restrict libevdev, +   const struct relabsd_parameters parameters [const restrict static 1] +) +{ +   int i, device_is_valid; +   unsigned int rel_code; + +   device_is_valid = 1; + +   for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i) +   { +      if (relabsd_axis_is_enabled(parameters->axes + i)) +      { +         rel_code = relabsd_axis_name_to_evdev_rel((enum relabsd_axis_name) i); + +         if (!libevdev_has_event_code(libevdev, EV_REL, rel_code)) +         { +            RELABSD_ERROR +            ( +               "Input device has no relative %s axis, yet the configuration " +               "file asks to convert it.", +               relabsd_axis_name_to_string((enum relabsd_axis_name) i) +            ); + +            device_is_valid = 0; +         } +      } +   } + +   return device_is_valid; +} diff --git a/src/config/parameters/parameters_accessors.c b/src/config/parameters/parameters_accessors.c index e1fd805..bd6624c 100644 --- a/src/config/parameters/parameters_accessors.c +++ b/src/config/parameters/parameters_accessors.c @@ -62,3 +62,13 @@ enum relabsd_parameters_run_mode relabsd_parameters_get_execution_mode  {     return parameters->mode;  } + +struct relabsd_axis * relabsd_parameters_get_axis +( +   const enum relabsd_axis_name i, +   const struct relabsd_parameters parameters [const restrict static 1] +) +{ +   return (parameters->axes + i); +} + diff --git a/src/device/axis/axis.c b/src/device/axis/axis.c index 2659c84..5fe313e 100644 --- a/src/device/axis/axis.c +++ b/src/device/axis/axis.c @@ -44,4 +44,10 @@ void relabsd_axis_enable     axis->is_enabled = 1;  } - +int relabsd_axis_is_enabled +( +   const struct relabsd_axis axis [const restrict static 1] +) +{ +   return axis->is_enabled; +} diff --git a/src/device/physical/physical_device.c b/src/device/physical/physical_device.c index 4582c2d..e7b4167 100644 --- a/src/device/physical/physical_device.c +++ b/src/device/physical/physical_device.c @@ -10,66 +10,13 @@  /**** RELABSD *****************************************************************/  #include <relabsd/debug.h> +#include <relabsd/config/parameters.h> + +#include <relabsd/device/physical_device.h> +  /******************************************************************************/  /**** LOCAL FUNCTIONS *********************************************************/  /******************************************************************************/ -/* - * Ensures that the input device has enabled the EV_REL axes mentioned - * in the configuration file. - * - * Returns -1 on (fatal) error, - *         0 all configured axes are accounted for. - */ -static int check_for_axes -( -   const struct libevdev * const dev, -   const struct relabsd_config * const conf -) -{ -   int i, device_is_valid; -   unsigned int rel_code; - -   device_is_valid = 1; - -   for (i = RELABSD_VALID_AXES_COUNT; i --> 0;) -   { -      if (conf->axis[i].enabled) -      { -         rel_code = relabsd_axis_to_rel((enum relabsd_axis) i); - -         if (!libevdev_has_event_code(dev, EV_REL, rel_code)) -         { -            RELABSD_FATAL -            ( -               "Input device has no relative %s axis, yet the configuration " -               "file asks to convert it.", -               relabsd_axis_to_name((enum relabsd_axis) i) -            ); - -            device_is_valid = 0; -         } -      } -   } - -   return (device_is_valid - 1); -} - -/* - * Ensures that the input device is compatible with the config file. - * - * Returns -1 on (fatal) error, - *         0 is the device is compatible. - */ -static int device_is_compatible -( -   const struct libevdev * const dev, -   const struct relabsd_config * const conf -) -{ - - -   return 0; -}  /******************************************************************************/  /**** EXPORTED FUNCTIONS ******************************************************/ @@ -77,8 +24,7 @@ static int device_is_compatible  int relabsd_physical_device_compatibility_test  (     const struct relabsd_physical_device device [const restrict static 1], -   const struct relabsd_parameters parameters [const restrict static 0], -   const int verbose +   const struct relabsd_parameters parameters [const restrict]  )  {     if (!libevdev_has_event_type(device->libevdev, EV_REL)) @@ -91,7 +37,7 @@ int relabsd_physical_device_compatibility_test     if     (        (parameters != (const struct relabsd_parameters *) NULL) -      && (check_for_axes(device->libevdev, parameters, verbose) < 0) +      && relabsd_parameters_are_compatible_with(device->libevdev, parameters)     )     {        RELABSD_S_FATAL @@ -174,7 +120,7 @@ void relabsd_physical_device_close  int relabsd_physical_device_read  ( -   const struct relabsd_physical_device device [const restrict static 1], +   struct relabsd_physical_device device [const restrict static 1],     unsigned int input_type [const restrict static 1],     unsigned int input_code [const restrict static 1],     int input_value [const restrict static 1] diff --git a/src/device/virtual/virtual_device.c b/src/device/virtual/virtual_device.c index 0c5eab4..7617c8c 100644 --- a/src/device/virtual/virtual_device.c +++ b/src/device/virtual/virtual_device.c @@ -5,6 +5,7 @@  #include <fcntl.h>  #include <stdlib.h>  #include <string.h> +#include <unistd.h>  /**** LIBEVDEV ****************************************************************/  #include <libevdev/libevdev.h> @@ -23,33 +24,38 @@  /******************************************************************************/  static void replace_rel_axes  ( -   const struct relabsd_parameters parameters [const restrict static 1], +   const struct relabsd_parameters parameters [const static 1],     const struct relabsd_virtual_device device [const restrict static 1]  )  {     int i; -   for (i = 0; i < RELABSD_VALID_AXES_COUNT; i++) +   for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; i++)     { -      if (config->axis[i].enabled) +      enum relabsd_axis_name axis_name; +      struct relabsd_axis * axis; + +      axis_name = ((enum relabsd_axis_name) i); +      axis = relabsd_parameters_get_axis(axis_name, parameters); + +      if (relabsd_axis_is_enabled(axis))        {           struct input_absinfo absinfo; - -         relabsd_config_get_absinfo(config, (enum relabsd_axis) i, &absinfo); +         relabsd_axis_to_absinfo(axis, &absinfo);           /* TODO: report failure? 0 on success, -1 otherwise, no cause given. */           (void) libevdev_disable_event_code           (              device->libevdev,              EV_REL, -            relabsd_axis_to_rel((enum relabsd_axis) i); +            relabsd_axis_name_to_evdev_rel(axis_name)           );           (void) libevdev_enable_event_code           (              device->libevdev,              EV_ABS, -            relabsd_axis_to_abs((enum relabsd_axis) i); +            relabsd_axis_name_to_evdev_abs(axis_name),              &absinfo           );        } @@ -79,7 +85,7 @@ static int rename_device         * I'm assuming that since they use the term 'string', it is \0         * terminated.         */ -      real_name = libevdev_get_name(dev); +      real_name = libevdev_get_name(device->libevdev);     }     new_name_size += strlen(real_name); @@ -96,7 +102,7 @@ static int rename_device        );        /* This frees whatever came from 'libevdev_get_name'. */ -      libevdev_set_name(dev, RELABSD_DEVICE_PREFIX); +      libevdev_set_name(device->libevdev, RELABSD_DEVICE_PREFIX);        return -1;     } @@ -124,7 +130,7 @@ static int rename_device        );        /* This frees whatever came from 'libevdev_get_name'. */ -      libevdev_set_name(dev, RELABSD_DEVICE_PREFIX); +      libevdev_set_name(device->libevdev, RELABSD_DEVICE_PREFIX);        free((void *) new_name); @@ -132,7 +138,7 @@ static int rename_device     }     /* This frees whatever came from 'libevdev_get_name'. */ -   libevdev_set_name(dev, new_name); +   libevdev_set_name(device->libevdev, new_name);     /* FIXME: not entirely sure I should be the one to free it. */     free((void *) new_name); @@ -149,6 +155,7 @@ int relabsd_virtual_device_create_from     struct relabsd_virtual_device device [const restrict static 1]  )  { +   int err;     struct libevdev * physical_device_libevdev;     int physical_device_file; @@ -185,18 +192,19 @@ int relabsd_virtual_device_create_from           strerror(-err)        ); -      (void) close(device->file); +      (void) close(physical_device_file);        return -1;     } +   device->libevdev = physical_device_libevdev; +     /* Not exactly fatal, is it? */ -   (void) rename_device(parameters, physical_device_libevdev); +   (void) rename_device(parameters, device);     libevdev_enable_event_type(physical_device_libevdev, EV_ABS); -   replace_rel_axes(parameters, physical_device_libevdev); - +   replace_rel_axes(parameters, device);     err =        libevdev_uinput_create_from_device @@ -218,9 +226,6 @@ int relabsd_virtual_device_create_from        return -1;     } -   /* For future modifications. */ -   device->libevdev = physical_device_libevdev; -     /*      * We only need the physical device's (now modified) profile, not to actually      * read from it. @@ -229,7 +234,7 @@ int relabsd_virtual_device_create_from     if (close(physical_device_file) == -1)     { -      RELABSD_ERROR("Could not close physical device: %s". strerror(errno)); +      RELABSD_ERROR("Could not close physical device: %s", strerror(errno));     }     RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Created virtual device."); @@ -317,15 +322,21 @@ void relabsd_virtual_device_set_axes_to_zero  {     int i; -   for (i = 0; i < RELABSD_VALID_AXES_COUNT; ++i) +   for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i)     { -      if (parameters->axis[i].enabled) +      if +      ( +         relabsd_axis_is_enabled +         ( +            relabsd_parameters_get_axis((enum relabsd_axis_name) i, parameters) +         ) +      )        {           relabsd_virtual_device_write_evdev_event           (              device,              EV_ABS, -            relabsd_axis_to_abs((enum relabsd_axis) i), +            relabsd_axis_name_to_evdev_abs((enum relabsd_axis_name) i),              0           );        } @@ -337,11 +348,15 @@ void relabsd_virtual_device_set_axes_to_zero     i =        libevdev_uinput_write_event(device->uinput_device, EV_SYN, SYN_REPORT, 0); -   RELABSD_ERROR -   ( -      "Unable to generate event {type = EV_SYN; code = SYN_REPORT; value = 0}:" -      " %s.", -      strerror(-i) -   ); +   if (i != 0) +   { +      RELABSD_ERROR +      ( +         "Unable to generate event" +         " {type = EV_SYN; code = SYN_REPORT; value = 0}:" +         " %s.", +         strerror(-i) +      ); +   }  } | 


