Changeset 16852 in vbox
- Timestamp:
- Feb 17, 2009 3:36:26 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/MouseFilter/VBoxMouse.cpp
r13837 r16852 119 119 volatile LONG fVBGLInitFailed; 120 120 volatile LONG fHostInformed; 121 volatile LONG fHostMouseFound; 121 122 } VBoxGlobalContext; 122 123 123 VBoxGlobalContext g_ctx = { 0, FALSE, FALSE, FALSE };124 125 BOOLEAN vboxIsVBGLInited (void)124 static VBoxGlobalContext g_ctx = { 0, FALSE, FALSE, FALSE, FALSE }; 125 126 static BOOLEAN vboxIsVBGLInited (void) 126 127 { 127 128 return InterlockedCompareExchange (&g_ctx.fVBGLInited, TRUE, TRUE) == TRUE; 128 129 } 129 130 130 BOOLEAN vboxIsVBGLInitFailed (void)131 static BOOLEAN vboxIsVBGLInitFailed (void) 131 132 { 132 133 return InterlockedCompareExchange (&g_ctx.fVBGLInitFailed, TRUE, TRUE) == TRUE; 133 134 } 134 135 135 BOOLEAN vboxIsHostInformed (void) 136 { 137 return InterlockedCompareExchange (&g_ctx.fVBGLInitFailed, TRUE, TRUE) == TRUE; 138 } 139 140 void vboxDeviceAdded (PDEVICE_EXTENSION devExt) 136 static BOOLEAN vboxIsHostInformed (void) 137 { 138 return InterlockedCompareExchange (&g_ctx.fHostInformed, TRUE, TRUE) == TRUE; 139 } 140 141 static BOOLEAN vboxIsHostMouseFound (void) 142 { 143 return InterlockedCompareExchange (&g_ctx.fHostMouseFound, TRUE, TRUE) == TRUE; 144 } 145 146 static void vboxDeviceAdded (PDEVICE_EXTENSION devExt) 141 147 { 142 148 LONG c = InterlockedIncrement (&g_ctx.cDevicesStarted); … … 155 161 InterlockedExchange (&g_ctx.fVBGLInited, TRUE); 156 162 dprintf(("VBoxMouse::vboxDeviceStarted: guest library initialization OK\n")); 157 158 /* Mark the first device as the Host one, that is the emulated mouse.159 * For this device the filter will query absolute mouse coords from the host.160 * @todo: Better would be to query the device information and detect the emulated device.161 */162 devExt->HostMouse = TRUE;163 163 } 164 164 else … … 169 169 } 170 170 } 171 } 172 173 void vboxDeviceRemoved (PDEVICE_EXTENSION devExt) 171 if (!vboxIsHostMouseFound ()) 172 { 173 WCHAR wszProperty[512]; 174 ULONG ResultLength = 0; 175 wszProperty[0] = 0; 176 NTSTATUS status = IoGetDeviceProperty(devExt->PDO, DevicePropertyDeviceDescription, 177 sizeof (wszProperty), 178 &wszProperty, 179 &ResultLength); 180 dprintf(("VBoxMouse::vboxDeviceAdded: looking for host mouse: %ls Len is %d, status %x\n", 181 wszProperty, ResultLength, status)); 182 183 if (status == STATUS_SUCCESS) 184 { 185 UNICODE_STRING MicrosoftPS2Mouse; 186 RtlInitUnicodeString (&MicrosoftPS2Mouse, L"Microsoft PS/2 Mouse"); 187 UNICODE_STRING DeviceDescription; 188 RtlInitUnicodeString (&DeviceDescription, wszProperty); 189 190 if (RtlCompareUnicodeString (&DeviceDescription, &MicrosoftPS2Mouse, TRUE) == 0) 191 { 192 /* Mark the PS/2 device as the Host one, that is the emulated mouse. 193 * For this device the filter will query absolute mouse coords from the host. 194 */ 195 InterlockedExchange (&g_ctx.fHostMouseFound, TRUE); 196 devExt->HostMouse = TRUE; 197 dprintf(("VBoxMouse::vboxDeviceAdded: host mouse found.\n")); 198 } 199 } 200 } 201 } 202 203 static void vboxDeviceRemoved (PDEVICE_EXTENSION devExt) 174 204 { 175 205 dprintf(("VBoxMouse::vboxDeviceRemoved\n")); 176 206 177 LONG c = InterlockedIncrement (&g_ctx.cDevicesStarted); 207 /* Save the allocated request pointer and clear the devExt. */ 208 VMMDevReqMouseStatus *reqSC = (VMMDevReqMouseStatus *)InterlockedExchangePointer (&devExt->reqSC, NULL); 209 210 if (devExt->HostMouse && vboxIsHostInformed ()) 211 { 212 // tell the VMM that from now on we can't handle absolute coordinates anymore 213 VMMDevReqMouseStatus *req = NULL; 214 215 int vboxRC = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus); 216 217 if (RT_SUCCESS(vboxRC)) 218 { 219 req->mouseFeatures = 0; 220 req->pointerXPos = 0; 221 req->pointerYPos = 0; 222 223 vboxRC = VbglGRPerform (&req->header); 224 225 if (RT_FAILURE(vboxRC) || RT_FAILURE(req->header.rc)) 226 { 227 dprintf(("VBoxMouse::vboxDeviceRemoved: ERROR communicating new mouse capabilities to VMMDev.\n" 228 "rc = %d, VMMDev rc = %Rrc\n", vboxRC, req->header.rc)); 229 } 230 231 VbglGRFree (&req->header); 232 } 233 else 234 { 235 dprintf(("VBoxMouse::vboxDeviceRemoved: the request allocation has failed.\n")); 236 } 237 238 InterlockedExchange (&g_ctx.fHostInformed, FALSE); 239 } 240 241 if (reqSC) 242 { 243 VbglGRFree (&reqSC->header); 244 } 245 246 LONG c = InterlockedDecrement (&g_ctx.cDevicesStarted); 178 247 179 248 if (c == 0) … … 184 253 InterlockedExchange (&g_ctx.fVBGLInitFailed, TRUE); 185 254 186 /* Save the allocated request pointer and clear the devExt. */187 VMMDevReqMouseStatus *reqSC = devExt->reqSC;188 devExt->reqSC = NULL;189 190 // tell the VMM that from now on we can't handle absolute coordinates anymore191 VMMDevReqMouseStatus *req = NULL;192 193 int vboxRC = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus);194 195 if (RT_SUCCESS(vboxRC))196 {197 req->mouseFeatures = 0;198 req->pointerXPos = 0;199 req->pointerYPos = 0;200 201 vboxRC = VbglGRPerform (&req->header);202 203 if (RT_FAILURE(vboxRC) || RT_FAILURE(req->header.rc))204 {205 dprintf(("VBoxMouse::vboxDeviceRemoved: ERROR communicating new mouse capabilities to VMMDev.\n"206 "rc = %d, VMMDev rc = %Rrc\n", vboxRC, req->header.rc));207 }208 209 VbglGRFree (&req->header);210 }211 212 if (reqSC)213 {214 VbglGRFree (&reqSC->header);215 }216 217 255 VbglTerminate (); 218 256 219 257 /* The VBGL is now in the not initialized state. */ 220 InterlockedExchange (&g_ctx.fHostInformed, FALSE);221 258 InterlockedExchange (&g_ctx.fVBGLInited, FALSE); 222 259 InterlockedExchange (&g_ctx.fVBGLInitFailed, FALSE); … … 225 262 } 226 263 227 void vboxInformHost (PDEVICE_EXTENSION devExt)264 static void vboxInformHost (PDEVICE_EXTENSION devExt) 228 265 { 229 266 dprintf (("VBoxMouse::vboxInformHost: %p\n", devExt)); … … 231 268 if (vboxIsVBGLInited ()) 232 269 { 233 if ( !vboxIsHostInformed ())270 if (devExt->HostMouse && !vboxIsHostInformed ()) 234 271 { 235 272 VMMDevReqMouseStatus *req = NULL; … … 269 306 if (RT_SUCCESS(vboxRC)) 270 307 { 271 devExt->reqSC = req;308 InterlockedExchangePointer (&devExt->reqSC, req); 272 309 dumpDevExt (devExt); 273 310 } … … 297 334 298 335 dprintf(("VBoxMouse::AddDevice Driver %p, PDO %p\n", Driver, PDO)); 336 337 #ifdef LOG_ENABLED 338 WCHAR wszProperty[512]; 339 ULONG ResultLength = 0; 340 wszProperty[0] = 0; 341 status = IoGetDeviceProperty(PDO, DevicePropertyDeviceDescription, 342 sizeof (wszProperty), 343 &wszProperty, 344 &ResultLength); 345 if (status == STATUS_SUCCESS) 346 { 347 dprintf(("VBoxMouse::AddDevice %ls Len is %d\n", wszProperty, ResultLength)); 348 } 349 #endif /* LOG_ENABLED */ 299 350 300 351 status = IoCreateDevice(Driver,
Note:
See TracChangeset
for help on using the changeset viewer.