VirtualBox

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

Last change on this file since 25985 was 25985, checked in by vboxsync, 15 years ago

pdmifs.h: the final batch of refactored interface ID code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1/* $Id: DrvMouseQueue.cpp 25985 2010-01-23 00:51:04Z 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.215389.xyz. 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 */
44typedef 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 */
67typedef 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 */
85static 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 */
114static 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 */
145static 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 */
162static 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 */
175static 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 */
188static 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 */
201static 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 */
213static 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 */
225static DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
226{
227 PDRVMOUSEQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
228 LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
229
230 /*
231 * Validate configuration.
232 */
233 if (!CFGMR3AreValuesValid(pCfgHandle, "QueueSize\0Interval\0"))
234 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
235
236 /*
237 * Init basic data members and interfaces.
238 */
239 pDrv->fInactive = true;
240 /* IBase. */
241 pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
242 /* IMousePort. */
243 pDrv->IPort.pfnPutEvent = drvMouseQueuePutEvent;
244
245 /*
246 * Get the IMousePort interface of the above driver/device.
247 */
248 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUSEPORT);
249 if (!pDrv->pUpPort)
250 {
251 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
252 return VERR_PDM_MISSING_INTERFACE_ABOVE;
253 }
254
255 /*
256 * Attach driver below and query it's connector interface.
257 */
258 PPDMIBASE pDownBase;
259 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
260 if (RT_FAILURE(rc))
261 {
262 AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
263 return rc;
264 }
265 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIMOUSECONNECTOR);
266 if (!pDrv->pDownConnector)
267 {
268 AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
269 return VERR_PDM_MISSING_INTERFACE_BELOW;
270 }
271
272 /*
273 * Create the queue.
274 */
275 uint32_t cMilliesInterval = 0;
276 rc = CFGMR3QueryU32(pCfgHandle, "Interval", &cMilliesInterval);
277 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
278 cMilliesInterval = 0;
279 else if (RT_FAILURE(rc))
280 {
281 AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
282 return rc;
283 }
284
285 uint32_t cItems = 0;
286 rc = CFGMR3QueryU32(pCfgHandle, "QueueSize", &cItems);
287 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
288 cItems = 128;
289 else if (RT_FAILURE(rc))
290 {
291 AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
292 return rc;
293 }
294
295 rc = PDMDrvHlpPDMQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, "Mouse", &pDrv->pQueue);
296 if (RT_FAILURE(rc))
297 {
298 AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
299 return rc;
300 }
301
302 return VINF_SUCCESS;
303}
304
305
306/**
307 * Mouse queue driver registration record.
308 */
309const PDMDRVREG g_DrvMouseQueue =
310{
311 /* u32Version */
312 PDM_DRVREG_VERSION,
313 /* szDriverName */
314 "MouseQueue",
315 /* szRCMod */
316 "",
317 /* szR0Mod */
318 "",
319 /* pszDescription */
320 "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
321 /* fFlags */
322 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
323 /* fClass. */
324 PDM_DRVREG_CLASS_MOUSE,
325 /* cMaxInstances */
326 ~0,
327 /* cbInstance */
328 sizeof(DRVMOUSEQUEUE),
329 /* pfnConstruct */
330 drvMouseQueueConstruct,
331 /* pfnRelocate */
332 NULL,
333 /* pfnDestruct */
334 NULL,
335 /* pfnIOCtl */
336 NULL,
337 /* pfnPowerOn */
338 drvMouseQueuePowerOn,
339 /* pfnReset */
340 drvMouseQueueReset,
341 /* pfnSuspend */
342 drvMouseQueueSuspend,
343 /* pfnResume */
344 drvMouseQueueResume,
345 /* pfnAttach */
346 NULL,
347 /* pfnDetach */
348 NULL,
349 /* pfnPowerOff */
350 drvMouseQueuePowerOff,
351 /* pfnSoftReset */
352 NULL,
353 /* u32EndVersion */
354 PDM_DRVREG_VERSION
355};
356
Note: See TracBrowser for help on using the repository browser.

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