VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/DrvMouseQueue.cpp@ 47313

Last change on this file since 47313 was 47259, checked in by vboxsync, 11 years ago

pdmifs: fix putEventMT definition.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1/* $Id: DrvMouseQueue.cpp 47259 2013-07-19 13:58:26Z vboxsync $ */
2/** @file
3 * VBox input devices: Mouse queue driver
4 */
5
6/*
7 * Copyright (C) 2006-2012 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 LOG_GROUP LOG_GROUP_DRV_MOUSE_QUEUE
23#include <VBox/vmm/pdmdrv.h>
24#include <iprt/assert.h>
25#include <iprt/uuid.h>
26
27#include "VBoxDD.h"
28
29
30
31/*******************************************************************************
32* Structures and Typedefs *
33*******************************************************************************/
34/**
35 * Mouse queue driver instance data.
36 *
37 * @implements PDMIMOUSECONNECTOR
38 * @implements PDMIMOUSEPORT
39 */
40typedef struct DRVMOUSEQUEUE
41{
42 /** Pointer to the driver instance structure. */
43 PPDMDRVINS pDrvIns;
44 /** Pointer to the mouse port interface of the driver/device above us. */
45 PPDMIMOUSEPORT pUpPort;
46 /** Pointer to the mouse port interface of the driver/device below us. */
47 PPDMIMOUSECONNECTOR pDownConnector;
48 /** Our mouse connector interface. */
49 PDMIMOUSECONNECTOR IConnector;
50 /** Our mouse port interface. */
51 PDMIMOUSEPORT IPort;
52 /** The queue handle. */
53 PPDMQUEUE pQueue;
54 /** Discard input when this flag is set.
55 * We only accept input when the VM is running. */
56 bool fInactive;
57} DRVMOUSEQUEUE, *PDRVMOUSEQUEUE;
58
59
60/**
61 * Event type for @a DRVMOUSEQUEUEITEM
62 */
63enum EVENTTYPE { RELATIVE, ABSOLUTE, MULTITOUCH };
64
65/**
66 * Mouse queue item.
67 */
68typedef struct DRVMOUSEQUEUEITEM
69{
70 /** The core part owned by the queue manager. */
71 PDMQUEUEITEMCORE Core;
72 enum EVENTTYPE enmType;
73 union
74 {
75 uint32_t padding[5];
76 struct
77 {
78 uint32_t fButtons;
79 int32_t dx;
80 int32_t dy;
81 int32_t dz;
82 int32_t dw;
83 } Relative;
84 struct
85 {
86 uint32_t fButtons;
87 uint32_t x;
88 uint32_t y;
89 int32_t dz;
90 int32_t dw;
91 } Absolute;
92 struct
93 {
94 bool fContact;
95 uint32_t x;
96 uint32_t y;
97 uint32_t cContact;
98 } MultiTouch;
99 } u;
100} DRVMOUSEQUEUEITEM, *PDRVMOUSEQUEUEITEM;
101
102
103
104/* -=-=-=-=- IBase -=-=-=-=- */
105
106/**
107 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
108 */
109static DECLCALLBACK(void *) drvMouseQueueQueryInterface(PPDMIBASE pInterface, const char *pszIID)
110{
111 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
112 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
113 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
114 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->IPort);
115 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pThis->IConnector);
116 return NULL;
117}
118
119
120/* -=-=-=-=- IMousePort -=-=-=-=- */
121
122/** Converts a pointer to DRVMOUSEQUEUE::Port to a DRVMOUSEQUEUE pointer. */
123#define IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IPort)) )
124
125
126/**
127 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEvent}
128 */
129static DECLCALLBACK(int) drvMouseQueuePutEvent(PPDMIMOUSEPORT pInterface,
130 int32_t dx, int32_t dy,
131 int32_t dz, int32_t dw,
132 uint32_t fButtons)
133{
134 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
135 if (pDrv->fInactive)
136 return VINF_SUCCESS;
137
138 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
139 if (pItem)
140 {
141 RT_ZERO(pItem->u.padding);
142 pItem->enmType = RELATIVE;
143 pItem->u.Relative.dx = dx;
144 pItem->u.Relative.dy = dy;
145 pItem->u.Relative.dz = dz;
146 pItem->u.Relative.dw = dw;
147 pItem->u.Relative.fButtons = fButtons;
148 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
149 return VINF_SUCCESS;
150 }
151 return VERR_PDM_NO_QUEUE_ITEMS;
152}
153
154/**
155 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventAbs}
156 */
157static DECLCALLBACK(int) drvMouseQueuePutEventAbs(PPDMIMOUSEPORT pInterface,
158 uint32_t x, uint32_t y,
159 int32_t dz, int32_t dw,
160 uint32_t fButtons)
161{
162 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
163 if (pDrv->fInactive)
164 return VINF_SUCCESS;
165
166 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
167 if (pItem)
168 {
169 RT_ZERO(pItem->u.padding);
170 pItem->enmType = ABSOLUTE;
171 pItem->u.Absolute.x = x;
172 pItem->u.Absolute.y = y;
173 pItem->u.Absolute.dz = dz;
174 pItem->u.Absolute.dw = dw;
175 pItem->u.Absolute.fButtons = fButtons;
176 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
177 return VINF_SUCCESS;
178 }
179 return VERR_PDM_NO_QUEUE_ITEMS;
180}
181
182
183/**
184 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventMT}
185 */
186static DECLCALLBACK(int) drvMouseQueuePutEventMT(PPDMIMOUSEPORT pInterface,
187 uint32_t x, uint32_t y,
188 uint32_t cContact,
189 uint32_t fContact)
190{
191 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
192 if (pDrv->fInactive)
193 return VINF_SUCCESS;
194
195 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
196 if (pItem)
197 {
198 RT_ZERO(pItem->u.padding);
199 pItem->enmType = MULTITOUCH;
200 pItem->u.MultiTouch.x = x;
201 pItem->u.MultiTouch.y = y;
202 pItem->u.MultiTouch.cContact = cContact;
203 pItem->u.MultiTouch.fContact = fContact;
204 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
205 return VINF_SUCCESS;
206 }
207 return VERR_PDM_NO_QUEUE_ITEMS;
208}
209
210
211/* -=-=-=-=- IConnector -=-=-=-=- */
212
213#define PPDMIMOUSECONNECTOR_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IConnector)) )
214
215
216/**
217 * Pass absolute mode status changes from the guest through to the frontend
218 * driver.
219 *
220 * @param pInterface Pointer to the mouse connector interface structure.
221 * @param fRel Is relative reporting supported?
222 * @param fAbs Is absolute reporting supported?
223 * @param fMT Is multi-touch reporting supported?
224 */
225static DECLCALLBACK(void) drvMousePassThruReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs, bool fMT)
226{
227 PDRVMOUSEQUEUE pDrv = PPDMIMOUSECONNECTOR_2_DRVMOUSEQUEUE(pInterface);
228 pDrv->pDownConnector->pfnReportModes(pDrv->pDownConnector, fRel, fAbs, fMT);
229}
230
231
232
233/* -=-=-=-=- queue -=-=-=-=- */
234
235/**
236 * Queue callback for processing a queued item.
237 *
238 * @returns Success indicator.
239 * If false the item will not be removed and the flushing will stop.
240 * @param pDrvIns The driver instance.
241 * @param pItemCore Pointer to the queue item to process.
242 */
243static DECLCALLBACK(bool) drvMouseQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
244{
245 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
246 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)pItemCore;
247 int rc;
248 if (pItem->enmType == RELATIVE)
249 rc = pThis->pUpPort->pfnPutEvent(pThis->pUpPort,
250 pItem->u.Relative.dx,
251 pItem->u.Relative.dy,
252 pItem->u.Relative.dz,
253 pItem->u.Relative.dw,
254 pItem->u.Relative.fButtons);
255 else if (pItem->enmType == ABSOLUTE)
256 rc = pThis->pUpPort->pfnPutEventAbs(pThis->pUpPort,
257 pItem->u.Absolute.x,
258 pItem->u.Absolute.y,
259 pItem->u.Absolute.dz,
260 pItem->u.Absolute.dw,
261 pItem->u.Absolute.fButtons);
262 else if (pItem->enmType == MULTITOUCH)
263 rc = pThis->pUpPort->pfnPutEventMT(pThis->pUpPort,
264 pItem->u.MultiTouch.x,
265 pItem->u.MultiTouch.y,
266 pItem->u.MultiTouch.cContact,
267 pItem->u.MultiTouch.fContact);
268 else
269 return false;
270 return RT_SUCCESS(rc);
271}
272
273
274/* -=-=-=-=- driver interface -=-=-=-=- */
275
276/**
277 * Power On notification.
278 *
279 * @returns VBox status.
280 * @param pDrvIns The drive instance data.
281 */
282static DECLCALLBACK(void) drvMouseQueuePowerOn(PPDMDRVINS pDrvIns)
283{
284 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
285 pThis->fInactive = false;
286}
287
288
289/**
290 * Reset notification.
291 *
292 * @returns VBox status.
293 * @param pDrvIns The drive instance data.
294 */
295static DECLCALLBACK(void) drvMouseQueueReset(PPDMDRVINS pDrvIns)
296{
297 //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
298 /** @todo purge the queue on reset. */
299}
300
301
302/**
303 * Suspend notification.
304 *
305 * @returns VBox status.
306 * @param pDrvIns The drive instance data.
307 */
308static DECLCALLBACK(void) drvMouseQueueSuspend(PPDMDRVINS pDrvIns)
309{
310 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
311 pThis->fInactive = true;
312}
313
314
315/**
316 * Resume notification.
317 *
318 * @returns VBox status.
319 * @param pDrvIns The drive instance data.
320 */
321static DECLCALLBACK(void) drvMouseQueueResume(PPDMDRVINS pDrvIns)
322{
323 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
324 pThis->fInactive = false;
325}
326
327
328/**
329 * Power Off notification.
330 *
331 * @param pDrvIns The drive instance data.
332 */
333static DECLCALLBACK(void) drvMouseQueuePowerOff(PPDMDRVINS pDrvIns)
334{
335 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
336 pThis->fInactive = true;
337}
338
339
340/**
341 * Construct a mouse driver instance.
342 *
343 * @copydoc FNPDMDRVCONSTRUCT
344 */
345static DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
346{
347 PDRVMOUSEQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
348 LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
349 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
350
351 /*
352 * Validate configuration.
353 */
354 if (!CFGMR3AreValuesValid(pCfg, "QueueSize\0Interval\0"))
355 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
356
357 /*
358 * Init basic data members and interfaces.
359 */
360 pDrv->fInactive = true;
361 /* IBase. */
362 pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
363 /* IMouseConnector. */
364 pDrv->IConnector.pfnReportModes = drvMousePassThruReportModes;
365 /* IMousePort. */
366 pDrv->IPort.pfnPutEvent = drvMouseQueuePutEvent;
367 pDrv->IPort.pfnPutEventAbs = drvMouseQueuePutEventAbs;
368 pDrv->IPort.pfnPutEventMT = drvMouseQueuePutEventMT;
369
370 /*
371 * Get the IMousePort interface of the above driver/device.
372 */
373 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUSEPORT);
374 if (!pDrv->pUpPort)
375 {
376 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
377 return VERR_PDM_MISSING_INTERFACE_ABOVE;
378 }
379
380 /*
381 * Attach driver below and query it's connector interface.
382 */
383 PPDMIBASE pDownBase;
384 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
385 if (RT_FAILURE(rc))
386 {
387 AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
388 return rc;
389 }
390 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIMOUSECONNECTOR);
391 if (!pDrv->pDownConnector)
392 {
393 AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
394 return VERR_PDM_MISSING_INTERFACE_BELOW;
395 }
396
397 /*
398 * Create the queue.
399 */
400 uint32_t cMilliesInterval = 0;
401 rc = CFGMR3QueryU32(pCfg, "Interval", &cMilliesInterval);
402 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
403 cMilliesInterval = 0;
404 else if (RT_FAILURE(rc))
405 {
406 AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
407 return rc;
408 }
409
410 uint32_t cItems = 0;
411 rc = CFGMR3QueryU32(pCfg, "QueueSize", &cItems);
412 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
413 cItems = 128;
414 else if (RT_FAILURE(rc))
415 {
416 AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
417 return rc;
418 }
419
420 rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, "Mouse", &pDrv->pQueue);
421 if (RT_FAILURE(rc))
422 {
423 AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
424 return rc;
425 }
426
427 return VINF_SUCCESS;
428}
429
430
431/**
432 * Mouse queue driver registration record.
433 */
434const PDMDRVREG g_DrvMouseQueue =
435{
436 /* u32Version */
437 PDM_DRVREG_VERSION,
438 /* szName */
439 "MouseQueue",
440 /* szRCMod */
441 "",
442 /* szR0Mod */
443 "",
444 /* pszDescription */
445 "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
446 /* fFlags */
447 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
448 /* fClass. */
449 PDM_DRVREG_CLASS_MOUSE,
450 /* cMaxInstances */
451 ~0U,
452 /* cbInstance */
453 sizeof(DRVMOUSEQUEUE),
454 /* pfnConstruct */
455 drvMouseQueueConstruct,
456 /* pfnRelocate */
457 NULL,
458 /* pfnDestruct */
459 NULL,
460 /* pfnIOCtl */
461 NULL,
462 /* pfnPowerOn */
463 drvMouseQueuePowerOn,
464 /* pfnReset */
465 drvMouseQueueReset,
466 /* pfnSuspend */
467 drvMouseQueueSuspend,
468 /* pfnResume */
469 drvMouseQueueResume,
470 /* pfnAttach */
471 NULL,
472 /* pfnDetach */
473 NULL,
474 /* pfnPowerOff */
475 drvMouseQueuePowerOff,
476 /* pfnSoftReset */
477 NULL,
478 /* u32EndVersion */
479 PDM_DRVREG_VERSION
480};
481
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