Changeset 78179 in vbox for trunk/src/VBox/HostServices/SharedClipboard
- Timestamp:
- Apr 17, 2019 7:06:26 PM (6 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedClipboard
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp
r78160 r78179 61 61 * @param pCtx The context. 62 62 */ 63 static int vboxClipboardChanged 63 static int vboxClipboardChanged(VBOXCLIPBOARDCONTEXT *pCtx) 64 64 { 65 65 if (pCtx->pClient == NULL) … … 69 69 bool fChanged = false; 70 70 /* Retrieve the formats currently in the clipboard and supported by vbox */ 71 int rc = queryNewPasteboardFormats 72 if (RT_SUCCESS 73 { 74 vboxSvcClipboardReportMsg 75 Log 71 int rc = queryNewPasteboardFormats(pCtx->pasteboard, &fFormats, &fChanged); 72 if (RT_SUCCESS(rc) && fChanged) 73 { 74 vboxSvcClipboardReportMsg(pCtx->pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, fFormats); 75 Log(("vboxClipboardChanged fFormats %02X\n", fFormats)); 76 76 } 77 77 … … 90 90 * 91 91 */ 92 static int vboxClipboardThread 93 { 94 Log 95 96 AssertPtrReturn 97 VBOXCLIPBOARDCONTEXT *pCtx = (VBOXCLIPBOARDCONTEXT *) 92 static int vboxClipboardThread(RTTHREAD ThreadSelf, void *pvUser) 93 { 94 Log(("vboxClipboardThread: starting clipboard thread\n")); 95 96 AssertPtrReturn(pvUser, VERR_INVALID_PARAMETER); 97 VBOXCLIPBOARDCONTEXT *pCtx = (VBOXCLIPBOARDCONTEXT *)pvUser; 98 98 99 99 while (!pCtx->fTerminate) … … 102 102 thread safe and in any case we're calling several methods. */ 103 103 VBoxSvcClipboardLock(); 104 vboxClipboardChanged 104 vboxClipboardChanged(pCtx); 105 105 VBoxSvcClipboardUnlock(); 106 106 107 107 /* Sleep for 200 msecs before next poll */ 108 RTThreadUserWait 109 } 110 111 Log 108 RTThreadUserWait(ThreadSelf, 200); 109 } 110 111 Log(("vboxClipboardThread: clipboard thread terminated successfully with return code %Rrc\n", VINF_SUCCESS)); 112 112 return VINF_SUCCESS; 113 113 } … … 118 118 119 119 /** Initialise the host side of the shared clipboard - called by the hgcm layer. */ 120 int vboxClipboardInit 121 { 122 Log 120 int vboxClipboardInit(void) 121 { 122 Log(("vboxClipboardInit\n")); 123 123 124 124 g_ctx.fTerminate = false; 125 125 126 int rc = initPasteboard 127 AssertRCReturn 128 129 rc = RTThreadCreate 130 131 if (RT_FAILURE 126 int rc = initPasteboard(&g_ctx.pasteboard); 127 AssertRCReturn(rc, rc); 128 129 rc = RTThreadCreate(&g_ctx.thread, vboxClipboardThread, &g_ctx, 0, 130 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 131 if (RT_FAILURE(rc)) 132 132 { 133 133 g_ctx.thread = NIL_RTTHREAD; 134 destroyPasteboard 134 destroyPasteboard(&g_ctx.pasteboard); 135 135 } 136 136 … … 139 139 140 140 /** Terminate the host side of the shared clipboard - called by the hgcm layer. */ 141 void vboxClipboardDestroy 142 { 143 Log 141 void vboxClipboardDestroy(void) 142 { 143 Log(("vboxClipboardDestroy\n")); 144 144 145 145 /* 146 146 * Signal the termination of the polling thread and wait for it to respond. 147 147 */ 148 ASMAtomicWriteBool 149 int rc = RTThreadUserSignal 150 AssertRC 151 rc = RTThreadWait 152 AssertRC 148 ASMAtomicWriteBool(&g_ctx.fTerminate, true); 149 int rc = RTThreadUserSignal(g_ctx.thread); 150 AssertRC(rc); 151 rc = RTThreadWait(g_ctx.thread, RT_INDEFINITE_WAIT, NULL); 152 AssertRC(rc); 153 153 154 154 /* 155 155 * Destroy the pasteboard and uninitialize the global context record. 156 156 */ 157 destroyPasteboard 157 destroyPasteboard(&g_ctx.pasteboard); 158 158 g_ctx.thread = NIL_RTTHREAD; 159 159 g_ctx.pClient = NULL; … … 167 167 * @returns RT status code 168 168 */ 169 int vboxClipboardConnect 169 int vboxClipboardConnect(VBOXCLIPBOARDCLIENTDATA *pClient, bool fHeadless) 170 170 { 171 171 NOREF(fHeadless); … … 182 182 183 183 /* Initially sync the host clipboard content with the client. */ 184 int rc = vboxClipboardSync 184 int rc = vboxClipboardSync(pClient); 185 185 186 186 VBoxSvcClipboardUnlock(); … … 192 192 * after a save and restore of the guest. 193 193 */ 194 int vboxClipboardSync 194 int vboxClipboardSync(VBOXCLIPBOARDCLIENTDATA *pClient) 195 195 { 196 196 /* Sync the host clipboard content with the client. */ 197 197 VBoxSvcClipboardLock(); 198 int rc = vboxClipboardChanged 198 int rc = vboxClipboardChanged(pClient->pCtx); 199 199 VBoxSvcClipboardUnlock(); 200 200 … … 205 205 * Shut down the shared clipboard subsystem and "disconnect" the guest. 206 206 */ 207 void vboxClipboardDisconnect 208 { 209 Log 207 void vboxClipboardDisconnect(VBOXCLIPBOARDCLIENTDATA *pClient) 208 { 209 Log(("vboxClipboardDisconnect\n")); 210 210 211 211 VBoxSvcClipboardLock(); … … 221 221 * @param u32Formats Clipboard formats the guest is offering 222 222 */ 223 void vboxClipboardFormatAnnounce 224 { 225 Log 223 void vboxClipboardFormatAnnounce(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats) 224 { 225 Log(("vboxClipboardFormatAnnounce u32Formats %02X\n", u32Formats)); 226 226 if (u32Formats == 0) 227 227 { … … 230 230 } 231 231 232 vboxSvcClipboardReportMsg (pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, 233 u32Formats); 232 vboxSvcClipboardReportMsg(pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, u32Formats); 234 233 } 235 234 … … 243 242 * @param pcbActual Where to write the actual size of the written data 244 243 */ 245 int vboxClipboardReadData 246 void *pv, uint32_t cb, uint32_t *pcbActual)244 int vboxClipboardReadData(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, 245 void *pv, uint32_t cb, uint32_t *pcbActual) 247 246 { 248 247 VBoxSvcClipboardLock(); … … 250 249 /* Default to no data available. */ 251 250 *pcbActual = 0; 252 int rc = readFromPasteboard 251 int rc = readFromPasteboard(pClient->pCtx->pasteboard, u32Format, pv, cb, pcbActual); 253 252 254 253 VBoxSvcClipboardUnlock(); … … 264 263 * @param u32Format The format of the data written 265 264 */ 266 void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, 267 uint32_t cb, uint32_t u32Format) 268 { 269 VBoxSvcClipboardLock(); 270 271 writeToPasteboard (pClient->pCtx->pasteboard, pv, cb, u32Format); 272 273 VBoxSvcClipboardUnlock(); 274 } 265 void vboxClipboardWriteData(VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format) 266 { 267 VBoxSvcClipboardLock(); 268 269 writeToPasteboard(pClient->pCtx->pasteboard, pv, cb, u32Format); 270 271 VBoxSvcClipboardUnlock(); 272 } -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11-stubs.cpp
r78160 r78179 40 40 41 41 /** Initialise the host side of the shared clipboard - called by the hgcm layer. */ 42 int vboxClipboardInit 42 int vboxClipboardInit(void) 43 43 { 44 44 LogFlowFunc(("called, returning VINF_SUCCESS.\n")); … … 47 47 48 48 /** Terminate the host side of the shared clipboard - called by the hgcm layer. */ 49 void vboxClipboardDestroy 49 void vboxClipboardDestroy(void) 50 50 { 51 51 LogFlowFunc(("called, returning.\n")); … … 59 59 * @returns RT status code 60 60 */ 61 int vboxClipboardConnect (VBOXCLIPBOARDCLIENTDATA *pClient, 62 bool fHeadless) 61 int vboxClipboardConnect(VBOXCLIPBOARDCLIENTDATA *pClient, bool fHeadless) 63 62 { 64 63 RT_NOREF(pClient, fHeadless); … … 71 70 * after a save and restore of the guest. 72 71 */ 73 int vboxClipboardSync 72 int vboxClipboardSync(VBOXCLIPBOARDCLIENTDATA * /* pClient */) 74 73 { 75 74 LogFlowFunc(("called, returning VINF_SUCCESS.\n")); … … 82 81 * @param pClient Structure containing context information about the guest system 83 82 */ 84 void vboxClipboardDisconnect 83 void vboxClipboardDisconnect(VBOXCLIPBOARDCLIENTDATA *pClient) 85 84 { 86 85 RT_NOREF(pClient); … … 95 94 * @param u32Formats Clipboard formats the guest is offering 96 95 */ 97 void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA *pClient, 98 uint32_t u32Formats) 96 void vboxClipboardFormatAnnounce(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats) 99 97 { 100 98 RT_NOREF(pClient, u32Formats); … … 111 109 * @param pcbActual Where to write the actual size of the written data 112 110 */ 113 int vboxClipboardReadData 114 111 int vboxClipboardReadData(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, 112 void *pv, uint32_t cb, uint32_t *pcbActual) 115 113 { 116 114 RT_NOREF(pClient, u32Format, pv, cb); … … 129 127 * @param u32Format The format of the data written 130 128 */ 131 void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv,132 uint32_t cb,uint32_t u32Format)129 void vboxClipboardWriteData(VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, 130 uint32_t u32Format) 133 131 { 134 132 RT_NOREF(pClient, pv, cb, u32Format); … … 136 134 } 137 135 136 -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp
r78160 r78179 56 56 * the backend is responsible for ensuring that this does not happen. */ 57 57 VBOXCLIPBOARDREQFROMVBOX *pReq; 58 59 58 /** Pointer to the opaque X11 backend structure */ 60 59 CLIPBACKEND *pBackend; … … 74 73 * @note Host glue code 75 74 */ 76 void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, 77 uint32_t u32Formats) 75 void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats) 78 76 { 79 77 LogRelFlowFunc(("called. pCtx=%p, u32Formats=%02X\n", pCtx, u32Formats)); … … 87 85 * @note Host glue code 88 86 */ 89 int vboxClipboardInit 87 int vboxClipboardInit(void) 90 88 { 91 89 return VINF_SUCCESS; … … 96 94 * @note host glue code 97 95 */ 98 void vboxClipboardDestroy 96 void vboxClipboardDestroy(void) 99 97 { 100 98 … … 107 105 * the clipboard and leave ownership to X11. 108 106 */ 109 int vboxClipboardConnect 107 int vboxClipboardConnect(VBOXCLIPBOARDCLIENTDATA *pClient, bool fHeadless) 110 108 { 111 109 int rc = VINF_SUCCESS; … … 113 111 114 112 LogRel(("Starting host clipboard service\n")); 115 VBOXCLIPBOARDCONTEXT *pCtx = 116 (VBOXCLIPBOARDCONTEXT *) RTMemAllocZ(sizeof(VBOXCLIPBOARDCONTEXT)); 113 VBOXCLIPBOARDCONTEXT *pCtx = (VBOXCLIPBOARDCONTEXT *)RTMemAllocZ(sizeof(VBOXCLIPBOARDCONTEXT)); 117 114 if (!pCtx) 118 115 rc = VERR_NO_MEMORY; … … 147 144 * @note Host glue code 148 145 */ 149 int vboxClipboardSync 146 int vboxClipboardSync(VBOXCLIPBOARDCLIENTDATA *pClient) 150 147 { 151 148 /* Tell the guest we have no data in case X11 is not available. If 152 149 * there is data in the host clipboard it will automatically be sent to 153 150 * the guest when the clipboard starts up. */ 154 vboxSvcClipboardReportMsg (pClient,155 VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 0);151 vboxSvcClipboardReportMsg(pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 0); 152 /** @todo r=andy Check rc code. */ 156 153 return VINF_SUCCESS; 157 154 } … … 161 158 * @note Host glue code 162 159 */ 163 void vboxClipboardDisconnect 160 void vboxClipboardDisconnect(VBOXCLIPBOARDCLIENTDATA *pClient) 164 161 { 165 162 LogRelFlow(("vboxClipboardDisconnect\n")); … … 192 189 * @note Host glue code 193 190 */ 194 void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA *pClient, 195 uint32_t u32Formats) 196 { 197 LogRelFlowFunc(("called. pClient=%p, u32Formats=%02X\n", pClient, 198 u32Formats)); 199 ClipAnnounceFormatToX11 (pClient->pCtx->pBackend, u32Formats); 191 void vboxClipboardFormatAnnounce(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats) 192 { 193 LogRelFlowFunc(("called. pClient=%p, u32Formats=%02X\n", pClient, u32Formats)); 194 195 ClipAnnounceFormatToX11(pClient->pCtx->pBackend, u32Formats); 200 196 } 201 197 … … 229 225 * 230 226 */ 231 int vboxClipboardReadData 232 233 227 int vboxClipboardReadData(VBOXCLIPBOARDCLIENTDATA *pClient, 228 uint32_t u32Format, void *pv, uint32_t cb, 229 uint32_t *pcbActual) 234 230 { 235 231 LogRelFlowFunc(("pClient=%p, u32Format=%02X, pv=%p, cb=%u, pcbActual=%p", 236 pClient, u32Format, pv, cb, pcbActual));232 pClient, u32Format, pv, cb, pcbActual)); 237 233 238 234 int rc = VINF_SUCCESS; 239 CLIPREADCBREQ *pReq = (CLIPREADCBREQ *) 235 CLIPREADCBREQ *pReq = (CLIPREADCBREQ *)RTMemAlloc(sizeof(CLIPREADCBREQ)); 240 236 if (!pReq) 241 237 rc = VERR_NO_MEMORY; … … 270 266 if (cb <= pReq->cb && cb != 0) 271 267 memcpy(pReq->pv, pv, cb); 268 272 269 RTMemFree(pReq); 270 273 271 vboxSvcClipboardCompleteReadData(pCtx->pClient, rc, cb); 274 272 } … … 293 291 { 294 292 int rc = VINF_SUCCESS; 293 295 294 LogRelFlowFunc(("pCtx=%p, pReq=%p, u32Format=%02X\n", pCtx, pReq, u32Format)); 295 296 296 /* Request data from VBox */ 297 297 vboxSvcClipboardReportMsg(pCtx->pClient, … … 321 321 /** Post a request for clipboard data to VBox/the guest and wait for it to be 322 322 * completed. */ 323 static int clipRequestDataFromVBox(VBOXCLIPBOARDCONTEXT *pCtx, 324 VBOXCLIPBOARDREQFROMVBOX *pReq, 325 uint32_t u32Format) 323 static int clipRequestDataFromVBox(VBOXCLIPBOARDCONTEXT *pCtx, VBOXCLIPBOARDREQFROMVBOX *pReq, uint32_t u32Format) 326 324 { 327 325 int rc = VINF_SUCCESS; 328 LogRelFlowFunc(("pCtx=%p, pReq=%p, u32Format=%02X\n", pCtx, pReq, 329 u32Format)); 326 327 LogRelFlowFunc(("pCtx=%p, pReq=%p, u32Format=%02X\n", pCtx, pReq, u32Format)); 328 330 329 /* Start by "posting" the request for the next invocation of 331 330 * vboxClipboardWriteData. */ … … 358 357 * @note Host glue code. 359 358 */ 360 int ClipRequestDataForX11 (VBOXCLIPBOARDCONTEXT *pCtx, 361 uint32_t u32Format, void **ppv, 362 uint32_t *pcb) 359 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb) 363 360 { 364 361 VBOXCLIPBOARDREQFROMVBOX request = { NULL, 0, 0, NIL_RTSEMEVENT }; 365 362 366 LogRelFlowFunc(("pCtx=%p, u32Format=%02X, ppv=%p, pcb=%p\n", pCtx, 367 u32Format, ppv, pcb)); 363 LogRelFlowFunc(("pCtx=%p, u32Format=%02X, ppv=%p, pcb=%p\n", pCtx, u32Format, ppv, pcb)); 364 368 365 if (pCtx->fShuttingDown) 369 366 { … … 378 375 RTSemEventDestroy(request.finished); 379 376 } 377 380 378 if (RT_SUCCESS(rc)) 381 379 { … … 383 381 *pcb = request.cb; 384 382 } 383 385 384 LogRelFlowFunc(("returning %Rrc\n", rc)); 385 386 386 if (RT_SUCCESS(rc)) 387 LogRelFlowFunc(("*ppv=%.*ls, *pcb=%u\n", *pcb / 2, *ppv, *pcb)); 387 LogRelFlowFunc(("*ppv=%.*ls, *pcb=%u\n",*pcb / 2,*ppv,*pcb)); 388 388 389 return rc; 389 390 } … … 398 399 * @note Host glue code 399 400 */ 400 void vboxClipboardWriteData 401 402 { 403 LogRelFlowFunc 404 pClient, pv, cb / 2, pv, cb, u32Format));401 void vboxClipboardWriteData(VBOXCLIPBOARDCLIENTDATA *pClient, 402 void *pv, uint32_t cb, uint32_t u32Format) 403 { 404 LogRelFlowFunc(("called. pClient=%p, pv=%p (%.*ls), cb=%u, u32Format=%02X\n", 405 pClient, pv, cb / 2, pv, cb, u32Format)); 405 406 406 407 VBOXCLIPBOARDCONTEXT *pCtx = pClient->pCtx; 407 /* Grab the mutex and check whether there is a pending request for data. 408 */408 409 /* Grab the mutex and check whether there is a pending request for data. */ 409 410 RTCritSectEnter(&pCtx->clipboardMutex); 411 410 412 VBOXCLIPBOARDREQFROMVBOX *pReq = pCtx->pReq; 411 413 if (pReq != NULL) … … 424 426 pCtx->pReq = NULL; 425 427 } 428 426 429 RTCritSectLeave(&pCtx->clipboardMutex); 427 430 } 428 431 429 432 #ifdef TESTCASE 430 # include <iprt/initterm.h>431 # include <iprt/stream.h>432 433 # define TEST_NAME "tstClipboardX11-2"433 # include <iprt/initterm.h> 434 # include <iprt/stream.h> 435 436 # define TEST_NAME "tstClipboardX11-2" 434 437 435 438 struct _CLIPBACKEND … … 460 463 }; 461 464 462 void vboxSvcClipboardReportMsg 463 { 464 RT_NOREF 1(u32Formats);465 void vboxSvcClipboardReportMsg(VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Msg, uint32_t u32Formats) 466 { 467 RT_NOREF(u32Formats); 465 468 CLIPBACKEND *pBackend = pClient->pCtx->pBackend; 466 if ( (u32Msg == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA) 469 470 if ((u32Msg == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA) 467 471 && !pBackend->writeData.timeout) 468 472 vboxClipboardWriteData(pClient, pBackend->writeData.pv, … … 480 484 } 481 485 482 CLIPBACKEND *ClipConstructX11(VBOXCLIPBOARDCONTEXT *pFrontend, bool)483 { 484 RT_NOREF 1(pFrontend);486 CLIPBACKEND* ClipConstructX11(VBOXCLIPBOARDCONTEXT *pFrontend, bool) 487 { 488 RT_NOREF(pFrontend); 485 489 return (CLIPBACKEND *)RTMemAllocZ(sizeof(CLIPBACKEND)); 486 490 } … … 492 496 493 497 int ClipStartX11(CLIPBACKEND *pBackend, bool) 498 { 499 RT_NOREF(pBackend); 500 return VINF_SUCCESS; 501 } 502 503 int ClipStopX11(CLIPBACKEND *pBackend) 494 504 { 495 505 RT_NOREF1(pBackend); … … 497 507 } 498 508 499 int ClipStopX11(CLIPBACKEND *pBackend) 500 { 501 RT_NOREF1(pBackend); 502 return VINF_SUCCESS; 503 } 504 505 void ClipAnnounceFormatToX11(CLIPBACKEND *pBackend, 506 uint32_t u32Formats) 509 void ClipAnnounceFormatToX11(CLIPBACKEND *pBackend, uint32_t u32Formats) 507 510 { 508 511 pBackend->formats = u32Formats; … … 547 550 else 548 551 { 549 if ( pBackend->readData.format != 550 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT 552 if ( pBackend->readData.format != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT 551 553 || pBackend->readData.pReq->pv != &u32Dummy 552 554 || pBackend->readData.pReq->cb != 42 … … 614 616 } 615 617 #endif /* TESTCASE */ 618
Note:
See TracChangeset
for help on using the changeset viewer.