VirtualBox

source: vbox/trunk/src/VBox/Main/os2/USBProxyServiceOs2.cpp@ 33223

Last change on this file since 33223 was 31892, checked in by vboxsync, 14 years ago

OSE header fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: USBProxyServiceOs2.cpp 31892 2010-08-24 08:00:51Z vboxsync $ */
2/** @file
3 * VirtualBox USB Proxy Service, OS/2 Specialization.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define INCL_BASE
23#define INCL_ERRORS
24#include "USBProxyService.h"
25#include "Logging.h"
26
27#include <VBox/usb.h>
28#include <VBox/err.h>
29
30#include <iprt/string.h>
31#include <iprt/alloc.h>
32#include <iprt/assert.h>
33#include <iprt/file.h>
34#include <iprt/err.h>
35
36
37/**
38 * Initialize data members.
39 */
40USBProxyServiceOs2::USBProxyServiceOs2 (Host *aHost)
41 : USBProxyService (aHost), mhev (NULLHANDLE), mhmod (NULLHANDLE),
42 mpfnUsbRegisterChangeNotification (NULL), mpfnUsbDeregisterNotification (NULL),
43 mpfnUsbQueryNumberDevices (NULL), mpfnUsbQueryDeviceReport (NULL)
44{
45 LogFlowThisFunc(("aHost=%p\n", aHost));
46
47 /*
48 * Try initialize the usbcalls stuff.
49 */
50 int rc = DosCreateEventSem (NULL, &mhev, 0, FALSE);
51 rc = RTErrConvertFromOS2 (rc);
52 if (RT_SUCCESS(rc))
53 {
54 rc = DosLoadModule (NULL, 0, (PCSZ)"usbcalls", &mhmod);
55 rc = RTErrConvertFromOS2 (rc);
56 if (RT_SUCCESS(rc))
57 {
58 if ( (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbQueryNumberDevices", (PPFN)&mpfnUsbQueryNumberDevices)) == NO_ERROR
59 && (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbQueryDeviceReport", (PPFN)&mpfnUsbQueryDeviceReport)) == NO_ERROR
60 && (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbRegisterChangeNotification", (PPFN)&mpfnUsbRegisterChangeNotification)) == NO_ERROR
61 && (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbDeregisterNotification", (PPFN)&mpfnUsbDeregisterNotification)) == NO_ERROR
62 )
63 {
64 rc = mpfnUsbRegisterChangeNotification (&mNotifyId, mhev, mhev);
65 if (!rc)
66 {
67 /*
68 * Start the poller thread.
69 */
70 rc = start();
71 if (RT_SUCCESS(rc))
72 {
73 LogFlowThisFunc(("returns successfully - mNotifyId=%d\n", mNotifyId));
74 mLastError = VINF_SUCCESS;
75 return;
76 }
77 }
78
79 LogRel (("USBProxyServiceOs2: failed to register change notification, rc=%d\n", rc));
80 }
81 else
82 LogRel (("USBProxyServiceOs2: failed to load usbcalls\n"));
83
84 DosFreeModule (mhmod);
85 }
86 else
87 LogRel (("USBProxyServiceOs2: failed to load usbcalls, rc=%d\n", rc));
88 mhmod = NULLHANDLE;
89 }
90 else
91 mhev = NULLHANDLE;
92
93 mLastError = rc;
94 LogFlowThisFunc(("returns failure!!! (rc=%Rrc)\n", rc));
95}
96
97
98/**
99 * Stop all service threads and free the device chain.
100 */
101USBProxyServiceOs2::~USBProxyServiceOs2()
102{
103 LogFlowThisFunc(("\n"));
104
105 /*
106 * Stop the service.
107 */
108 if (isActive())
109 stop();
110
111 /*
112 * Free resources.
113 */
114 if (mhmod)
115 {
116 if (mpfnUsbDeregisterNotification)
117 mpfnUsbDeregisterNotification (mNotifyId);
118
119 mpfnUsbRegisterChangeNotification = NULL;
120 mpfnUsbDeregisterNotification = NULL;
121 mpfnUsbQueryNumberDevices = NULL;
122 mpfnUsbQueryDeviceReport = NULL;
123
124 DosFreeModule (mhmod);
125 mhmod = NULLHANDLE;
126 }
127}
128
129
130int USBProxyServiceOs2::captureDevice (HostUSBDevice *aDevice)
131{
132 Log (("USBProxyServiceOs2::captureDevice: %p\n", aDevice));
133 AssertReturn(aDevice, VERR_GENERAL_FAILURE);
134 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
135
136 /*
137 * Don't think we need to do anything when the device is held... fake it.
138 */
139 Assert(aDevice->isStatePending());
140 interruptWait();
141
142 return VINF_SUCCESS;
143}
144
145
146int USBProxyServiceOs2::releaseDevice (HostUSBDevice *aDevice)
147{
148 Log (("USBProxyServiceOs2::releaseDevice: %p\n", aDevice));
149 AssertReturn(aDevice, VERR_GENERAL_FAILURE);
150 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
151
152 /*
153 * We're not really holding it atm., just fake it.
154 */
155 Assert(aDevice->isStatePending());
156 interruptWait();
157
158 return VINF_SUCCESS;
159}
160
161
162bool USBProxyServiceOs2::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine)
163{
164 return updateDeviceStateFake(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine);
165}
166
167
168
169int USBProxyServiceOs2::wait(RTMSINTERVAL aMillies)
170{
171 int rc = DosWaitEventSem(mhev, aMillies);
172 return RTErrConvertFromOS2(rc);
173}
174
175
176int USBProxyServiceOs2::interruptWait (void)
177{
178 int rc = DosPostEventSem (mhev);
179 return rc == NO_ERROR || rc == ERROR_ALREADY_POSTED
180 ? VINF_SUCCESS
181 : RTErrConvertFromOS2 (rc);
182}
183
184#include <stdio.h>
185
186PUSBDEVICE USBProxyServiceOs2::getDevices (void)
187{
188 /*
189 * Count the devices.
190 */
191 ULONG cDevices = 0;
192 int rc = mpfnUsbQueryNumberDevices ((PULONG)&cDevices); /* Thanks to com/xpcom, PULONG and ULONG * aren't the same. */
193 if (rc)
194 return NULL;
195
196 /*
197 * Retrieve information about each device.
198 */
199 PUSBDEVICE pFirst = NULL;
200 PUSBDEVICE *ppNext = &pFirst;
201 for (ULONG i = 0; i < cDevices; i++)
202 {
203 /*
204 * Query the device and config descriptors.
205 */
206 uint8_t abBuf[1024];
207 ULONG cb = sizeof(abBuf);
208 rc = mpfnUsbQueryDeviceReport(i + 1, (PULONG)&cb, &abBuf[0]); /* see above (PULONG) */
209 if (rc)
210 continue;
211 PUSBDEVICEDESC pDevDesc = (PUSBDEVICEDESC)&abBuf[0];
212 if ( cb < sizeof(*pDevDesc)
213 || pDevDesc->bDescriptorType != USB_DT_DEVICE
214 || pDevDesc->bLength < sizeof(*pDevDesc)
215 || pDevDesc->bLength > sizeof(*pDevDesc) * 2)
216 continue;
217 PUSBCONFIGDESC pCfgDesc = (PUSBCONFIGDESC)&abBuf[pDevDesc->bLength];
218 if ( pCfgDesc->bDescriptorType != USB_DT_CONFIG
219 || pCfgDesc->bLength >= sizeof(*pCfgDesc))
220 pCfgDesc = NULL;
221
222 /*
223 * Skip it if it's some kind of hub.
224 */
225 if (pDevDesc->bDeviceClass == USB_HUB_CLASSCODE)
226 continue;
227
228 /*
229 * Allocate a new device node and initialize it with the basic stuff.
230 */
231 PUSBDEVICE pCur = (PUSBDEVICE)RTMemAlloc(sizeof(*pCur));
232 pCur->bcdUSB = pDevDesc->bcdUSB;
233 pCur->bDeviceClass = pDevDesc->bDeviceClass;
234 pCur->bDeviceSubClass = pDevDesc->bDeviceSubClass;
235 pCur->bDeviceProtocol = pDevDesc->bDeviceProtocol;
236 pCur->idVendor = pDevDesc->idVendor;
237 pCur->idProduct = pDevDesc->idProduct;
238 pCur->bcdDevice = pDevDesc->bcdDevice;
239 pCur->pszManufacturer = RTStrDup("");
240 pCur->pszProduct = RTStrDup("");
241 pCur->pszSerialNumber = NULL;
242 pCur->u64SerialHash = 0;
243 //pCur->bNumConfigurations = pDevDesc->bNumConfigurations;
244 pCur->bNumConfigurations = 0;
245 pCur->paConfigurations = NULL;
246 pCur->enmState = USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
247 pCur->enmSpeed = USBDEVICESPEED_UNKNOWN;
248 pCur->pszAddress = NULL;
249 RTStrAPrintf((char **)&pCur->pszAddress, "p=0x%04RX16;v=0x%04RX16;r=0x%04RX16;e=0x%08RX32",
250 pDevDesc->idProduct, pDevDesc->idVendor, pDevDesc->bcdDevice, i);
251
252 pCur->bBus = 0;
253 pCur->bLevel = 0;
254 pCur->bDevNum = 0;
255 pCur->bDevNumParent = 0;
256 pCur->bPort = 0;
257 pCur->bNumDevices = 0;
258 pCur->bMaxChildren = 0;
259
260 /* link it */
261 pCur->pNext = NULL;
262 pCur->pPrev = *ppNext;
263 *ppNext = pCur;
264 ppNext = &pCur->pNext;
265 }
266
267 return pFirst;
268}
269
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette