Changeset 80444 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- Aug 27, 2019 5:47:44 PM (5 years ago)
- Location:
- trunk/src/VBox/GuestHost/SharedClipboard
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp
r80285 r80444 22 22 #include <iprt/alloc.h> 23 23 #include <iprt/assert.h> 24 #include <iprt/semaphore.h> 24 25 #include <iprt/path.h> 25 26 … … 28 29 #include <VBox/GuestHost/clipboard-helper.h> 29 30 #include <VBox/HostServices/VBoxClipboardSvc.h> 31 32 33 /** 34 * Allocates a new event payload. 35 * 36 * @returns VBox status code. 37 * @param uID Event ID to associate payload to. 38 * @param pvData Data block to associate to this payload. 39 * @param cbData Size (in bytes) of data block to associate. 40 * @param ppPayload Where to store the allocated event payload on success. 41 */ 42 int SharedClipboardPayloadAlloc(uint32_t uID, const void *pvData, uint32_t cbData, 43 PSHAREDCLIPBOARDEVENTPAYLOAD *ppPayload) 44 { 45 AssertPtrReturn(pvData, VERR_INVALID_POINTER); 46 AssertReturn (cbData, VERR_INVALID_PARAMETER); 47 48 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload = 49 (PSHAREDCLIPBOARDEVENTPAYLOAD)RTMemAlloc(sizeof(SHAREDCLIPBOARDEVENTPAYLOAD)); 50 if (!pPayload) 51 return VERR_NO_MEMORY; 52 53 pPayload->pvData = RTMemAlloc(cbData); 54 if (pPayload->pvData) 55 { 56 memcpy(pPayload->pvData, pvData, cbData); 57 58 pPayload->cbData = cbData; 59 pPayload->uID = uID; 60 61 *ppPayload = pPayload; 62 63 return VINF_SUCCESS; 64 } 65 66 RTMemFree(pPayload); 67 return VERR_NO_MEMORY; 68 } 69 70 /** 71 * Frees an event payload. 72 * 73 * @returns VBox status code. 74 * @param pPayload Event payload to free. 75 */ 76 void SharedClipboardPayloadFree(PSHAREDCLIPBOARDEVENTPAYLOAD pPayload) 77 { 78 if (!pPayload) 79 return; 80 81 if (pPayload->pvData) 82 { 83 Assert(pPayload->cbData); 84 RTMemFree(pPayload->pvData); 85 pPayload->pvData = NULL; 86 } 87 88 pPayload->cbData = 0; 89 90 RTMemFree(pPayload); 91 pPayload = NULL; 92 } 93 94 int SharedClipboardEventCreate(PSHAREDCLIPBOARDEVENT pEvent, uint16_t uID) 95 { 96 AssertPtrReturn(pEvent, VERR_INVALID_POINTER); 97 98 LogFlowFunc(("Event %RU16\n", uID)); 99 100 int rc = RTSemEventCreate(&pEvent->hEventSem); 101 if (RT_SUCCESS(rc)) 102 { 103 pEvent->uID = uID; 104 pEvent->pPayload = NULL; 105 } 106 107 return rc; 108 } 109 110 void SharedClipboardEventDestroy(PSHAREDCLIPBOARDEVENT pEvent) 111 { 112 if (!pEvent) 113 return; 114 115 LogFlowFunc(("Event %RU16\n", pEvent->uID)); 116 117 if (pEvent->hEventSem != NIL_RTSEMEVENT) 118 { 119 RTSemEventDestroy(pEvent->hEventSem); 120 pEvent->hEventSem = NIL_RTSEMEVENT; 121 } 122 123 SharedClipboardPayloadFree(pEvent->pPayload); 124 125 pEvent->uID = 0; 126 } 127 128 int SharedClipboardEventSourceCreate(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID) 129 { 130 AssertPtrReturn(pSource, VERR_INVALID_POINTER); 131 132 LogFlowFunc(("pSource=%p, uID=%RU16\n", pSource, uID)); 133 134 int rc = VINF_SUCCESS; 135 136 RTListInit(&pSource->lstEvents); 137 138 pSource->uID = uID; 139 pSource->uEventIDNext = 1; /* Event ID 0 always is reserved (marks "unused"). */ 140 141 LogFlowFuncLeaveRC(rc); 142 return rc; 143 } 144 145 void SharedClipboardEventSourceDestroy(PSHAREDCLIPBOARDEVENTSOURCE pSource) 146 { 147 if (!pSource) 148 return; 149 150 LogFlowFunc(("ID=%RU16\n", pSource->uID)); 151 152 PSHAREDCLIPBOARDEVENT pEvIt; 153 PSHAREDCLIPBOARDEVENT pEvItNext; 154 RTListForEachSafe(&pSource->lstEvents, pEvIt, pEvItNext, SHAREDCLIPBOARDEVENT, Node) 155 { 156 SharedClipboardEventDestroy(pEvIt); 157 RTMemFree(pEvIt); 158 } 159 } 160 161 /** 162 * Generates a new event ID for a specific event source. 163 * 164 * @returns New event ID generated, or 0 on error. 165 * @param pSource Event source to generate event for. 166 */ 167 uint16_t SharedClipboardEventIDGenerate(PSHAREDCLIPBOARDEVENTSOURCE pSource) 168 { 169 AssertPtrReturn(pSource, 0); 170 171 LogFlowFunc(("uSource=%RU16: New event: %RU16\n", pSource->uID, pSource->uEventIDNext)); 172 return pSource->uEventIDNext++; /** @todo Improve this. */ 173 } 174 175 /** 176 * Returns a specific event of a event source. 177 * 178 * @returns Pointer to event if found, or NULL if not found. 179 * @param pSource Event source to get event from. 180 * @param uID Event ID to get. 181 */ 182 inline PSHAREDCLIPBOARDEVENT sharedClipboardEventGet(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID) 183 { 184 PSHAREDCLIPBOARDEVENT pEvIt; 185 RTListForEach(&pSource->lstEvents, pEvIt, SHAREDCLIPBOARDEVENT, Node) 186 { 187 if (pEvIt->uID == uID) 188 return pEvIt; 189 } 190 191 return NULL; 192 } 193 194 /** 195 * Registers an event. 196 * 197 * @returns VBox status code. 198 * @param pSource Event source to register event for. 199 * @param uID Event ID to register. 200 */ 201 int SharedClipboardEventRegister(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID) 202 { 203 AssertPtrReturn(pSource, VERR_INVALID_POINTER); 204 205 int rc; 206 207 LogFlowFunc(("uSource=%RU16, uEvent=%RU16\n", pSource->uID, uID)); 208 209 if (sharedClipboardEventGet(pSource, uID) == NULL) 210 { 211 PSHAREDCLIPBOARDEVENT pEvent 212 = (PSHAREDCLIPBOARDEVENT)RTMemAllocZ(sizeof(SHAREDCLIPBOARDEVENT)); 213 if (pEvent) 214 { 215 rc = SharedClipboardEventCreate(pEvent, uID); 216 if (RT_SUCCESS(rc)) 217 { 218 RTListAppend(&pSource->lstEvents, &pEvent->Node); 219 220 LogFlowFunc(("Event %RU16\n", uID)); 221 } 222 } 223 else 224 rc = VERR_NO_MEMORY; 225 } 226 else 227 rc = VERR_ALREADY_EXISTS; 228 229 #ifdef DEBUG_andy 230 AssertRC(rc); 231 #endif 232 233 LogFlowFuncLeaveRC(rc); 234 return rc; 235 } 236 237 /** 238 * Unregisters an event. 239 * 240 * @returns VBox status code. 241 * @param pSource Event source to unregister event for. 242 * @param uID Event ID to unregister. 243 */ 244 int SharedClipboardEventUnregister(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID) 245 { 246 AssertPtrReturn(pSource, VERR_INVALID_POINTER); 247 248 int rc; 249 250 LogFlowFunc(("uSource=%RU16, uEvent=%RU16\n", pSource->uID, uID)); 251 252 PSHAREDCLIPBOARDEVENT pEvent = sharedClipboardEventGet(pSource, uID); 253 if (pEvent) 254 { 255 LogFlowFunc(("Event %RU16\n", pEvent->uID)); 256 257 SharedClipboardEventDestroy(pEvent); 258 RTMemFree(pEvent); 259 260 RTListNodeRemove(&pEvent->Node); 261 262 rc = VINF_SUCCESS; 263 } 264 else 265 rc = VERR_NOT_FOUND; 266 267 AssertRC(rc); 268 269 LogFlowFuncLeaveRC(rc); 270 return rc; 271 } 272 273 /** 274 * Waits for an event to get signalled. 275 * 276 * @returns VBox status code. 277 * @param pSource Event source that contains the event to wait for. 278 * @param uID Event ID to wait for. 279 * @param uTimeoutMs Timeout (in ms) to wait. 280 * @param ppPayload Where to store the (allocated) event payload on success. Needs to be free'd with 281 * SharedClipboardPayloadFree(). 282 */ 283 int SharedClipboardEventWait(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID, RTMSINTERVAL uTimeoutMs, 284 PSHAREDCLIPBOARDEVENTPAYLOAD* ppPayload) 285 { 286 AssertPtrReturn(pSource, VERR_INVALID_POINTER); 287 288 LogFlowFuncEnter(); 289 290 int rc; 291 292 PSHAREDCLIPBOARDEVENT pEvent = sharedClipboardEventGet(pSource, uID); 293 if (pEvent) 294 { 295 rc = RTSemEventWait(pEvent->hEventSem, uTimeoutMs); 296 if (RT_SUCCESS(rc)) 297 { 298 *ppPayload = pEvent->pPayload; 299 300 pEvent->pPayload = NULL; 301 } 302 } 303 else 304 rc = VERR_NOT_FOUND; 305 306 LogFlowFuncLeaveRC(rc); 307 return rc; 308 } 309 310 /** 311 * Signals an event. 312 * 313 * @returns VBox status code. 314 * @param pSource Event source of event to signal. 315 * @param uID Event ID to signal. 316 * @param pPayload Event payload to associate. Takes ownership. Optional. 317 */ 318 int SharedClipboardEventSignal(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID, 319 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload) 320 { 321 AssertPtrReturn(pSource, VERR_INVALID_POINTER); 322 323 int rc; 324 325 LogFlowFunc(("uSource=%RU16, uEvent=%RU16\n", pSource->uID, uID)); 326 327 PSHAREDCLIPBOARDEVENT pEvent = sharedClipboardEventGet(pSource, uID); 328 if (pEvent) 329 { 330 Assert(pEvent->pPayload == NULL); 331 332 pEvent->pPayload = pPayload; 333 334 rc = RTSemEventSignal(pEvent->hEventSem); 335 } 336 else 337 rc = VERR_NOT_FOUND; 338 339 #ifdef DEBUG_andy 340 AssertRC(rc); 341 #endif 342 343 LogFlowFuncLeaveRC(rc); 344 return rc; 345 } 346 347 /** 348 * Detaches a payload from an event. 349 * 350 * @returns VBox status code. 351 * @param pSource Event source of event to detach payload for. 352 * @param uID Event ID to detach payload for. 353 */ 354 void SharedClipboardEventPayloadDetach(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_t uID) 355 { 356 AssertPtrReturnVoid(pSource); 357 358 LogFlowFunc(("uSource=%RU16, uEvent=%RU16\n", pSource->uID, uID)); 359 360 PSHAREDCLIPBOARDEVENT pEvent = sharedClipboardEventGet(pSource, uID); 361 if (pEvent) 362 { 363 pEvent->pPayload = NULL; 364 } 365 #ifdef DEBUG_andy 366 else 367 AssertMsgFailed(("uSource=%RU16, uEvent=%RU16\n", pSource->uID, uID)); 368 #endif 369 } 30 370 31 371 /** @todo use const where appropriate; delinuxify the code (*Lin* -> *Host*); use AssertLogRel*. */ … … 421 761 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT); 422 762 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA); 423 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_ REPORT_FORMATS);763 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS_WRITE); 424 764 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START); 425 765 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOT_LIST_HDR_READ); … … 453 793 switch (uMsg) 454 794 { 455 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_REPORT_FORMATS); 456 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_READ_DATA); 457 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_WRITE_DATA); 795 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_GET_HOST_MSG_OLD); 796 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_FORMATS_WRITE); 797 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_DATA_READ); 798 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_DATA_WRITE); 799 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_CONNECT); 458 800 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_PEEK_NOWAIT); 459 801 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_PEEK_WAIT); … … 477 819 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_CANCEL); 478 820 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_ERROR); 479 RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT);480 821 } 481 822 return "Unknown"; 482 823 } 824 -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-uri.cpp
r80374 r80444 21 21 #include <iprt/dir.h> 22 22 #include <iprt/file.h> 23 #include <iprt/list.h> 23 24 #include <iprt/path.h> 24 25 #include <iprt/semaphore.h> … … 31 32 static int sharedClipboardURITransferThreadCreate(PSHAREDCLIPBOARDURITRANSFER pTransfer, PFNRTTHREAD pfnThreadFunc, void *pvUser); 32 33 static int sharedClipboardURITransferThreadDestroy(PSHAREDCLIPBOARDURITRANSFER pTransfer, RTMSINTERVAL uTimeoutMs); 33 static int sharedClipboardURITransferWriteThread(RTTHREAD hThread, void *pvUser);34 34 static PSHAREDCLIPBOARDURITRANSFER sharedClipboardURICtxGetTransferInternal(PSHAREDCLIPBOARDURICTX pURI, uint32_t uIdx); 35 35 static int sharedClipboardConvertFileCreateFlags(bool fWritable, unsigned fShClFlags, RTFMODE fMode, … … 695 695 pParms->pszPath = NULL; 696 696 } 697 } 698 699 /** 700 * Returns a specific object handle info of a transfer. 701 * 702 * @returns Pointer to object handle info if found, or NULL if not found. 703 * @param pTransfer URI clipboard transfer to get object handle info from. 704 * @param hObj Object handle of the object to get handle info for. 705 */ 706 inline PSHAREDCLIPBOARDURIOBJHANDLEINFO sharedClipboardURIObjectGet(PSHAREDCLIPBOARDURITRANSFER pTransfer, 707 SHAREDCLIPBOARDOBJHANDLE hObj) 708 { 709 PSHAREDCLIPBOARDURIOBJHANDLEINFO pIt; 710 RTListForEach(&pTransfer->lstObj, pIt, SHAREDCLIPBOARDURIOBJHANDLEINFO, Node) 711 { 712 if (pIt->hObj == hObj) 713 return pIt; 714 } 715 716 return NULL; 697 717 } 698 718 … … 744 764 if (RT_SUCCESS(rc)) 745 765 { 746 const SHAREDCLIPBOARDOBJHANDLE hObj = pTransfer->uObjHandleNext++; 747 766 pInfo->hObj = pTransfer->uObjHandleNext++; 748 767 pInfo->enmType = SHAREDCLIPBOARDURIOBJTYPE_FILE; 749 768 750 pTransfer->pMapObj->insert( 751 std::pair<SHAREDCLIPBOARDOBJHANDLE, PSHAREDCLIPBOARDURIOBJHANDLEINFO>(hObj, pInfo)); 752 753 *phObj = hObj; 769 RTListAppend(&pTransfer->lstObj, &pInfo->Node); 770 771 *phObj = pInfo->hObj; 754 772 } 755 773 … … 789 807 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 790 808 { 791 SharedClipboardURIObjMap::iterator itObj = pTransfer->pMapObj->find(hObj); 792 if (itObj != pTransfer->pMapObj->end()) 793 { 794 PSHAREDCLIPBOARDURIOBJHANDLEINFO pInfo = itObj->second; 795 AssertPtr(pInfo); 796 809 PSHAREDCLIPBOARDURIOBJHANDLEINFO pInfo = sharedClipboardURIObjectGet(pTransfer, hObj); 810 if (pInfo) 811 { 797 812 switch (pInfo->enmType) 798 813 { … … 820 835 RTMemFree(pInfo); 821 836 822 pTransfer->pMapObj->erase(itObj);837 RTListNodeRemove(&pInfo->Node); 823 838 } 824 839 else … … 862 877 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 863 878 { 864 SharedClipboardURIObjMap::iterator itObj = pTransfer->pMapObj->find(hObj); 865 if (itObj != pTransfer->pMapObj->end()) 866 { 867 PSHAREDCLIPBOARDURIOBJHANDLEINFO pInfo = itObj->second; 868 AssertPtr(pInfo); 869 879 PSHAREDCLIPBOARDURIOBJHANDLEINFO pInfo = sharedClipboardURIObjectGet(pTransfer, hObj); 880 if (pInfo) 881 { 870 882 switch (pInfo->enmType) 871 883 { … … 927 939 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 928 940 { 929 SharedClipboardURIObjMap::iterator itObj = pTransfer->pMapObj->find(hObj); 930 if (itObj != pTransfer->pMapObj->end()) 931 { 932 PSHAREDCLIPBOARDURIOBJHANDLEINFO pInfo = itObj->second; 933 AssertPtr(pInfo); 934 941 PSHAREDCLIPBOARDURIOBJHANDLEINFO pInfo = sharedClipboardURIObjectGet(pTransfer, hObj); 942 if (pInfo) 943 { 935 944 switch (pInfo->enmType) 936 945 { … … 1070 1079 pTransfer->uListHandleNext = 1; 1071 1080 pTransfer->uObjHandleNext = 1; 1072 pTransfer->uEventIDNext = 1;1073 1081 1074 1082 pTransfer->uTimeoutMs = 30 * 1000; /* 30s timeout by default. */ … … 1080 1088 RT_ZERO(pTransfer->Callbacks); 1081 1089 1082 pTransfer->pMapEvents = new SharedClipboardURITransferEventMap(); 1083 if (pTransfer->pMapEvents) 1084 { 1085 pTransfer->pMapLists = new SharedClipboardURIListMap(); 1086 if (pTransfer->pMapLists) 1087 { 1088 pTransfer->pMapObj = new SharedClipboardURIObjMap(); 1089 if (pTransfer->pMapObj) 1090 *ppTransfer = pTransfer; 1091 } 1092 } 1093 else 1094 rc = VERR_NO_MEMORY; 1090 RTListInit(&pTransfer->lstList); 1091 RTListInit(&pTransfer->lstObj); 1092 1093 pTransfer->cRoots = 0; 1094 RTListInit(&pTransfer->lstRoots); 1095 1096 *ppTransfer = pTransfer; 1095 1097 1096 1098 if (RT_FAILURE(rc)) … … 1126 1128 RTStrFree(pTransfer->pszPathRootAbs); 1127 1129 1128 if (pTransfer->pMapEvents) 1129 { 1130 SharedClipboardURITransferEventMap::iterator itEvent = pTransfer->pMapEvents->begin(); 1131 while (itEvent != pTransfer->pMapEvents->end()) 1132 { 1133 1134 itEvent = pTransfer->pMapEvents->begin(); 1135 } 1136 1137 delete pTransfer->pMapEvents; 1138 pTransfer->pMapEvents = NULL; 1139 } 1140 1141 if (pTransfer->pMapLists) 1142 { 1143 SharedClipboardURIListMap::iterator itList = pTransfer->pMapLists->begin(); 1144 while (itList != pTransfer->pMapLists->end()) 1145 { 1146 SharedClipboardURIListHandleInfoDestroy(itList->second); 1147 pTransfer->pMapLists->erase(itList); 1148 itList = pTransfer->pMapLists->begin(); 1149 } 1150 1151 Assert(pTransfer->pMapLists->size() == 0); 1152 1153 delete pTransfer->pMapLists; 1154 pTransfer->pMapLists = NULL; 1155 } 1156 1157 if (pTransfer->pMapObj) 1158 { 1159 SharedClipboardURIObjMap::iterator itObj = pTransfer->pMapObj->begin(); 1160 while (itObj != pTransfer->pMapObj->end()) 1161 { 1162 SharedClipboardURIObjectHandleInfoDestroy(itObj->second); 1163 pTransfer->pMapObj->erase(itObj); 1164 itObj = pTransfer->pMapObj->begin(); 1165 } 1166 1167 Assert(pTransfer->pMapObj->size() == 0); 1168 1169 delete pTransfer->pMapObj; 1170 pTransfer->pMapObj = NULL; 1130 SharedClipboardEventSourceDestroy(&pTransfer->Events); 1131 1132 PSHAREDCLIPBOARDURILISTHANDLEINFO pItList, pItListNext; 1133 RTListForEachSafe(&pTransfer->lstList, pItList, pItListNext, SHAREDCLIPBOARDURILISTHANDLEINFO, Node) 1134 { 1135 SharedClipboardURIListHandleInfoDestroy(pItList); 1136 1137 RTListNodeRemove(&pItList->Node); 1138 1139 RTMemFree(pItList); 1140 } 1141 1142 PSHAREDCLIPBOARDURIOBJHANDLEINFO pItObj, pItObjNext; 1143 RTListForEachSafe(&pTransfer->lstObj, pItObj, pItObjNext, SHAREDCLIPBOARDURIOBJHANDLEINFO, Node) 1144 { 1145 SharedClipboardURIObjectHandleInfoDestroy(pItObj); 1146 1147 RTListNodeRemove(&pItObj->Node); 1148 1149 RTMemFree(pItObj); 1171 1150 } 1172 1151 … … 1198 1177 1199 1178 /** 1179 * Returns a specific list handle info of a transfer. 1180 * 1181 * @returns Pointer to list handle info if found, or NULL if not found. 1182 * @param pTransfer URI clipboard transfer to get list handle info from. 1183 * @param hList List handle of the list to get handle info for. 1184 */ 1185 inline PSHAREDCLIPBOARDURILISTHANDLEINFO sharedClipboardURITransferListGet(PSHAREDCLIPBOARDURITRANSFER pTransfer, 1186 SHAREDCLIPBOARDLISTHANDLE hList) 1187 { 1188 PSHAREDCLIPBOARDURILISTHANDLEINFO pIt; 1189 RTListForEach(&pTransfer->lstList, pIt, SHAREDCLIPBOARDURILISTHANDLEINFO, Node) 1190 { 1191 if (pIt->hList == hList) 1192 return pIt; 1193 } 1194 1195 return NULL; 1196 } 1197 1198 /** 1200 1199 * Creates a new list handle (local only). 1201 1200 * … … 1203 1202 * @param pTransfer URI clipboard transfer to create new list handle for. 1204 1203 */ 1205 staticSHAREDCLIPBOARDLISTHANDLE sharedClipboardURITransferListHandleNew(PSHAREDCLIPBOARDURITRANSFER pTransfer)1204 inline SHAREDCLIPBOARDLISTHANDLE sharedClipboardURITransferListHandleNew(PSHAREDCLIPBOARDURITRANSFER pTransfer) 1206 1205 { 1207 1206 return pTransfer->uListHandleNext++; /** @todo Good enough for now. Improve this later. */ … … 1244 1243 { 1245 1244 rc = RTDirOpen(&pInfo->u.Local.hDir, pOpenParms->pszPath); 1245 break; 1246 1246 } 1247 1247 … … 1260 1260 if (RT_SUCCESS(rc)) 1261 1261 { 1262 hList = sharedClipboardURITransferListHandleNew(pTransfer); 1263 1264 pTransfer->pMapLists->insert( 1265 std::pair<SHAREDCLIPBOARDLISTHANDLE, PSHAREDCLIPBOARDURILISTHANDLEINFO>(hList, pInfo)); /** @todo Can this throw? */ 1262 pInfo->hList = sharedClipboardURITransferListHandleNew(pTransfer); 1263 1264 RTListAppend(&pTransfer->lstList, &pInfo->Node); 1266 1265 } 1267 1266 else … … 1323 1322 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 1324 1323 { 1325 SharedClipboardURIListMap::iterator itList = pTransfer->pMapLists->find(hList); 1326 if (itList != pTransfer->pMapLists->end()) 1327 { 1328 PSHAREDCLIPBOARDURILISTHANDLEINFO pInfo = itList->second; 1329 AssertPtr(pInfo); 1330 1324 PSHAREDCLIPBOARDURILISTHANDLEINFO pInfo = sharedClipboardURITransferListGet(pTransfer, hList); 1325 if (pInfo) 1326 { 1331 1327 switch (pInfo->enmType) 1332 1328 { … … 1343 1339 } 1344 1340 1341 RTListNodeRemove(&pInfo->Node); 1342 1345 1343 RTMemFree(pInfo); 1346 1347 pTransfer->pMapLists->erase(itList);1348 1344 } 1349 1345 else … … 1559 1555 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 1560 1556 { 1561 SharedClipboardURIListMap::iterator itList = pTransfer->pMapLists->find(hList);1562 if ( itList != pTransfer->pMapLists->end())1557 PSHAREDCLIPBOARDURILISTHANDLEINFO pInfo = sharedClipboardURITransferListGet(pTransfer, hList); 1558 if (pInfo) 1563 1559 { 1564 1560 rc = SharedClipboardURIListHdrInit(pHdr); 1565 1561 if (RT_SUCCESS(rc)) 1566 1562 { 1567 PSHAREDCLIPBOARDURILISTHANDLEINFO pInfo = itList->second;1568 AssertPtr(pInfo);1569 1570 1563 switch (pInfo->enmType) 1571 1564 { … … 1666 1659 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 1667 1660 { 1668 SharedClipboardURIListMap::iterator itList = pTransfer->pMapLists->find(hList); 1669 if (itList != pTransfer->pMapLists->end()) 1670 { 1671 PSHAREDCLIPBOARDURILISTHANDLEINFO pInfo = itList->second; 1672 AssertPtr(pInfo); 1673 1661 PSHAREDCLIPBOARDURILISTHANDLEINFO pInfo = sharedClipboardURITransferListGet(pTransfer, hList); 1662 if (pInfo) 1663 { 1674 1664 switch (pInfo->enmType) 1675 1665 { … … 1826 1816 if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL) 1827 1817 { 1828 SharedClipboardURIListMap::iterator itList = pTransfer->pMapLists->find(hList); 1829 fIsValid = itList != pTransfer->pMapLists->end(); 1818 fIsValid = sharedClipboardURITransferListGet(pTransfer, hList) != NULL; 1830 1819 } 1831 1820 else if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_REMOTE) … … 1927 1916 } 1928 1917 1929 pTransfer->lstRootEntries.clear(); 1918 PSHAREDCLIPBOARDURILISTROOT pListRoot, pListRootNext; 1919 RTListForEachSafe(&pTransfer->lstRoots, pListRoot, pListRootNext, SHAREDCLIPBOARDURILISTROOT, Node) 1920 { 1921 RTStrFree(pListRoot->pszPathAbs); 1922 1923 RTListNodeRemove(&pListRoot->Node); 1924 1925 RTMemFree(pListRoot); 1926 pListRoot = NULL; 1927 } 1928 1929 pTransfer->cRoots = 0; 1930 1930 } 1931 1931 … … 1952 1952 sharedClipboardURIListTransferRootsClear(pTransfer); 1953 1953 1954 char *pszPathRootAbs = NULL;1954 char *pszPathRootAbs = NULL; 1955 1955 1956 1956 RTCList<RTCString> lstRootEntries = RTCString(pszRoots, cbRoots - 1).split("\r\n"); 1957 1957 for (size_t i = 0; i < lstRootEntries.size(); ++i) 1958 1958 { 1959 SHAREDCLIPBOARDURILISTROOT listRoot; 1960 listRoot.strPathAbs = lstRootEntries.at(i); 1959 PSHAREDCLIPBOARDURILISTROOT pListRoot = (PSHAREDCLIPBOARDURILISTROOT)RTMemAlloc(sizeof(SHAREDCLIPBOARDURILISTROOT)); 1960 AssertPtrBreakStmt(pListRoot, rc = VERR_NO_MEMORY); 1961 1962 pListRoot->pszPathAbs = RTStrDup(lstRootEntries.at(i).c_str()); 1963 AssertPtrBreakStmt(pListRoot->pszPathAbs, rc = VERR_NO_MEMORY); 1961 1964 1962 1965 if (!pszPathRootAbs) 1963 1966 { 1964 pszPathRootAbs = RTStrDup( listRoot.strPathAbs.c_str());1967 pszPathRootAbs = RTStrDup(pListRoot->pszPathAbs); 1965 1968 if (pszPathRootAbs) 1966 1969 { … … 1976 1979 1977 1980 /* Make sure all entries have the same root path. */ 1978 if (!RTStrStartsWith( listRoot.strPathAbs.c_str(), pszPathRootAbs))1981 if (!RTStrStartsWith(pListRoot->pszPathAbs, pszPathRootAbs)) 1979 1982 { 1980 1983 rc = VERR_INVALID_PARAMETER; … … 1982 1985 } 1983 1986 1984 pTransfer->lstRootEntries.append(listRoot); 1987 RTListAppend(&pTransfer->lstRoots, &pListRoot->Node); 1988 1989 pTransfer->cRoots++; 1985 1990 } 1986 1991 … … 1990 1995 { 1991 1996 pTransfer->pszPathRootAbs = pszPathRootAbs; 1992 LogFlowFunc(("pszPathRootAbs=%s, cRoots=%zu\n", pTransfer->pszPathRootAbs, pTransfer-> lstRootEntries.size()));1997 LogFlowFunc(("pszPathRootAbs=%s, cRoots=%zu\n", pTransfer->pszPathRootAbs, pTransfer->cRoots)); 1993 1998 } 1994 1999 … … 2034 2039 AssertPtrReturn(pTransfer, 0); 2035 2040 2036 return (uint32_t)pTransfer->lstRootEntries.size(); 2041 return (uint32_t)pTransfer->cRoots; 2042 } 2043 2044 /** 2045 * Returns a specific root list entry of a transfer. 2046 * 2047 * @returns Pointer to root list entry if found, or NULL if not found. 2048 * @param pTransfer URI clipboard transfer to get root list entry from. 2049 * @param uIdx Index of root list entry to return. 2050 */ 2051 inline PSHAREDCLIPBOARDURILISTROOT sharedClipboardURILTransferRootsGet(PSHAREDCLIPBOARDURITRANSFER pTransfer, uint32_t uIdx) 2052 { 2053 if (uIdx >= pTransfer->cRoots) 2054 return NULL; 2055 2056 PSHAREDCLIPBOARDURILISTROOT pIt = RTListGetFirst(&pTransfer->lstRoots, SHAREDCLIPBOARDURILISTROOT, Node); 2057 while (uIdx--) 2058 pIt = RTListGetNext(&pTransfer->lstRoots, pIt, SHAREDCLIPBOARDURILISTROOT, Node); 2059 2060 return pIt; 2037 2061 } 2038 2062 … … 2046 2070 */ 2047 2071 int SharedClipboardURILTransferRootsEntry(PSHAREDCLIPBOARDURITRANSFER pTransfer, 2048 uint 32_t uIndex, PVBOXCLIPBOARDROOTLISTENTRY pEntry)2072 uint64_t uIndex, PVBOXCLIPBOARDROOTLISTENTRY pEntry) 2049 2073 { 2050 2074 AssertPtrReturn(pTransfer, VERR_INVALID_POINTER); 2051 2075 AssertPtrReturn(pEntry, VERR_INVALID_POINTER); 2052 2076 2053 if (uIndex >= pTransfer-> lstRootEntries.size())2077 if (uIndex >= pTransfer->cRoots) 2054 2078 return VERR_INVALID_PARAMETER; 2055 2079 2056 2080 int rc; 2057 2081 2058 PSHAREDCLIPBOARDURILISTROOT pRoot = &pTransfer->lstRootEntries.at(uIndex);2059 AssertPtrReturn(pRoot, VERR_INVALID_P OINTER);2082 PSHAREDCLIPBOARDURILISTROOT pRoot = sharedClipboardURILTransferRootsGet(pTransfer, uIndex); 2083 AssertPtrReturn(pRoot, VERR_INVALID_PARAMETER); 2060 2084 2061 2085 /* Make sure that we only advertise relative source paths, not absolute ones. */ 2062 const char *pcszSrcPath = pRoot-> strPathAbs.c_str();2086 const char *pcszSrcPath = pRoot->pszPathAbs; 2063 2087 2064 2088 char *pszFileName = RTPathFilename(pcszSrcPath); … … 2124 2148 return VERR_NO_MEMORY; 2125 2149 2126 const uint 32_t cRoots = (uint32_t)pTransfer->lstRootEntries.size();2127 2128 LogFlowFunc(("cRoots=%RU 32\n", cRoots));2150 const uint64_t cRoots = (uint32_t)pTransfer->cRoots; 2151 2152 LogFlowFunc(("cRoots=%RU64\n", cRoots)); 2129 2153 2130 2154 if (cRoots) … … 2134 2158 if (paRootListEntries) 2135 2159 { 2136 for (uint 32_t i = 0; i < cRoots; ++i)2160 for (uint64_t i = 0; i < cRoots; ++i) 2137 2161 { 2138 2162 rc = SharedClipboardURILTransferRootsEntry(pTransfer, i, &paRootListEntries[i]); … … 2250 2274 2251 2275 /** 2252 * Allocates a new event payload.2253 *2254 * @returns VBox status code.2255 * @param uID Event ID to associate payload to.2256 * @param pvData Data block to associate to this payload.2257 * @param cbData Size (in bytes) of data block to associate.2258 * @param ppPayload Where to store the allocated event payload on success.2259 */2260 int SharedClipboardURITransferPayloadAlloc(uint32_t uID, const void *pvData, uint32_t cbData,2261 PSHAREDCLIPBOARDURITRANSFERPAYLOAD *ppPayload)2262 {2263 PSHAREDCLIPBOARDURITRANSFERPAYLOAD pPayload =2264 (PSHAREDCLIPBOARDURITRANSFERPAYLOAD)RTMemAlloc(sizeof(SHAREDCLIPBOARDURITRANSFERPAYLOAD));2265 if (!pPayload)2266 return VERR_NO_MEMORY;2267 2268 pPayload->pvData = RTMemAlloc(cbData);2269 if (pPayload->pvData)2270 {2271 memcpy(pPayload->pvData, pvData, cbData);2272 2273 pPayload->cbData = cbData;2274 pPayload->uID = uID;2275 2276 *ppPayload = pPayload;2277 2278 return VINF_SUCCESS;2279 }2280 2281 RTMemFree(pPayload);2282 return VERR_NO_MEMORY;2283 }2284 2285 /**2286 * Frees an event payload.2287 *2288 * @returns VBox status code.2289 * @param pPayload URI clipboard transfer event payload to free.2290 */2291 void SharedClipboardURITransferPayloadFree(PSHAREDCLIPBOARDURITRANSFERPAYLOAD pPayload)2292 {2293 if (!pPayload)2294 return;2295 2296 if (pPayload->pvData)2297 {2298 Assert(pPayload->cbData);2299 RTMemFree(pPayload->pvData);2300 pPayload->pvData = NULL;2301 }2302 2303 pPayload->cbData = 0;2304 2305 RTMemFree(pPayload);2306 pPayload = NULL;2307 }2308 2309 /**2310 * Generates a new event ID for a specific URI transfer.2311 *2312 * @returns New event ID generated, or 0 on error.2313 * @param pTransfer URI clipboard transfer to generate event for.2314 */2315 uint16_t SharedClipboardURITransferEventIDGenerate(PSHAREDCLIPBOARDURITRANSFER pTransfer)2316 {2317 LogFlowFunc(("New event %RU16\n", pTransfer->uEventIDNext));2318 return pTransfer->uEventIDNext++; /** @todo Improve this. */2319 }2320 2321 /**2322 * Registers an URI transfer event.2323 *2324 * @returns VBox status code.2325 * @param pTransfer URI clipboard transfer to register event for.2326 * @param uID Event ID to register.2327 */2328 int SharedClipboardURITransferEventRegister(PSHAREDCLIPBOARDURITRANSFER pTransfer, uint16_t uID)2329 {2330 int rc;2331 2332 SharedClipboardURITransferEventMap::iterator itEvent = pTransfer->pMapEvents->find(uID);2333 if (itEvent == pTransfer->pMapEvents->end())2334 {2335 PSHAREDCLIPBOARDURITRANSFEREVENT pEvent2336 = (PSHAREDCLIPBOARDURITRANSFEREVENT)RTMemAllocZ(sizeof(SHAREDCLIPBOARDURITRANSFEREVENT));2337 if (pEvent)2338 {2339 rc = RTSemEventCreate(&pEvent->hEventSem);2340 if (RT_SUCCESS(rc))2341 {2342 pTransfer->pMapEvents->insert(std::pair<uint16_t, PSHAREDCLIPBOARDURITRANSFEREVENT>(uID, pEvent)); /** @todo Can this throw? */2343 2344 LogFlowFunc(("Event %RU16\n", uID));2345 }2346 }2347 else2348 rc = VERR_NO_MEMORY;2349 }2350 else2351 rc = VERR_ALREADY_EXISTS;2352 2353 #ifdef DEBUG_andy2354 AssertRC(rc);2355 #endif2356 2357 LogFlowFuncLeaveRC(rc);2358 return rc;2359 }2360 2361 /**2362 * Unregisters an URI transfer event.2363 *2364 * @returns VBox status code.2365 * @param pTransfer URI clipboard transfer to unregister event for.2366 * @param uID Event ID to unregister.2367 */2368 int SharedClipboardURITransferEventUnregister(PSHAREDCLIPBOARDURITRANSFER pTransfer, uint16_t uID)2369 {2370 int rc;2371 2372 SharedClipboardURITransferEventMap::const_iterator itEvent = pTransfer->pMapEvents->find(uID);2373 if (itEvent != pTransfer->pMapEvents->end())2374 {2375 SharedClipboardURITransferPayloadFree(itEvent->second->pPayload);2376 2377 RTSemEventDestroy(itEvent->second->hEventSem);2378 2379 RTMemFree(itEvent->second);2380 2381 pTransfer->pMapEvents->erase(itEvent);2382 2383 LogFlowFunc(("Event %RU16\n", uID));2384 2385 rc = VINF_SUCCESS;2386 }2387 else2388 rc = VERR_NOT_FOUND;2389 2390 AssertRC(rc);2391 2392 LogFlowFuncLeaveRC(rc);2393 return rc;2394 }2395 2396 /**2397 * Waits for an URI transfer event to get signalled.2398 *2399 * @returns VBox status code.2400 * @param pTransfer URI clipboard transfer that contains the event to wait for.2401 * @param uID Event ID to wait for.2402 * @param uTimeoutMs Timeout (in ms) to wait.2403 * @param ppPayload Where to store the (allocated) event payload on success. Needs to be free'd with2404 * SharedClipboardURITransferPayloadFree().2405 */2406 int SharedClipboardURITransferEventWait(PSHAREDCLIPBOARDURITRANSFER pTransfer, uint16_t uID, RTMSINTERVAL uTimeoutMs,2407 PSHAREDCLIPBOARDURITRANSFERPAYLOAD *ppPayload)2408 {2409 LogFlowFuncEnter();2410 2411 int rc;2412 2413 SharedClipboardURITransferEventMap::const_iterator itEvent = pTransfer->pMapEvents->find(uID);2414 if (itEvent != pTransfer->pMapEvents->end())2415 {2416 rc = RTSemEventWait(itEvent->second->hEventSem, uTimeoutMs);2417 if (RT_SUCCESS(rc))2418 {2419 *ppPayload = itEvent->second->pPayload;2420 2421 itEvent->second->pPayload = NULL;2422 }2423 }2424 else2425 rc = VERR_NOT_FOUND;2426 2427 LogFlowFuncLeaveRC(rc);2428 return rc;2429 }2430 2431 /**2432 * Signals an URI transfer event.2433 *2434 * @returns VBox status code.2435 * @param pTransfer URI clipboard transfer of event to signal.2436 * @param uID Event ID to signal.2437 * @param pPayload Event payload to associate. Takes ownership. Optional.2438 */2439 int SharedClipboardURITransferEventSignal(PSHAREDCLIPBOARDURITRANSFER pTransfer, uint16_t uID,2440 PSHAREDCLIPBOARDURITRANSFERPAYLOAD pPayload)2441 {2442 int rc;2443 2444 SharedClipboardURITransferEventMap::const_iterator itEvent = pTransfer->pMapEvents->find(uID);2445 if (itEvent != pTransfer->pMapEvents->end())2446 {2447 Assert(itEvent->second->pPayload == NULL);2448 2449 itEvent->second->pPayload = pPayload;2450 2451 rc = RTSemEventSignal(itEvent->second->hEventSem);2452 }2453 else2454 rc = VERR_NOT_FOUND;2455 2456 #ifdef DEBUG_andy2457 AssertRC(rc);2458 #endif2459 2460 LogFlowFuncLeaveRC(rc);2461 return rc;2462 }2463 2464 /**2465 2276 * Creates a thread for a clipboard URI transfer. 2466 2277 * … … 2708 2519 AssertPtrReturnVoid(pURI); 2709 2520 2710 LogFlowFunc(("c Running=%RU32\n", pURI->cRunning));2521 LogFlowFunc(("cTransfers=%RU32, cRunning=%RU32\n", pURI->cTransfers, pURI->cRunning)); 2711 2522 2712 2523 /* Remove all transfers which are not in a running state (e.g. only announced). */ … … 2724 2535 Assert(pURI->cTransfers); 2725 2536 pURI->cTransfers--; 2726 2727 LogFlowFunc(("cTransfers=%RU32\n", pURI->cTransfers));2728 2537 } 2729 2538 } -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp
r79672 r80444 384 384 * @returns VBox status code. 385 385 * @param pCtx Windows clipboard context to retrieve formats for. 386 * @param p fFormats Where to store the retrieved formats of type VBOX_SHARED_CLIPBOARD_FMT_ (bitmask).387 */ 388 int VBoxClipboardWinGetFormats(PVBOXCLIPBOARDWINCTX pCtx, P VBOXCLIPBOARDFORMATS pfFormats)389 { 390 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);391 AssertPtrReturn(p fFormats, VERR_INVALID_POINTER);386 * @param pFormats Where to store the retrieved formats. 387 */ 388 int VBoxClipboardWinGetFormats(PVBOXCLIPBOARDWINCTX pCtx, PSHAREDCLIPBOARDFORMATDATA pFormats) 389 { 390 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 391 AssertPtrReturn(pFormats, VERR_INVALID_POINTER); 392 392 393 393 VBOXCLIPBOARDFORMATS fFormats = VBOX_SHARED_CLIPBOARD_FMT_NONE; … … 412 412 { 413 413 LogFlowFunc(("fFormats=0x%08X\n", fFormats)); 414 *pfFormats = fFormats; 414 415 pFormats->uFormats = fFormats; 416 pFormats->fFlags = 0; /** @todo Handle flags. */ 415 417 } 416 418 -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r78583 r80444 588 588 * unit test. So keep it simple, be paranoid and log everything. 589 589 */ 590 static void clipConvertX11Targets(Widget widget, XtPointer pClient Data,590 static void clipConvertX11Targets(Widget widget, XtPointer pClient, 591 591 Atom * /* selection */, Atom *atomType, 592 592 XtPointer pValue, long unsigned int *pcLen, … … 594 594 { 595 595 RT_NOREF1(piFormat); 596 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClient Data);596 CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClient); 597 597 Atom *pAtoms = (Atom *)pValue; 598 598 unsigned i, j; … … 1764 1764 * the X11 clipboard contains a format we understand. 1765 1765 */ 1766 static void clipConvertX11CB(void *pClient Data, void *pvSrc, unsigned cbSrc)1767 { 1768 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pClient Data;1766 static void clipConvertX11CB(void *pClient, void *pvSrc, unsigned cbSrc) 1767 { 1768 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pClient; 1769 1769 LogRelFlowFunc(("pReq->mFormat=%02X, pReq->mTextFormat=%u, " 1770 1770 "pReq->mBitmapFormat=%u, pReq->mHtmlFormat=%u, pReq->mCtx=%p\n", … … 1909 1909 * the X11 clipboard contains a format we understand. 1910 1910 */ 1911 static void cbConvertX11CB(Widget widget, XtPointer pClient Data,1911 static void cbConvertX11CB(Widget widget, XtPointer pClient, 1912 1912 Atom * /* selection */, Atom *atomType, 1913 1913 XtPointer pvSrc, long unsigned int *pcLen, … … 1916 1916 RT_NOREF1(widget); 1917 1917 if (*atomType == XT_CONVERT_FAIL) /* Xt timeout */ 1918 clipConvertX11CB(pClient Data, NULL, 0);1918 clipConvertX11CB(pClient, NULL, 0); 1919 1919 else 1920 clipConvertX11CB(pClient Data, pvSrc, (*pcLen) * (*piFormat) / 8);1920 clipConvertX11CB(pClient, pvSrc, (*pcLen) * (*piFormat) / 8); 1921 1921 1922 1922 XtFree((char *)pvSrc);
Note:
See TracChangeset
for help on using the changeset viewer.