1 | /* $Id: DrvMouseQueue.cpp 26173 2010-02-02 21:11:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox input devices: Mouse queue driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_DRV_MOUSE_QUEUE
|
---|
27 | #include <VBox/pdmdrv.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/uuid.h>
|
---|
30 |
|
---|
31 | #include "Builtins.h"
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 | /*******************************************************************************
|
---|
36 | * Structures and Typedefs *
|
---|
37 | *******************************************************************************/
|
---|
38 | /**
|
---|
39 | * Mouse queue driver instance data.
|
---|
40 | *
|
---|
41 | * @implements PDMIMOUSECONNECTOR
|
---|
42 | * @implements PDMIMOUSEPORT
|
---|
43 | */
|
---|
44 | typedef struct DRVMOUSEQUEUE
|
---|
45 | {
|
---|
46 | /** Pointer to the driver instance structure. */
|
---|
47 | PPDMDRVINS pDrvIns;
|
---|
48 | /** Pointer to the mouse port interface of the driver/device above us. */
|
---|
49 | PPDMIMOUSEPORT pUpPort;
|
---|
50 | /** Pointer to the mouse port interface of the driver/device below us. */
|
---|
51 | PPDMIMOUSECONNECTOR pDownConnector;
|
---|
52 | /** Our mouse connector interface. */
|
---|
53 | PDMIMOUSECONNECTOR IConnector;
|
---|
54 | /** Our mouse port interface. */
|
---|
55 | PDMIMOUSEPORT IPort;
|
---|
56 | /** The queue handle. */
|
---|
57 | PPDMQUEUE pQueue;
|
---|
58 | /** Discard input when this flag is set.
|
---|
59 | * We only accept input when the VM is running. */
|
---|
60 | bool fInactive;
|
---|
61 | } DRVMOUSEQUEUE, *PDRVMOUSEQUEUE;
|
---|
62 |
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Mouse queue item.
|
---|
66 | */
|
---|
67 | typedef struct DRVMOUSEQUEUEITEM
|
---|
68 | {
|
---|
69 | /** The core part owned by the queue manager. */
|
---|
70 | PDMQUEUEITEMCORE Core;
|
---|
71 | int32_t i32DeltaX;
|
---|
72 | int32_t i32DeltaY;
|
---|
73 | int32_t i32DeltaZ;
|
---|
74 | int32_t i32DeltaW;
|
---|
75 | uint32_t fButtonStates;
|
---|
76 | } DRVMOUSEQUEUEITEM, *PDRVMOUSEQUEUEITEM;
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 | /* -=-=-=-=- IBase -=-=-=-=- */
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
84 | */
|
---|
85 | static DECLCALLBACK(void *) drvMouseQueueQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
86 | {
|
---|
87 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
88 | PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
89 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
90 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->IPort);
|
---|
91 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pThis->IConnector);
|
---|
92 | return NULL;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | /* -=-=-=-=- IMousePort -=-=-=-=- */
|
---|
97 |
|
---|
98 | /** Converts a pointer to DRVMOUSEQUEUE::Port to a DRVMOUSEQUEUE pointer. */
|
---|
99 | #define IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IPort)) )
|
---|
100 |
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Queues a mouse event.
|
---|
104 | * Because of the event queueing the EMT context requirement is lifted.
|
---|
105 | *
|
---|
106 | * @returns VBox status code.
|
---|
107 | * @param pInterface Pointer to interface structure.
|
---|
108 | * @param i32DeltaX The X delta.
|
---|
109 | * @param i32DeltaY The Y delta.
|
---|
110 | * @param i32DeltaZ The Z delta.
|
---|
111 | * @param fButtonStates The button states.
|
---|
112 | * @thread Any thread.
|
---|
113 | */
|
---|
114 | static DECLCALLBACK(int) drvMouseQueuePutEvent(PPDMIMOUSEPORT pInterface, int32_t i32DeltaX, int32_t i32DeltaY, int32_t i32DeltaZ, int32_t i32DeltaW, uint32_t fButtonStates)
|
---|
115 | {
|
---|
116 | PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
|
---|
117 | if (pDrv->fInactive)
|
---|
118 | return VINF_SUCCESS;
|
---|
119 |
|
---|
120 | PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
|
---|
121 | if (pItem)
|
---|
122 | {
|
---|
123 | pItem->i32DeltaX = i32DeltaX;
|
---|
124 | pItem->i32DeltaY = i32DeltaY;
|
---|
125 | pItem->i32DeltaZ = i32DeltaZ;
|
---|
126 | pItem->i32DeltaW = i32DeltaW;
|
---|
127 | pItem->fButtonStates = fButtonStates;
|
---|
128 | PDMQueueInsert(pDrv->pQueue, &pItem->Core);
|
---|
129 | return VINF_SUCCESS;
|
---|
130 | }
|
---|
131 | return VERR_PDM_NO_QUEUE_ITEMS;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | /* -=-=-=-=- queue -=-=-=-=- */
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Queue callback for processing a queued item.
|
---|
139 | *
|
---|
140 | * @returns Success indicator.
|
---|
141 | * If false the item will not be removed and the flushing will stop.
|
---|
142 | * @param pDrvIns The driver instance.
|
---|
143 | * @param pItemCore Pointer to the queue item to process.
|
---|
144 | */
|
---|
145 | static DECLCALLBACK(bool) drvMouseQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
|
---|
146 | {
|
---|
147 | PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
148 | PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)pItemCore;
|
---|
149 | int rc = pThis->pUpPort->pfnPutEvent(pThis->pUpPort, pItem->i32DeltaX, pItem->i32DeltaY, pItem->i32DeltaZ, pItem->i32DeltaW, pItem->fButtonStates);
|
---|
150 | return RT_SUCCESS(rc);
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | /* -=-=-=-=- driver interface -=-=-=-=- */
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Power On notification.
|
---|
158 | *
|
---|
159 | * @returns VBox status.
|
---|
160 | * @param pDrvIns The drive instance data.
|
---|
161 | */
|
---|
162 | static DECLCALLBACK(void) drvMouseQueuePowerOn(PPDMDRVINS pDrvIns)
|
---|
163 | {
|
---|
164 | PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
165 | pThis->fInactive = false;
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Reset notification.
|
---|
171 | *
|
---|
172 | * @returns VBox status.
|
---|
173 | * @param pDrvIns The drive instance data.
|
---|
174 | */
|
---|
175 | static DECLCALLBACK(void) drvMouseQueueReset(PPDMDRVINS pDrvIns)
|
---|
176 | {
|
---|
177 | //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
178 | /** @todo purge the queue on reset. */
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Suspend notification.
|
---|
184 | *
|
---|
185 | * @returns VBox status.
|
---|
186 | * @param pDrvIns The drive instance data.
|
---|
187 | */
|
---|
188 | static DECLCALLBACK(void) drvMouseQueueSuspend(PPDMDRVINS pDrvIns)
|
---|
189 | {
|
---|
190 | PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
191 | pThis->fInactive = true;
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Resume notification.
|
---|
197 | *
|
---|
198 | * @returns VBox status.
|
---|
199 | * @param pDrvIns The drive instance data.
|
---|
200 | */
|
---|
201 | static DECLCALLBACK(void) drvMouseQueueResume(PPDMDRVINS pDrvIns)
|
---|
202 | {
|
---|
203 | PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
204 | pThis->fInactive = false;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Power Off notification.
|
---|
210 | *
|
---|
211 | * @param pDrvIns The drive instance data.
|
---|
212 | */
|
---|
213 | static DECLCALLBACK(void) drvMouseQueuePowerOff(PPDMDRVINS pDrvIns)
|
---|
214 | {
|
---|
215 | PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
216 | pThis->fInactive = true;
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Construct a mouse driver instance.
|
---|
222 | *
|
---|
223 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
224 | */
|
---|
225 | static DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
226 | {
|
---|
227 | PDRVMOUSEQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
|
---|
228 | LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
229 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
230 |
|
---|
231 | /*
|
---|
232 | * Validate configuration.
|
---|
233 | */
|
---|
234 | if (!CFGMR3AreValuesValid(pCfg, "QueueSize\0Interval\0"))
|
---|
235 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
236 |
|
---|
237 | /*
|
---|
238 | * Init basic data members and interfaces.
|
---|
239 | */
|
---|
240 | pDrv->fInactive = true;
|
---|
241 | /* IBase. */
|
---|
242 | pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
|
---|
243 | /* IMousePort. */
|
---|
244 | pDrv->IPort.pfnPutEvent = drvMouseQueuePutEvent;
|
---|
245 |
|
---|
246 | /*
|
---|
247 | * Get the IMousePort interface of the above driver/device.
|
---|
248 | */
|
---|
249 | pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUSEPORT);
|
---|
250 | if (!pDrv->pUpPort)
|
---|
251 | {
|
---|
252 | AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
|
---|
253 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * Attach driver below and query it's connector interface.
|
---|
258 | */
|
---|
259 | PPDMIBASE pDownBase;
|
---|
260 | int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
|
---|
261 | if (RT_FAILURE(rc))
|
---|
262 | {
|
---|
263 | AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
|
---|
264 | return rc;
|
---|
265 | }
|
---|
266 | pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIMOUSECONNECTOR);
|
---|
267 | if (!pDrv->pDownConnector)
|
---|
268 | {
|
---|
269 | AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
|
---|
270 | return VERR_PDM_MISSING_INTERFACE_BELOW;
|
---|
271 | }
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * Create the queue.
|
---|
275 | */
|
---|
276 | uint32_t cMilliesInterval = 0;
|
---|
277 | rc = CFGMR3QueryU32(pCfg, "Interval", &cMilliesInterval);
|
---|
278 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
279 | cMilliesInterval = 0;
|
---|
280 | else if (RT_FAILURE(rc))
|
---|
281 | {
|
---|
282 | AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
|
---|
283 | return rc;
|
---|
284 | }
|
---|
285 |
|
---|
286 | uint32_t cItems = 0;
|
---|
287 | rc = CFGMR3QueryU32(pCfg, "QueueSize", &cItems);
|
---|
288 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
289 | cItems = 128;
|
---|
290 | else if (RT_FAILURE(rc))
|
---|
291 | {
|
---|
292 | AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
|
---|
293 | return rc;
|
---|
294 | }
|
---|
295 |
|
---|
296 | rc = PDMDrvHlpPDMQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, "Mouse", &pDrv->pQueue);
|
---|
297 | if (RT_FAILURE(rc))
|
---|
298 | {
|
---|
299 | AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
|
---|
300 | return rc;
|
---|
301 | }
|
---|
302 |
|
---|
303 | return VINF_SUCCESS;
|
---|
304 | }
|
---|
305 |
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Mouse queue driver registration record.
|
---|
309 | */
|
---|
310 | const PDMDRVREG g_DrvMouseQueue =
|
---|
311 | {
|
---|
312 | /* u32Version */
|
---|
313 | PDM_DRVREG_VERSION,
|
---|
314 | /* szName */
|
---|
315 | "MouseQueue",
|
---|
316 | /* szRCMod */
|
---|
317 | "",
|
---|
318 | /* szR0Mod */
|
---|
319 | "",
|
---|
320 | /* pszDescription */
|
---|
321 | "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
|
---|
322 | /* fFlags */
|
---|
323 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
324 | /* fClass. */
|
---|
325 | PDM_DRVREG_CLASS_MOUSE,
|
---|
326 | /* cMaxInstances */
|
---|
327 | ~0,
|
---|
328 | /* cbInstance */
|
---|
329 | sizeof(DRVMOUSEQUEUE),
|
---|
330 | /* pfnConstruct */
|
---|
331 | drvMouseQueueConstruct,
|
---|
332 | /* pfnRelocate */
|
---|
333 | NULL,
|
---|
334 | /* pfnDestruct */
|
---|
335 | NULL,
|
---|
336 | /* pfnIOCtl */
|
---|
337 | NULL,
|
---|
338 | /* pfnPowerOn */
|
---|
339 | drvMouseQueuePowerOn,
|
---|
340 | /* pfnReset */
|
---|
341 | drvMouseQueueReset,
|
---|
342 | /* pfnSuspend */
|
---|
343 | drvMouseQueueSuspend,
|
---|
344 | /* pfnResume */
|
---|
345 | drvMouseQueueResume,
|
---|
346 | /* pfnAttach */
|
---|
347 | NULL,
|
---|
348 | /* pfnDetach */
|
---|
349 | NULL,
|
---|
350 | /* pfnPowerOff */
|
---|
351 | drvMouseQueuePowerOff,
|
---|
352 | /* pfnSoftReset */
|
---|
353 | NULL,
|
---|
354 | /* u32EndVersion */
|
---|
355 | PDM_DRVREG_VERSION
|
---|
356 | };
|
---|
357 |
|
---|