VirtualBox

Changeset 74211 in vbox


Ignore:
Timestamp:
Sep 12, 2018 9:52:38 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124988
Message:

DnD/HostService: Renaming, documentation.

Location:
trunk/src/VBox/HostServices/DragAndDrop
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp

    r69500 r74211  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3939*********************************************************************************************************************************/
    4040
    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 */
     48int 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 */
     71int DnDManager::AddMsg(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fAppend /* = true */)
    4272{
    4373    int rc;
     
    4575    try
    4676    {
    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);
    5679    }
    5780    catch(std::bad_alloc &)
     
    6487}
    6588
    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 */
     96int DnDManager::GetNextMsgInfo(uint32_t *puType, uint32_t *pcParms)
     97{
     98    AssertPtrReturn(puType, VERR_INVALID_POINTER);
    8099    AssertPtrReturn(pcParms, VERR_INVALID_POINTER);
    81100
    82101    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    }
    85107    else
    86108    {
    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));
    94119    return rc;
    95120}
    96121
    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 */
     131int DnDManager::GetNextMsg(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    98132{
    99133    LogFlowFunc(("uMsg=%RU32, cParms=%RU32\n", uMsg, cParms));
    100134
    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);
    120147
    121148    /*
     
    127154    {
    128155        /* Clear any pending messages. */
    129         clear();
     156        Reset();
    130157
    131158        /* Create a new cancel message to inform the guest + call
     
    137164                LogFlowFunc(("Operation was cancelled\n"));
    138165
    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);
    141170
    142171            if (m_pfnProgressCallback)
     
    160189}
    161190
    162 void DnDManager::clear(void)
     191/**
     192 * Resets the manager by clearing the message queue and internal state.
     193 */
     194void DnDManager::Reset(void)
    163195{
    164196    LogFlowFuncEnter();
    165197
    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  
    44
    55/*
    6  * Copyright (C) 2011-2017 Oracle Corporation
     6 * Copyright (C) 2011-2018 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232 * message classes.
    3333 */
    34 class DnDMessage
     34class DnDMessage : public HGCM::Message
    3535{
    3636public:
    3737
    3838    DnDMessage(void)
    39         : m_pNextMsg(NULL)
    4039    {
    4140    }
    4241
    43     virtual ~DnDMessage(void)
    44     {
    45         clearNextMsg();
    46     }
     42    DnDMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
     43        : Message(uMsg, cParms, aParms) { }
    4744
    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) { }
    9346};
    9447
     
    10154public:
    10255    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) { }
    10657};
    10758
     
    11566    DnDHGCancelMessage(void)
    11667    {
    117         m_pNextMsg
    118             = 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);
    12071    }
    12172};
     
    13081
    13182    DnDManager(PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser)
    132         : m_pCurMsg(NULL)
    133         , m_pfnProgressCallback(pfnProgressCallback)
     83        : m_pfnProgressCallback(pfnProgressCallback)
    13484        , m_pvProgressUser(pvProgressUser)
    13585    {}
     
    13787    virtual ~DnDManager(void)
    13888    {
    139         clear();
     89        Reset();
    14090    }
    14191
    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);
    14394
    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[]);
    14797
    148     void clear(void);
    149     int doReschedule(void);
     98    void Reset(void);
    15099
    151 private:
    152     DnDMessage           *m_pCurMsg;
    153     RTCList<DnDMessage*>  m_dndMessageQueue;
     100protected:
    154101
    155     /* Progress stuff */
     102    /** DnD message queue (FIFO). */
     103    RTCList<DnDMessage *> m_queueMsg;
     104    /** Pointer to host progress callback. Optional, can be NULL. */
    156105    PFNDNDPROGRESS        m_pfnProgressCallback;
     106    /** Pointer to progress callback user context. Can be NULL if not used. */
    157107    void                 *m_pvProgressUser;
    158108};
  • trunk/src/VBox/HostServices/DragAndDrop/service.cpp

    r74205 r74211  
    236236        {
    237237            /*
    238              * Clear the message queue as soon as a new clients connect
     238             * Reset the message queue as soon as a new clients connect
    239239             * to ensure that every client has the same state.
    240240             */
    241241            if (m_pManager)
    242                 m_pManager->clear();
     242                m_pManager->Reset();
    243243        }
    244244    }
     
    429429                if (cParms == 3)
    430430                {
    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 */);
    432432                    if (RT_FAILURE(rc)) /* No queued messages available? */
    433433                    {
     
    449449
    450450                        if (RT_FAILURE(rc))
    451                             rc = m_pManager->nextMessage(u32Function, cParms, paParms);
     451                            rc = m_pManager->GetNextMsg(u32Function, cParms, paParms);
    452452
    453453                        /* Some error occurred or no (new) messages available? */
     
    975975            {
    976976                /* 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);
    978978                if (rc == VERR_NO_DATA) /* Manager has no new messsages? Try asking the host. */
    979979                {
     
    10721072            case HOST_DND_HG_EVT_ENTER:
    10731073            {
    1074                 /* Clear the 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();
    10761076
    10771077                fSendToGuest = true;
     
    10841084                LogFlowFunc(("Cancelling all waiting clients ...\n"));
    10851085
    1086                 /* Clear the 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();
    10881088
    10891089                /*
     
    11441144            }
    11451145
    1146             rc = m_pManager->addMessage(u32Function, cParms, paParms, true /* fAppend */);
     1146            rc = m_pManager->AddMsg(u32Function, cParms, paParms, true /* fAppend */);
    11471147            if (RT_FAILURE(rc))
    11481148            {
     
    11741174            uint32_t uMsgNext   = 0;
    11751175            uint32_t cParmsNext = 0;
    1176             int rcNext = m_pManager->nextMessageInfo(&uMsgNext, &cParmsNext);
     1176            int rcNext = m_pManager->GetNextMsgInfo(&uMsgNext, &cParmsNext);
    11771177
    11781178            LogFlowFunc(("uMsgClient=%RU32, uMsgNext=%RU32, cParmsNext=%RU32, rcNext=%Rrc\n",
     
    11941194                else if (uMsgClient == uMsgNext)
    11951195                {
    1196                     rc = m_pManager->nextMessage(u32Function, cParms, paParms);
     1196                    rc = m_pManager->GetNextMsg(u32Function, cParms, paParms);
    11971197
    11981198                    /* Note: Report the current rc back to the guest. */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette