VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxRestore.cpp@ 17610

Last change on this file since 17610 was 10777, checked in by vboxsync, 16 years ago

Windows VBoxService: Getting rid of custom logging routines; now using the R3 guest lib.

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/** @file
2 *
3 * VBoxRestore - Restore notification
4 *
5 */
6
7/*
8 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22#define _WIN32_WINNT 0x0500
23#include <windows.h>
24#include "VBoxTray.h"
25#include "VBoxRestore.h"
26#include <VBoxDisplay.h>
27#include <VBox/VBoxDev.h>
28#include <VBoxGuestInternal.h>
29#include <iprt/assert.h>
30#include "helpers.h"
31
32typedef struct _VBOXRESTORECONTEXT
33{
34 const VBOXSERVICEENV *pEnv;
35
36 BOOL fRDPState;
37} VBOXRESTORECONTEXT;
38
39
40static VBOXRESTORECONTEXT gCtx = {0};
41
42
43int VBoxRestoreInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
44{
45 Log(("VBoxRestoreInit\n"));
46
47 gCtx.pEnv = pEnv;
48 gCtx.fRDPState = FALSE;
49
50 VBoxRestoreCheckVRDP();
51
52 *pfStartThread = true;
53 *ppInstance = &gCtx;
54 return VINF_SUCCESS;
55}
56
57
58void VBoxRestoreDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
59{
60 Log(("VBoxRestoreDestroy\n"));
61 return;
62}
63
64void VBoxRestoreSession()
65{
66 VBoxRestoreCheckVRDP();
67}
68
69void VBoxRestoreCheckVRDP()
70{
71 HDC hdc;
72 BOOL ret;
73
74 /* Check VRDP activity */
75 hdc = GetDC(HWND_DESKTOP);
76
77 /* send to display driver */
78 ret = ExtEscape(hdc, VBOXESC_ISVRDPACTIVE, 0, NULL, 0, NULL);
79 Log(("VBoxRestoreSession -> VRDP activate state = %d\n", ret));
80 ReleaseDC(HWND_DESKTOP, hdc);
81
82 if (ret != gCtx.fRDPState)
83 {
84 DWORD cbReturned;
85
86 if (!DeviceIoControl (gCtx.pEnv->hDriver, (ret) ? VBOXGUEST_IOCTL_ENABLE_VRDP_SESSION : VBOXGUEST_IOCTL_DISABLE_VRDP_SESSION, NULL, 0, NULL, 0, &cbReturned, NULL))
87 {
88 Log(("VBoxRestoreThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
89 }
90 gCtx.fRDPState = ret;
91 }
92}
93
94/**
95 * Thread function to wait for and process seamless mode change
96 * requests
97 */
98unsigned __stdcall VBoxRestoreThread(void *pInstance)
99{
100 VBOXRESTORECONTEXT *pCtx = (VBOXRESTORECONTEXT *)pInstance;
101 HANDLE gVBoxDriver = pCtx->pEnv->hDriver;
102 bool fTerminate = false;
103 VBoxGuestFilterMaskInfo maskInfo;
104 DWORD cbReturned;
105
106 maskInfo.u32OrMask = VMMDEV_EVENT_RESTORED;
107 maskInfo.u32NotMask = 0;
108 if (DeviceIoControl (gVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
109 {
110 Log(("VBoxRestoreThread: DeviceIOControl(CtlMask - or) succeeded\n"));
111 }
112 else
113 {
114 Log(("VBoxRestoreThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
115 return 0;
116 }
117
118 do
119 {
120 /* wait for a seamless change event */
121 VBoxGuestWaitEventInfo waitEvent;
122 waitEvent.u32TimeoutIn = 5000;
123 waitEvent.u32EventMaskIn = VMMDEV_EVENT_RESTORED;
124 if (DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
125 {
126 Log(("VBoxRestoreThread: DeviceIOControl succeded\n"));
127
128 /* are we supposed to stop? */
129 if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 0) == WAIT_OBJECT_0)
130 break;
131
132 Log(("VBoxRestoreThread: checking event\n"));
133
134 /* did we get the right event? */
135 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_RESTORED)
136 PostMessage(gToolWindow, WM_VBOX_RESTORED, 0, 0);
137 else
138 /** @todo Don't poll, but wait for connect/disconnect events */
139 PostMessage(gToolWindow, WM_VBOX_CHECK_VRDP, 0, 0);
140 }
141 else
142 {
143 Log(("VBoxTray: error 0 from DeviceIoControl VBOXGUEST_IOCTL_WAITEVENT\n"));
144
145 /* sleep a bit to not eat too much CPU in case the above call always fails */
146 if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 10) == WAIT_OBJECT_0)
147 {
148 fTerminate = true;
149 break;
150 }
151 }
152 }
153 while (!fTerminate);
154
155 maskInfo.u32OrMask = 0;
156 maskInfo.u32NotMask = VMMDEV_EVENT_RESTORED;
157 if (DeviceIoControl (gVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
158 {
159 Log(("VBoxRestoreThread: DeviceIOControl(CtlMask - not) succeeded\n"));
160 }
161 else
162 {
163 Log(("VBoxRestoreThread: DeviceIOControl(CtlMask) failed\n"));
164 }
165
166 Log(("VBoxRestoreThread: finished seamless change request thread\n"));
167 return 0;
168}
169
170
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