Update to new libusb
[bcusdk.git] / eibd / backend / usbif.h
blobbdaa29e2c9116f6bde846fe30c3c60fc73669198
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2009 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef EIB_USB_H
21 #define EIB_USB_H
23 #include "lowlevel.h"
24 #include "libusb.h"
26 typedef struct
28 int bus;
29 int device;
30 int config;
31 int altsetting;
32 int interface;
33 } USBEndpoint;
35 typedef struct
37 libusb_device *dev;
38 int config;
39 int altsetting;
40 int interface;
41 int sendep;
42 int recvep;
43 } USBDevice;
45 USBEndpoint parseUSBEndpoint (const char *addr);
46 USBDevice detectUSBEndpoint (USBEndpoint e);
48 class USBLowLevelDriver:public LowLevelDriverInterface, private Thread
50 libusb_device_handle *dev;
51 USBDevice d;
52 /** debug output */
53 Trace *t;
54 /** semaphore for inqueue */
55 pth_sem_t in_signal;
56 /** semaphore for outqueue */
57 pth_sem_t out_signal;
58 /** input queue */
59 Queue < CArray > inqueue;
60 /** output queue */
61 Queue < CArray * >outqueue;
62 /** event to wait for outqueue */
63 pth_event_t getwait;
64 /** semaphore to signal empty sendqueue */
65 pth_sem_t send_empty;
66 int state;
68 void Run (pth_sem_t * stop);
70 public:
71 USBLowLevelDriver (const char *device, Trace * tr);
72 ~USBLowLevelDriver ();
73 bool init ();
75 void Send_Packet (CArray l);
76 bool Send_Queue_Empty ();
77 pth_sem_t *Send_Queue_Empty_Cond ();
78 CArray *Get_Packet (pth_event_t stop);
79 void SendReset ();
80 bool Connection_Lost ();
81 EMIVer getEMIVer ();
84 #endif