GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add hotplug support. · Raghuvardhan-Reddy78/libusb@7801ff9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • doc
    • doxygen.cfg.in
  • examples
    • Makefile.am
    • hotplugtest.c
  • libusb
    • Makefile.am
    • core.c
    • hotplug.c
    • hotplug.h
    • io.c
    • libusb.h
    • libusbi.h
    • version.h
    • version_nano.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ examples/xusb
2929
examples/dpfp
3030
examples/dpfp_threaded
3131
examples/fxload
32+
examples/hotplugtest
3233
tests/stress
3334
*.exe
3435
*.pc
Collapse file

‎doc/doxygen.cfg.in‎

Copy file name to clipboardExpand all lines: doc/doxygen.cfg.in
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ RECURSIVE = NO
505505
# excluded from the INPUT source files. This way you can easily exclude a
506506
# subdirectory from a directory tree whose root is specified with the INPUT tag.
507507

508-
EXCLUDE = @top_srcdir@/libusb/libusbi.h
508+
EXCLUDE = @top_srcdir@/libusb/libusbi.h @top_srcdir@/libusb/hotplug.h
509509

510510
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
511511
# directories that are symbolic links (a Unix filesystem feature) are excluded
Collapse file

‎examples/Makefile.am‎

Copy file name to clipboardExpand all lines: examples/Makefile.am
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
AM_CPPFLAGS = -I$(top_srcdir)/libusb
22
LDADD = ../libusb/libusb-1.0.la
33

4-
noinst_PROGRAMS = listdevs xusb fxload
4+
noinst_PROGRAMS = listdevs xusb fxload hotplugtest
55

66
if HAVE_SIGACTION
77
noinst_PROGRAMS += dpfp
Collapse file

‎examples/hotplugtest.c‎

Copy file name to clipboard
+96Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* libusb example program for hotplug API
3+
* Copyright © 2012-2013 Nathan Hjelm <[email protected]>
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include <stdlib.h>
21+
#include <stdio.h>
22+
23+
#include "libusb.h"
24+
25+
int done = 0;
26+
libusb_device_handle *handle;
27+
28+
static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
29+
{
30+
struct libusb_device_descriptor desc;
31+
int rc;
32+
33+
rc = libusb_get_device_descriptor(dev, &desc);
34+
if (LIBUSB_SUCCESS != rc) {
35+
fprintf (stderr, "Error getting device descriptor\n");
36+
}
37+
38+
printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct);
39+
40+
libusb_open (dev, &handle);
41+
42+
done++;
43+
44+
return 0;
45+
}
46+
47+
static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
48+
{
49+
printf ("Device detached\n");
50+
51+
libusb_close (handle);
52+
53+
done++;
54+
return 0;
55+
}
56+
57+
int main(int argc, char *argv[])
58+
{
59+
libusb_hotplug_callback_handle hp[2];
60+
int product_id, vendor_id, class_id;
61+
int rc;
62+
63+
vendor_id = (argc > 1) ? strtol (argv[1], NULL, 0) : 0x045a;
64+
product_id = (argc > 2) ? strtol (argv[2], NULL, 0) : 0x5005;
65+
class_id = (argc > 3) ? strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
66+
67+
libusb_init (NULL);
68+
69+
if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
70+
printf ("Hotplug capabilites are not supported on this platform\n");
71+
libusb_exit (NULL);
72+
return EXIT_FAILURE;
73+
}
74+
75+
rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id,
76+
product_id, class_id, hotplug_callback, NULL, &hp[0]);
77+
if (LIBUSB_SUCCESS != rc) {
78+
fprintf (stderr, "Error registering callback 0\n");
79+
libusb_exit (NULL);
80+
return EXIT_FAILURE;
81+
}
82+
83+
rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id,
84+
product_id,class_id, hotplug_callback_detach, NULL, &hp[1]);
85+
if (LIBUSB_SUCCESS != rc) {
86+
fprintf (stderr, "Error registering callback 1\n");
87+
libusb_exit (NULL);
88+
return EXIT_FAILURE;
89+
}
90+
91+
while (done < 2) {
92+
libusb_handle_events (NULL);
93+
}
94+
95+
libusb_exit (NULL);
96+
}
Collapse file

‎libusb/Makefile.am‎

Copy file name to clipboardExpand all lines: libusb/Makefile.am
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ endif
5050
libusb_1_0_la_CFLAGS = $(AM_CFLAGS)
5151
libusb_1_0_la_LDFLAGS = $(LTLDFLAGS)
5252
libusb_1_0_la_SOURCES = libusbi.h core.c descriptor.c io.c sync.c $(OS_SRC) \
53-
os/linux_usbfs.h os/darwin_usb.h os/windows_usb.h \
54-
$(THREADS_SRC) \
55-
os/poll_posix.h os/poll_windows.h \
56-
os/windows_common.h
53+
os/linux_usbfs.h os/darwin_usb.h os/windows_usb.h os/windows_common.h \
54+
hotplug.h hotplug.c $(THREADS_SRC) os/poll_posix.h os/poll_windows.h
5755

5856
hdrdir = $(includedir)/libusb-1.0
5957
hdr_HEADERS = libusb.h

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.