#include <sys/queue.h>
#include <libprop/proplib.h>
#define UDEV_DEVICE_PATH "/dev/udev"
#define LOCAL_BACKLOG 5
#define UDEV_DEVICE_FD_IDX 0
#define UDEV_SOCKET_FD_IDX 1
#define NFDS 2
struct pdev_array_entry {
int32_t refs;
int64_t generation;
prop_array_t pdev_array;
TAILQ_ENTRY(pdev_array_entry) link;
};
struct event_filter {
int id;
int neg;
int type;
char *key;
char *wildcard_match;
regex_t regex_match;
TAILQ_ENTRY(event_filter) link;
};
struct udev_monitor;
struct client_info {
pthread_t tid;
int fd;
struct udev_monitor *udm;
struct event_filter ev_filt;
};
struct udev_monitor_event {
prop_dictionary_t ev_dict;
TAILQ_ENTRY(udev_monitor_event) link;
};
struct udev_monitor {
pthread_mutex_t q_lock;
pthread_cond_t cond;
struct client_info *cli;
TAILQ_HEAD(, event_filter) ev_filt;
TAILQ_HEAD(, udev_monitor_event) ev_queue;
TAILQ_ENTRY(udev_monitor) link;
};
struct cmd_function {
const char *cmd;
int (*fn)(struct client_info *, prop_dictionary_t);
};
int init_local_server(const char *sockfile, int socktype, int nonblock);
int block_descriptor(int s);
int unblock_descriptor(int s);
int read_xml(int s, char **buf);
int send_xml(int s, char *xml);
void pdev_array_entry_ref(struct pdev_array_entry *pae);
void pdev_array_entry_unref(struct pdev_array_entry *pae);
void pdev_array_entry_insert(prop_array_t pa);
void pdev_array_clean(void);
struct pdev_array_entry *pdev_array_entry_get(int64_t generation);
struct pdev_array_entry *pdev_array_entry_get_last(void);
void handle_new_connection(int s);
int client_cmd_getdevs(struct client_info *cli, prop_dictionary_t dict);
void monitor_queue_event(prop_dictionary_t ev_dict);
int client_cmd_monitor(struct client_info *cli, prop_dictionary_t dict);
int match_event_filter(struct udev_monitor *udm, prop_dictionary_t ev_dict);
struct udev_monitor *udev_monitor_init(struct client_info *cli, prop_array_t filters);
void udev_monitor_free(struct udev_monitor *udm);
int ignore_signal(int signum);