Changeset 100412 in vbox
- Timestamp:
- Jul 6, 2023 2:08:30 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/SharedClipboard-win.h
r100407 r100412 295 295 static int Thread(RTTHREAD hThread, void *pvUser); 296 296 297 inline int lock(void); 298 inline int unlock(void); 299 297 300 int readDir(PSHCLTRANSFER pTransfer, const Utf8Str &strPath); 298 301 … … 304 307 void registerFormat(LPFORMATETC pFormatEtc, CLIPFORMAT clipFormat, TYMED tyMed = TYMED_HGLOBAL, 305 308 LONG lindex = -1, DWORD dwAspect = DVASPECT_CONTENT, DVTARGETDEVICE *pTargetDevice = NULL); 309 int setTransferLocked(PSHCLTRANSFER pTransfer); 306 310 int setStatusLocked(Status enmStatus, int rc = VINF_SUCCESS); 307 311 -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
r100407 r100412 206 206 switch(ShClTransferGetDir(pCbCtx->pTransfer)) 207 207 { 208 case SHCLTRANSFERDIR_FROM_REMOTE: 209 { 210 AssertPtrBreak(pCtx->Win.pDataObjInFlight); 211 rc = pCtx->Win.pDataObjInFlight->SetTransfer(pCbCtx->pTransfer); 212 if (RT_SUCCESS(rc)) 213 rc = pCtx->Win.pDataObjInFlight->SetStatus(SharedClipboardWinDataObject::Running); 208 case SHCLTRANSFERDIR_TO_REMOTE: /* G->H */ 209 { 210 rc = SharedClipboardWinTransferGetRootsFromClipboard(&pCtx->Win, pCbCtx->pTransfer); 211 break; 212 } 213 214 case SHCLTRANSFERDIR_FROM_REMOTE: /* H->G */ 215 { 216 SharedClipboardWinDataObject *pObj = pCtx->Win.pDataObjInFlight; 217 if (pObj) 218 { 219 rc = pObj->SetTransfer(pCbCtx->pTransfer); 220 if (RT_SUCCESS(rc)) 221 rc = pObj->SetStatus(SharedClipboardWinDataObject::Running); 222 223 pCtx->Win.pDataObjInFlight = NULL; /* Hand off to Windows. */ 224 } 225 else 226 AssertMsgFailed(("No data object in flight!\n")); 227 214 228 break; 215 229 } -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp
r100407 r100412 188 188 AssertReturnVoid(m_lRefCount == 0); 189 189 190 /* Make sure to release the transfer. */ 191 setTransferLocked(NULL); 192 190 193 int rc = RTCritSectDelete(&m_CritSect); 191 194 AssertRC(rc); … … 310 313 GlobalFree(hGlobal); 311 314 return VERR_ACCESS_DENIED; 315 } 316 317 inline int SharedClipboardWinDataObject::lock(void) 318 { 319 int rc = RTCritSectEnter(&m_CritSect); 320 AssertRCReturn(rc, rc); 321 322 return rc; 323 } 324 325 inline int SharedClipboardWinDataObject::unlock(void) 326 { 327 int rc = RTCritSectLeave(&m_CritSect); 328 AssertRCReturn(rc, rc); 329 330 return rc; 312 331 } 313 332 … … 675 694 AssertPtrReturn(pMedium, DV_E_FORMATETC); 676 695 677 int rc2 = RTCritSectEnter(&m_CritSect); 678 AssertRCReturn(rc2, E_UNEXPECTED); 696 lock(); 679 697 680 698 LogFlowFunc(("lIndex=%RI32, enmStatus=%#x\n", pFormatEtc->lindex, m_enmStatus)); … … 702 720 703 721 /* Leave lock while requesting + waiting. */ 704 rc2 = RTCritSectLeave(&m_CritSect); 705 AssertRCBreak(rc); 722 unlock(); 706 723 707 724 /* Start the transfer. */ … … 715 732 * Windows Explorer unresponsive (i.e. "ghost window") when waiting for too long. */ 716 733 rc = RTSemEventWait(m_EventStatusChanged, RT_MS_10SEC); 717 AssertRCBreak(rc);718 734 719 735 /* Re-acquire lock. */ 720 rc = RTCritSectEnter(&m_CritSect); 721 AssertRCBreak(rc); 736 lock(); 737 738 if (RT_FAILURE(rc)) 739 { 740 LogRel(("Shared Clipboard: Waiting for IDataObject status status failed, rc=%Rrc\n", rc)); 741 break; 742 } 722 743 723 744 if (m_enmStatus != Running) … … 757 778 758 779 /* Leave lock while waiting. */ 759 rc = RTCritSectLeave(&m_CritSect); 760 AssertRCReturn(rc, E_UNEXPECTED); 780 unlock(); 761 781 762 782 /* Don't block for too long here, as this also will screw other apps running on the OS. */ … … 765 785 766 786 /* Re-acquire lock. */ 767 rc = RTCritSectEnter(&m_CritSect); 768 AssertRCReturn(rc, E_UNEXPECTED); 787 lock(); 769 788 } 770 789 } … … 847 866 } 848 867 849 rc2 = RTCritSectLeave(&m_CritSect); 850 AssertRCReturn(rc2, E_UNEXPECTED); 868 unlock(); 851 869 852 870 LogFlowFunc(("hr=%Rhrc\n", hr)); … … 1012 1030 1013 1031 /** 1014 * Assigns a transfer object for the data object .1032 * Assigns a transfer object for the data object, internal version. 1015 1033 * 1016 1034 * @returns VBox status code. 1017 1035 * @param pTransfer Transfer to assign. 1018 * Must be in started state. 1019 */ 1020 int SharedClipboardWinDataObject::SetTransfer(PSHCLTRANSFER pTransfer) 1021 { 1022 AssertReturn(m_pTransfer == NULL, VERR_WRONG_ORDER); /* Transfer already set? */ 1023 1024 int rc = RTCritSectEnter(&m_CritSect); 1025 if (RT_SUCCESS(rc)) 1026 { 1036 * Must be in INITIALIZED state. 1037 * When set to NULL, the transfer will be released from the object. 1038 */ 1039 int SharedClipboardWinDataObject::setTransferLocked(PSHCLTRANSFER pTransfer) 1040 { 1041 LogFlowFunc(("pTransfer=%p\n", pTransfer)); 1042 1043 int rc = VINF_SUCCESS; 1044 1045 if (pTransfer) /* Set */ 1046 { 1047 Assert(m_pTransfer == NULL); /* Transfer already set? */ 1048 1027 1049 if (m_enmStatus == Initialized) 1028 1050 { … … 1039 1061 else 1040 1062 AssertFailedStmt(rc = VERR_WRONG_ORDER); 1041 1042 RTCritSectLeave(&m_CritSect); 1043 } 1063 } 1064 else /* Unset */ 1065 { 1066 if (m_pTransfer) 1067 { 1068 ShClTransferRelease(m_pTransfer); 1069 m_pTransfer = NULL; 1070 } 1071 } 1072 1073 return rc; 1074 } 1075 1076 /** 1077 * Assigns a transfer object for the data object. 1078 * 1079 * @returns VBox status code. 1080 * @param pTransfer Transfer to assign. 1081 * Must be in INITIALIZED state. 1082 * When set to NULL, the transfer will be released from the object. 1083 */ 1084 int SharedClipboardWinDataObject::SetTransfer(PSHCLTRANSFER pTransfer) 1085 { 1086 lock(); 1087 1088 int rc = setTransferLocked(pTransfer); 1089 1090 unlock(); 1044 1091 1045 1092 return rc; … … 1057 1104 int SharedClipboardWinDataObject::SetStatus(Status enmStatus, int rcSts /* = VINF_SUCCESS */) 1058 1105 { 1059 int rc = RTCritSectEnter(&m_CritSect); 1060 if (RT_SUCCESS(rc)) 1061 { 1062 rc = setStatusLocked(enmStatus, rcSts); 1063 1064 RTCritSectLeave(&m_CritSect); 1065 } 1066 1106 lock(); 1107 1108 int rc = setStatusLocked(enmStatus, rcSts); 1109 1110 unlock(); 1067 1111 return rc; 1068 1112 } … … 1141 1185 RT_NOREF(rc); 1142 1186 1143 int rc2 = RTCritSectEnter(&m_CritSect); 1144 if (RT_SUCCESS(rc2)) 1145 { 1146 LogFlowFunc(("enmStatus=%#x (current is: %#x)\n", enmStatus, m_enmStatus)); 1147 1148 switch (enmStatus) 1149 { 1150 case Completed: 1151 { 1152 LogFlowFunc(("m_uObjIdx=%RU32 (total: %zu)\n", m_uObjIdx, m_lstEntries.size())); 1153 1154 const bool fComplete = m_uObjIdx == m_lstEntries.size() - 1 /* Object index is zero-based */; 1155 if (fComplete) 1156 m_enmStatus = Completed; 1157 break; 1158 } 1159 1160 default: 1161 { 1162 m_enmStatus = enmStatus; 1163 break; 1164 } 1165 } 1166 1167 if (RT_FAILURE(rc)) 1168 LogRel(("Shared Clipboard: Data object received error %Rrc (status %#x)\n", rc, enmStatus)); 1169 1170 if (m_EventStatusChanged != NIL_RTSEMEVENT) 1171 rc2 = RTSemEventSignal(m_EventStatusChanged); 1172 1173 RTCritSectLeave(&m_CritSect); 1174 } 1187 LogFlowFunc(("enmStatus=%#x (current is: %#x)\n", enmStatus, m_enmStatus)); 1188 1189 int rc2 = VINF_SUCCESS; 1190 1191 switch (enmStatus) 1192 { 1193 case Completed: 1194 { 1195 LogFlowFunc(("m_uObjIdx=%RU32 (total: %zu)\n", m_uObjIdx, m_lstEntries.size())); 1196 1197 const bool fComplete = m_uObjIdx == m_lstEntries.size() - 1 /* Object index is zero-based */; 1198 if (fComplete) 1199 m_enmStatus = Completed; 1200 break; 1201 } 1202 1203 default: 1204 { 1205 m_enmStatus = enmStatus; 1206 break; 1207 } 1208 } 1209 1210 if (RT_FAILURE(rc)) 1211 LogRel(("Shared Clipboard: Data object received error %Rrc (status %#x)\n", rc, enmStatus)); 1212 1213 if (m_EventStatusChanged != NIL_RTSEMEVENT) 1214 rc2 = RTSemEventSignal(m_EventStatusChanged); 1175 1215 1176 1216 return rc2; -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp
r100394 r100412 301 301 static DECLCALLBACK(void) shClSvcWinTransferOnInitializedCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx) 302 302 { 303 LogFlowFuncEnter(); 304 303 305 PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser; 304 306 AssertPtr(pCtx); … … 317 319 { 318 320 SharedClipboardWinDataObject *pObj = pCtx->Win.pDataObjInFlight; 319 AssertPtrReturnVoid(pObj); 320 rc = pObj->SetTransfer(pTransfer); 321 322 pCtx->Win.pDataObjInFlight = NULL; /* Hand off to Windows. */ 321 if (pObj) 322 { 323 rc = pObj->SetTransfer(pTransfer); 324 if (RT_SUCCESS(rc)) 325 rc = pObj->SetStatus(SharedClipboardWinDataObject::Running); 326 327 pCtx->Win.pDataObjInFlight = NULL; /* Hand off to Windows. */ 328 } 329 else 330 AssertMsgFailed(("No data object in flight!\n")); 323 331 324 332 int rc2 = RTCritSectLeave(&pCtx->Win.CritSect); … … 350 358 static DECLCALLBACK(void) shClSvcWinTransferOnDestroyCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx) 351 359 { 360 LogFlowFuncEnter(); 361 352 362 PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser; 353 363 AssertPtr(pCtx); … … 360 370 361 371 /** 362 * @copydoc SHCLTRANSFERCALLBACKS::pfnOnStarted 372 * @copydoc SharedClipboardWinDataObject::CALLBACKS::pfnTransferStart 373 * 374 * Called by SharedClipboardWinDataObject::GetData() when the user wants to paste data. 375 * This then creates and initializes a new transfer on the host + lets the guest know about that new transfer. 363 376 * 364 377 * @thread Service main thread. 365 378 */ 366 static DECLCALLBACK(void) shClSvcWinTransferOnStartedCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx) 367 { 379 static DECLCALLBACK(int) shClSvcWinDataObjectTransferStartCallback(SharedClipboardWinDataObject::PCALLBACKCTX pCbCtx) 380 { 381 LogFlowFuncEnter(); 382 368 383 PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser; 369 384 AssertPtr(pCtx); 370 385 371 PSHCLTRANSFER pTransfer = pCbCtx->pTransfer; 372 AssertPtr(pTransfer); 373 374 if (ShClTransferGetDir(pTransfer) == SHCLTRANSFERDIR_FROM_REMOTE) /* G->H */ 375 { 376 /* Report to the guest that we now entered the STARTED state. */ 377 ShClSvcTransferStart(pCtx->pClient, pTransfer); 378 } 386 PSHCLTRANSFER pTransfer; 387 int rc = ShClSvcTransferCreate(pCtx->pClient, SHCLTRANSFERDIR_FROM_REMOTE, SHCLSOURCE_REMOTE, 388 NIL_SHCLTRANSFERID /* Creates a new transfer ID */, &pTransfer); 389 if (RT_SUCCESS(rc)) 390 { 391 /* Initialize the transfer on the host side. */ 392 rc = ShClSvcTransferInit(pCtx->pClient, pTransfer); 393 if (RT_FAILURE(rc)) 394 ShClSvcTransferDestroy(pCtx->pClient, pTransfer); 395 } 396 397 LogFlowFuncLeaveRC(rc); 398 return rc; 379 399 } 380 400 #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */ … … 545 565 546 566 int rc = SharedClipboardWinClearAndAnnounceFormats(pWinCtx, fFormats, hWnd); 547 if (RT_FAILURE(rc)) 548 LogRel(("Shared Clipboard: Reporting clipboard formats %#x to Windows host failed with %Rrc\n", fFormats, rc)); 549 567 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS 568 if ( RT_SUCCESS(rc) 569 && fFormats & VBOX_SHCL_FMT_URI_LIST) 570 { 571 /* 572 * Create our IDataObject implementation and push it to the Windows clibpoard. 573 * That way Windows will recognize that there is a data transfer available. 574 */ 575 SharedClipboardWinDataObject::CALLBACKS Callbacks; 576 RT_ZERO(Callbacks); 577 Callbacks.pfnTransferStart = shClSvcWinDataObjectTransferStartCallback; 578 579 rc = SharedClipboardWinTransferCreateAndSetDataObject(pWinCtx, pCtx, &Callbacks); 580 } 581 #else 582 RT_NOREF(rc); 583 #endif 550 584 LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: lastErr=%ld\n", GetLastError())); 551 585 break; … … 828 862 pClient->Transfers.Callbacks.pfnOnCreated = shClSvcWinTransferOnCreatedCallback; 829 863 pClient->Transfers.Callbacks.pfnOnInitialized = shClSvcWinTransferOnInitializedCallback; 830 pClient->Transfers.Callbacks.pfnOnStarted = shClSvcWinTransferOnStartedCallback;831 864 pClient->Transfers.Callbacks.pfnOnDestroy = shClSvcWinTransferOnDestroyCallback; 832 865 #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
Note:
See TracChangeset
for help on using the changeset viewer.