hotplug.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
  2. /*
  3. * Hotplug support for libusbx
  4. * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
  5. * Copyright © 2012-2013 Peter Stuge <peter@stuge.se>
  6. *
  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.
  11. *
  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.
  16. *
  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
  20. */
  21. #if !defined(USBI_HOTPLUG_H)
  22. #define USBI_HOTPLUG_H
  23. #ifndef LIBUSBI_H
  24. #include "libusbi.h"
  25. #endif
  26. /** \ingroup hotplug
  27. * The hotplug callback structure. The user populates this structure with
  28. * libusb_hotplug_prepare_callback() and then calls libusb_hotplug_register_callback()
  29. * to receive notification of hotplug events.
  30. */
  31. struct libusb_hotplug_callback {
  32. /** Context this callback is associated with */
  33. struct libusb_context *ctx;
  34. /** Vendor ID to match or LIBUSB_HOTPLUG_MATCH_ANY */
  35. int vendor_id;
  36. /** Product ID to match or LIBUSB_HOTPLUG_MATCH_ANY */
  37. int product_id;
  38. /** Device class to match or LIBUSB_HOTPLUG_MATCH_ANY */
  39. int dev_class;
  40. /** Hotplug callback flags */
  41. libusb_hotplug_flag flags;
  42. /** Event(s) that will trigger this callback */
  43. libusb_hotplug_event events;
  44. /** Callback function to invoke for matching event/device */
  45. libusb_hotplug_callback_fn cb;
  46. /** Handle for this callback (used to match on deregister) */
  47. libusb_hotplug_callback_handle handle;
  48. /** User data that will be passed to the callback function */
  49. void *user_data;
  50. /** Callback is marked for deletion */
  51. int needs_free;
  52. /** List this callback is registered in (ctx->hotplug_cbs) */
  53. struct list_head list;
  54. };
  55. typedef struct libusb_hotplug_callback libusb_hotplug_callback;
  56. struct libusb_hotplug_message {
  57. libusb_hotplug_event event;
  58. struct libusb_device *device;
  59. };
  60. typedef struct libusb_hotplug_message libusb_hotplug_message;
  61. void usbi_hotplug_deregister_all(struct libusb_context *ctx);
  62. void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
  63. libusb_hotplug_event event);
  64. #endif