OpenCBM
WINDOWS/dynlibusb.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2010 Spiro Trikaliotis
8  *
9 */
10 
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 
25 #include "opencbm.h"
26 
27 #include "arch.h"
28 #include "dynlibusb.h"
29 #include "getpluginaddress.h"
30 
31 usb_dll_t usb = { NULL };
32 
33 int dynlibusb_init(void) {
34  int error = 1;
35 
36  do {
37  usb.shared_object_handle = plugin_load("libusb0.dll");
38  if ( ! usb.shared_object_handle ) {
39  break;
40  }
41 
42 #define READ(_x) \
43  usb._x = plugin_get_address(usb.shared_object_handle, "usb_" ## #_x); \
44  if (usb._x == NULL) { \
45  break; \
46  }
47 
48  READ(open);
49  READ(close);
50 // READ(get_string);
51 // READ(get_string_simple);
52 // READ(get_descriptor_by_endpoint);
53 // READ(get_descriptor);
54  READ(bulk_write);
55  READ(bulk_read);
56 // READ(interrupt_write);
57 // READ(interrupt_read);
58  READ(control_msg);
59  READ(set_configuration);
60  READ(claim_interface);
61  READ(release_interface);
62 // READ(set_altinterface);
63  READ(resetep);
64  READ(clear_halt);
65 // READ(reset);
66  READ(strerror);
67  READ(init);
68 // READ(set_debug);
69  READ(find_busses);
70  READ(find_devices);
71  READ(device);
72  READ(get_busses);
73 
74  error = 0;
75  } while (0);
76 
77  return error;
78 }
79 
80 void dynlibusb_uninit(void) {
81 
82  do {
83  if (usb.shared_object_handle == NULL) {
84  break;
85  }
86 
87  plugin_unload(usb.shared_object_handle);
88 
89  memset(&usb, 0, sizeof usb);
90 
91  } while (0);
92 
93 }
Allow for libusb (0.1) to be loaded dynamically (Currently, this is used on Windows only) ...
#define READ(_x)
@@@
Definition: checkcable.c:156
Shared library / DLL for accessing the driver Functions for obtaining the addresses of plugin functio...
void plugin_unload(SHARED_OBJECT_HANDLE handle)
@@@
SHARED_OBJECT_HANDLE plugin_load(const char *name)
@@@
DLL interface for accessing the driver.
Define makros and functions which account for differences between the different architectures.