Changeset 79120 in vbox for trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider-HostService.cpp
- Timestamp:
- Jun 13, 2019 10:08:33 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider-HostService.cpp
r79088 r79120 27 27 #include <iprt/dir.h> 28 28 #include <iprt/errcore.h> 29 #include <iprt/semaphore.h> 29 30 #include <iprt/file.h> 30 31 #include <iprt/path.h> … … 34 35 35 36 37 38 SharedClipboardProviderHostService::Event::Event(uint32_t uMsg) 39 : mMsg(uMsg) 40 , mpvData(NULL) 41 , mcbData(0) 42 { 43 int rc2 = RTSemEventCreate(&mEvent); 44 AssertRC(rc2); 45 } 46 47 SharedClipboardProviderHostService::Event::~Event() 48 { 49 if (mpvData) 50 { 51 Assert(mcbData); 52 53 RTMemFree(mpvData); 54 mpvData = NULL; 55 } 56 57 int rc2 = RTSemEventDestroy(mEvent); 58 AssertRC(rc2); 59 } 60 61 /** 62 * Sets user data associated to an event. 63 * 64 * @returns VBox status code. 65 * @param pvData Pointer to user data to set. 66 * @param cbData Size (in bytes) of user data to set. 67 */ 68 int SharedClipboardProviderHostService::Event::SetData(const void *pvData, uint32_t cbData) 69 { 70 Assert(mpvData == NULL); 71 Assert(mcbData == 0); 72 73 if (!cbData) 74 return VINF_SUCCESS; 75 76 mpvData = RTMemDup(pvData, cbData); 77 if (!mpvData) 78 return VERR_NO_MEMORY; 79 80 mcbData = cbData; 81 82 return VINF_SUCCESS; 83 } 84 85 /** 86 * Waits for an event to get signalled. 87 * Will return VERR_NOT_FOUND if no event has been found. 88 * 89 * @returns VBox status code. 90 * @param uTimeoutMs Timeout (in ms) to wait. 91 */ 92 int SharedClipboardProviderHostService::Event::Wait(RTMSINTERVAL uTimeoutMs) 93 { 94 LogFlowFuncEnter(); 95 96 int rc = RTSemEventWait(mEvent, uTimeoutMs); 97 98 LogFlowFuncLeaveRC(rc); 99 return rc; 100 } 101 102 void *SharedClipboardProviderHostService::Event::DataRaw() 103 { 104 return mpvData; 105 } 106 107 uint32_t SharedClipboardProviderHostService::Event::DataSize() 108 { 109 return mcbData; 110 } 111 36 112 SharedClipboardProviderHostService::SharedClipboardProviderHostService(void) 113 : m_uTimeoutMs(30 * 1000 /* 30s timeout by default */) 37 114 { 38 115 LogFlowFuncEnter(); … … 41 118 SharedClipboardProviderHostService::~SharedClipboardProviderHostService(void) 42 119 { 120 Reset(); 43 121 } 44 122 45 123 int SharedClipboardProviderHostService::ReadDataHdr(PVBOXCLIPBOARDDATAHDR pDataHdr) 124 { 125 int rc; 126 127 Event *pEvent = eventGet(VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_DATA_HDR); 128 if (pEvent) 129 { 130 rc = pEvent->Wait(m_uTimeoutMs); 131 if (RT_SUCCESS(rc)) 132 memcpy(pDataHdr, pEvent->DataRaw(), pEvent->DataSize()); 133 } 134 else 135 rc = VERR_NOT_FOUND; 136 137 LogFlowFuncLeaveRC(rc); 138 return rc; 139 } 140 141 int SharedClipboardProviderHostService::WriteDataHdr(const PVBOXCLIPBOARDDATAHDR pDataHdr) 46 142 { 47 143 RT_NOREF(pDataHdr); … … 49 145 } 50 146 51 int SharedClipboardProviderHostService::WriteDataHdr(const PVBOXCLIPBOARDDATAHDR pDataHdr) 52 { 53 RT_NOREF(pDataHdr); 147 int SharedClipboardProviderHostService::ReaaDataChunk(const PVBOXCLIPBOARDDATAHDR pDataHdr, void *pvChunk, uint32_t cbChunk, 148 uint32_t *pcbRead, uint32_t fFlags /* = 0 */) 149 { 150 RT_NOREF(pDataHdr, pvChunk, cbChunk, pcbRead, fFlags); 54 151 return VERR_NOT_IMPLEMENTED; 55 152 } 56 153 57 int SharedClipboardProviderHostService::ReadMetaData(const PVBOXCLIPBOARDDATAHDR pDataHdr, void *pvMeta, uint32_t cbMeta, 58 uint32_t *pcbRead, uint32_t fFlags /* = 0 */) 59 { 60 RT_NOREF(pDataHdr, pvMeta, cbMeta, pcbRead, fFlags); 61 return VERR_NOT_IMPLEMENTED; 62 } 63 64 int SharedClipboardProviderHostService::WriteMetaData(const PVBOXCLIPBOARDDATAHDR pDataHdr, const void *pvMeta, uint32_t cbMeta, 65 uint32_t *pcbWritten, uint32_t fFlags /* = 0 */) 154 int SharedClipboardProviderHostService::WriteDataChunk(const PVBOXCLIPBOARDDATAHDR pDataHdr, const void *pvMeta, uint32_t cbMeta, 155 uint32_t *pcbWritten, uint32_t fFlags /* = 0 */) 66 156 { 67 157 RT_NOREF(pDataHdr, pvMeta, cbMeta, pcbWritten, fFlags); … … 143 233 void SharedClipboardProviderHostService::Reset(void) 144 234 { 145 } 146 235 LogFlowFuncEnter(); 236 237 EventMap::const_iterator itEvent = m_mapEvents.begin(); 238 while (itEvent != m_mapEvents.end()) 239 { 240 delete itEvent->second; 241 m_mapEvents.erase(itEvent); 242 243 itEvent = m_mapEvents.begin(); 244 } 245 246 int rc2 = eventRegister(VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_DATA_HDR); 247 AssertRC(rc2); 248 } 249 250 int SharedClipboardProviderHostService::OnRead(PSHAREDCLIPBOARDPROVIDERREADPARMS pParms) 251 { 252 RT_NOREF(pParms); 253 254 LogFlowFuncEnter(); 255 256 int rc = VERR_NOT_IMPLEMENTED; 257 258 LogFlowFuncLeaveRC(rc); 259 return rc; 260 } 261 262 int SharedClipboardProviderHostService::OnWrite(PSHAREDCLIPBOARDPROVIDERWRITEPARMS pParms) 263 { 264 LogFlowFuncEnter(); 265 266 int rc = VINF_SUCCESS; 267 268 switch (pParms->u.HostService.uMsg) 269 { 270 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_DATA_HDR: 271 { 272 VBOXCLIPBOARDDATAHDR dataHdr; 273 rc = VBoxSvcClipboardURIReadDataHdr(pParms->u.HostService.cParms, pParms->u.HostService.paParms, 274 &dataHdr); 275 if (RT_SUCCESS(rc)) 276 { 277 Event *pEvent = eventGet(pParms->u.HostService.uMsg); 278 if (pEvent) 279 { 280 rc = pEvent->SetData(&dataHdr, sizeof(dataHdr)); 281 } 282 } 283 break; 284 } 285 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_DATA_CHUNK: 286 { 287 break; 288 } 289 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_DIR: 290 RT_FALL_THROUGH(); 291 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_FILE_HDR: 292 RT_FALL_THROUGH(); 293 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_FILE_DATA: 294 RT_FALL_THROUGH(); 295 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_CANCEL: 296 RT_FALL_THROUGH(); 297 case VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_ERROR: 298 { 299 300 } 301 302 default: 303 rc = VERR_NOT_IMPLEMENTED; 304 break; 305 } 306 307 if (RT_SUCCESS(rc)) 308 { 309 rc = eventSignal(pParms->u.HostService.uMsg); 310 if (rc == VERR_NOT_FOUND) /* Having an event is optional, so don't fail here. */ 311 rc = VINF_SUCCESS; 312 } 313 314 LogFlowFuncLeaveRC(rc); 315 return rc; 316 } 317 318 /** 319 * Registers a new event. 320 * Will fail if an event with the same message ID already exists. 321 * 322 * @returns VBox status code. 323 * @param uMsg Message ID to register event for. 324 */ 325 int SharedClipboardProviderHostService::eventRegister(uint32_t uMsg) 326 { 327 LogFlowFuncEnter(); 328 329 int rc; 330 331 EventMap::const_iterator itEvent = m_mapEvents.find(uMsg); 332 if (itEvent == m_mapEvents.end()) 333 { 334 SharedClipboardProviderHostService::Event *pEvent = new SharedClipboardProviderHostService::Event(uMsg); 335 if (pEvent) /** @todo Can this throw? */ 336 { 337 rc = VINF_SUCCESS; 338 } 339 else 340 rc = VERR_NO_MEMORY; 341 } 342 else 343 rc = VERR_ALREADY_EXISTS; 344 345 LogFlowFuncLeaveRC(rc); 346 return rc; 347 } 348 349 /** 350 * Unregisters an existing event. 351 * Will return VERR_NOT_FOUND if no event has been found. 352 * 353 * @returns VBox status code. 354 * @param uMsg Message ID to unregister event for. 355 */ 356 int SharedClipboardProviderHostService::eventUnregister(uint32_t uMsg) 357 { 358 LogFlowFuncEnter(); 359 360 int rc; 361 362 EventMap::const_iterator itEvent = m_mapEvents.find(uMsg); 363 if (itEvent != m_mapEvents.end()) 364 { 365 delete itEvent->second; 366 m_mapEvents.erase(itEvent); 367 368 rc = VINF_SUCCESS; 369 } 370 else 371 rc = VERR_NOT_FOUND; 372 373 LogFlowFuncLeaveRC(rc); 374 return rc; 375 } 376 377 /** 378 * Signals an event. 379 * Will return VERR_NOT_FOUND if no event has been found. 380 * 381 * @returns VBox status code. 382 * @param uMsg Message ID of event to signal. 383 */ 384 int SharedClipboardProviderHostService::eventSignal(uint32_t uMsg) 385 { 386 LogFlowFuncEnter(); 387 388 int rc; 389 390 EventMap::const_iterator itEvent = m_mapEvents.find(uMsg); 391 if (itEvent != m_mapEvents.end()) 392 { 393 rc = RTSemEventSignal(itEvent->second->mEvent); 394 } 395 else 396 rc = VERR_NOT_FOUND; 397 398 LogFlowFuncLeaveRC(rc); 399 return rc; 400 } 401 402 /** 403 * Returns the event for a specific message ID. 404 * 405 * @returns Pointer to event if found, or NULL if no event has been found 406 * @param uMsg Messagae ID to return event for. 407 */ 408 SharedClipboardProviderHostService::Event *SharedClipboardProviderHostService::eventGet(uint32_t uMsg) 409 { 410 LogFlowFuncEnter(); 411 412 EventMap::const_iterator itEvent = m_mapEvents.find(uMsg); 413 if (itEvent != m_mapEvents.end()) 414 return itEvent->second; 415 416 return NULL; 417 } 418
Note:
See TracChangeset
for help on using the changeset viewer.