VirtualBox

source: vbox/trunk/src/VBox/Main/MouseImpl.cpp@ 34796

Last change on this file since 34796 was 34754, checked in by vboxsync, 14 years ago

Main/VMMDev: optionally report multi-monitor mouse co-ordinates relative to the whole virtual framebuffer and not to the first screen

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1/* $Id: MouseImpl.cpp 34754 2010-12-06 14:40:03Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2008 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#include <iprt/cpp/utils.h>
19
20#include "MouseImpl.h"
21#include "DisplayImpl.h"
22#include "VMMDev.h"
23
24#include "AutoCaller.h"
25#include "Logging.h"
26
27#include <VBox/pdmdrv.h>
28#include <VBox/VMMDev.h>
29
30#include <iprt/asm.h>
31
32/** @name Mouse device capabilities bitfield
33 * @{ */
34enum
35{
36 /** The mouse device can do relative reporting */
37 MOUSE_DEVCAP_RELATIVE = 1,
38 /** The mouse device can do absolute reporting */
39 MOUSE_DEVCAP_ABSOLUTE = 2
40};
41/** @} */
42
43/**
44 * Mouse driver instance data.
45 */
46struct DRVMAINMOUSE
47{
48 /** Pointer to the mouse object. */
49 Mouse *pMouse;
50 /** Pointer to the driver instance structure. */
51 PPDMDRVINS pDrvIns;
52 /** Pointer to the mouse port interface of the driver/device above us. */
53 PPDMIMOUSEPORT pUpPort;
54 /** Our mouse connector interface. */
55 PDMIMOUSECONNECTOR IConnector;
56 /** The capabilities of this device. */
57 uint32_t u32DevCaps;
58};
59
60
61// constructor / destructor
62/////////////////////////////////////////////////////////////////////////////
63
64Mouse::Mouse()
65 : mParent(NULL)
66{
67}
68
69Mouse::~Mouse()
70{
71}
72
73
74HRESULT Mouse::FinalConstruct()
75{
76 RT_ZERO(mpDrv);
77 mcLastAbsX = 0x8000;
78 mcLastAbsY = 0x8000;
79 mfLastButtons = 0;
80 mfVMMDevGuestCaps = 0;
81 return S_OK;
82}
83
84void Mouse::FinalRelease()
85{
86 uninit();
87}
88
89// public methods only for internal purposes
90/////////////////////////////////////////////////////////////////////////////
91
92/**
93 * Initializes the mouse object.
94 *
95 * @returns COM result indicator
96 * @param parent handle of our parent object
97 */
98HRESULT Mouse::init (Console *parent)
99{
100 LogFlowThisFunc(("\n"));
101
102 ComAssertRet(parent, E_INVALIDARG);
103
104 /* Enclose the state transition NotReady->InInit->Ready */
105 AutoInitSpan autoInitSpan(this);
106 AssertReturn(autoInitSpan.isOk(), E_FAIL);
107
108 unconst(mParent) = parent;
109
110#ifndef VBOXBFE_WITHOUT_COM
111 unconst(mEventSource).createObject();
112 HRESULT rc = mEventSource->init(static_cast<IMouse*>(this));
113 AssertComRCReturnRC(rc);
114 mMouseEvent.init(mEventSource, VBoxEventType_OnGuestMouse,
115 0, 0, 0, 0, 0);
116#endif
117
118 /* Confirm a successful initialization */
119 autoInitSpan.setSucceeded();
120
121 return S_OK;
122}
123
124/**
125 * Uninitializes the instance and sets the ready flag to FALSE.
126 * Called either from FinalRelease() or by the parent when it gets destroyed.
127 */
128void Mouse::uninit()
129{
130 LogFlowThisFunc(("\n"));
131
132 /* Enclose the state transition Ready->InUninit->NotReady */
133 AutoUninitSpan autoUninitSpan(this);
134 if (autoUninitSpan.uninitDone())
135 return;
136
137 for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
138 {
139 if (mpDrv[i])
140 mpDrv[i]->pMouse = NULL;
141 mpDrv[i] = NULL;
142 }
143
144#ifdef VBOXBFE_WITHOUT_COM
145 mParent = NULL;
146#else
147 mMouseEvent.uninit();
148 unconst(mEventSource).setNull();
149 unconst(mParent) = NULL;
150#endif
151}
152
153
154// IMouse properties
155/////////////////////////////////////////////////////////////////////////////
156
157/** Report the front-end's mouse handling capabilities to the VMM device and
158 * thus to the guest.
159 * @note all calls out of this object are made with no locks held! */
160HRESULT Mouse::updateVMMDevMouseCaps(uint32_t fCapsAdded,
161 uint32_t fCapsRemoved)
162{
163 VMMDev *pVMMDev = mParent->getVMMDev();
164 if (!pVMMDev)
165 return E_FAIL; /* No assertion, as the front-ends can send events
166 * at all sorts of inconvenient times. */
167 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
168 ComAssertRet(pVMMDevPort, E_FAIL);
169
170 int rc = pVMMDevPort->pfnUpdateMouseCapabilities(pVMMDevPort, fCapsAdded,
171 fCapsRemoved);
172 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
173}
174
175/**
176 * Returns whether the current setup can accept absolute mouse events, either
177 * because an emulated absolute pointing device is active or because the Guest
178 * Additions are.
179 *
180 * @returns COM status code
181 * @param absoluteSupported address of result variable
182 */
183STDMETHODIMP Mouse::COMGETTER(AbsoluteSupported) (BOOL *absoluteSupported)
184{
185 if (!absoluteSupported)
186 return E_POINTER;
187
188 AutoCaller autoCaller(this);
189 if (FAILED(autoCaller.rc())) return autoCaller.rc();
190
191 *absoluteSupported = supportsAbs();
192 return S_OK;
193}
194
195/**
196 * Returns whether the current setup can accept relative mouse events, that is,
197 * whether an emulated relative pointing device is active.
198 *
199 * @returns COM status code
200 * @param relativeSupported address of result variable
201 */
202STDMETHODIMP Mouse::COMGETTER(RelativeSupported) (BOOL *relativeSupported)
203{
204 if (!relativeSupported)
205 return E_POINTER;
206
207 AutoCaller autoCaller(this);
208 if (FAILED(autoCaller.rc())) return autoCaller.rc();
209
210 *relativeSupported = supportsRel();
211 return S_OK;
212}
213
214/**
215 * Returns whether the guest can currently switch to drawing the mouse cursor
216 * itself if it is asked to by the front-end.
217 *
218 * @returns COM status code
219 * @param pfNeedsHostCursor address of result variable
220 */
221STDMETHODIMP Mouse::COMGETTER(NeedsHostCursor) (BOOL *pfNeedsHostCursor)
222{
223 if (!pfNeedsHostCursor)
224 return E_POINTER;
225
226 AutoCaller autoCaller(this);
227 if (FAILED(autoCaller.rc())) return autoCaller.rc();
228
229 *pfNeedsHostCursor = guestNeedsHostCursor();
230 return S_OK;
231}
232
233// IMouse methods
234/////////////////////////////////////////////////////////////////////////////
235
236/** Converts a bitfield containing information about mouse buttons currently
237 * held down from the format used by the front-end to the format used by PDM
238 * and the emulated pointing devices. */
239static uint32_t mouseButtonsToPDM(LONG buttonState)
240{
241 uint32_t fButtons = 0;
242 if (buttonState & MouseButtonState_LeftButton)
243 fButtons |= PDMIMOUSEPORT_BUTTON_LEFT;
244 if (buttonState & MouseButtonState_RightButton)
245 fButtons |= PDMIMOUSEPORT_BUTTON_RIGHT;
246 if (buttonState & MouseButtonState_MiddleButton)
247 fButtons |= PDMIMOUSEPORT_BUTTON_MIDDLE;
248 if (buttonState & MouseButtonState_XButton1)
249 fButtons |= PDMIMOUSEPORT_BUTTON_X1;
250 if (buttonState & MouseButtonState_XButton2)
251 fButtons |= PDMIMOUSEPORT_BUTTON_X2;
252 return fButtons;
253}
254
255#ifndef VBOXBFE_WITHOUT_COM
256STDMETHODIMP Mouse::COMGETTER(EventSource)(IEventSource ** aEventSource)
257{
258 CheckComArgOutPointerValid(aEventSource);
259
260 AutoCaller autoCaller(this);
261 if (FAILED(autoCaller.rc())) return autoCaller.rc();
262
263 // no need to lock - lifetime constant
264 mEventSource.queryInterfaceTo(aEventSource);
265
266 return S_OK;
267}
268#endif
269
270/**
271 * Send a relative pointer event to the relative device we deem most
272 * appropriate.
273 *
274 * @returns COM status code
275 */
276HRESULT Mouse::reportRelEventToMouseDev(int32_t dx, int32_t dy, int32_t dz,
277 int32_t dw, uint32_t fButtons)
278{
279 if (dx || dy || dz || dw || fButtons != mfLastButtons)
280 {
281 PPDMIMOUSEPORT pUpPort = NULL;
282 {
283 AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
284
285 for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i)
286 {
287 if (mpDrv[i] && (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_RELATIVE))
288 pUpPort = mpDrv[i]->pUpPort;
289 }
290 }
291 if (!pUpPort)
292 return S_OK;
293
294 int vrc = pUpPort->pfnPutEvent(pUpPort, dx, dy, dz, dw, fButtons);
295
296 if (RT_FAILURE(vrc))
297 return setError(VBOX_E_IPRT_ERROR,
298 tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
299 vrc);
300 mfLastButtons = fButtons;
301 }
302 return S_OK;
303}
304
305
306/**
307 * Send an absolute pointer event to the emulated absolute device we deem most
308 * appropriate.
309 *
310 * @returns COM status code
311 */
312HRESULT Mouse::reportAbsEventToMouseDev(uint32_t mouseXAbs, uint32_t mouseYAbs,
313 int32_t dz, int32_t dw, uint32_t fButtons)
314{
315 if ( mouseXAbs != mcLastAbsX || mouseYAbs != mcLastAbsY
316 || dz || dw || fButtons != mfLastButtons)
317 {
318 PPDMIMOUSEPORT pUpPort = NULL;
319 {
320 AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
321
322 for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i)
323 {
324 if (mpDrv[i] && (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_ABSOLUTE))
325 pUpPort = mpDrv[i]->pUpPort;
326 }
327 }
328 if (!pUpPort)
329 return S_OK;
330
331 int vrc = pUpPort->pfnPutEventAbs(pUpPort, mouseXAbs, mouseYAbs, dz,
332 dw, fButtons);
333 if (RT_FAILURE(vrc))
334 return setError(VBOX_E_IPRT_ERROR,
335 tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
336 vrc);
337 mfLastButtons = fButtons;
338
339 }
340 return S_OK;
341}
342
343
344/**
345 * Send an absolute position event to the VMM device.
346 * @note all calls out of this object are made with no locks held!
347 *
348 * @returns COM status code
349 */
350HRESULT Mouse::reportAbsEventToVMMDev(uint32_t mouseXAbs, uint32_t mouseYAbs)
351{
352 VMMDev *pVMMDev = mParent->getVMMDev();
353 ComAssertRet(pVMMDev, E_FAIL);
354 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
355 ComAssertRet(pVMMDevPort, E_FAIL);
356
357 if (mouseXAbs != mcLastAbsX || mouseYAbs != mcLastAbsY)
358 {
359 int vrc = pVMMDevPort->pfnSetAbsoluteMouse(pVMMDevPort,
360 mouseXAbs, mouseYAbs);
361 if (RT_FAILURE(vrc))
362 return setError(VBOX_E_IPRT_ERROR,
363 tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
364 vrc);
365 }
366 return S_OK;
367}
368
369
370/**
371 * Send an absolute pointer event to a pointing device (the VMM device if
372 * possible or whatever emulated absolute device seems best to us if not).
373 *
374 * @returns COM status code
375 */
376HRESULT Mouse::reportAbsEvent(uint32_t mouseXAbs, uint32_t mouseYAbs,
377 int32_t dz, int32_t dw, uint32_t fButtons,
378 bool fUsesVMMDevEvent)
379{
380 HRESULT rc;
381 /** If we are using the VMMDev to report absolute position but without
382 * VMMDev IRQ support then we need to send a small "jiggle" to the emulated
383 * relative mouse device to alert the guest to changes. */
384 LONG cJiggle = 0;
385
386 if (vmmdevCanAbs())
387 {
388 /*
389 * Send the absolute mouse position to the VMM device.
390 */
391 if (mouseXAbs != mcLastAbsX || mouseYAbs != mcLastAbsY)
392 {
393 rc = reportAbsEventToVMMDev(mouseXAbs, mouseYAbs);
394 cJiggle = !fUsesVMMDevEvent;
395 }
396 rc = reportRelEventToMouseDev(cJiggle, 0, dz, dw, fButtons);
397 }
398 else
399 rc = reportAbsEventToMouseDev(mouseXAbs, mouseYAbs, dz, dw, fButtons);
400
401 mcLastAbsX = mouseXAbs;
402 mcLastAbsY = mouseYAbs;
403 return rc;
404}
405
406/**
407 * Send a relative mouse event to the guest.
408 * @note the VMMDev capability change is so that the guest knows we are sending
409 * real events over the PS/2 device and not dummy events to signal the
410 * arrival of new absolute pointer data
411 *
412 * @returns COM status code
413 * @param dx X movement
414 * @param dy Y movement
415 * @param dz Z movement
416 * @param buttonState The mouse button state
417 */
418STDMETHODIMP Mouse::PutMouseEvent(LONG dx, LONG dy, LONG dz, LONG dw, LONG buttonState)
419{
420 HRESULT rc;
421 uint32_t fButtons;
422
423 AutoCaller autoCaller(this);
424 if (FAILED(autoCaller.rc())) return autoCaller.rc();
425 LogRel3(("%s: dx=%d, dy=%d, dz=%d, dw=%d\n", __PRETTY_FUNCTION__,
426 dx, dy, dz, dw));
427
428 fButtons = mouseButtonsToPDM(buttonState);
429 /* Make sure that the guest knows that we are sending real movement
430 * events to the PS/2 device and not just dummy wake-up ones. */
431 updateVMMDevMouseCaps(0, VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE);
432 rc = reportRelEventToMouseDev(dx, dy, dz, dw, fButtons);
433
434#ifndef VBOXBFE_WITHOUT_COM
435 mMouseEvent.reinit(VBoxEventType_OnGuestMouse, false, dx, dy, dz, dw, fButtons);
436 mMouseEvent.fire(0);
437#endif
438
439 return rc;
440}
441
442/**
443 * Convert an (X, Y) value pair in screen co-ordinates (starting from 1) to a
444 * value from 0 to 0xffff.
445 *
446 * @returns COM status value
447 */
448HRESULT Mouse::convertDisplayRes(LONG x, LONG y, uint32_t *pcX, uint32_t *pcY)
449{
450 AssertPtrReturn(pcX, E_POINTER);
451 AssertPtrReturn(pcY, E_POINTER);
452 Display *pDisplay = mParent->getDisplay();
453 ComAssertRet(pDisplay, E_FAIL);
454
455 if (!(mfVMMDevGuestCaps & VMMDEV_MOUSE_NEW_PROTOCOL))
456 {
457 ULONG displayWidth, displayHeight;
458 /* Takes the display lock */
459 HRESULT rc = pDisplay->GetScreenResolution(0, &displayWidth, &displayHeight,
460 NULL);
461 if (FAILED(rc))
462 return rc;
463
464 *pcX = displayWidth ? ((x - 1) * 0xFFFF) / displayWidth: 0;
465 *pcY = displayHeight ? ((y - 1) * 0xFFFF) / displayHeight: 0;
466 }
467 else
468 {
469 int32_t x1, y1, x2, y2;
470 pDisplay->getFramebufferDimensions(&x1, &y1, &x2, &y2);
471 *pcX = x1 != x2 ? (x - 1 - x1) * 0xFFFF / (x2 - x1) : 0;
472 *pcY = y1 != y2 ? (y - 1 - y1) * 0xFFFF / (y2 - y1) : 0;
473 }
474 return S_OK;
475}
476
477
478/**
479 * Send an absolute mouse event to the VM. This requires either VirtualBox-
480 * specific drivers installed in the guest or absolute pointing device
481 * emulation.
482 * @note the VMMDev capability change is so that the guest knows we are sending
483 * dummy events over the PS/2 device to signal the arrival of new
484 * absolute pointer data, and not pointer real movement data
485 * @note all calls out of this object are made with no locks held!
486 *
487 * @returns COM status code
488 * @param x X position (pixel), starting from 1
489 * @param y Y position (pixel), starting from 1
490 * @param dz Z movement
491 * @param buttonState The mouse button state
492 */
493STDMETHODIMP Mouse::PutMouseEventAbsolute(LONG x, LONG y, LONG dz, LONG dw,
494 LONG buttonState)
495{
496 AutoCaller autoCaller(this);
497 if (FAILED(autoCaller.rc())) return autoCaller.rc();
498
499 LogRel3(("%s: x=%d, y=%d, dz=%d, dw=%d, buttonState=0x%x\n",
500 __PRETTY_FUNCTION__, x, y, dz, dw, buttonState));
501
502 uint32_t mouseXAbs, mouseYAbs, fButtons;
503
504 /** @todo the front end should do this conversion to avoid races */
505 /** @note Or maybe not... races are pretty inherent in everything done in
506 * this object and not really bad as far as I can see. */
507 HRESULT rc = convertDisplayRes(x, y, &mouseXAbs, &mouseYAbs);
508 if (FAILED(rc)) return rc;
509
510 /** @todo multi-monitor Windows guests expect this to be unbounded.
511 * Understand the issues involved and fix for the rest. */
512 /* if (mouseXAbs > 0xffff)
513 mouseXAbs = mcLastAbsX;
514 if (mouseYAbs > 0xffff)
515 mouseYAbs = mcLastAbsY; */
516
517 fButtons = mouseButtonsToPDM(buttonState);
518 /* If we are doing old-style (IRQ-less) absolute reporting to the VMM
519 * device then make sure the guest is aware of it, so that it knows to
520 * ignore relative movement on the PS/2 device. */
521 updateVMMDevMouseCaps(VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE, 0);
522 rc = reportAbsEvent(mouseXAbs, mouseYAbs, dz, dw, fButtons,
523 RT_BOOL( mfVMMDevGuestCaps
524 & VMMDEV_MOUSE_NEW_PROTOCOL));
525
526#ifndef VBOXBFE_WITHOUT_COM
527 mMouseEvent.reinit(VBoxEventType_OnGuestMouse, true, x, y, dz, dw, fButtons);
528 mMouseEvent.fire(0);
529#endif
530
531 return rc;
532}
533
534// private methods
535/////////////////////////////////////////////////////////////////////////////
536
537
538/** Does the guest currently rely on the host to draw the mouse cursor or
539 * can it switch to doing it itself in software? */
540bool Mouse::guestNeedsHostCursor(void)
541{
542 return RT_BOOL(mfVMMDevGuestCaps & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR);
543}
544
545
546/** Check what sort of reporting can be done using the devices currently
547 * enabled. Does not consider the VMM device. */
548void Mouse::getDeviceCaps(bool *pfAbs, bool *pfRel)
549{
550 bool fAbsDev = false;
551 bool fRelDev = false;
552
553 AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
554
555 for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
556 if (mpDrv[i])
557 {
558 if (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_ABSOLUTE)
559 fAbsDev = true;
560 if (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_RELATIVE)
561 fRelDev = true;
562 }
563 if (pfAbs)
564 *pfAbs = fAbsDev;
565 if (pfRel)
566 *pfRel = fRelDev;
567}
568
569
570/** Does the VMM device currently support absolute reporting? */
571bool Mouse::vmmdevCanAbs(void)
572{
573 bool fRelDev;
574
575 getDeviceCaps(NULL, &fRelDev);
576 return (mfVMMDevGuestCaps & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE)
577 && fRelDev;
578}
579
580
581/** Does the VMM device currently support absolute reporting? */
582bool Mouse::deviceCanAbs(void)
583{
584 bool fAbsDev;
585
586 getDeviceCaps(&fAbsDev, NULL);
587 return fAbsDev;
588}
589
590
591/** Can we currently send relative events to the guest? */
592bool Mouse::supportsRel(void)
593{
594 bool fRelDev;
595
596 getDeviceCaps(NULL, &fRelDev);
597 return fRelDev;
598}
599
600
601/** Can we currently send absolute events to the guest? */
602bool Mouse::supportsAbs(void)
603{
604 bool fAbsDev;
605
606 getDeviceCaps(&fAbsDev, NULL);
607 return fAbsDev || vmmdevCanAbs();
608}
609
610
611/** Check what sort of reporting can be done using the devices currently
612 * enabled (including the VMM device) and notify the guest and the front-end.
613 */
614void Mouse::sendMouseCapsNotifications(void)
615{
616 bool fAbsDev, fRelDev, fCanAbs, fNeedsHostCursor;
617
618 {
619 AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
620
621 getDeviceCaps(&fAbsDev, &fRelDev);
622 fCanAbs = supportsAbs();
623 fNeedsHostCursor = guestNeedsHostCursor();
624 }
625 if (fAbsDev)
626 updateVMMDevMouseCaps(VMMDEV_MOUSE_HOST_HAS_ABS_DEV, 0);
627 else
628 updateVMMDevMouseCaps(0, VMMDEV_MOUSE_HOST_HAS_ABS_DEV);
629 /** @todo this call takes the Console lock in order to update the cached
630 * callback data atomically. However I can't see any sign that the cached
631 * data is ever used again. */
632 mParent->onMouseCapabilityChange(fCanAbs, fRelDev, fNeedsHostCursor);
633}
634
635
636/**
637 * @interface_method_impl{PDMIMOUSECONNECTOR,pfnReportModes}
638 * A virtual device is notifying us about its current state and capabilities
639 */
640DECLCALLBACK(void) Mouse::mouseReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs)
641{
642 PDRVMAINMOUSE pDrv = RT_FROM_MEMBER(pInterface, DRVMAINMOUSE, IConnector);
643 if (fRel)
644 pDrv->u32DevCaps |= MOUSE_DEVCAP_RELATIVE;
645 else
646 pDrv->u32DevCaps &= ~MOUSE_DEVCAP_RELATIVE;
647 if (fAbs)
648 pDrv->u32DevCaps |= MOUSE_DEVCAP_ABSOLUTE;
649 else
650 pDrv->u32DevCaps &= ~MOUSE_DEVCAP_ABSOLUTE;
651
652 pDrv->pMouse->sendMouseCapsNotifications();
653}
654
655
656/**
657 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
658 */
659DECLCALLBACK(void *) Mouse::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
660{
661 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
662 PDRVMAINMOUSE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
663
664 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
665 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pDrv->IConnector);
666 return NULL;
667}
668
669
670/**
671 * Destruct a mouse driver instance.
672 *
673 * @returns VBox status.
674 * @param pDrvIns The driver instance data.
675 */
676DECLCALLBACK(void) Mouse::drvDestruct(PPDMDRVINS pDrvIns)
677{
678 PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
679 LogFlow(("Mouse::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
680 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
681
682 if (pData->pMouse)
683 {
684 AutoWriteLock mouseLock(pData->pMouse COMMA_LOCKVAL_SRC_POS);
685 for (unsigned cDev = 0; cDev < MOUSE_MAX_DEVICES; ++cDev)
686 if (pData->pMouse->mpDrv[cDev] == pData)
687 {
688 pData->pMouse->mpDrv[cDev] = NULL;
689 break;
690 }
691 }
692}
693
694
695/**
696 * Construct a mouse driver instance.
697 *
698 * @copydoc FNPDMDRVCONSTRUCT
699 */
700DECLCALLBACK(int) Mouse::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
701{
702 PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
703 LogFlow(("drvMainMouse_Construct: iInstance=%d\n", pDrvIns->iInstance));
704 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
705
706 /*
707 * Validate configuration.
708 */
709 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
710 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
711 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
712 ("Configuration error: Not possible to attach anything to this driver!\n"),
713 VERR_PDM_DRVINS_NO_ATTACH);
714
715 /*
716 * IBase.
717 */
718 pDrvIns->IBase.pfnQueryInterface = Mouse::drvQueryInterface;
719
720 pData->IConnector.pfnReportModes = Mouse::mouseReportModes;
721
722 /*
723 * Get the IMousePort interface of the above driver/device.
724 */
725 pData->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMIMOUSEPORT_IID);
726 if (!pData->pUpPort)
727 {
728 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
729 return VERR_PDM_MISSING_INTERFACE_ABOVE;
730 }
731
732 /*
733 * Get the Mouse object pointer and update the mpDrv member.
734 */
735 void *pv;
736 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
737 if (RT_FAILURE(rc))
738 {
739 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
740 return rc;
741 }
742 pData->pMouse = (Mouse *)pv; /** @todo Check this cast! */
743 unsigned cDev;
744 {
745 AutoReadLock mouseLock(pData->pMouse COMMA_LOCKVAL_SRC_POS);
746
747 for (cDev = 0; cDev < MOUSE_MAX_DEVICES; ++cDev)
748 if (!pData->pMouse->mpDrv[cDev])
749 {
750 pData->pMouse->mpDrv[cDev] = pData;
751 break;
752 }
753 }
754 if (cDev == MOUSE_MAX_DEVICES)
755 return VERR_NO_MORE_HANDLES;
756
757 return VINF_SUCCESS;
758}
759
760
761/**
762 * Main mouse driver registration record.
763 */
764const PDMDRVREG Mouse::DrvReg =
765{
766 /* u32Version */
767 PDM_DRVREG_VERSION,
768 /* szName */
769 "MainMouse",
770 /* szRCMod */
771 "",
772 /* szR0Mod */
773 "",
774 /* pszDescription */
775 "Main mouse driver (Main as in the API).",
776 /* fFlags */
777 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
778 /* fClass. */
779 PDM_DRVREG_CLASS_MOUSE,
780 /* cMaxInstances */
781 ~0,
782 /* cbInstance */
783 sizeof(DRVMAINMOUSE),
784 /* pfnConstruct */
785 Mouse::drvConstruct,
786 /* pfnDestruct */
787 Mouse::drvDestruct,
788 /* pfnRelocate */
789 NULL,
790 /* pfnIOCtl */
791 NULL,
792 /* pfnPowerOn */
793 NULL,
794 /* pfnReset */
795 NULL,
796 /* pfnSuspend */
797 NULL,
798 /* pfnResume */
799 NULL,
800 /* pfnAttach */
801 NULL,
802 /* pfnDetach */
803 NULL,
804 /* pfnPowerOff */
805 NULL,
806 /* pfnSoftReset */
807 NULL,
808 /* u32EndVersion */
809 PDM_DRVREG_VERSION
810};
811/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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