Changeset 74211 in vbox
- Timestamp:
- Sep 12, 2018 9:52:38 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 124988
- Location:
- trunk/src/VBox/HostServices/DragAndDrop
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp
r69500 r74211 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 39 39 *********************************************************************************************************************************/ 40 40 41 int DnDManager::addMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fAppend /* = true */) 41 /** 42 * Adds a DnD message to the manager's queue. 43 * 44 * @returns IPRT status code. 45 * @param pMsg Pointer to DnD message to add. The queue then owns the pointer. 46 * @param fAppend Whether to append or prepend the message to the queue. 47 */ 48 int DnDManager::AddMsg(DnDMessage *pMsg, bool fAppend /* = true */) 49 { 50 AssertPtrReturn(pMsg, VERR_INVALID_POINTER); 51 52 LogFlowFunc(("uMsg=%RU32, cParms=%RU32, fAppend=%RTbool\n", pMsg->GetType(), pMsg->GetParamCount(), fAppend)); 53 54 if (fAppend) 55 m_queueMsg.append(pMsg); 56 else 57 m_queueMsg.prepend(pMsg); 58 59 /** @todo Catch / handle OOM? */ 60 61 return VINF_SUCCESS; 62 } 63 64 /** 65 * Adds a DnD message to the manager's queue. 66 * 67 * @returns IPRT status code. 68 * @param pMsg Pointer to DnD message to add. The queue then owns the pointer. 69 * @param fAppend Whether to append or prepend the message to the queue. 70 */ 71 int DnDManager::AddMsg(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fAppend /* = true */) 42 72 { 43 73 int rc; … … 45 75 try 46 76 { 47 LogFlowFunc(("uMsg=%RU32, cParms=%RU32, fAppend=%RTbool\n", uMsg, cParms, fAppend)); 48 49 DnDMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms); 50 if (fAppend) 51 m_dndMessageQueue.append(pMessage); 52 else 53 m_dndMessageQueue.prepend(pMessage); 54 55 rc = VINF_SUCCESS; 77 DnDMessage *pMsg = new DnDGenericMessage(uMsg, cParms, paParms); 78 rc = AddMsg(pMsg, fAppend); 56 79 } 57 80 catch(std::bad_alloc &) … … 64 87 } 65 88 66 HGCM::Message* DnDManager::nextHGCMMessage(void) 67 { 68 if (m_pCurMsg) 69 return m_pCurMsg->nextHGCMMessage(); 70 71 if (m_dndMessageQueue.isEmpty()) 72 return NULL; 73 74 return m_dndMessageQueue.first()->nextHGCMMessage(); 75 } 76 77 int DnDManager::nextMessageInfo(uint32_t *puMsg, uint32_t *pcParms) 78 { 79 AssertPtrReturn(puMsg, VERR_INVALID_POINTER); 89 /** 90 * Retrieves information about the next message in the queue. 91 * 92 * @returns IPRT status code. VERR_NO_DATA if no next message is available. 93 * @param puType Where to store the message type. 94 * @param pcParms Where to store the message parameter count. 95 */ 96 int DnDManager::GetNextMsgInfo(uint32_t *puType, uint32_t *pcParms) 97 { 98 AssertPtrReturn(puType, VERR_INVALID_POINTER); 80 99 AssertPtrReturn(pcParms, VERR_INVALID_POINTER); 81 100 82 101 int rc; 83 if (m_pCurMsg) 84 rc = m_pCurMsg->currentMessageInfo(puMsg, pcParms); 102 103 if (m_queueMsg.isEmpty()) 104 { 105 rc = VERR_NO_DATA; 106 } 85 107 else 86 108 { 87 if (m_dndMessageQueue.isEmpty()) 88 rc = VERR_NO_DATA; 89 else 90 rc = m_dndMessageQueue.first()->currentMessageInfo(puMsg, pcParms); 91 } 92 93 LogFlowFunc(("Returning puMsg=%RU32, pcParms=%RU32, rc=%Rrc\n", *puMsg, *pcParms, rc)); 109 DnDMessage *pMsg = m_queueMsg.first(); 110 AssertPtr(pMsg); 111 112 *puType = pMsg->GetType(); 113 *pcParms = pMsg->GetParamCount(); 114 115 rc = VINF_SUCCESS; 116 } 117 118 LogFlowFunc(("Returning puMsg=%RU32, pcParms=%RU32, rc=%Rrc\n", *puType, *pcParms, rc)); 94 119 return rc; 95 120 } 96 121 97 int DnDManager::nextMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) 122 /** 123 * Retrieves the next queued up message and removes it from the queue on success. 124 * Will return VERR_NO_DATA if no next message is available. 125 * 126 * @returns IPRT status code. 127 * @param uMsg Message type to retrieve. 128 * @param cParms Number of parameters the \@a paParms array can store. 129 * @param paParms Where to store the message parameters. 130 */ 131 int DnDManager::GetNextMsg(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) 98 132 { 99 133 LogFlowFunc(("uMsg=%RU32, cParms=%RU32\n", uMsg, cParms)); 100 134 101 if (!m_pCurMsg) 102 { 103 /* Check for pending messages in our queue. */ 104 if (m_dndMessageQueue.isEmpty()) 105 return VERR_NO_DATA; 106 107 m_pCurMsg = m_dndMessageQueue.first(); 108 AssertPtr(m_pCurMsg); 109 m_dndMessageQueue.removeFirst(); 110 } 111 112 /* Fetch the current message info */ 113 int rc = m_pCurMsg->currentMessage(uMsg, cParms, paParms); 114 /* If this message doesn't provide any additional sub messages, clear it. */ 115 if (!m_pCurMsg->isMessageWaiting()) 116 { 117 delete m_pCurMsg; 118 m_pCurMsg = NULL; 119 } 135 /* Check for pending messages in our queue. */ 136 if (m_queueMsg.isEmpty()) 137 return VERR_NO_DATA; 138 139 /* Get the current message. */ 140 DnDMessage *pMsg = m_queueMsg.first(); 141 AssertPtr(pMsg); 142 143 m_queueMsg.removeFirst(); /* Remove the current message from the queue. */ 144 145 /* Fetch the current message info. */ 146 int rc = pMsg->GetData(uMsg, cParms, paParms); 120 147 121 148 /* … … 127 154 { 128 155 /* Clear any pending messages. */ 129 clear();156 Reset(); 130 157 131 158 /* Create a new cancel message to inform the guest + call … … 137 164 LogFlowFunc(("Operation was cancelled\n")); 138 165 139 Assert(!m_pCurMsg); 140 m_pCurMsg = new DnDHGCancelMessage(); 166 DnDHGCancelMessage *pMsgCancel = new DnDHGCancelMessage(); 167 168 int rc2 = AddMsg(pMsgCancel, false /* Prepend */); 169 AssertRC(rc2); 141 170 142 171 if (m_pfnProgressCallback) … … 160 189 } 161 190 162 void DnDManager::clear(void) 191 /** 192 * Resets the manager by clearing the message queue and internal state. 193 */ 194 void DnDManager::Reset(void) 163 195 { 164 196 LogFlowFuncEnter(); 165 197 166 if (m_pCurMsg) 167 { 168 delete m_pCurMsg; 169 m_pCurMsg = NULL; 170 } 171 172 while (!m_dndMessageQueue.isEmpty()) 173 { 174 delete m_dndMessageQueue.last(); 175 m_dndMessageQueue.removeLast(); 176 } 177 } 178 179 /** 180 * Triggers a rescheduling of the manager's message queue by setting the first 181 * message available in the queue as the current one to process. 182 * 183 * @return IPRT status code. VERR_NO_DATA if not message to process is available at 184 * the time of calling. 185 */ 186 int DnDManager::doReschedule(void) 187 { 188 LogFlowFunc(("Rescheduling ...\n")); 189 190 if (!m_dndMessageQueue.isEmpty()) 191 { 192 m_pCurMsg = m_dndMessageQueue.first(); 193 m_dndMessageQueue.removeFirst(); 194 195 return VINF_SUCCESS; 196 } 197 198 return VERR_NO_DATA; 199 } 200 198 while (!m_queueMsg.isEmpty()) 199 { 200 delete m_queueMsg.last(); 201 m_queueMsg.removeLast(); 202 } 203 } 204 -
trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h
r73939 r74211 4 4 5 5 /* 6 * Copyright (C) 2011-201 7Oracle Corporation6 * Copyright (C) 2011-2018 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 * message classes. 33 33 */ 34 class DnDMessage 34 class DnDMessage : public HGCM::Message 35 35 { 36 36 public: 37 37 38 38 DnDMessage(void) 39 : m_pNextMsg(NULL)40 39 { 41 40 } 42 41 43 virtual ~DnDMessage(void) 44 { 45 clearNextMsg(); 46 } 42 DnDMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) 43 : Message(uMsg, cParms, aParms) { } 47 44 48 virtual HGCM::Message* nextHGCMMessage(void) 49 { 50 return m_pNextMsg; 51 } 52 53 virtual int currentMessageInfo(uint32_t *puMsg, uint32_t *pcParms) 54 { 55 AssertPtrReturn(puMsg, VERR_INVALID_POINTER); 56 AssertPtrReturn(pcParms, VERR_INVALID_POINTER); 57 58 if (!m_pNextMsg) 59 return VERR_NO_DATA; 60 61 *puMsg = m_pNextMsg->GetType(); 62 *pcParms = m_pNextMsg->GetParamCount(); 63 64 return VINF_SUCCESS; 65 } 66 67 virtual int currentMessage(uint32_t uMsg, uint32_t cParms, 68 VBOXHGCMSVCPARM paParms[]) 69 { 70 if (!m_pNextMsg) 71 return VERR_NO_DATA; 72 int rc = m_pNextMsg->GetData(uMsg, cParms, paParms); 73 74 clearNextMsg(); 75 76 return rc; 77 } 78 79 virtual void clearNextMsg(void) 80 { 81 if (m_pNextMsg) 82 { 83 delete m_pNextMsg; 84 m_pNextMsg = NULL; 85 } 86 } 87 88 virtual bool isMessageWaiting(void) const { return m_pNextMsg != NULL; } 89 90 protected: 91 92 HGCM::Message *m_pNextMsg; 45 virtual ~DnDMessage(void) { } 93 46 }; 94 47 … … 101 54 public: 102 55 DnDGenericMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) 103 { 104 m_pNextMsg = new HGCM::Message(uMsg, cParms, paParms); 105 } 56 : DnDMessage(uMsg, cParms, paParms) { } 106 57 }; 107 58 … … 115 66 DnDHGCancelMessage(void) 116 67 { 117 m_pNextMsg118 = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_EVT_CANCEL,119 0 /* cParms */, 0 /* aParms */);68 int rc2 = initData(DragAndDropSvc::HOST_DND_HG_EVT_CANCEL, 69 0 /* cParms */, 0 /* aParms */); 70 AssertRC(rc2); 120 71 } 121 72 }; … … 130 81 131 82 DnDManager(PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser) 132 : m_pCurMsg(NULL) 133 , m_pfnProgressCallback(pfnProgressCallback) 83 : m_pfnProgressCallback(pfnProgressCallback) 134 84 , m_pvProgressUser(pvProgressUser) 135 85 {} … … 137 87 virtual ~DnDManager(void) 138 88 { 139 clear();89 Reset(); 140 90 } 141 91 142 int addMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fAppend = true); 92 int AddMsg(DnDMessage *pMessage, bool fAppend = true); 93 int AddMsg(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fAppend = true); 143 94 144 HGCM::Message *nextHGCMMessage(void); 145 int nextMessageInfo(uint32_t *puMsg, uint32_t *pcParms); 146 int nextMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]); 95 int GetNextMsgInfo(uint32_t *puType, uint32_t *pcParms); 96 int GetNextMsg(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]); 147 97 148 void clear(void); 149 int doReschedule(void); 98 void Reset(void); 150 99 151 private: 152 DnDMessage *m_pCurMsg; 153 RTCList<DnDMessage*> m_dndMessageQueue; 100 protected: 154 101 155 /* Progress stuff */ 102 /** DnD message queue (FIFO). */ 103 RTCList<DnDMessage *> m_queueMsg; 104 /** Pointer to host progress callback. Optional, can be NULL. */ 156 105 PFNDNDPROGRESS m_pfnProgressCallback; 106 /** Pointer to progress callback user context. Can be NULL if not used. */ 157 107 void *m_pvProgressUser; 158 108 }; -
trunk/src/VBox/HostServices/DragAndDrop/service.cpp
r74205 r74211 236 236 { 237 237 /* 238 * Clearthe message queue as soon as a new clients connect238 * Reset the message queue as soon as a new clients connect 239 239 * to ensure that every client has the same state. 240 240 */ 241 241 if (m_pManager) 242 m_pManager-> clear();242 m_pManager->Reset(); 243 243 } 244 244 } … … 429 429 if (cParms == 3) 430 430 { 431 rc = m_pManager-> nextMessageInfo(&paParms[0].u.uint32 /* uMsg */, &paParms[1].u.uint32 /* cParms */);431 rc = m_pManager->GetNextMsgInfo(&paParms[0].u.uint32 /* uMsg */, &paParms[1].u.uint32 /* cParms */); 432 432 if (RT_FAILURE(rc)) /* No queued messages available? */ 433 433 { … … 449 449 450 450 if (RT_FAILURE(rc)) 451 rc = m_pManager-> nextMessage(u32Function, cParms, paParms);451 rc = m_pManager->GetNextMsg(u32Function, cParms, paParms); 452 452 453 453 /* Some error occurred or no (new) messages available? */ … … 975 975 { 976 976 /* All other messages are handled by the DnD manager. */ 977 rc = m_pManager-> nextMessage(u32Function, cParms, paParms);977 rc = m_pManager->GetNextMsg(u32Function, cParms, paParms); 978 978 if (rc == VERR_NO_DATA) /* Manager has no new messsages? Try asking the host. */ 979 979 { … … 1072 1072 case HOST_DND_HG_EVT_ENTER: 1073 1073 { 1074 /* Clearthe message queue as a new DnD operation just began. */1075 m_pManager-> clear();1074 /* Reset the message queue as a new DnD operation just began. */ 1075 m_pManager->Reset(); 1076 1076 1077 1077 fSendToGuest = true; … … 1084 1084 LogFlowFunc(("Cancelling all waiting clients ...\n")); 1085 1085 1086 /* Clearthe message queue as the host cancelled the whole operation. */1087 m_pManager-> clear();1086 /* Reset the message queue as the host cancelled the whole operation. */ 1087 m_pManager->Reset(); 1088 1088 1089 1089 /* … … 1144 1144 } 1145 1145 1146 rc = m_pManager-> addMessage(u32Function, cParms, paParms, true /* fAppend */);1146 rc = m_pManager->AddMsg(u32Function, cParms, paParms, true /* fAppend */); 1147 1147 if (RT_FAILURE(rc)) 1148 1148 { … … 1174 1174 uint32_t uMsgNext = 0; 1175 1175 uint32_t cParmsNext = 0; 1176 int rcNext = m_pManager-> nextMessageInfo(&uMsgNext, &cParmsNext);1176 int rcNext = m_pManager->GetNextMsgInfo(&uMsgNext, &cParmsNext); 1177 1177 1178 1178 LogFlowFunc(("uMsgClient=%RU32, uMsgNext=%RU32, cParmsNext=%RU32, rcNext=%Rrc\n", … … 1194 1194 else if (uMsgClient == uMsgNext) 1195 1195 { 1196 rc = m_pManager-> nextMessage(u32Function, cParms, paParms);1196 rc = m_pManager->GetNextMsg(u32Function, cParms, paParms); 1197 1197 1198 1198 /* Note: Report the current rc back to the guest. */
Note:
See TracChangeset
for help on using the changeset viewer.