Allow -1 as valid fd in libevdev_change_fd
[platform/upstream/libevdev.git] / libevdev / libevdev-int.h
index dd38cc8..847fe56 100644 (file)
  * OF THIS SOFTWARE.
  */
 
-#ifndef libevdev_INT_H
-#define libevdev_INT_H
+#ifndef LIBEVDEV_INT_H
+#define LIBEVDEV_INT_H
 
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <errno.h>
 #include "libevdev.h"
 
@@ -38,6 +39,8 @@
 #define ABS_MT_MAX ABS_MT_TOOL_Y
 #define ABS_MT_CNT (ABS_MT_MAX - ABS_MT_MIN + 1)
 #define LIBEVDEV_EXPORT __attribute__((visibility("default")))
+#define LIBEVDEV_PRINTF(_format, _args) __attribute__ ((format (printf, _format, _args)))
+#define ALIAS(_to) __attribute__((alias(#_to)))
 
 #undef min
 #undef max
@@ -57,9 +60,9 @@
  * default state: SYNC_NONE
  *
  * SYNC_NONE → SYN_DROPPED or forced sync → SYNC_NEEDED
- * SYNC_NEEDED → libevdev_next_event(LIBEVDEV_READ_SYNC) → SYNC_IN_PROGRESS
- * SYNC_NEEDED → libevdev_next_event(LIBEVDEV_READ_SYNC_NONE) → SYNC_NONE
- * SYNC_IN_PROGRESS → libevdev_next_event(LIBEVDEV_READ_SYNC_NONE) → SYNC_NONE
+ * SYNC_NEEDED → libevdev_next_event(LIBEVDEV_READ_FLAG_SYNC) → SYNC_IN_PROGRESS
+ * SYNC_NEEDED → libevdev_next_event(LIBEVDEV_READ_FLAG_SYNC_NONE) → SYNC_NONE
+ * SYNC_IN_PROGRESS → libevdev_next_event(LIBEVDEV_READ_FLAG_SYNC_NONE) → SYNC_NONE
  * SYNC_IN_PROGRESS → no sync events left → SYNC_NONE
  *
  */
@@ -71,8 +74,7 @@ enum SyncState {
 
 struct libevdev {
        int fd;
-       libevdev_log_func_t log;
-
+       bool initialized;
        char *name;
        char *phys;
        char *uniq;
@@ -109,6 +111,30 @@ struct libevdev {
        struct timeval last_event_time;
 };
 
+struct logdata {
+       enum libevdev_log_priority priority;    /** minimum logging priority */
+       libevdev_log_func_t handler;            /** handler function */
+       void *userdata;                         /** user-defined data pointer */
+};
+extern struct logdata log_data;
+
+#define log_msg_cond(priority, ...) \
+       do { \
+               if (libevdev_get_log_priority() >= priority) \
+                       log_msg(priority, log_data.userdata, __FILE__, __LINE__, __func__, __VA_ARGS__); \
+       } while(0)
+
+#define log_error(...) log_msg_cond(LIBEVDEV_LOG_ERROR, __VA_ARGS__)
+#define log_info(...) log_msg_cond(LIBEVDEV_LOG_INFO, __VA_ARGS__)
+#define log_dbg(...) log_msg_cond(LIBEVDEV_LOG_DEBUG, __VA_ARGS__)
+#define log_bug(...) log_msg_cond(LIBEVDEV_LOG_ERROR, "BUG: "__VA_ARGS__)
+
+extern void
+log_msg(enum libevdev_log_priority priority,
+       void *data,
+       const char *file, int line, const char *func,
+       const char *format, ...) LIBEVDEV_PRINTF(6, 7);
+
 /**
  * @return a pointer to the next element in the queue, or NULL if the queue
  * is full.