VirtualBox

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

Last change on this file since 5627 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1/** @file
2 *
3 * VBox input devices:
4 * Mouse queue driver
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#define LOG_GROUP LOG_GROUP_DRV_MOUSE_QUEUE
24#include <VBox/pdmdrv.h>
25#include <iprt/assert.h>
26
27#include "Builtins.h"
28
29
30
31/*******************************************************************************
32* Structures and Typedefs *
33*******************************************************************************/
34/**
35 * Mouse queue driver instance data.
36 */
37typedef struct DRVMOUSEQUEUE
38{
39 /** Pointer to the driver instance structure. */
40 PPDMDRVINS pDrvIns;
41 /** Pointer to the mouse port interface of the driver/device above us. */
42 PPDMIMOUSEPORT pUpPort;
43 /** Pointer to the mouse port interface of the driver/device below us. */
44 PPDMIMOUSECONNECTOR pDownConnector;
45 /** Our mouse connector interface. */
46 PDMIMOUSECONNECTOR Connector;
47 /** Our mouse port interface. */
48 PDMIMOUSEPORT Port;
49 /** The queue handle. */
50 PPDMQUEUE pQueue;
51 /** Discard input when this flag is set.
52 * We only accept input when the VM is running. */
53 bool fInactive;
54} DRVMOUSEQUEUE, *PDRVMOUSEQUEUE;
55
56
57/**
58 * Mouse queue item.
59 */
60typedef struct DRVMOUSEQUEUEITEM
61{
62 /** The core part owned by the queue manager. */
63 PDMQUEUEITEMCORE Core;
64 int32_t i32DeltaX;
65 int32_t i32DeltaY;
66 int32_t i32DeltaZ;
67 uint32_t fButtonStates;
68} DRVMOUSEQUEUEITEM, *PDRVMOUSEQUEUEITEM;
69
70
71
72/* -=-=-=-=- IBase -=-=-=-=- */
73
74/**
75 * Queries an interface to the driver.
76 *
77 * @returns Pointer to interface.
78 * @returns NULL if the interface was not supported by the driver.
79 * @param pInterface Pointer to this interface structure.
80 * @param enmInterface The requested interface identification.
81 */
82static DECLCALLBACK(void *) drvMouseQueueQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
83{
84 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
85 PDRVMOUSEQUEUE pDrv = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
86 switch (enmInterface)
87 {
88 case PDMINTERFACE_BASE:
89 return &pDrvIns->IBase;
90 case PDMINTERFACE_MOUSE_PORT:
91 return &pDrv->Port;
92 case PDMINTERFACE_MOUSE_CONNECTOR:
93 return &pDrv->Connector;
94 default:
95 return NULL;
96 }
97}
98
99
100/* -=-=-=-=- IMousePort -=-=-=-=- */
101
102/** Converts a pointer to DRVMOUSEQUEUE::Port to a DRVMOUSEQUEUE pointer. */
103#define IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, Port)) )
104
105
106/**
107 * Queues a mouse event.
108 * Because of the event queueing the EMT context requirement is lifted.
109 *
110 * @returns VBox status code.
111 * @param pInterface Pointer to interface structure.
112 * @param i32DeltaX The X delta.
113 * @param i32DeltaY The Y delta.
114 * @param i32DeltaZ The Z delta.
115 * @param fButtonStates The button states.
116 * @thread Any thread.
117 */
118static DECLCALLBACK(int) drvMouseQueuePutEvent(PPDMIMOUSEPORT pInterface, int32_t i32DeltaX, int32_t i32DeltaY, int32_t i32DeltaZ, uint32_t fButtonStates)
119{
120 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
121 if (pDrv->fInactive)
122 return VINF_SUCCESS;
123
124 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
125 if (pItem)
126 {
127 pItem->i32DeltaX = i32DeltaX;
128 pItem->i32DeltaY = i32DeltaY;
129 pItem->i32DeltaZ = i32DeltaZ;
130 pItem->fButtonStates = fButtonStates;
131 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
132 return VINF_SUCCESS;
133 }
134 AssertMsgFailed(("drvMouseQueuePutEvent: Queue is full!!!!\n"));
135 return VERR_PDM_NO_QUEUE_ITEMS;
136}
137
138
139/* -=-=-=-=- queue -=-=-=-=- */
140
141/**
142 * Queue callback for processing a queued item.
143 *
144 * @returns Success indicator.
145 * If false the item will not be removed and the flushing will stop.
146 * @param pDrvIns The driver instance.
147 * @param pItemCore Pointer to the queue item to process.
148 */
149static DECLCALLBACK(bool) drvMouseQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
150{
151 PDRVMOUSEQUEUE pData = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
152 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)pItemCore;
153 int rc = pData->pUpPort->pfnPutEvent(pData->pUpPort, pItem->i32DeltaX, pItem->i32DeltaY, pItem->i32DeltaZ, pItem->fButtonStates);
154 return VBOX_SUCCESS(rc);
155}
156
157
158/* -=-=-=-=- driver interface -=-=-=-=- */
159
160/**
161 * Power On notification.
162 *
163 * @returns VBox status.
164 * @param pDrvIns The drive instance data.
165 */
166static DECLCALLBACK(void) drvMouseQueuePowerOn(PPDMDRVINS pDrvIns)
167{
168 PDRVMOUSEQUEUE pData = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
169 pData->fInactive = false;
170}
171
172
173/**
174 * Reset notification.
175 *
176 * @returns VBox status.
177 * @param pDrvIns The drive instance data.
178 */
179static DECLCALLBACK(void) drvMouseQueueReset(PPDMDRVINS pDrvIns)
180{
181 //PDRVKBDQUEUE pData = PDMINS2DATA(pDrvIns, PDRVKBDQUEUE);
182 /** @todo purge the queue on reset. */
183}
184
185
186/**
187 * Suspend notification.
188 *
189 * @returns VBox status.
190 * @param pDrvIns The drive instance data.
191 */
192static DECLCALLBACK(void) drvMouseQueueSuspend(PPDMDRVINS pDrvIns)
193{
194 PDRVMOUSEQUEUE pData = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
195 pData->fInactive = true;
196}
197
198
199/**
200 * Resume notification.
201 *
202 * @returns VBox status.
203 * @param pDrvIns The drive instance data.
204 */
205static DECLCALLBACK(void) drvMouseQueueResume(PPDMDRVINS pDrvIns)
206{
207 PDRVMOUSEQUEUE pData = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
208 pData->fInactive = false;
209}
210
211
212/**
213 * Power Off notification.
214 *
215 * @param pDrvIns The drive instance data.
216 */
217static DECLCALLBACK(void) drvMouseQueuePowerOff(PPDMDRVINS pDrvIns)
218{
219 PDRVMOUSEQUEUE pData = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
220 pData->fInactive = true;
221}
222
223
224/**
225 * Construct a mouse driver instance.
226 *
227 * @returns VBox status.
228 * @param pDrvIns The driver instance data.
229 * If the registration structure is needed, pDrvIns->pDrvReg points to it.
230 * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
231 * of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
232 * iInstance it's expected to be used a bit in this function.
233 */
234static DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
235{
236 PDRVMOUSEQUEUE pDrv = PDMINS2DATA(pDrvIns, PDRVMOUSEQUEUE);
237 LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
238
239 /*
240 * Validate configuration.
241 */
242 if (!CFGMR3AreValuesValid(pCfgHandle, "QueueSize\0Interval\0"))
243 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
244
245 /*
246 * Init basic data members and interfaces.
247 */
248 pDrv->fInactive = true;
249 /* IBase. */
250 pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
251 /* IMousePort. */
252 pDrv->Port.pfnPutEvent = drvMouseQueuePutEvent;
253
254 /*
255 * Get the IMousePort interface of the above driver/device.
256 */
257 pDrv->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MOUSE_PORT);
258 if (!pDrv->pUpPort)
259 {
260 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
261 return VERR_PDM_MISSING_INTERFACE_ABOVE;
262 }
263
264 /*
265 * Attach driver below and query it's connector interface.
266 */
267 PPDMIBASE pDownBase;
268 int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pDownBase);
269 if (VBOX_FAILURE(rc))
270 {
271 AssertMsgFailed(("Failed to attach driver below us! rc=%Vra\n", rc));
272 return rc;
273 }
274 pDrv->pDownConnector = (PPDMIMOUSECONNECTOR)pDownBase->pfnQueryInterface(pDownBase, PDMINTERFACE_MOUSE_CONNECTOR);
275 if (!pDrv->pDownConnector)
276 {
277 AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
278 return VERR_PDM_MISSING_INTERFACE_BELOW;
279 }
280
281 /*
282 * Create the queue.
283 */
284 uint32_t cMilliesInterval = 0;
285 rc = CFGMR3QueryU32(pCfgHandle, "Interval", &cMilliesInterval);
286 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
287 cMilliesInterval = 0;
288 else if (VBOX_FAILURE(rc))
289 {
290 AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Vrc\n", rc));
291 return rc;
292 }
293
294 uint32_t cItems = 0;
295 rc = CFGMR3QueryU32(pCfgHandle, "QueueSize", &cItems);
296 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
297 cItems = 128;
298 else if (VBOX_FAILURE(rc))
299 {
300 AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Vrc\n", rc));
301 return rc;
302 }
303
304 rc = pDrvIns->pDrvHlp->pfnPDMQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, &pDrv->pQueue);
305 if (VBOX_FAILURE(rc))
306 {
307 AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Vrc\n", cItems, cMilliesInterval, rc));
308 return rc;
309 }
310
311 return VINF_SUCCESS;
312}
313
314
315/**
316 * Mouse queue driver registration record.
317 */
318const PDMDRVREG g_DrvMouseQueue =
319{
320 /* u32Version */
321 PDM_DRVREG_VERSION,
322 /* szDriverName */
323 "MouseQueue",
324 /* pszDescription */
325 "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
326 /* fFlags */
327 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
328 /* fClass. */
329 PDM_DRVREG_CLASS_MOUSE,
330 /* cMaxInstances */
331 ~0,
332 /* cbInstance */
333 sizeof(DRVMOUSEQUEUE),
334 /* pfnConstruct */
335 drvMouseQueueConstruct,
336 /* pfnDestruct */
337 NULL,
338 /* pfnIOCtl */
339 NULL,
340 /* pfnPowerOn */
341 drvMouseQueuePowerOn,
342 /* pfnReset */
343 drvMouseQueueReset,
344 /* pfnSuspend */
345 drvMouseQueueSuspend,
346 /* pfnResume */
347 drvMouseQueueResume,
348 /* pfnDetach */
349 NULL,
350 /** pfnPowerOff */
351 drvMouseQueuePowerOff
352};
353
354
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