| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input.c | 92 | ||||
| -rw-r--r-- | src/input.h | 6 | ||||
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/relabsd_device.c | 79 | ||||
| -rw-r--r-- | src/relabsd_device.h | 6 | 
5 files changed, 100 insertions, 85 deletions
| diff --git a/src/input.c b/src/input.c index 05484ae..96fc01d 100644 --- a/src/input.c +++ b/src/input.c @@ -145,11 +145,16 @@ int relabsd_input_read     int rc;     struct input_event event; +   if (libevdev_has_event_pending(input->dev) == 0) +   { +      return -1; +   } +     rc =        libevdev_next_event        (           input->dev, -         (LIBEVDEV_READ_FLAG_NORMAL | LIBEVDEV_READ_FLAG_BLOCKING), +         (LIBEVDEV_READ_FLAG_NORMAL /*| LIBEVDEV_READ_FLAG_BLOCKING*/),           &event        ); @@ -183,3 +188,88 @@ int relabsd_input_read     return 0;  } + +int relabsd_input_wait_for_next_event +( +   const struct relabsd_input * 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, +      &(curr_timeout) +   ); + +   if (errno != 0) +   { +      RELABSD_ERROR +      ( +         "Unable to wait for timeout: %s (errno: %d).", +         strerror(errno), +         errno +      ); + +      if (errno == EINTR) +      { +         /* Signal interruption? */ +      } +      else +      { +         /* TODO: error message */ +      } + +      errno = old_errno; + +      return -1; +   } + +   if (ready_fds == -1) +   { +      /* TODO: error message */ + +      RELABSD_S_ERROR +      ( +         "Unable to wait for timeout, yet errno was not set to anything." +      ); + +      errno = old_errno; + +      return -1; +   } + +   RELABSD_ERROR +   ( +      "Input is ready, ready_fds = %d", ready_fds +   ); + +   errno = old_errno; + +   return ready_fds; +} diff --git a/src/input.h b/src/input.h index 2be236c..e48b970 100644 --- a/src/input.h +++ b/src/input.h @@ -43,4 +43,10 @@ int relabsd_input_read     int * const input_value  ); +int relabsd_input_wait_for_next_event +( +   const struct relabsd_input * const input, +   const struct relabsd_config * const config +); +  #endif @@ -67,7 +67,7 @@ static void convert_input     {        if (conf->enable_timeout)        { -         switch (relabsd_device_wait_next_event(dev, conf)) +         switch (relabsd_input_wait_for_next_event(input, conf))           {              case 1:                 break; diff --git a/src/relabsd_device.c b/src/relabsd_device.c index 334243a..d62ff28 100644 --- a/src/relabsd_device.c +++ b/src/relabsd_device.c @@ -203,7 +203,7 @@ int relabsd_device_create        return -1;     } -   dev->fd = fd; +   close(fd);     return 0;  } @@ -214,7 +214,6 @@ void relabsd_device_destroy (const struct relabsd_device * const dev)     libevdev_uinput_destroy(dev->uidev);     libevdev_free(dev->dev); -   close(dev->fd);  }  int relabsd_device_write_evdev_event @@ -264,8 +263,8 @@ void relabsd_device_set_axes_to_zero           relabsd_device_write_evdev_event           (              dev, -            relabsd_axis_to_abs((enum relabsd_axis) i),              EV_ABS, +            relabsd_axis_to_abs((enum relabsd_axis) i),              0           );        } @@ -277,77 +276,3 @@ void relabsd_device_set_axes_to_zero     libevdev_uinput_write_event(dev->uidev, EV_SYN, SYN_REPORT, 0);  } -int relabsd_device_wait_next_event -( -   const struct relabsd_device * const dev, -   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(dev->fd, &ready_to_read); - -   /* call to select may alter timeout */ -   memcpy -   ( -      (void *) &(curr_timeout), -      (const void *) &(config->timeout), -      sizeof(struct timeval) -   ); - -   errno = 0; - -   ready_fds = select -   ( -      (dev->fd + 1), -      &ready_to_read, -      (fd_set *) NULL, -      (fd_set *) NULL, -      &(curr_timeout) -   ); - -   if (errno != 0) -   { -      RELABSD_ERROR -      ( -         "Unable to wait for timeout: %s (errno: %d).", -         strerror(errno), -         errno -      ); - -      if (errno == EINTR) -      { -         /* Signal interruption? */ -      } -      else -      { -         /* TODO: error message */ -      } - -      errno = old_errno; - -      return -1; -   } - -   if (ready_fds == -1) -   { -      /* TODO: error message */ - -      RELABSD_S_ERROR -      ( -         "Unable to wait for timeout, yet errno was not set to anything." -      ); - -      errno = old_errno; - -      return -1; -   } - -   errno = old_errno; - -   return ready_fds; -} diff --git a/src/relabsd_device.h b/src/relabsd_device.h index 8e83196..4aa181d 100644 --- a/src/relabsd_device.h +++ b/src/relabsd_device.h @@ -10,7 +10,6 @@ struct relabsd_device  {     struct libevdev * dev;     struct libevdev_uinput * uidev; -   int fd;  };  /* @@ -61,10 +60,5 @@ void relabsd_device_set_axes_to_zero     const struct relabsd_config * const config  ); -int relabsd_device_wait_next_event -( -   const struct relabsd_device * const dev, -   const struct relabsd_config * const config -);  #endif | 


