1 | /* $Id: VBoxGuestR3LibEvent.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Events.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2020 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 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <VBox/log.h>
|
---|
32 | #include <iprt/assert.h>
|
---|
33 | #include "VBoxGuestR3LibInternal.h"
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Wait for the host to signal one or more events and return which.
|
---|
38 | *
|
---|
39 | * The events will only be delivered by the host if they have been enabled
|
---|
40 | * previously using @a VbglR3CtlFilterMask. If one or several of the events
|
---|
41 | * have already been signalled but not yet waited for, this function will return
|
---|
42 | * immediately and return those events.
|
---|
43 | *
|
---|
44 | * @returns IPRT status code.
|
---|
45 | *
|
---|
46 | * @param fMask The events we want to wait for, or-ed together.
|
---|
47 | * @param cMillies How long to wait before giving up and returning
|
---|
48 | * (VERR_TIMEOUT). Use RT_INDEFINITE_WAIT to wait until we
|
---|
49 | * are interrupted or one of the events is signalled.
|
---|
50 | * @param pfEvents Where to store the events signalled. Optional.
|
---|
51 | */
|
---|
52 | VBGLR3DECL(int) VbglR3WaitEvent(uint32_t fMask, uint32_t cMillies, uint32_t *pfEvents)
|
---|
53 | {
|
---|
54 | LogFlow(("VbglR3WaitEvent: fMask=%#x, cMillies=%u, pfEvents=%p\n", fMask, cMillies, pfEvents));
|
---|
55 | AssertReturn((fMask & ~VMMDEV_EVENT_VALID_EVENT_MASK) == 0, VERR_INVALID_PARAMETER);
|
---|
56 | AssertPtrNullReturn(pfEvents, VERR_INVALID_POINTER);
|
---|
57 |
|
---|
58 | VBGLIOCWAITFOREVENTS WaitEvents;
|
---|
59 | VBGLREQHDR_INIT(&WaitEvents.Hdr, WAIT_FOR_EVENTS);
|
---|
60 | WaitEvents.u.In.fEvents = fMask;
|
---|
61 | WaitEvents.u.In.cMsTimeOut = cMillies;
|
---|
62 | int rc = vbglR3DoIOCtl(VBGL_IOCTL_WAIT_FOR_EVENTS, &WaitEvents.Hdr, sizeof(WaitEvents));
|
---|
63 | if (pfEvents)
|
---|
64 | {
|
---|
65 | if (RT_SUCCESS(rc))
|
---|
66 | *pfEvents = WaitEvents.u.Out.fEvents;
|
---|
67 | else
|
---|
68 | *pfEvents = 0;
|
---|
69 | }
|
---|
70 |
|
---|
71 | LogFlow(("VbglR3WaitEvent: rc=%Rrc fEvents=%#x\n", rc, WaitEvents.u.Out.fEvents));
|
---|
72 | return rc;
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Causes any pending VbglR3WaitEvent calls (VBGL_IOCTL_WAIT_FOR_EVENTS) to
|
---|
78 | * return with a VERR_INTERRUPTED status.
|
---|
79 | *
|
---|
80 | * Can be used in combination with a termination flag variable for interrupting
|
---|
81 | * event loops. After calling this, VBGL_IOCTL_WAIT_FOR_EVENTS should no longer
|
---|
82 | * be called in the same session. At the time of writing this is not enforced;
|
---|
83 | * at the time of reading it may be.
|
---|
84 | *
|
---|
85 | * @returns IPRT status code.
|
---|
86 | */
|
---|
87 | VBGLR3DECL(int) VbglR3InterruptEventWaits(void)
|
---|
88 | {
|
---|
89 | VBGLREQHDR Req;
|
---|
90 | VBGLREQHDR_INIT(&Req, INTERRUPT_ALL_WAIT_FOR_EVENTS);
|
---|
91 | return vbglR3DoIOCtl(VBGL_IOCTL_INTERRUPT_ALL_WAIT_FOR_EVENTS, &Req, sizeof(Req));
|
---|
92 | }
|
---|
93 |
|
---|