Changeset 80468 in vbox for trunk/src/VBox
- Timestamp:
- Aug 28, 2019 9:57:23 AM (5 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp
r80459 r80468 24 24 #include <iprt/semaphore.h> 25 25 #include <iprt/path.h> 26 #include <iprt/rand.h> 26 27 27 28 #include <iprt/errcore.h> … … 35 36 * 36 37 * @returns VBox status code. 37 * @param uID Event ID to associate payload to.38 * @param uID Payload ID to set for this payload. Useful for consequtive payloads. 38 39 * @param pvData Data block to associate to this payload. 39 40 * @param cbData Size (in bytes) of data block to associate. … … 97 98 * @returns VBox status code. 98 99 * @param pEvent Event to initialize. 99 * @param uID ID to use for the event.100 */ 101 int SharedClipboardEventCreate(PSHAREDCLIPBOARDEVENT pEvent, uint16_tuID)100 * @param uID Event ID to use. 101 */ 102 int SharedClipboardEventCreate(PSHAREDCLIPBOARDEVENT pEvent, VBOXCLIPBOARDEVENTID uID) 102 103 { 103 104 AssertPtrReturn(pEvent, VERR_INVALID_POINTER); … … 145 146 * @param uID ID to use for event source. 146 147 */ 147 int SharedClipboardEventSourceCreate(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID)148 int SharedClipboardEventSourceCreate(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTSOURCEID uID) 148 149 { 149 150 AssertPtrReturn(pSource, VERR_INVALID_POINTER); … … 156 157 157 158 pSource->uID = uID; 158 pSource->uEventIDNext = 1; /* Event ID 0 always is reserved (marks "unused"). */ 159 /* Choose a random event ID starting point. */ 160 pSource->uEventIDNext = RTRandU32() % VBOX_SHARED_CLIPBOARD_MAX_EVENTS; 159 161 160 162 LogFlowFuncLeaveRC(rc); … … 189 191 * @param pSource Event source to generate event for. 190 192 */ 191 uint16_tSharedClipboardEventIDGenerate(PSHAREDCLIPBOARDEVENTSOURCE pSource)193 VBOXCLIPBOARDEVENTID SharedClipboardEventIDGenerate(PSHAREDCLIPBOARDEVENTSOURCE pSource) 192 194 { 193 195 AssertPtrReturn(pSource, 0); 194 196 195 197 LogFlowFunc(("uSource=%RU16: New event: %RU16\n", pSource->uID, pSource->uEventIDNext)); 196 return pSource->uEventIDNext++; /** @todo Improve this.*/198 return pSource->uEventIDNext++; /** @todo Handle rollovers? */ 197 199 } 198 200 … … 204 206 * @param uID Event ID to get. 205 207 */ 206 inline PSHAREDCLIPBOARDEVENT sharedClipboardEventGet(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID)208 inline PSHAREDCLIPBOARDEVENT sharedClipboardEventGet(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTID uID) 207 209 { 208 210 PSHAREDCLIPBOARDEVENT pEvIt; … … 223 225 * @param uID Event ID to register. 224 226 */ 225 int SharedClipboardEventRegister(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID)227 int SharedClipboardEventRegister(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTID uID) 226 228 { 227 229 AssertPtrReturn(pSource, VERR_INVALID_POINTER); … … 266 268 * @param uID Event ID to unregister. 267 269 */ 268 int SharedClipboardEventUnregister(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID)270 int SharedClipboardEventUnregister(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTID uID) 269 271 { 270 272 AssertPtrReturn(pSource, VERR_INVALID_POINTER); … … 305 307 * SharedClipboardPayloadFree(). 306 308 */ 307 int SharedClipboardEventWait(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID, RTMSINTERVAL uTimeoutMs,309 int SharedClipboardEventWait(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTID uID, RTMSINTERVAL uTimeoutMs, 308 310 PSHAREDCLIPBOARDEVENTPAYLOAD* ppPayload) 309 311 { … … 340 342 * @param pPayload Event payload to associate. Takes ownership. Optional. 341 343 */ 342 int SharedClipboardEventSignal(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID,344 int SharedClipboardEventSignal(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTID uID, 343 345 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload) 344 346 { … … 376 378 * @param uID Event ID to detach payload for. 377 379 */ 378 void SharedClipboardEventPayloadDetach(PSHAREDCLIPBOARDEVENTSOURCE pSource, uint16_tuID)380 void SharedClipboardEventPayloadDetach(PSHAREDCLIPBOARDEVENTSOURCE pSource, VBOXCLIPBOARDEVENTID uID) 379 381 { 380 382 AssertPtrReturnVoid(pSource); -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-internal.h
r80444 r80468 181 181 } VBOXCLIPBOARDCLIENT, *PVBOXCLIPBOARDCLIENT; 182 182 183 /** 184 * Structure for keeping a single (HGCM) client map entry. 185 * Currently empty. 186 */ 183 187 typedef struct _VBOXCLIPBOARDCLIENTMAPENTRY 184 188 { 185 189 } VBOXCLIPBOARDCLIENTMAPENTRY; 186 190 187 /** Map holding pointers to drag and drop clients. Key is the (unique) HGCM client ID. */ 191 /** 192 * Structure for keeping a single event source map entry. 193 * Currently empty. 194 */ 195 typedef struct _VBOXCLIPBOARDEVENTSOURCEMAPENTRY 196 { 197 } VBOXCLIPBOARDEVENTSOURCEMAPENTRY; 198 199 /** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID. */ 188 200 typedef std::map<uint32_t, VBOXCLIPBOARDCLIENTMAPENTRY> ClipboardClientMap; 201 202 /** Map holding information about event sources. Key is the (unique) event source ID. */ 203 typedef std::map<VBOXCLIPBOARDEVENTSOURCEID, VBOXCLIPBOARDEVENTSOURCEMAPENTRY> ClipboardEventSourceMap; 189 204 190 205 /** Simple queue (list) which holds deferred (waiting) clients. */ -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-uri.cpp
r80444 r80468 89 89 if (pMsgHdr) 90 90 { 91 uint16_t uEventHdrRead= SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);92 93 HGCMSvcSetU32(&pMsgHdr->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent HdrRead));91 VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 92 93 HGCMSvcSetU32(&pMsgHdr->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); 94 94 HGCMSvcSetU32(&pMsgHdr->m_paParms[1], 0 /* fRoots */); 95 95 … … 97 97 if (RT_SUCCESS(rc)) 98 98 { 99 int rc2 = SharedClipboardEventRegister(&pCtx->pTransfer->Events, uEvent HdrRead);99 int rc2 = SharedClipboardEventRegister(&pCtx->pTransfer->Events, uEvent); 100 100 AssertRC(rc2); 101 101 … … 104 104 { 105 105 PSHAREDCLIPBOARDEVENTPAYLOAD pPayloadHdr; 106 rc = SharedClipboardEventWait(&pCtx->pTransfer->Events, uEvent HdrRead,106 rc = SharedClipboardEventWait(&pCtx->pTransfer->Events, uEvent, 107 107 pCtx->pTransfer->uTimeoutMs, &pPayloadHdr); 108 108 if (RT_SUCCESS(rc)) … … 128 128 VBOX_SHARED_CLIPBOARD_CPARMS_ROOT_LIST_ENTRY_READ_REQ); 129 129 130 u int16_t uEventEntryRead= SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);130 uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 131 131 132 132 HGCMSvcSetU32(&pMsgEntry->m_paParms[0], 133 VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent EntryRead));133 VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); 134 134 HGCMSvcSetU32(&pMsgEntry->m_paParms[1], 0 /* fRoots */); 135 135 HGCMSvcSetU32(&pMsgEntry->m_paParms[2], i /* uIndex */); 136 136 137 rc2 = SharedClipboardEventRegister(&pCtx->pTransfer->Events, uEvent EntryRead);137 rc2 = SharedClipboardEventRegister(&pCtx->pTransfer->Events, uEvent); 138 138 AssertRC(rc2); 139 139 … … 143 143 144 144 PSHAREDCLIPBOARDEVENTPAYLOAD pPayloadEntry; 145 rc = SharedClipboardEventWait(&pCtx->pTransfer->Events, uEvent EntryRead,145 rc = SharedClipboardEventWait(&pCtx->pTransfer->Events, uEvent, 146 146 pCtx->pTransfer->uTimeoutMs, &pPayloadEntry); 147 147 if (RT_FAILURE(rc)) … … 155 155 SharedClipboardPayloadFree(pPayloadEntry); 156 156 157 SharedClipboardEventUnregister(&pCtx->pTransfer->Events, uEvent EntryRead);157 SharedClipboardEventUnregister(&pCtx->pTransfer->Events, uEvent); 158 158 159 159 if (RT_FAILURE(rc)) … … 182 182 } 183 183 184 SharedClipboardEventUnregister(&pCtx->pTransfer->Events, uEvent HdrRead);184 SharedClipboardEventUnregister(&pCtx->pTransfer->Events, uEvent); 185 185 } 186 186 } … … 206 206 if (pMsg) 207 207 { 208 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);208 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 209 209 210 210 pMsg->m_Ctx.uContextID = VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent); … … 263 263 if (pMsg) 264 264 { 265 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);265 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 266 266 267 267 pMsg->m_Ctx.uContextID = VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent); … … 310 310 if (pMsg) 311 311 { 312 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);312 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 313 313 314 314 HGCMSvcSetU32(&pMsg->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); … … 370 370 if (pMsg) 371 371 { 372 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);372 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 373 373 374 374 HGCMSvcSetU32(&pMsg->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); … … 429 429 if (pMsg) 430 430 { 431 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);431 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 432 432 433 433 LogFlowFunc(("pszPath=%s, fCreate=0x%x\n", pCreateParms->pszPath, pCreateParms->fCreate)); … … 488 488 if (pMsg) 489 489 { 490 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);490 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 491 491 492 492 HGCMSvcSetU32(&pMsg->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); … … 541 541 if (pMsg) 542 542 { 543 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);543 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 544 544 545 545 HGCMSvcSetU32(&pMsg->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); … … 599 599 if (pMsg) 600 600 { 601 const uint16_tuEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events);601 const VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pCtx->pTransfer->Events); 602 602 603 603 HGCMSvcSetU32(&pMsg->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pCtx->pTransfer->State.uID, uEvent)); … … 1181 1181 if (RT_SUCCESS(rc)) 1182 1182 { 1183 const uint16_tuEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID);1183 const VBOXCLIPBOARDEVENTID uEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID); 1184 1184 1185 1185 LogFlowFunc(("uCID=%RU32 -> uEvent=%RU32\n", uCID, uEvent)); … … 1422 1422 if (RT_SUCCESS(rc)) 1423 1423 { 1424 const uint16_tuEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID);1424 const VBOXCLIPBOARDEVENTID uEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID); 1425 1425 1426 1426 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload; … … 1471 1471 if (RT_SUCCESS(rc)) 1472 1472 { 1473 const uint16_tuEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID);1473 const VBOXCLIPBOARDEVENTID uEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID); 1474 1474 1475 1475 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload; … … 1551 1551 if (RT_SUCCESS(rc)) 1552 1552 { 1553 const uint16_tuEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID);1553 const VBOXCLIPBOARDEVENTID uEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID); 1554 1554 1555 1555 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload; … … 1599 1599 if (RT_SUCCESS(rc)) 1600 1600 { 1601 const uint16_tuEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID);1601 const VBOXCLIPBOARDEVENTID uEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID); 1602 1602 1603 1603 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload; … … 1645 1645 if (RT_SUCCESS(rc)) 1646 1646 { 1647 const uint16_tuEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID);1647 const VBOXCLIPBOARDEVENTID uEvent = VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uCID); 1648 1648 1649 1649 PSHAREDCLIPBOARDEVENTPAYLOAD pPayload; -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp
r80444 r80468 186 186 #include <iprt/assert.h> 187 187 #include <iprt/critsect.h> 188 #include <iprt/rand.h> 188 189 189 190 #include <VBox/err.h> … … 228 229 ClipboardClientMap g_mapClients; 229 230 231 /** Global map of all registered event sources. */ 232 ClipboardEventSourceMap g_mapEventSources; 233 230 234 /** Global list of all clients which are queued up (deferred return) and ready 231 235 * to process new commands. The key is the (unique) client ID. */ 232 236 ClipboardClientQueue g_listClientsDeferred; 233 237 238 239 /** 240 * Creates a (unique) event source ID. 241 * 242 * @returns VBox status code, or VERR_NOT_FOUND on error. 243 * @param puID Where to store the created event source ID on success. 244 */ 245 int vboxSvcClipboardEventSourceCreateID(PVBOXCLIPBOARDEVENTSOURCEID puID) 246 { 247 AssertPtrReturn(puID, VERR_INVALID_POINTER); 248 249 for (uint32_t i = 0; i < 32; i++) /* Don't try too hard. */ 250 { 251 VBOXCLIPBOARDEVENTSOURCEID uID = RTRandU32() % VBOX_SHARED_CLIPBOARD_MAX_EVENT_SOURCES; 252 if (g_mapEventSources.find(uID) == g_mapEventSources.end()) 253 { 254 *puID = uID; 255 return VINF_SUCCESS; 256 } 257 } 258 259 return VERR_NOT_FOUND; 260 } 234 261 235 262 uint32_t vboxSvcClipboardGetMode(void) … … 738 765 if (pMsg) 739 766 { 740 uint16_tuEvent = SharedClipboardEventIDGenerate(&pClient->Events);767 VBOXCLIPBOARDEVENTID uEvent = SharedClipboardEventIDGenerate(&pClient->Events); 741 768 742 769 HGCMSvcSetU32(&pMsg->m_paParms[0], VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(pClient->Events.uID, uEvent)); … … 1035 1062 RT_NOREF(fRequestor, fRestoring); 1036 1063 1037 int rc = VINF_SUCCESS;1038 1039 1064 PVBOXCLIPBOARDCLIENT pClient = (PVBOXCLIPBOARDCLIENT)pvClient; 1040 1065 AssertPtr(pvClient); … … 1044 1069 1045 1070 /* Create the client's own event source. */ 1046 SharedClipboardEventSourceCreate(&pClient->Events, (uint16_t)g_mapClients.size()); 1047 1048 LogFlowFunc(("[Client %RU32] Using event source %RU32\n", u32ClientID, pClient->Events.uID)); 1049 1050 /* Reset the client state. */ 1051 vboxSvcClipboardClientStateReset(&pClient->State); 1052 1053 /* (Re-)initialize the client state. */ 1054 vboxSvcClipboardClientStateInit(&pClient->State, u32ClientID); 1055 1056 rc = VBoxClipboardSvcImplConnect(pClient, VBoxSvcClipboardGetHeadless()); 1071 VBOXCLIPBOARDEVENTSOURCEID uEventSourceID; 1072 int rc = vboxSvcClipboardEventSourceCreateID(&uEventSourceID); 1073 if (RT_SUCCESS(rc)) 1074 rc = SharedClipboardEventSourceCreate(&pClient->Events, uEventSourceID); 1075 if (RT_SUCCESS(rc)) 1076 { 1077 LogFlowFunc(("[Client %RU32] Using event source %RU32\n", u32ClientID, pClient->Events.uID)); 1078 1079 /* Reset the client state. */ 1080 vboxSvcClipboardClientStateReset(&pClient->State); 1081 1082 /* (Re-)initialize the client state. */ 1083 rc = vboxSvcClipboardClientStateInit(&pClient->State, u32ClientID); 1084 if (RT_SUCCESS(rc)) 1085 { 1086 rc = VBoxClipboardSvcImplConnect(pClient, VBoxSvcClipboardGetHeadless()); 1057 1087 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 1058 if (RT_SUCCESS(rc))1059 rc = SharedClipboardURICtxInit(&pClient->URI);1088 if (RT_SUCCESS(rc)) 1089 rc = SharedClipboardURICtxInit(&pClient->URI); 1060 1090 #endif 1061 1062 if (RT_SUCCESS(rc)) 1063 { 1064 VBOXCLIPBOARDCLIENTMAPENTRY ClientEntry; 1065 RT_ZERO(ClientEntry); 1066 1067 g_mapClients[u32ClientID] = ClientEntry; /** @todo Handle OOM / collisions? */ 1091 if (RT_SUCCESS(rc)) 1092 { 1093 VBOXCLIPBOARDCLIENTMAPENTRY ClientEntry; 1094 RT_ZERO(ClientEntry); 1095 1096 g_mapClients[u32ClientID] = ClientEntry; /** @todo Handle OOM / collisions? */ 1097 } 1098 } 1068 1099 } 1069 1100
Note:
See TracChangeset
for help on using the changeset viewer.