1 /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
3 * Hotplug support for libusb
4 * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
5 * Copyright © 2012-2013 Peter Stuge <peter@stuge.se>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef USBI_HOTPLUG_H
23 #define USBI_HOTPLUG_H
27 enum usbi_hotplug_flags {
28 /* This callback is interested in device arrivals */
29 USBI_HOTPLUG_DEVICE_ARRIVED = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED,
31 /* This callback is interested in device removals */
32 USBI_HOTPLUG_DEVICE_LEFT = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
34 /* IMPORTANT: The values for the below entries must start *after*
35 * the highest value of the above entries!!!
38 /* The vendor_id field is valid for matching */
39 USBI_HOTPLUG_VENDOR_ID_VALID = (1 << 3),
41 /* The product_id field is valid for matching */
42 USBI_HOTPLUG_PRODUCT_ID_VALID = (1 << 4),
44 /* The dev_class field is valid for matching */
45 USBI_HOTPLUG_DEV_CLASS_VALID = (1 << 5),
47 /* This callback has been unregistered and needs to be freed */
48 USBI_HOTPLUG_NEEDS_FREE = (1 << 6),
52 * The hotplug callback structure. The user populates this structure with
53 * libusb_hotplug_prepare_callback() and then calls libusb_hotplug_register_callback()
54 * to receive notification of hotplug events.
56 struct libusb_hotplug_callback {
57 /** Flags that control how this callback behaves */
60 /** Vendor ID to match (if flags says this is valid) */
63 /** Product ID to match (if flags says this is valid) */
66 /** Device class to match (if flags says this is valid) */
69 /** Callback function to invoke for matching event/device */
70 libusb_hotplug_callback_fn cb;
72 /** Handle for this callback (used to match on deregister) */
73 libusb_hotplug_callback_handle handle;
75 /** User data that will be passed to the callback function */
78 /** List this callback is registered in (ctx->hotplug_cbs) */
79 struct list_head list;
82 struct libusb_hotplug_message {
83 /** The hotplug event that occurred */
84 libusb_hotplug_event event;
86 /** The device for which this hotplug event occurred */
87 struct libusb_device *device;
89 /** List this message is contained in (ctx->hotplug_msgs) */
90 struct list_head list;
93 void usbi_hotplug_deregister(struct libusb_context *ctx, int forced);
94 void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
95 libusb_hotplug_event event);
96 void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev,
97 libusb_hotplug_event event);