VirtualBox

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

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

pdmifs.h: Converted the mouse interface ids. Committing early to see how MSC likes PDMIBASE_QUERY_INTERFACE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/* $Id: DrvMouseQueue.cpp 25969 2010-01-22 12:22:38Z 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 Connector;
54 /** Our mouse port interface. */
55 PDMIMOUSEPORT Port;
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 if (RTUuidCompare2Strs(pszIID, PDMIBASE_IID) == 0)
90 return &pDrvIns->IBase;
91 if (RTUuidCompare2Strs(pszIID, PDMIMOUSEPORT_IID) == 0)
92 return &pThis->Port;
93 if (RTUuidCompare2Strs(pszIID, PDMIMOUSECONNECTOR_IID) == 0)
94 return &pThis->Connector;
95 return NULL;
96}
97
98
99/* -=-=-=-=- IMousePort -=-=-=-=- */
100
101/** Converts a pointer to DRVMOUSEQUEUE::Port to a DRVMOUSEQUEUE pointer. */
102#define IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, Port)) )
103
104
105/**
106 * Queues a mouse event.
107 * Because of the event queueing the EMT context requirement is lifted.
108 *
109 * @returns VBox status code.
110 * @param pInterface Pointer to interface structure.
111 * @param i32DeltaX The X delta.
112 * @param i32DeltaY The Y delta.
113 * @param i32DeltaZ The Z delta.
114 * @param fButtonStates The button states.
115 * @thread Any thread.
116 */
117static DECLCALLBACK(int) drvMouseQueuePutEvent(PPDMIMOUSEPORT pInterface, int32_t i32DeltaX, int32_t i32DeltaY, int32_t i32DeltaZ, int32_t i32DeltaW, uint32_t fButtonStates)
118{
119 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
120 if (pDrv->fInactive)
121 return VINF_SUCCESS;
122
123 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
124 if (pItem)
125 {
126 pItem->i32DeltaX = i32DeltaX;
127 pItem->i32DeltaY = i32DeltaY;
128 pItem->i32DeltaZ = i32DeltaZ;
129 pItem->i32DeltaW = i32DeltaW;
130 pItem->fButtonStates = fButtonStates;
131 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
132 return VINF_SUCCESS;
133 }
134 return VERR_PDM_NO_QUEUE_ITEMS;
135}
136
137
138/* -=-=-=-=- queue -=-=-=-=- */
139
140/**
141 * Queue callback for processing a queued item.
142 *
143 * @returns Success indicator.
144 * If false the item will not be removed and the flushing will stop.
145 * @param pDrvIns The driver instance.
146 * @param pItemCore Pointer to the queue item to process.
147 */
148static DECLCALLBACK(bool) drvMouseQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
149{
150 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
151 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)pItemCore;
152 int rc = pThis->pUpPort->pfnPutEvent(pThis->pUpPort, pItem->i32DeltaX, pItem->i32DeltaY, pItem->i32DeltaZ, pItem->i32DeltaW, pItem->fButtonStates);
153 return RT_SUCCESS(rc);
154}
155
156
157/* -=-=-=-=- driver interface -=-=-=-=- */
158
159/**
160 * Power On notification.
161 *
162 * @returns VBox status.
163 * @param pDrvIns The drive instance data.
164 */
165static DECLCALLBACK(void) drvMouseQueuePowerOn(PPDMDRVINS pDrvIns)
166{
167 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
168 pThis->fInactive = false;
169}
170
171
172/**
173 * Reset notification.
174 *
175 * @returns VBox status.
176 * @param pDrvIns The drive instance data.
177 */
178static DECLCALLBACK(void) drvMouseQueueReset(PPDMDRVINS pDrvIns)
179{
180 //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
181 /** @todo purge the queue on reset. */
182}
183
184
185/**
186 * Suspend notification.
187 *
188 * @returns VBox status.
189 * @param pDrvIns The drive instance data.
190 */
191static DECLCALLBACK(void) drvMouseQueueSuspend(PPDMDRVINS pDrvIns)
192{
193 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
194 pThis->fInactive = true;
195}
196
197
198/**
199 * Resume notification.
200 *
201 * @returns VBox status.
202 * @param pDrvIns The drive instance data.
203 */
204static DECLCALLBACK(void) drvMouseQueueResume(PPDMDRVINS pDrvIns)
205{
206 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
207 pThis->fInactive = false;
208}
209
210
211/**
212 * Power Off notification.
213 *
214 * @param pDrvIns The drive instance data.
215 */
216static DECLCALLBACK(void) drvMouseQueuePowerOff(PPDMDRVINS pDrvIns)
217{
218 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
219 pThis->fInactive = true;
220}
221
222
223/**
224 * Construct a mouse driver instance.
225 *
226 * @copydoc FNPDMDRVCONSTRUCT
227 */
228static DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
229{
230 PDRVMOUSEQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
231 LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
232
233 /*
234 * Validate configuration.
235 */
236 if (!CFGMR3AreValuesValid(pCfgHandle, "QueueSize\0Interval\0"))
237 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
238
239 /*
240 * Init basic data members and interfaces.
241 */
242 pDrv->fInactive = true;
243 /* IBase. */
244 pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
245 /* IMousePort. */
246 pDrv->Port.pfnPutEvent = drvMouseQueuePutEvent;
247
248 /*
249 * Get the IMousePort interface of the above driver/device.
250 */
251 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUSEPORT);
252 if (!pDrv->pUpPort)
253 {
254 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
255 return VERR_PDM_MISSING_INTERFACE_ABOVE;
256 }
257
258 /*
259 * Attach driver below and query it's connector interface.
260 */
261 PPDMIBASE pDownBase;
262 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
263 if (RT_FAILURE(rc))
264 {
265 AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
266 return rc;
267 }
268 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIMOUSECONNECTOR);
269 if (!pDrv->pDownConnector)
270 {
271 AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
272 return VERR_PDM_MISSING_INTERFACE_BELOW;
273 }
274
275 /*
276 * Create the queue.
277 */
278 uint32_t cMilliesInterval = 0;
279 rc = CFGMR3QueryU32(pCfgHandle, "Interval", &cMilliesInterval);
280 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
281 cMilliesInterval = 0;
282 else if (RT_FAILURE(rc))
283 {
284 AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
285 return rc;
286 }
287
288 uint32_t cItems = 0;
289 rc = CFGMR3QueryU32(pCfgHandle, "QueueSize", &cItems);
290 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
291 cItems = 128;
292 else if (RT_FAILURE(rc))
293 {
294 AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
295 return rc;
296 }
297
298 rc = PDMDrvHlpPDMQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, "Mouse", &pDrv->pQueue);
299 if (RT_FAILURE(rc))
300 {
301 AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
302 return rc;
303 }
304
305 return VINF_SUCCESS;
306}
307
308
309/**
310 * Mouse queue driver registration record.
311 */
312const PDMDRVREG g_DrvMouseQueue =
313{
314 /* u32Version */
315 PDM_DRVREG_VERSION,
316 /* szDriverName */
317 "MouseQueue",
318 /* szRCMod */
319 "",
320 /* szR0Mod */
321 "",
322 /* pszDescription */
323 "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
324 /* fFlags */
325 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
326 /* fClass. */
327 PDM_DRVREG_CLASS_MOUSE,
328 /* cMaxInstances */
329 ~0,
330 /* cbInstance */
331 sizeof(DRVMOUSEQUEUE),
332 /* pfnConstruct */
333 drvMouseQueueConstruct,
334 /* pfnRelocate */
335 NULL,
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 /* pfnAttach */
349 NULL,
350 /* pfnDetach */
351 NULL,
352 /* pfnPowerOff */
353 drvMouseQueuePowerOff,
354 /* pfnSoftReset */
355 NULL,
356 /* u32EndVersion */
357 PDM_DRVREG_VERSION
358};
359
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