Mark three deprecated functions as such
[platform/upstream/libevdev.git] / libevdev / libevdev.h
index e99fcbb..8d75acb 100644 (file)
 #ifndef LIBEVDEV_H
 #define LIBEVDEV_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <linux/input.h>
 #include <stdarg.h>
 
  *      }
  *      printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
  *      printf("Input device ID: bus %#x vendor %#x product %#x\n",
- *             libevdev_get_bustype(dev),
- *             libevdev_get_vendor_id(dev),
- *             libevdev_get_product_id(dev));
+ *             libevdev_get_id_bustype(dev),
+ *             libevdev_get_id_vendor(dev),
+ *             libevdev_get_id_product(dev));
  *      if (!libevdev_has_event_type(dev, EV_REL) ||
  *          !libevdev_has_event_code(dev, EV_KEY, BTN_LEFT)) {
  *              printf("This device does not look like a mouse\n");
  *
  *      do {
  *              struct input_event ev;
- *              rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
+ *              rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
  *              if (rc == 0)
  *                      printf("Event: %s %s %d\n",
  *                             libevdev_get_event_type_name(ev.type),
  *
  * dev = libevdev_new();
  * if (!dev)
- *         return ENOSPC;
+ *         return ENOMEM;
  *
  * err = libevdev_set_fd(dev, fd);
  * if (err < 0) {
  */
 struct libevdev;
 
-enum EvdevReadFlags {
-       LIBEVDEV_READ_SYNC              = 1, /**< Process data in sync mode */
-       LIBEVDEV_READ_NORMAL            = 2, /**< Process data in normal mode */
-       LIBEVDEV_FORCE_SYNC             = 4, /**< Pretend the next event is a SYN_DROPPED. There is
-                                                 no reason to ever use this except for
-                                                 automated tests, so don't. */
-       LIBEVDEV_READ_BLOCKING          = 8, /**< The fd is not in O_NONBLOCK and a read may block */
+/**
+ * @ingroup events
+ */
+enum libevdev_read_flag {
+       LIBEVDEV_READ_FLAG_SYNC         = 1, /**< Process data in sync mode */
+       LIBEVDEV_READ_FLAG_NORMAL       = 2, /**< Process data in normal mode */
+       LIBEVDEV_READ_FLAG_FORCE_SYNC   = 4, /**< Pretend the next event is a SYN_DROPPED and
+                                                 require the caller to sync */
+       LIBEVDEV_READ_FLAG_BLOCKING     = 8, /**< The fd is not in O_NONBLOCK and a read may block */
+
 };
 
 /**
@@ -346,35 +353,80 @@ int libevdev_new_from_fd(int fd, struct libevdev **dev);
 void libevdev_free(struct libevdev *dev);
 
 /**
+ * @ingroup init
+ */
+enum libevdev_log_priority {
+       LIBEVDEV_LOG_ERROR = 10,        /**< critical errors and application bugs */
+       LIBEVDEV_LOG_INFO  = 20,        /**< informational messages */
+       LIBEVDEV_LOG_DEBUG = 30,        /**< debug information */
+};
+
+/**
+ * @ingroup init
+ *
  * Logging function called by library-internal logging.
- * This function is expected to treat it's input like printf would.
+ * This function is expected to treat its input like printf would.
  *
+ * @param priority Log priority of this message
+ * @param data User-supplied data pointer (see libevdev_set_log_function())
+ * @param file libevdev source code file generating this message
+ * @param line libevdev source code line generating this message
+ * @param func libevdev source code function generating this message
  * @param format printf-style format string
  * @param args List of arguments
  *
- * @see libevdev_set_log_handler
+ * @see libevdev_set_log_function
  */
-typedef void (*libevdev_log_func_t)(const char *format, va_list args);
+typedef void (*libevdev_log_func_t)(enum libevdev_log_priority priority,
+                                   void *data,
+                                   const char *file, int line,
+                                   const char *func,
+                                   const char *format, va_list args);
 
 /**
+ * @ingroup init
+ *
  * Set a printf-style logging handler for library-internal logging. The default
- * logging function is a noop.
+ * logging function is to stdout.
  *
- * @param dev The evdev device
  * @param logfunc The logging function for this device. If NULL, the current
- * logging function is unset.
+ * logging function is unset and no logging is performed.
+ * @param data User-specific data passed to the log handler.
  *
  * @note This function may be called before libevdev_set_fd().
  */
-void libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc);
+void libevdev_set_log_function(libevdev_log_func_t logfunc, void *data);
 
+/**
+ * @ingroup init
+ *
+ * Define the minimum level to be printed to the log handler.
+ * Messages higher than this level are printed, others are discarded. This
+ * is a global setting and applies to any future logging messages.
+ *
+ * @param priority Minimum priority to be printed to the log.
+ *
+ */
+void libevdev_set_log_priority(enum libevdev_log_priority priority);
 
-enum EvdevGrabModes {
-       LIBEVDEV_GRAB = 3,
-       LIBEVDEV_UNGRAB = 4,
+/**
+ * @ingroup init
+ *
+ * @return the current log level
+ */
+enum libevdev_log_priority libevdev_get_log_priority(void);
+
+/**
+ * @ingroup init
+ */
+enum libevdev_grab_mode {
+       LIBEVDEV_GRAB = 3,      /**< Grab the device if not currently grabbed */
+       LIBEVDEV_UNGRAB = 4,    /**< Ungrab the device if currently grabbed */
 };
 
 /**
+ * @ingroup init
+ *
  * Grab or ungrab the device through a kernel EVIOCGRAB. This prevents other
  * clients (including kernel-internal ones such as rfkill) from receiving
  * events from this device.
@@ -390,7 +442,7 @@ enum EvdevGrabModes {
  * @return 0 if the device was successfull grabbed or ungrabbed, or a
  * negative errno in case of failure.
  */
-int libevdev_grab(struct libevdev *dev, int grab);
+int libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab);
 
 /**
  * @ingroup init
@@ -440,6 +492,8 @@ int libevdev_set_fd(struct libevdev* dev, int fd);
 int libevdev_change_fd(struct libevdev* dev, int fd);
 
 /**
+ * @ingroup init
+ *
  * @param dev The evdev device
  *
  * @return The previously set fd, or -1 if none had been set previously.
@@ -447,36 +501,59 @@ int libevdev_change_fd(struct libevdev* dev, int fd);
  */
 int libevdev_get_fd(const struct libevdev* dev);
 
+
+/**
+ * @ingroup events
+ */
+enum libevdev_read_status {
+       /**
+        * libevdev_next_event() has finished without an error
+        * and an event is available for processing.
+        *
+        * @see libevdev_next_event
+        */
+       LIBEVDEV_READ_STATUS_SUCCESS = 0,
+       /**
+        * Depending on the libevdev_next_event() read flag:
+        * * libevdev received a SYN_DROPPED from the device, and the caller should
+        * now resync the device, or,
+        * * an event has been read in sync mode.
+        *
+        * @see libevdev_next_event
+        */
+       LIBEVDEV_READ_STATUS_SYNC = 1,
+};
 /**
  * @ingroup events
  *
  * Get the next event from the device. This function operates in two different
  * modes: normal mode or sync mode.
  *
- * In normal mode, this function returns 0 and returns the event in the
- * parameter ev. If no events are available at this time, it returns -EAGAIN
- * and ev is undefined.
+ * In normal mode, this function returns LIBEVDEV_READ_STATUS_SUCCESS and
+ * returns the event in the parameter ev. If no events are available at this
+ * time, it returns -EAGAIN and ev is undefined.
  *
- * If a SYN_DROPPED is read from the device, this function returns 1. The
- * caller should now call this function with the LIBEVDEV_READ_SYNC flag set,
- * to get the set of events that make up the device state delta. This function
- * returns 1 for each event part of that delta, until it returns -EAGAIN once
- * all events have been synced.
+ * If a SYN_DROPPED is read from the device, this function returns
+ * LIBEVDEV_READ_STATUS_SYNC. The caller should now call this function with the
+ * LIBEVDEV_READ_FLAG_SYNC flag set, to get the set of events that make up the
+ * device state delta. This function returns LIBEVDEV_READ_STATUS_SYNC for
+ * each event part of that delta, until it returns -EAGAIN once all events
+ * have been synced.
  *
  * If a device needs to be synced by the caller but the caller does not call
- * with the LIBEVDEV_READ_SYNC flag set, all events from the diff are dropped
- * and event processing continues as normal.
+ * with the LIBEVDEV_READ_STATUS_SYNC flag set, all events from the diff are
+ * dropped and event processing continues as normal.
  *
  * @param dev The evdev device, already initialized with libevdev_set_fd()
- * @param flags Set of flags to determine behaviour. If LIBEVDEV_READ_NORMAL
- * is set, the next event is read in normal mode. If LIBEVDEV_READ_SYNC is
+ * @param flags Set of flags to determine behaviour. If LIBEVDEV_READ_FLAG_NORMAL
+ * is set, the next event is read in normal mode. If LIBEVDEV_READ_FLAG_SYNC is
  * set, the next event is read in sync mode.
  * @param ev On success, set to the current event.
  * @return On failure, a negative errno is returned.
- * @retval 0 One or more events where read of the device
+ * @retval LIBEVDEV_READ_STATUS_SUCCESS One or more events where read of the device
  * @retval -EAGAIN No events are currently available on the device
- * @retval 1 A SYN_DROPPED event was received, or a synced event was
- * returned.
+ * @retval LIBEVDEV_READ_STATUS_SYNC A SYN_DROPPED event was received, or a
+ * synced event was returned.
  *
  * @note This function is signal-safe.
  */
@@ -799,6 +876,10 @@ const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, un
  * Behaviour of this function is undefined if the device does not provide
  * the event.
  *
+ * If the device supports ABS_MT_SLOT, the value returned for any ABS_MT_*
+ * event code is the value of the currently active slot. You should use
+ * libevdev_get_slot_value() instead.
+ *
  * @param dev The evdev device, already initialized with libevdev_set_fd()
  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
  * @param code The event code to query for, one of ABS_X, REL_X, etc.
@@ -814,6 +895,34 @@ const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, un
 int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
 
 /**
+ * @ingroup kernel
+ *
+ * Set the value for a given event type and code. This only makes sense for
+ * some event types, e.g. setting the value for EV_REL is pointless.
+ *
+ * This is a local modification only affecting only this representation of
+ * this device. A future call to libevdev_get_event_value() will return this
+ * value, unless the value was overwritten by an event.
+ *
+ * If the device supports ABS_MT_SLOT, the value set for any ABS_MT_*
+ * event code is the value of the currently active slot. You should use
+ * libevdev_set_slot_value() instead.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
+ * @param code The event code to set the value for, one of ABS_X, LED_NUML, etc.
+ * @param value The new value to set
+ *
+ * @return 0 on success, or -1 on failure.
+ * @retval -1 the device does not have the event type or code enabled, or the code is outside the
+ * allowed limits for the given type, or the type cannot be set.
+ *
+ * @see libevdev_set_slot_value
+ * @see libevdev_get_event_value
+ */
+int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value);
+
+/**
  * @ingroup bits
  *
  * Fetch the current value of the event type. This is a shortcut for
@@ -851,7 +960,7 @@ int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, un
  *
  * @param dev The evdev device, already initialized with libevdev_set_fd()
  * @param slot The numerical slot number, must be smaller than the total number
- * of slots on this device
+ * of slots on this device
  * @param code The event code to query for, one of ABS_MT_POSITION_X, etc.
  *
  * @note This function is signal-safe.
@@ -863,6 +972,34 @@ int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, un
 int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
 
 /**
+ * @ingroup kernel
+ *
+ * Set the value for a given code for the given slot.
+ *
+ * This is a local modification only affecting only this representation of
+ * this device. A future call to libevdev_get_slot_value() will return this
+ * value, unless the value was overwritten by an event.
+ *
+ * This function does not set event values for axes outside the ABS_MT range,
+ * use libevdev_set_event_value() instead.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param slot The numerical slot number, must be smaller than the total number
+ * of slots on this device
+ * @param code The event code to set the value for, one of ABS_MT_POSITION_X, etc.
+ * @param value The new value to set
+ *
+ * @return 0 on success, or -1 on failure.
+ * @retval -1 the device does not have the event code enabled, or the code is
+ * outside the allowed limits for multitouch events, or the slot number is outside
+ * the limits for this device, or the device does not support multitouch events.
+ *
+ * @see libevdev_set_event_value
+ * @see libevdev_get_slot_value
+ */
+int libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value);
+
+/**
  * @ingroup mt
  *
  * Fetch the current value of the code for the given slot. This is a shortcut for
@@ -996,9 +1133,10 @@ int libevdev_enable_event_type(struct libevdev *dev, unsigned int type);
  * @ingroup kernel
  *
  * Forcibly disable an event type on this device, even if the underlying
- * device provides it, effectively muting all keys or axes. libevdev will
- * filter any events matching this type and none will reach the caller.
- * libevdev_has_event_type() will return false for this type.
+ * device provides it. This effectively mutes the respective set of
+ * events. libevdev will filter any events matching this type and none will
+ * reach the caller. libevdev_has_event_type() will return false for this
+ * type.
  *
  * In most cases, a caller likely only wants to disable a single code, not
  * the whole type. Use libevdev_disable_event_code() for that.
@@ -1052,10 +1190,10 @@ int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned
  * @ingroup kernel
  *
  * Forcibly disable an event code on this device, even if the underlying
- * device provides it, effectively muting this key or axis. libevdev will
- * filter any events matching this type and code and none will reach the
- * caller.
- * libevdev_has_event_code() will return false for this code combination.
+ * device provides it. This effectively mutes the respective set of
+ * events. libevdev will filter any events matching this type and code and
+ * none will reach the caller. libevdev_has_event_code() will return false for
+ * this code.
  *
  * Disabling all event codes for a given type will not disable the event
  * type. Use libevdev_disable_event_type() for that.
@@ -1091,7 +1229,72 @@ int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigne
  *
  * @see libevdev_enable_event_code
  */
-int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
+int libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
+
+
+/**
+ * @ingroup kernel
+ */
+enum libevdev_led_value {
+       LIBEVDEV_LED_ON = 3,
+       LIBEVDEV_LED_OFF = 4,
+};
+
+/**
+ * @ingroup kernel
+ *
+ * Turn an LED on or off. Convenience function, if you need to modify multiple
+ * LEDs simultaneously, use libevdev_kernel_set_led_values() instead.
+ *
+ * @note enabling an LED requires write permissions on the device's file descriptor.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param code The EV_LED event code to modify, one of LED_NUML, LED_CAPSL, ...
+ * @param value Specifies whether to turn the LED on or off
+ * @return zero on success, or a negative errno on failure
+ */
+int libevdev_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value);
+
+/**
+ * @ingroup kernel
+ *
+ * Turn multiple LEDs on or off simultaneously. This function expects a pair
+ * of LED codes and values to set them to, terminated by a -1. For example, to
+ * switch the NumLock LED on but the CapsLock LED off, use:
+ *
+ * @code
+ *     libevdev_kernel_set_led_values(dev, LED_NUML, LIBEVDEV_LED_ON,
+ *                                         LED_CAPSL, LIBEVDEV_LED_OFF,
+ *                                         -1);
+ * @endcode
+ *
+ * If any LED code or value is invalid, this function returns -EINVAL and no
+ * LEDs are modified.
+ *
+ * @note enabling an LED requires write permissions on the device's file descriptor.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param ... A pair of LED_* event codes and libevdev_led_value_t, followed by
+ * -1 to terminate the list.
+ * @return zero on success, or a negative errno on failure
+ */
+int libevdev_kernel_set_led_values(struct libevdev *dev, ...);
+
+/**
+ * @ingroup kernel
+ *
+ * Set the clock ID to be used for timestamps. Further events from this device
+ * will report an event time based on the given clock.
+ *
+ * This is a modification only affecting this representation of
+ * this device.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param clockid The clock to use for future events. Permitted values
+ * are CLOCK_MONOTONIC and CLOCK_REALTIME (the default).
+ * @return zero on success, or a negative errno on failure
+ */
+int libevdev_set_clock_id(struct libevdev *dev, int clockid);
 
 /**
  * @ingroup misc
@@ -1104,6 +1307,9 @@ int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const
  * with the exception that some sanity checks are performed to ensure type
  * is valid.
  *
+ * @note The ranges for types are compiled into libevdev. If the kernel
+ * changes the max value, libevdev will not automatically pick these up.
+ *
  * @param ev The input event to check
  * @param type Input event type to compare the event against (EV_REL, EV_ABS,
  * etc.)
@@ -1111,7 +1317,7 @@ int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const
  * @return 1 if the event type matches the given type, 0 otherwise (or if
  * type is invalid)
  */
-int libevdev_is_event_type(const struct input_event *ev, unsigned int type);
+int libevdev_event_is_type(const struct input_event *ev, unsigned int type);
 
 /**
  * @ingroup misc
@@ -1124,6 +1330,9 @@ int libevdev_is_event_type(const struct input_event *ev, unsigned int type);
  * with the exception that some sanity checks are performed to ensure type and
  * code are valid.
  *
+ * @note The ranges for types and codes are compiled into libevdev. If the kernel
+ * changes the max value, libevdev will not automatically pick these up.
+ *
  * @param ev The input event to check
  * @param type Input event type to compare the event against (EV_REL, EV_ABS,
  * etc.)
@@ -1133,7 +1342,7 @@ int libevdev_is_event_type(const struct input_event *ev, unsigned int type);
  * @return 1 if the event type matches the given type and code, 0 otherwise
  * (or if type/code are invalid)
  */
-int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code);
+int libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code);
 
 /**
  * @ingroup misc
@@ -1146,7 +1355,7 @@ int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsi
  * @note The list of names is compiled into libevdev. If the kernel adds new
  * defines for new properties libevdev will not automatically pick these up.
  */
-const char * libevdev_get_event_type_name(unsigned int type);
+const char * libevdev_event_type_get_name(unsigned int type);
 /**
  * @ingroup misc
  *
@@ -1159,7 +1368,7 @@ const char * libevdev_get_event_type_name(unsigned int type);
  * @note The list of names is compiled into libevdev. If the kernel adds new
  * defines for new properties libevdev will not automatically pick these up.
  */
-const char * libevdev_get_event_code_name(unsigned int type, unsigned int code);
+const char * libevdev_event_code_get_name(unsigned int type, unsigned int code);
 
 /**
  * @ingroup misc
@@ -1172,9 +1381,9 @@ const char * libevdev_get_event_code_name(unsigned int type, unsigned int code);
  * @note The list of names is compiled into libevdev. If the kernel adds new
  * defines for new properties libevdev will not automatically pick these up.
  * @note On older kernels input properties may not be defined and
- * libevdev_get_input_prop_name() will always return NULL
+ * libevdev_property_get_name() will always return NULL
  */
-const char* libevdev_get_property_name(unsigned int prop);
+const char* libevdev_property_get_name(unsigned int prop);
 
 /**
  * @ingroup misc
@@ -1188,7 +1397,7 @@ const char* libevdev_get_property_name(unsigned int prop);
  * @note The max value is compiled into libevdev. If the kernel changes the
  * max value, libevdev will not automatically pick these up.
  */
-int libevdev_get_event_type_max(unsigned int type);
+int libevdev_event_type_get_max(unsigned int type);
 
 /**
  * @ingroup bits
@@ -1213,18 +1422,38 @@ int libevdev_get_repeat(struct libevdev *dev, int *delay, int *period);
 #define LIBEVDEV_DEPRECATED
 #endif
 
-/* replacement: libevdev_get_abs_minimum */
-int libevdev_get_abs_min(const struct libevdev *dev, unsigned int code) LIBEVDEV_DEPRECATED;
-/* replacement: libevdev_get_abs_maximum */
-int libevdev_get_abs_max(const struct libevdev *dev, unsigned int code) LIBEVDEV_DEPRECATED;
+LIBEVDEV_DEPRECATED extern const enum libevdev_read_flag LIBEVDEV_READ_SYNC;
+LIBEVDEV_DEPRECATED extern const enum libevdev_read_flag LIBEVDEV_READ_NORMAL;
+LIBEVDEV_DEPRECATED extern const enum libevdev_read_flag LIBEVDEV_FORCE_SYNC;
+LIBEVDEV_DEPRECATED extern const enum libevdev_read_flag LIBEVDEV_READ_BLOCKING;
+
+/* replacement: libevdev_kernel_set_abs_info */
+int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs) LIBEVDEV_DEPRECATED;
 
-/* replacement: libevdev_get_property_name */
-const char* libevdev_get_input_prop_name(unsigned int prop) LIBEVDEV_DEPRECATED;
 
-int libevdev_get_product_id(const struct libevdev *dev) LIBEVDEV_DEPRECATED;
-int libevdev_get_vendor_id(const struct libevdev *dev) LIBEVDEV_DEPRECATED;
-int libevdev_get_bustype(const struct libevdev *dev) LIBEVDEV_DEPRECATED;
-int libevdev_get_version(const struct libevdev *dev) LIBEVDEV_DEPRECATED;
+/* replacement: libevdev_set_log_function */
+void libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc) LIBEVDEV_DEPRECATED;
 
+/** replacement: libevdev_event_type_get_max */
+int libevdev_get_event_type_max(unsigned int type) LIBEVDEV_DEPRECATED;
+
+/** replacement: libevdev_property_get_name */
+const char* libevdev_get_property_name(unsigned int prop) LIBEVDEV_DEPRECATED;
+
+/** replacement: libevdev_event_type_get_name */
+const char * libevdev_get_event_type_name(unsigned int type) LIBEVDEV_DEPRECATED;
+/** replacement: libevdev_event_code_get_name */
+const char * libevdev_get_event_code_name(unsigned int type, unsigned int code) LIBEVDEV_DEPRECATED;
+
+/** replacement: libevdev_event_is_type */
+int libevdev_is_event_type(const struct input_event *ev, unsigned int type) LIBEVDEV_DEPRECATED;
+
+/** replacement: libevdev_event_is_code */
+int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code) LIBEVDEV_DEPRECATED;
 /**************************************/
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* LIBEVDEV_H */