DrvMouseQueue.cpp revision e76125bd1eb207f3c5892c545c94f73627baaf14
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * VBox input devices: Mouse queue driver
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync * Copyright (C) 2006-2012 Oracle Corporation
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * available from http://www.virtualbox.org. This file is free software;
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * General Public License (GPL) as published by the Free Software
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync/*******************************************************************************
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync* Header Files *
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync*******************************************************************************/
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync/*******************************************************************************
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync* Structures and Typedefs *
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync*******************************************************************************/
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * Mouse queue driver instance data.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @implements PDMIMOUSECONNECTOR
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @implements PDMIMOUSEPORT
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /** Pointer to the driver instance structure. */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /** Pointer to the mouse port interface of the driver/device above us. */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /** Pointer to the mouse port interface of the driver/device below us. */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /** Our mouse connector interface. */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /** Our mouse port interface. */
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync /** The queue handle. */
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync /** Discard input when this flag is set.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * We only accept input when the VM is running. */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * Event type for @a DRVMOUSEQUEUEITEM
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Mouse queue item.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /** The core part owned by the queue manager. */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync/* -=-=-=-=- IBase -=-=-=-=- */
8a204879c937e7c55da35682a0e5d2e1df91c856vboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsyncstatic DECLCALLBACK(void *) drvMouseQueueQueryInterface(PPDMIBASE pInterface, const char *pszIID)
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->IPort);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pThis->IConnector);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync/* -=-=-=-=- IMousePort -=-=-=-=- */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync/** Converts a pointer to DRVMOUSEQUEUE::Port to a DRVMOUSEQUEUE pointer. */
8a204879c937e7c55da35682a0e5d2e1df91c856vboxsync#define IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IPort)) )
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @interface_method_impl{PDMIMOUSEPORT,pfnPutEvent}
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsyncstatic DECLCALLBACK(int) drvMouseQueuePutEvent(PPDMIMOUSEPORT pInterface,
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventAbs}
174f3dff60f96d89b320f9a322307118676db1dbvboxsyncstatic DECLCALLBACK(int) drvMouseQueuePutEventAbs(PPDMIMOUSEPORT pInterface,
174f3dff60f96d89b320f9a322307118676db1dbvboxsync PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventMT}
174f3dff60f96d89b320f9a322307118676db1dbvboxsyncstatic DECLCALLBACK(int) drvMouseQueuePutEventMT(PPDMIMOUSEPORT pInterface,
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync/* -=-=-=-=- IConnector -=-=-=-=- */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync#define PPDMIMOUSECONNECTOR_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IConnector)) )
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Pass absolute mode status changes from the guest through to the frontend
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @param pInterface Pointer to the mouse connector interface structure.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @param fRel Is relative reporting supported?
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync * @param fAbs Is absolute reporting supported?
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync * @param fMT Is multi-touch reporting supported?
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsyncstatic DECLCALLBACK(void) drvMousePassThruReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs, bool fMT)
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync PDRVMOUSEQUEUE pDrv = PPDMIMOUSECONNECTOR_2_DRVMOUSEQUEUE(pInterface);
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync pDrv->pDownConnector->pfnReportModes(pDrv->pDownConnector, fRel, fAbs, fMT);
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync/* -=-=-=-=- queue -=-=-=-=- */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Queue callback for processing a queued item.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @returns Success indicator.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * If false the item will not be removed and the flushing will stop.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @param pDrvIns The driver instance.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @param pItemCore Pointer to the queue item to process.
174f3dff60f96d89b320f9a322307118676db1dbvboxsyncstatic DECLCALLBACK(bool) drvMouseQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)pItemCore;
174f3dff60f96d89b320f9a322307118676db1dbvboxsync rc = pThis->pUpPort->pfnPutEventAbs(pThis->pUpPort,
174f3dff60f96d89b320f9a322307118676db1dbvboxsync return false;
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync/* -=-=-=-=- driver interface -=-=-=-=- */
8a204879c937e7c55da35682a0e5d2e1df91c856vboxsync * Power On notification.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @returns VBox status.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @param pDrvIns The drive instance data.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsyncstatic DECLCALLBACK(void) drvMouseQueuePowerOn(PPDMDRVINS pDrvIns)
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * Reset notification.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @returns VBox status.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @param pDrvIns The drive instance data.
174f3dff60f96d89b320f9a322307118676db1dbvboxsyncstatic DECLCALLBACK(void) drvMouseQueueReset(PPDMDRVINS pDrvIns)
8a204879c937e7c55da35682a0e5d2e1df91c856vboxsync //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /** @todo purge the queue on reset. */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Suspend notification.
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync * @returns VBox status.
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync * @param pDrvIns The drive instance data.
174f3dff60f96d89b320f9a322307118676db1dbvboxsyncstatic DECLCALLBACK(void) drvMouseQueueSuspend(PPDMDRVINS pDrvIns)
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync * Resume notification.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @returns VBox status.
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync * @param pDrvIns The drive instance data.
174f3dff60f96d89b320f9a322307118676db1dbvboxsyncstatic DECLCALLBACK(void) drvMouseQueueResume(PPDMDRVINS pDrvIns)
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync * Power Off notification.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * @param pDrvIns The drive instance data.
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsyncstatic DECLCALLBACK(void) drvMouseQueuePowerOff(PPDMDRVINS pDrvIns)
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Construct a mouse driver instance.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * @copydoc FNPDMDRVCONSTRUCT
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsyncstatic DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync PDRVMOUSEQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Validate configuration.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync if (!CFGMR3AreValuesValid(pCfg, "QueueSize\0Interval\0"))
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * Init basic data members and interfaces.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* IBase. */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* IMouseConnector. */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync pDrv->IConnector.pfnReportModes = drvMousePassThruReportModes;
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* IMousePort. */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync pDrv->IPort.pfnPutEventAbs = drvMouseQueuePutEventAbs;
174f3dff60f96d89b320f9a322307118676db1dbvboxsync pDrv->IPort.pfnPutEventMT = drvMouseQueuePutEventMT;
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync * Get the IMousePort interface of the above driver/device.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUSEPORT);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Attach driver below and query it's connector interface.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIMOUSECONNECTOR);
6e4f0a21de35da7e77586bc1fab65d1bbf611eeevboxsync AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Create the queue.
174f3dff60f96d89b320f9a322307118676db1dbvboxsync rc = CFGMR3QueryU32(pCfg, "Interval", &cMilliesInterval);
174f3dff60f96d89b320f9a322307118676db1dbvboxsync AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
174f3dff60f96d89b320f9a322307118676db1dbvboxsync AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, "Mouse", &pDrv->pQueue);
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
174f3dff60f96d89b320f9a322307118676db1dbvboxsync * Mouse queue driver registration record.
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* u32Version */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* szName */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync "MouseQueue",
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* szRCMod */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* szR0Mod */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* pszDescription */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* fFlags */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* fClass. */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* cMaxInstances */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* cbInstance */
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync /* pfnConstruct */
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync /* pfnRelocate */
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync /* pfnDestruct */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* pfnIOCtl */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* pfnPowerOn */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* pfnReset */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* pfnSuspend */
e95cc69731ec79cf167e6167808e1c9b275ea007vboxsync /* pfnResume */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* pfnAttach */
174f3dff60f96d89b320f9a322307118676db1dbvboxsync /* pfnDetach */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* pfnPowerOff */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* pfnSoftReset */
5f80794f0fac6c6ae43bf4d2baaef60babb2a7c7vboxsync /* u32EndVersion */