Changeset 47211 in vbox for trunk/src/VBox
- Timestamp:
- Jul 17, 2013 12:33:23 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp
r47195 r47211 31 31 #include <iprt/mem.h> 32 32 #include <VBoxGuestInternal.h> 33 34 35 33 36 34 … … 73 71 } VBOXIPCSESSION, *PVBOXIPCSESSION; 74 72 75 int vboxIPCSessionDestroyLocked(PVBOXIPCCONTEXT pCtx, PVBOXIPCSESSION pSession); 73 int vboxIPCSessionDestroyLocked(PVBOXIPCSESSION pSession); 74 75 static int vboxIPCHandleVBoxTrayRestart(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr) 76 { 77 AssertPtrReturn(pHdr, VERR_INVALID_POINTER); 78 79 /** @todo Not implemented yet; don't return an error here. */ 80 return VINF_SUCCESS; 81 } 82 83 static int vboxIPCHandleShowBalloonMsg(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr) 84 { 85 AssertPtrReturn(pHdr, VERR_INVALID_POINTER); 86 AssertReturn(pHdr->uMsgLen > 0, VERR_INVALID_PARAMETER); 87 88 VBOXTRAYIPCMSG_SHOWBALLOONMSG ipcMsg; 89 int rc = RTLocalIpcSessionRead(hSession, &ipcMsg, pHdr->uMsgLen, 90 NULL /* Exact read, blocking */); 91 if (RT_SUCCESS(rc)) 92 { 93 /* Showing the balloon tooltip is not critical. */ 94 int rc2 = hlpShowBalloonTip(ghInstance, ghwndToolWindow, ID_TRAYICON, 95 ipcMsg.szMsgContent, ipcMsg.szMsgTitle, 96 ipcMsg.uShowMS, ipcMsg.uType); 97 LogFlowFunc(("Showing \"%s\" - \"%s\" (type %RU32, %RU32ms), rc=%Rrc\n", 98 ipcMsg.szMsgTitle, ipcMsg.szMsgContent, 99 ipcMsg.uType, ipcMsg.uShowMS, rc2)); 100 } 101 102 return rc; 103 } 104 105 static int vboxIPCHandleUserLastInput(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr) 106 { 107 AssertPtrReturn(pHdr, VERR_INVALID_POINTER); 108 /* No actual message from client. */ 109 110 int rc = VINF_SUCCESS; 111 112 LASTINPUTINFO lastInput; 113 lastInput.cbSize = sizeof(LASTINPUTINFO); 114 BOOL fRc = GetLastInputInfo(&lastInput); 115 if (fRc) 116 { 117 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 118 ipcRes.uTickCount = lastInput.dwTime; /** @sa GetTickCount(). */ 119 rc = RTLocalIpcSessionWrite(hSession, &ipcRes, sizeof(ipcRes)); 120 } 121 else 122 rc = RTErrConvertFromWin32(GetLastError()); 123 124 return rc; 125 } 76 126 77 127 /** … … 99 149 if (RT_SUCCESS(rc)) 100 150 { 101 rc = RTLocalIpcServerCreate(&gCtx.hServer, "VBoxTrayIPCSvc", RTLOCALIPC_FLAGS_MULTI_SESSION); 151 rc = RTLocalIpcServerCreate(&gCtx.hServer, VBOXTRAY_IPC_PIPENAME, 152 RTLOCALIPC_FLAGS_MULTI_SESSION); 102 153 if (RT_FAILURE(rc)) 103 154 { … … 116 167 void VBoxIPCStop(const VBOXSERVICEENV *pEnv, void *pInstance) 117 168 { 118 AssertPtr (pEnv);119 AssertPtr (pInstance);169 AssertPtrReturnVoid(pEnv); 170 AssertPtrReturnVoid(pInstance); 120 171 121 172 LogFunc(("Stopping pInstance=%p\n", pInstance)); … … 148 199 RTListForEach(&pCtx->SessionList, pSession, VBOXIPCSESSION, Node) 149 200 { 150 int rc2 = vboxIPCSessionDestroyLocked(p Ctx, pSession);201 int rc2 = vboxIPCSessionDestroyLocked(pSession); 151 202 if (RT_FAILURE(rc2)) 152 203 { … … 186 237 LogFunc(("pThis=%p\n", pThis)); 187 238 239 int rc = VINF_SUCCESS; 240 188 241 /* 189 242 * Process client requests until it quits or we're cancelled on termination. 190 243 */ 191 while (!ASMAtomicUoReadBool(&pThis->fTerminate)) 192 { 193 int rc = RTLocalIpcSessionWaitForData(hSession, 1000 /* Timeout in ms. */); 244 while ( !ASMAtomicUoReadBool(&pThis->fTerminate) 245 && RT_SUCCESS(rc)) 246 { 247 /* The next call will be cancelled via VBoxIPCStop if needed. */ 248 rc = RTLocalIpcSessionWaitForData(hSession, RT_INDEFINITE_WAIT); 194 249 if (RT_FAILURE(rc)) 195 250 { 196 251 if (rc == VERR_CANCELLED) 197 252 { 198 LogFunc((" Waiting for data cancelled\n"));253 LogFunc(("Session %p: Waiting for data cancelled\n", pThis)); 199 254 rc = VINF_SUCCESS; 200 255 break; 201 256 } 202 else if (rc != VERR_TIMEOUT) 203 { 204 LogFunc(("Waiting for data failed, rc=%Rrc\n", rc)); 205 break; 206 } 207 } 208 209 /** @todo Implement handler. */ 210 } 257 else 258 LogRelFunc(("Session %p: Waiting for session data failed with rc=%Rrc\n", 259 pThis, rc)); 260 } 261 else 262 { 263 VBOXTRAYIPCHEADER ipcHdr; 264 rc = RTLocalIpcSessionRead(hSession, &ipcHdr, sizeof(ipcHdr), 265 NULL /* Exact read, blocking */); 266 if (RT_SUCCESS(rc)) 267 { 268 switch (ipcHdr.uMsgType) 269 { 270 case VBOXTRAYIPCMSGTYPE_RESTART: 271 rc = vboxIPCHandleVBoxTrayRestart(hSession, &ipcHdr); 272 break; 273 274 case VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG: 275 rc = vboxIPCHandleShowBalloonMsg(hSession, &ipcHdr); 276 break; 277 278 case VBOXTRAYIPCMSGTYPE_USERLASTINPUT: 279 rc = vboxIPCHandleUserLastInput(hSession, &ipcHdr); 280 break; 281 282 default: 283 { 284 static int s_cRejectedCmds = 0; 285 if (++s_cRejectedCmds <= 3) 286 { 287 LogRelFunc(("Session %p: Received unknown command %RU32 (%RU32 bytes), rejecting (%RU32/3)\n", 288 pThis, ipcHdr.uMsgType, ipcHdr.uMsgLen, s_cRejectedCmds + 1)); 289 if (ipcHdr.uMsgLen) 290 { 291 /* Get and discard payload data. */ 292 size_t cbRead; 293 uint8_t devNull[_1K]; 294 while (ipcHdr.uMsgLen) 295 { 296 rc = RTLocalIpcSessionRead(hSession, &devNull, sizeof(devNull), &cbRead); 297 if (RT_FAILURE(rc)) 298 break; 299 AssertRelease(cbRead <= ipcHdr.uMsgLen); 300 ipcHdr.uMsgLen -= (uint32_t)cbRead; 301 } 302 } 303 } 304 else 305 rc = VERR_INVALID_PARAMETER; /* Enough fun, bail out. */ 306 break; 307 } 308 309 if (RT_FAILURE(rc)) 310 LogFunc(("Session %p: Handling command %RU32 failed with rc=%Rrc\n", 311 pThis, ipcHdr.uMsgType, rc)); 312 } 313 } 314 } 315 } 316 317 LogRelFunc(("Session %p: Handler ended with rc=%Rrc\n", rc)); 211 318 212 319 /* … … 214 321 */ 215 322 PVBOXIPCCONTEXT pCtx = ASMAtomicReadPtrT(&pThis->pCtx, PVBOXIPCCONTEXT); 216 if (pCtx) 217 RTCritSectEnter(&pCtx->CritSect); 218 else 219 AssertMsgFailed(("Session %p: No context found\n", pThis)); 220 221 ASMAtomicXchgHandle(&pThis->hSession, NIL_RTLOCALIPCSESSION, &hSession); 222 if (hSession != NIL_RTLOCALIPCSESSION) 223 RTLocalIpcSessionClose(hSession); 224 else 225 AssertMsgFailed(("Session %p: No/invalid session handle\n", pThis)); 226 227 if (pCtx) 228 { 229 //RTSemEventSignal(pCtx->hSessionEvent); 230 RTCritSectLeave(&pCtx->CritSect); 231 } 232 233 LogFunc(("pThis=%p terminated\n", pThis)); 234 return VINF_SUCCESS; 323 AssertMsg(pCtx, ("Session %p: No context found\n", pThis)); 324 rc = RTCritSectEnter(&pCtx->CritSect); 325 if (RT_SUCCESS(rc)) 326 { 327 rc = vboxIPCSessionDestroyLocked(pThis); 328 329 int rc2 = RTCritSectLeave(&pCtx->CritSect); 330 if (RT_SUCCESS(rc)) 331 rc = rc2; 332 } 333 334 LogFunc(("Session %p: Terminated\n", pThis)); 335 return rc; 235 336 } 236 337 … … 280 381 } 281 382 282 static int vboxIPCSessionDestroyLocked(PVBOXIPCCONTEXT pCtx, PVBOXIPCSESSION pSession) 283 { 284 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 383 static int vboxIPCSessionDestroyLocked(PVBOXIPCSESSION pSession) 384 { 285 385 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 286 287 386 pSession->hThread = NIL_RTTHREAD; 288 387 289 388 RTLOCALIPCSESSION hSession; 290 389 ASMAtomicXchgHandle(&pSession->hSession, NIL_RTLOCALIPCSESSION, &hSession); 291 if (hSession != NIL_RTLOCALIPCSESSION) 292 RTLocalIpcSessionClose(hSession); 390 int rc = RTLocalIpcSessionClose(hSession); 293 391 294 392 RTListNodeRemove(&pSession->Node); … … 297 395 pSession = NULL; 298 396 299 return VINF_SUCCESS;397 return rc; 300 398 } 301 399
Note:
See TracChangeset
for help on using the changeset viewer.