+static int handle_remove_user_event(struct device_handler *handler,
+ struct event *event)
+{
+ struct device *device = device_handler_find(handler, event->device);
+
+ if (!device)
+ return 0;
+
+ discover_server_notify_device_remove(handler->server, device);
+
+ /* remove device from handler device array */
+ device_handler_remove(handler, device);
+
+ talloc_free(device);
+ return 0;
+}
+
+typedef int (*event_handler)(struct device_handler *, struct event *);
+
+static event_handler handlers[EVENT_TYPE_MAX][EVENT_ACTION_MAX] = {
+ [EVENT_TYPE_UDEV] = {
+ [EVENT_ACTION_ADD] = handle_add_udev_event,
+ [EVENT_ACTION_REMOVE] = handle_remove_udev_event,
+ },
+ [EVENT_TYPE_USER] = {
+ [EVENT_ACTION_ADD] = handle_add_user_event,
+ [EVENT_ACTION_REMOVE] = handle_remove_user_event,
+ }
+};
+
+int device_handler_event(struct device_handler *handler,
+ struct event *event)
+{
+ if (event->type >= EVENT_TYPE_MAX ||
+ event->action >= EVENT_ACTION_MAX ||
+ !handlers[event->type][event->action]) {
+ pb_log("%s unknown type/action: %d/%d\n", __func__,
+ event->type, event->action);
+ return 0;
+ }
+
+ return handlers[event->type][event->action](handler, event);
+}
+
+struct device_handler *device_handler_init(struct discover_server *server,
+ int dry_run)