VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxService/VBoxRestore.cpp@ 4302

Last change on this file since 4302 was 4302, checked in by vboxsync, 17 years ago

Disabled code for VRDP status checks

File size: 4.4 KB
Line 
1/** @file
2 *
3 * VBoxRestore - Restore notification
4 *
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18#define _WIN32_WINNT 0x0500
19#include <windows.h>
20#include "VBoxService.h"
21#include "VBoxRestore.h"
22#include <VBoxDisplay.h>
23#include <VBox/VBoxDev.h>
24#include <iprt/assert.h>
25#include "helpers.h"
26
27typedef struct _VBOXRESTORECONTEXT
28{
29 const VBOXSERVICEENV *pEnv;
30} VBOXRESTORECONTEXT;
31
32
33static VBOXRESTORECONTEXT gCtx = {0};
34
35
36int VBoxRestoreInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
37{
38 dprintf(("VBoxRestoreInit\n"));
39
40 gCtx.pEnv = pEnv;
41
42 VBoxRestoreCheckVRDP();
43
44 *pfStartThread = true;
45 *ppInstance = &gCtx;
46 return VINF_SUCCESS;
47}
48
49
50void VBoxRestoreDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
51{
52 dprintf(("VBoxRestoreDestroy\n"));
53 return;
54}
55
56void VBoxRestoreSession()
57{
58 VBoxRestoreCheckVRDP();
59}
60
61void VBoxRestoreCheckVRDP()
62{
63 HDC hdc;
64 BOOL ret;
65
66 /* Check VRDP activity */
67 hdc = GetDC(HWND_DESKTOP);
68
69 /* send to display driver */
70 ret = ExtEscape(hdc, VBOXESC_ISVRDPACTIVE, 0, NULL, 0, NULL);
71 dprintf(("VBoxRestoreSession -> VRDP activate state = %d\n", ret));
72
73 ReleaseDC(HWND_DESKTOP, hdc);
74}
75
76/**
77 * Thread function to wait for and process seamless mode change
78 * requests
79 */
80unsigned __stdcall VBoxRestoreThread(void *pInstance)
81{
82 VBOXRESTORECONTEXT *pCtx = (VBOXRESTORECONTEXT *)pInstance;
83 HANDLE gVBoxDriver = pCtx->pEnv->hDriver;
84 bool fTerminate = false;
85 VBoxGuestFilterMaskInfo maskInfo;
86 DWORD cbReturned;
87
88 maskInfo.u32OrMask = VMMDEV_EVENT_RESTORED;
89 maskInfo.u32NotMask = 0;
90 if (DeviceIoControl (gVBoxDriver, IOCTL_VBOXGUEST_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
91 {
92 dprintf(("VBoxRestoreThread: DeviceIOControl(CtlMask - or) succeeded\n"));
93 }
94 else
95 {
96 dprintf(("VBoxRestoreThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
97 return 0;
98 }
99
100 do
101 {
102 /* wait for a seamless change event */
103 VBoxGuestWaitEventInfo waitEvent;
104 waitEvent.u32TimeoutIn = 1000;
105 waitEvent.u32EventMaskIn = VMMDEV_EVENT_RESTORED;
106 if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
107 {
108 dprintf(("VBoxRestoreThread: DeviceIOControl succeded\n"));
109
110 /* are we supposed to stop? */
111 if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 0) == WAIT_OBJECT_0)
112 break;
113
114 dprintf(("VBoxRestoreThread: checking event\n"));
115
116 /* did we get the right event? */
117 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_RESTORED)
118 PostMessage(gToolWindow, WM_VBOX_RESTORED, 0, 0);
119
120 }
121 else
122 {
123 dprintf(("VBoxService: error 0 from DeviceIoControl IOCTL_VBOXGUEST_WAITEVENT\n"));
124
125 /** @todo Don't poll, but wait for connect/disconnect events */
126 PostMessage(gToolWindow, WM_VBOX_CHECK_VRDP, 0, 0);
127 /* sleep a bit to not eat too much CPU in case the above call always fails */
128 if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 10) == WAIT_OBJECT_0)
129 {
130 fTerminate = true;
131 break;
132 }
133 }
134 }
135 while (!fTerminate);
136
137 maskInfo.u32OrMask = 0;
138 maskInfo.u32NotMask = VMMDEV_EVENT_RESTORED;
139 if (DeviceIoControl (gVBoxDriver, IOCTL_VBOXGUEST_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
140 {
141 dprintf(("VBoxRestoreThread: DeviceIOControl(CtlMask - not) succeeded\n"));
142 }
143 else
144 {
145 dprintf(("VBoxRestoreThread: DeviceIOControl(CtlMask) failed\n"));
146 }
147
148 dprintf(("VBoxRestoreThread: finished seamless change request thread\n"));
149 return 0;
150}
151
152
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