VirtualBox

Changeset 85318 in vbox


Ignore:
Timestamp:
Jul 13, 2020 9:07:41 PM (4 years ago)
Author:
vboxsync
Message:

HostServices: Clang 11++ adjustments. Eliminated pointless auto_ptr. Added a whole bunch of RT_NOEXCEPT to the DnD service abstraction. Misc cleanups. bugref:9790

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HostServices/Service.h

    r85121 r85318  
    3030#endif
    3131
    32 #include <memory>  /* for auto_ptr */
    33 
    3432#include <VBox/log.h>
    3533#include <VBox/hgcmsvc.h>
     
    3937#include <iprt/cpp/utils.h>
    4038
     39#include <new>
     40
    4141
    4242namespace HGCM
     
    5050    /** HGCM helper functions. */
    5151    PVBOXHGCMSVCHELPERS pHelpers;
    52     /*
     52    /**
    5353     * Callback function supplied by the host for notification of updates
    5454     * to properties.
     
    6565{
    6666public:
    67 
    6867    Message(void);
    69 
    7068    Message(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]);
    71 
    7269    virtual ~Message(void);
    7370
    74     uint32_t GetParamCount(void) const;
    75 
    76     int GetData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) const;
    77 
    78     int GetParmU32(uint32_t uParm, uint32_t *pu32Info) const;
    79 
    80     int GetParmU64(uint32_t uParm, uint64_t *pu64Info) const;
    81 
    82     int GetParmPtr(uint32_t uParm, void **ppvAddr, uint32_t *pcbSize) const;
    83 
    84     uint32_t GetType(void) const;
    85 
    86 public:
    87 
    88     static int CopyParms(PVBOXHGCMSVCPARM paParmsDst, uint32_t cParmsDst,
    89                          PVBOXHGCMSVCPARM paParmsSrc, uint32_t cParmsSrc,
    90                          bool fDeepCopy);
    91 
    92 protected:
    93 
    94     int initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]);
    95 
    96     void reset();
     71    uint32_t    GetParamCount(void) const RT_NOEXCEPT;
     72    int         GetData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) const RT_NOEXCEPT;
     73    int         GetParmU32(uint32_t uParm, uint32_t *pu32Info) const RT_NOEXCEPT;
     74    int         GetParmU64(uint32_t uParm, uint64_t *pu64Info) const RT_NOEXCEPT;
     75    int         GetParmPtr(uint32_t uParm, void **ppvAddr, uint32_t *pcbSize) const RT_NOEXCEPT;
     76    uint32_t    GetType(void) const RT_NOEXCEPT;
     77
     78public:
     79    static int  CopyParms(PVBOXHGCMSVCPARM paParmsDst, uint32_t cParmsDst,
     80                          PVBOXHGCMSVCPARM paParmsSrc, uint32_t cParmsSrc,
     81                          bool fDeepCopy) RT_NOEXCEPT;
     82
     83protected:
     84    int         initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) RT_NOEXCEPT;
     85    void        reset() RT_NOEXCEPT;
    9786
    9887protected:
     
    112101{
    113102public:
    114 
    115     Client(uint32_t uClientID);
    116 
     103    Client(uint32_t idClient);
    117104    virtual ~Client(void);
    118105
    119106public:
    120 
    121     int Complete(VBOXHGCMCALLHANDLE hHandle, int rcOp = VINF_SUCCESS);
    122 
    123     int CompleteDeferred(int rcOp = VINF_SUCCESS);
    124 
    125     uint32_t GetClientID(void) const;
    126 
    127     VBOXHGCMCALLHANDLE GetHandle(void) const;
    128 
    129     uint32_t GetMsgType(void) const;
    130 
    131     uint32_t GetMsgParamCount(void) const;
    132 
    133     uint32_t GetProtocolVer(void) const;
    134 
    135     bool IsDeferred(void) const;
    136 
    137     void SetDeferred(VBOXHGCMCALLHANDLE hHandle, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    138 
    139     void SetProtocolVer(uint32_t uVersion);
    140 
    141     void SetSvcContext(const VBOXHGCMSVCTX &SvcCtx);
    142 
    143 public:
    144 
    145     int SetDeferredMsgInfo(uint32_t uMsg, uint32_t cParms);
    146 
    147     int SetDeferredMsgInfo(const Message *pMessage);
    148 
    149 protected:
    150 
    151     int completeInternal(VBOXHGCMCALLHANDLE hHandle, int rcOp);
    152 
    153     void reset(void);
    154 
    155 protected:
    156 
     107    int         Complete(VBOXHGCMCALLHANDLE hHandle, int rcOp = VINF_SUCCESS) RT_NOEXCEPT;
     108    int         CompleteDeferred(int rcOp = VINF_SUCCESS) RT_NOEXCEPT;
     109    uint32_t    GetClientID(void) const RT_NOEXCEPT;
     110    VBOXHGCMCALLHANDLE GetHandle(void) const RT_NOEXCEPT;
     111    uint32_t    GetMsgType(void) const RT_NOEXCEPT;
     112    uint32_t    GetMsgParamCount(void) const RT_NOEXCEPT;
     113    uint32_t    GetProtocolVer(void) const RT_NOEXCEPT;
     114    bool        IsDeferred(void) const RT_NOEXCEPT;
     115    void        SetDeferred(VBOXHGCMCALLHANDLE hHandle, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT;
     116    void        SetProtocolVer(uint32_t uVersion) RT_NOEXCEPT;
     117    void        SetSvcContext(const VBOXHGCMSVCTX &SvcCtx) RT_NOEXCEPT;
     118
     119public:
     120    int         SetDeferredMsgInfo(uint32_t uMsg, uint32_t cParms) RT_NOEXCEPT;
     121    int         SetDeferredMsgInfo(const Message *pMessage) RT_NOEXCEPT;
     122
     123protected:
     124    int         completeInternal(VBOXHGCMCALLHANDLE hHandle, int rcOp) RT_NOEXCEPT;
     125    void        reset(void) RT_NOEXCEPT;
     126
     127protected:
    157128    /** The client's HGCM client ID. */
    158     uint32_t           m_uClientID;
    159     /** Optional protocol version the client uses. Set to 0 by default. */
     129    uint32_t           m_idClient;
     130    /** Optional protocol version the client uses. Set to 0 by default.
     131     * @todo r=bird: This does not belong here.  Whether a service has a "protocol
     132     * version" isn't given and I've argued that it's an inflexible bad idea. */
    160133    uint32_t           m_uProtocolVer;
    161134    /** The HGCM service context this client is bound to. */
     
    172145        /** The client's HGCM call handle. Needed for completing a deferred call. */
    173146        VBOXHGCMCALLHANDLE hHandle;
    174         /** Message type (function number) to use when completing the deferred call. */
     147        /** Message type (function number) to use when completing the deferred call.
     148         * @todo r=bird: uType or uMsg? Make up your mind (Message::m_uMsg).  */
    175149        uint32_t           uType;
    176150        /** Parameter count to use when completing the deferred call. */
     
    204178            else
    205179            {
    206                 RT_GCC_NO_WARN_DEPRECATED_BEGIN
    207                 std::auto_ptr<AbstractService> apService;
    208                 /* No exceptions may propagate outside. */
    209                 try
    210                 {
    211                     apService = std::auto_ptr<AbstractService>(new T(pTable->pHelpers));
    212                 } catch (int rcThrown)
    213                 {
    214                     rc = rcThrown;
    215                 } catch (...)
    216                 {
    217                     rc = VERR_UNRESOLVED_ERROR;
    218                 }
    219                 RT_GCC_NO_WARN_DEPRECATED_END
     180                AbstractService *pService = NULL;
     181                /* No exceptions may propagate outside (callbacks like this one are nothrow/noexcept). */
     182                try { pService = new T(pTable->pHelpers); }
     183                catch (std::bad_alloc &) { rc = VERR_NO_MEMORY; }
     184                catch (...)              { rc = VERR_UNEXPECTED_EXCEPTION; }
    220185                if (RT_SUCCESS(rc))
    221186                {
    222                     /*
    223                      * We don't need an additional client data area on the host,
    224                      * because we're a class which can have members for that :-).
    225                      */
    226                     pTable->cbClient = 0;
     187                    /* We don't need an additional client data area on the host,
     188                       because we're a class which can have members for that :-). */
     189                    pTable->cbClient              = 0;
    227190
    228191                    /* These functions are mandatory */
     
    238201
    239202                    /* Let the service itself initialize. */
    240                     rc = apService->init(pTable);
    241 
    242                     /* Only on success stop the auto release of the auto_ptr. */
     203                    rc = pService->init(pTable);
    243204                    if (RT_SUCCESS(rc))
    244                         pTable->pvService = apService.release();
     205                        pTable->pvService = pService;
     206                    else
     207                        delete pService;
    245208                }
    246209            }
     
    258221        m_SvcCtx.pHelpers = pHelpers;
    259222    }
    260     virtual int  init(VBOXHGCMSVCFNTABLE *ptable) { RT_NOREF1(ptable); return VINF_SUCCESS; }
    261     virtual int  uninit() { return VINF_SUCCESS; }
    262     virtual int  clientConnect(uint32_t u32ClientID, void *pvClient) = 0;
    263     virtual int  clientDisconnect(uint32_t u32ClientID, void *pvClient) = 0;
    264     virtual void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) = 0;
    265     virtual int  hostCall(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     223    virtual int  init(VBOXHGCMSVCFNTABLE *ptable) RT_NOEXCEPT
     224    { RT_NOREF1(ptable); return VINF_SUCCESS; }
     225    virtual int  uninit()  RT_NOEXCEPT
     226    { return VINF_SUCCESS; }
     227    virtual int  clientConnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT = 0;
     228    virtual int  clientDisconnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT = 0;
     229    virtual void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t idClient, void *pvClient, uint32_t eFunction,
     230                           uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT = 0;
     231    virtual int  hostCall(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT
    266232    { RT_NOREF3(eFunction, cParms, paParms); return VINF_SUCCESS; }
    267233
     
    291257     */
    292258    static DECLCALLBACK(int) svcConnect(void *pvService,
    293                                         uint32_t u32ClientID,
     259                                        uint32_t idClient,
    294260                                        void *pvClient,
    295261                                        uint32_t fRequestor,
     
    298264        RT_NOREF(fRequestor, fRestoring);
    299265        AssertLogRelReturn(VALID_PTR(pvService), VERR_INVALID_PARAMETER);
    300         LogFlowFunc(("pvService=%p, u32ClientID=%u, pvClient=%p\n", pvService, u32ClientID, pvClient));
    301         SELF *pSelf = reinterpret_cast<SELF *>(pvService);
    302         int rc = pSelf->clientConnect(u32ClientID, pvClient);
     266        LogFlowFunc(("pvService=%p, idClient=%u, pvClient=%p\n", pvService, idClient, pvClient));
     267        SELF *pSelf = reinterpret_cast<SELF *>(pvService);
     268        int rc = pSelf->clientConnect(idClient, pvClient);
    303269        LogFlowFunc(("rc=%Rrc\n", rc));
    304270        return rc;
     
    310276     */
    311277    static DECLCALLBACK(int) svcDisconnect(void *pvService,
    312                                            uint32_t u32ClientID,
     278                                           uint32_t idClient,
    313279                                           void *pvClient)
    314280    {
    315281        AssertLogRelReturn(VALID_PTR(pvService), VERR_INVALID_PARAMETER);
    316         LogFlowFunc(("pvService=%p, u32ClientID=%u, pvClient=%p\n", pvService, u32ClientID, pvClient));
    317         SELF *pSelf = reinterpret_cast<SELF *>(pvService);
    318         int rc = pSelf->clientDisconnect(u32ClientID, pvClient);
     282        LogFlowFunc(("pvService=%p, idClient=%u, pvClient=%p\n", pvService, idClient, pvClient));
     283        SELF *pSelf = reinterpret_cast<SELF *>(pvService);
     284        int rc = pSelf->clientDisconnect(idClient, pvClient);
    319285        LogFlowFunc(("rc=%Rrc\n", rc));
    320286        return rc;
     
    325291     * Wraps to the call member function
    326292     */
    327     static DECLCALLBACK(void) svcCall(void * pvService,
     293    static DECLCALLBACK(void) svcCall(void *pvService,
    328294                                      VBOXHGCMCALLHANDLE callHandle,
    329                                       uint32_t u32ClientID,
     295                                      uint32_t idClient,
    330296                                      void *pvClient,
    331297                                      uint32_t u32Function,
     
    335301    {
    336302        AssertLogRelReturnVoid(VALID_PTR(pvService));
    337         LogFlowFunc(("pvService=%p, callHandle=%p, u32ClientID=%u, pvClient=%p, u32Function=%u, cParms=%u, paParms=%p\n", pvService, callHandle, u32ClientID, pvClient, u32Function, cParms, paParms));
    338         SELF *pSelf = reinterpret_cast<SELF *>(pvService);
    339         pSelf->guestCall(callHandle, u32ClientID, pvClient, u32Function, cParms, paParms);
     303        LogFlowFunc(("pvService=%p, callHandle=%p, idClient=%u, pvClient=%p, u32Function=%u, cParms=%u, paParms=%p\n",
     304                     pvService, callHandle, idClient, pvClient, u32Function, cParms, paParms));
     305        SELF *pSelf = reinterpret_cast<SELF *>(pvService);
     306        pSelf->guestCall(callHandle, idClient, pvClient, u32Function, cParms, paParms);
    340307        LogFlowFunc(("returning\n"));
    341308        RT_NOREF_PV(tsArrival);
  • trunk/src/VBox/HostServices/DragAndDrop/VBoxDragAndDropSvc.cpp

    r85145 r85318  
    5050{
    5151public:
    52 
    53     DragAndDropClient(uint32_t uClientID)
    54         : HGCM::Client(uClientID)
     52    DragAndDropClient(uint32_t idClient)
     53        : HGCM::Client(idClient)
    5554    {
    5655        RT_ZERO(m_SvcCtx);
     
    6362
    6463public:
    65 
    66     void disconnect(void);
     64    void disconnect(void) RT_NOEXCEPT;
    6765};
    6866
     
    7977{
    8078public:
    81 
    8279    explicit DragAndDropService(PVBOXHGCMSVCHELPERS pHelpers)
    8380        : HGCM::AbstractService<DragAndDropService>(pHelpers)
    84         , m_pManager(NULL) {}
     81        , m_pManager(NULL)
     82        , m_u32Mode(VBOX_DRAG_AND_DROP_MODE_OFF)
     83    {}
    8584
    8685protected:
    87 
    88     int  init(VBOXHGCMSVCFNTABLE *pTable);
    89     int  uninit(void);
    90     int  clientConnect(uint32_t u32ClientID, void *pvClient);
    91     int  clientDisconnect(uint32_t u32ClientID, void *pvClient);
    92     void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    93     int  hostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    94 
    95     int modeSet(uint32_t u32Mode);
    96     inline uint32_t modeGet(void) const { return m_u32Mode; };
    97 
    98 protected:
     86    int  init(VBOXHGCMSVCFNTABLE *pTable) RT_NOEXCEPT RT_OVERRIDE;
     87    int  uninit(void) RT_NOEXCEPT RT_OVERRIDE;
     88    int  clientConnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT RT_OVERRIDE;
     89    int  clientDisconnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT RT_OVERRIDE;
     90    void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t idClient, void *pvClient, uint32_t u32Function,
     91                   uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT RT_OVERRIDE;
     92    int  hostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT RT_OVERRIDE;
     93
     94private:
     95    int  modeSet(uint32_t u32Mode) RT_NOEXCEPT;
     96    inline uint32_t modeGet(void) const RT_NOEXCEPT
     97    { return m_u32Mode; };
    9998
    10099    static DECLCALLBACK(int) progressCallback(uint32_t uStatus, uint32_t uPercentage, int rc, void *pvUser);
    101100
    102 protected:
    103 
     101private:
    104102    /** Pointer to our DnD manager instance. */
    105103    DnDManager                        *m_pManager;
     
    112110     *  to process new commands. The key is the (unique) client ID. */
    113111    DnDClientQueue                     m_clientQueue;
    114     /** Current drag and drop mode. */
     112    /** Current drag and drop mode, VBOX_DRAG_AND_DROP_MODE_XXX. */
    115113    uint32_t                           m_u32Mode;
    116114};
     
    123121/**
    124122 * Called when the HGCM client disconnected on the guest side.
     123 *
    125124 * This function takes care of the client's data cleanup and also lets the host
    126125 * know that the client has been disconnected.
    127  *
    128126 */
    129 void DragAndDropClient::disconnect(void)
     127void DragAndDropClient::disconnect(void) RT_NOEXCEPT
    130128{
    131     LogFlowThisFunc(("uClient=%RU32\n", m_uClientID));
     129    LogFlowThisFunc(("uClient=%RU32\n", m_idClient));
    132130
    133131    if (IsDeferred())
     
    146144        int rc2 = m_SvcCtx.pfnHostCallback(m_SvcCtx.pvHostData, GUEST_DND_DISCONNECT, &data, sizeof(data));
    147145        if (RT_FAILURE(rc2))
    148             LogFlowFunc(("Warning: Unable to notify host about client %RU32 disconnect, rc=%Rrc\n", m_uClientID, rc2));
     146            LogFlowFunc(("Warning: Unable to notify host about client %RU32 disconnect, rc=%Rrc\n", m_idClient, rc2));
    149147        /* Not fatal. */
    150148    }
     
    156154*********************************************************************************************************************************/
    157155
    158 int DragAndDropService::init(VBOXHGCMSVCFNTABLE *pTable)
     156int DragAndDropService::init(VBOXHGCMSVCFNTABLE *pTable) RT_NOEXCEPT
    159157{
    160158    /* Register functions. */
     
    174172        m_pManager = new DnDManager(&DragAndDropService::progressCallback, this);
    175173    }
    176     catch(std::bad_alloc &)
     174    catch (std::bad_alloc &)
    177175    {
    178176        rc = VERR_NO_MEMORY;
     
    183181}
    184182
    185 int DragAndDropService::uninit(void)
     183int DragAndDropService::uninit(void) RT_NOEXCEPT
    186184{
    187185    LogFlowFuncEnter();
     
    205203}
    206204
    207 int DragAndDropService::clientConnect(uint32_t u32ClientID, void *pvClient)
     205int DragAndDropService::clientConnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT
    208206{
    209207    RT_NOREF1(pvClient);
     
    214212    }
    215213
    216     int rc = VINF_SUCCESS;
    217214
    218215    /*
    219216     * Add client to our client map.
    220217     */
    221     if (m_clientMap.find(u32ClientID) != m_clientMap.end())
    222         rc = VERR_ALREADY_EXISTS;
    223 
    224     if (RT_SUCCESS(rc))
    225     {
    226         try
    227         {
    228             DragAndDropClient *pClient = new DragAndDropClient(u32ClientID);
    229             pClient->SetSvcContext(m_SvcCtx);
    230             m_clientMap[u32ClientID] = pClient;
    231         }
    232         catch(std::bad_alloc &)
    233         {
    234             rc = VERR_NO_MEMORY;
    235         }
    236 
    237         if (RT_SUCCESS(rc))
    238         {
    239             /*
    240              * Reset the message queue as soon as a new clients connect
    241              * to ensure that every client has the same state.
    242              */
    243             if (m_pManager)
    244                 m_pManager->Reset();
    245         }
    246     }
    247 
    248     LogFlowFunc(("Client %RU32 connected, rc=%Rrc\n", u32ClientID, rc));
    249     return rc;
     218    if (m_clientMap.find(idClient) != m_clientMap.end())
     219    {
     220        LogFunc(("Client %RU32 is already connected!\n", idClient));
     221        return VERR_ALREADY_EXISTS;
     222    }
     223
     224    try
     225    {
     226        DragAndDropClient *pClient = new DragAndDropClient(idClient);
     227        pClient->SetSvcContext(m_SvcCtx);
     228        m_clientMap[idClient] = pClient;
     229    }
     230    catch (std::bad_alloc &)
     231    {
     232        LogFunc(("Client %RU32 - VERR_NO_MEMORY!\n", idClient));
     233        return VERR_NO_MEMORY;
     234    }
     235
     236    /*
     237     * Reset the message queue as soon as a new clients connect
     238     * to ensure that every client has the same state.
     239     */
     240    if (m_pManager)
     241        m_pManager->Reset();
     242
     243    LogFlowFunc(("Client %RU32 connected (VINF_SUCCESS)\n", idClient));
     244    return VINF_SUCCESS;
    250245}
    251246
    252 int DragAndDropService::clientDisconnect(uint32_t u32ClientID, void *pvClient)
     247int DragAndDropService::clientDisconnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT
    253248{
    254249    RT_NOREF1(pvClient);
    255250
    256251    /* Client not found? Bail out early. */
    257     DnDClientMap::iterator itClient =  m_clientMap.find(u32ClientID);
     252    DnDClientMap::iterator itClient =  m_clientMap.find(idClient);
    258253    if (itClient == m_clientMap.end())
     254    {
     255        LogFunc(("Client %RU32 not found!\n", idClient));
    259256        return VERR_NOT_FOUND;
     257    }
    260258
    261259    /*
    262260     * Remove from waiters queue.
    263261     */
    264     m_clientQueue.remove(u32ClientID);
     262    m_clientQueue.remove(idClient);
    265263
    266264    /*
     
    272270    m_clientMap.erase(itClient);
    273271
    274     LogFlowFunc(("Client %RU32 disconnected\n", u32ClientID));
     272    LogFlowFunc(("Client %RU32 disconnected\n", idClient));
    275273    return VINF_SUCCESS;
    276274}
    277275
    278 int DragAndDropService::modeSet(uint32_t u32Mode)
     276int DragAndDropService::modeSet(uint32_t u32Mode) RT_NOEXCEPT
    279277{
    280278#ifndef VBOX_WITH_DRAG_AND_DROP_GH
     
    304302}
    305303
    306 void DragAndDropService::guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID,
     304void DragAndDropService::guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t idClient,
    307305                                   void *pvClient, uint32_t u32Function,
    308                                    uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     306                                   uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT
    309307{
    310308    RT_NOREF1(pvClient);
    311     LogFlowFunc(("u32ClientID=%RU32, u32Function=%RU32, cParms=%RU32\n",
    312                  u32ClientID, u32Function, cParms));
     309    LogFlowFunc(("idClient=%RU32, u32Function=%RU32, cParms=%RU32\n", idClient, u32Function, cParms));
    313310
    314311    /* Check if we've the right mode set. */
     
    319316        {
    320317            if (modeGet() != VBOX_DRAG_AND_DROP_MODE_OFF)
    321             {
    322318                rc = VINF_SUCCESS;
    323             }
    324319            else
    325320            {
     
    341336            break;
    342337        }
     338
    343339        case GUEST_DND_HG_ACK_OP:
    344340        case GUEST_DND_HG_REQ_DATA:
     
    347343            if (   modeGet() == VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
    348344                || modeGet() == VBOX_DRAG_AND_DROP_MODE_HOST_TO_GUEST)
    349             {
    350345                rc = VINF_SUCCESS;
    351             }
    352346            else
    353                 LogFlowFunc(("Host -> Guest DnD mode disabled, ignoring request\n"));
     347                LogFlowFunc(("Host -> Guest DnD mode disabled, failing request\n"));
    354348            break;
    355349        }
     
    366360            if (   modeGet() == VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
    367361                || modeGet() == VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
    368             {
    369362                rc = VINF_SUCCESS;
    370             }
    371363            else
    372364#endif
    373                 LogFlowFunc(("Guest -> Host DnD mode disabled, ignoring request\n"));
     365                LogFlowFunc(("Guest -> Host DnD mode disabled, failing request\n"));
    374366            break;
    375367        }
     
    397389    DragAndDropClient *pClient = NULL;
    398390
    399     DnDClientMap::iterator itClient =  m_clientMap.find(u32ClientID);
     391    DnDClientMap::iterator itClient =  m_clientMap.find(idClient);
    400392    if (itClient != m_clientMap.end())
    401393    {
     
    405397    else
    406398    {
    407         LogFunc(("Client %RU32 was not found\n", u32ClientID));
     399        LogFunc(("Client %RU32 was not found\n", idClient));
    408400        rc = VERR_NOT_FOUND;
    409401    }
     
    412404 * Will set rc to VERR_INVALID_PARAMETER otherwise. See #9777. */
    413405#define VERIFY_BUFFER_SIZE_UINT32(a_ParmUInt32, a_SizeExpected) \
    414 { \
     406do { \
    415407    uint32_t cbTemp = 0; \
    416408    rc = HGCMSvcGetU32(&a_ParmUInt32, &cbTemp); \
    417409    ASSERT_GUEST_STMT(RT_SUCCESS(rc) && cbTemp == a_SizeExpected, rc = VERR_INVALID_PARAMETER); \
    418 }
     410} while (0)
    419411
    420412    if (rc == VINF_SUCCESS) /* Note: rc might be VINF_HGCM_ASYNC_EXECUTE! */
     
    990982            AssertPtr(pClient);
    991983            pClient->SetDeferred(callHandle, u32Function, cParms, paParms);
    992             m_clientQueue.push_back(u32ClientID);
     984            m_clientQueue.push_back(idClient);
    993985        }
    994986        catch (std::bad_alloc &)
     
    10101002
    10111003int DragAndDropService::hostCall(uint32_t u32Function,
    1012                                  uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     1004                                 uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT
    10131005{
    10141006    LogFlowFunc(("u32Function=%RU32, cParms=%RU32, cClients=%zu, cQueue=%zu\n",
     
    10161008
    10171009    int rc;
    1018 
    1019     do
    1020     {
    1021         bool fSendToGuest = false; /* Whether to send the message down to the guest side or not. */
    1022 
    1023         switch (u32Function)
     1010    bool fSendToGuest = false; /* Whether to send the message down to the guest side or not. */
     1011
     1012    switch (u32Function)
     1013    {
     1014        case HOST_DND_SET_MODE:
    10241015        {
    1025             case HOST_DND_SET_MODE:
    1026             {
    1027                 if (cParms != 1)
    1028                     rc = VERR_INVALID_PARAMETER;
    1029                 else if (paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT)
    1030                     rc = VERR_INVALID_PARAMETER;
    1031                 else
    1032                     rc = modeSet(paParms[0].u.uint32);
    1033                 break;
    1034             }
    1035 
    1036             case HOST_DND_CANCEL:
    1037             {
    1038                 LogFlowFunc(("Cancelling all waiting clients ...\n"));
    1039 
    1040                 /* Reset the message queue as the host cancelled the whole operation. */
    1041                 m_pManager->Reset();
    1042 
    1043                 rc = m_pManager->AddMsg(u32Function, cParms, paParms, true /* fAppend */);
    1044                 if (RT_FAILURE(rc))
    1045                 {
    1046                     AssertMsgFailed(("Adding new message of type=%RU32 failed with rc=%Rrc\n", u32Function, rc));
    1047                     break;
    1048                 }
    1049 
    1050                 /*
    1051                  * Wake up all deferred clients and tell them to process
    1052                  * the cancelling message next.
    1053                  */
    1054                 DnDClientQueue::iterator itQueue = m_clientQueue.begin();
    1055                 while (itQueue != m_clientQueue.end())
    1056                 {
    1057                     DnDClientMap::iterator itClient = m_clientMap.find(*itQueue);
    1058                     Assert(itClient != m_clientMap.end());
    1059 
    1060                     DragAndDropClient *pClient = itClient->second;
    1061                     AssertPtr(pClient);
    1062 
    1063                     int rc2 = pClient->SetDeferredMsgInfo(HOST_DND_CANCEL,
    1064                                                           /* Protocol v3+ also contains the context ID. */
    1065                                                           pClient->GetProtocolVer() >= 3 ? 1 : 0);
    1066                     pClient->CompleteDeferred(rc2);
    1067 
    1068                     m_clientQueue.erase(itQueue);
    1069                     itQueue = m_clientQueue.begin();
    1070                 }
    1071 
    1072                 Assert(m_clientQueue.empty());
    1073 
    1074                 /* Tell the host that everything went well. */
    1075                 rc = VINF_SUCCESS;
    1076                 break;
    1077             }
    1078 
    1079             case HOST_DND_HG_EVT_ENTER:
    1080             {
    1081                 /* Reset the message queue as a new DnD operation just began. */
    1082                 m_pManager->Reset();
    1083 
    1084                 fSendToGuest = true;
    1085                 rc = VINF_SUCCESS;
    1086                 break;
    1087             }
    1088 
    1089             default:
    1090             {
    1091                 fSendToGuest = true;
    1092                 rc = VINF_SUCCESS;
    1093                 break;
    1094             }
     1016            if (cParms != 1)
     1017                rc = VERR_INVALID_PARAMETER;
     1018            else if (paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT)
     1019                rc = VERR_INVALID_PARAMETER;
     1020            else
     1021                rc = modeSet(paParms[0].u.uint32);
     1022            break;
    10951023        }
    10961024
     1025        case HOST_DND_CANCEL:
     1026        {
     1027            LogFlowFunc(("Cancelling all waiting clients ...\n"));
     1028
     1029            /* Reset the message queue as the host cancelled the whole operation. */
     1030            m_pManager->Reset();
     1031
     1032            rc = m_pManager->AddMsg(u32Function, cParms, paParms, true /* fAppend */);
     1033            if (RT_FAILURE(rc))
     1034            {
     1035                AssertMsgFailed(("Adding new message of type=%RU32 failed with rc=%Rrc\n", u32Function, rc));
     1036                break;
     1037            }
     1038
     1039            /*
     1040             * Wake up all deferred clients and tell them to process
     1041             * the cancelling message next.
     1042             */
     1043            DnDClientQueue::iterator itQueue = m_clientQueue.begin();
     1044            while (itQueue != m_clientQueue.end())
     1045            {
     1046                DnDClientMap::iterator itClient = m_clientMap.find(*itQueue);
     1047                Assert(itClient != m_clientMap.end());
     1048
     1049                DragAndDropClient *pClient = itClient->second;
     1050                AssertPtr(pClient);
     1051
     1052                int rc2 = pClient->SetDeferredMsgInfo(HOST_DND_CANCEL,
     1053                                                      /* Protocol v3+ also contains the context ID. */
     1054                                                      pClient->GetProtocolVer() >= 3 ? 1 : 0);
     1055                pClient->CompleteDeferred(rc2);
     1056
     1057                m_clientQueue.erase(itQueue);
     1058                itQueue = m_clientQueue.begin();
     1059            }
     1060
     1061            Assert(m_clientQueue.empty());
     1062
     1063            /* Tell the host that everything went well. */
     1064            rc = VINF_SUCCESS;
     1065            break;
     1066        }
     1067
     1068        case HOST_DND_HG_EVT_ENTER:
     1069        {
     1070            /* Reset the message queue as a new DnD operation just began. */
     1071            m_pManager->Reset();
     1072
     1073            fSendToGuest = true;
     1074            rc = VINF_SUCCESS;
     1075            break;
     1076        }
     1077
     1078        default:
     1079        {
     1080            fSendToGuest = true;
     1081            rc = VINF_SUCCESS;
     1082            break;
     1083        }
     1084    }
     1085
     1086    do /* goto avoidance break-loop. */
     1087    {
    10971088        if (fSendToGuest)
    10981089        {
  • trunk/src/VBox/HostServices/common/client.cpp

    r82968 r85318  
    2727using namespace HGCM;
    2828
    29 Client::Client(uint32_t uClientID)
    30     : m_uClientID(uClientID)
     29Client::Client(uint32_t idClient)
     30    : m_idClient(idClient)
    3131    , m_uProtocolVer(0)
    3232    , m_fDeferred(false)
     
    4949 * @param   rcOp                Return code to return to the guest side.
    5050 */
    51 int Client::completeInternal(VBOXHGCMCALLHANDLE hHandle, int rcOp)
    52 {
    53     LogFlowThisFunc(("uClientID=%RU32\n", m_uClientID));
     51int Client::completeInternal(VBOXHGCMCALLHANDLE hHandle, int rcOp) RT_NOEXCEPT
     52{
     53    LogFlowThisFunc(("idClient=%RU32\n", m_idClient));
    5454
    5555    if (   m_SvcCtx.pHelpers
     
    6868 * Resets the client's internal state.
    6969 */
    70 void Client::reset(void)
     70void Client::reset(void) RT_NOEXCEPT
    7171{
    7272   m_fDeferred = false;
     
    8383 * @param   rcOp                Return code to return to the guest side.
    8484 */
    85 int Client::Complete(VBOXHGCMCALLHANDLE hHandle, int rcOp /* = VINF_SUCCESS */)
     85int Client::Complete(VBOXHGCMCALLHANDLE hHandle, int rcOp /* = VINF_SUCCESS */) RT_NOEXCEPT
    8686{
    8787    return completeInternal(hHandle, rcOp);
     
    9595 * @param   rcOp                Return code to return to the guest side.
    9696 */
    97 int Client::CompleteDeferred(int rcOp)
     97int Client::CompleteDeferred(int rcOp) RT_NOEXCEPT
    9898{
    9999    if (m_fDeferred)
     
    108108    }
    109109
    110     AssertMsg(m_fDeferred, ("Client %RU32 is not in deferred mode\n", m_uClientID));
     110    AssertMsg(m_fDeferred, ("Client %RU32 is not in deferred mode\n", m_idClient));
    111111    return VERR_INVALID_STATE;
    112112}
     
    117117 * @returns HGCM handle.
    118118 */
    119 VBOXHGCMCALLHANDLE Client::GetHandle(void) const
     119VBOXHGCMCALLHANDLE Client::GetHandle(void) const RT_NOEXCEPT
    120120{
    121121    return m_Deferred.hHandle;
     
    127127 * @returns HGCM handle.
    128128 */
    129 uint32_t Client::GetMsgType(void) const
     129uint32_t Client::GetMsgType(void) const RT_NOEXCEPT
    130130{
    131131    return m_Deferred.uType;
    132132}
    133133
    134 uint32_t Client::GetMsgParamCount(void) const
     134uint32_t Client::GetMsgParamCount(void) const RT_NOEXCEPT
    135135{
    136136    return m_Deferred.cParms;
     
    142142 * @returns The client's (HGCM) ID.
    143143 */
    144 uint32_t Client::GetClientID(void) const
    145 {
    146     return m_uClientID;
     144uint32_t Client::GetClientID(void) const RT_NOEXCEPT
     145{
     146    return m_idClient;
    147147}
    148148
     
    152152 * @returns Protocol version, or 0 if not set.
    153153 */
    154 uint32_t Client::GetProtocolVer(void) const
     154uint32_t Client::GetProtocolVer(void) const RT_NOEXCEPT
    155155{
    156156    return m_uProtocolVer;
     
    162162 * @returns \c True if in deferred mode, \c False if not.
    163163 */
    164 bool Client::IsDeferred(void) const
     164bool Client::IsDeferred(void) const RT_NOEXCEPT
    165165{
    166166    return m_fDeferred;
     
    171171 * until CompleteDeferred() has been called.
    172172 */
    173 void Client::SetDeferred(VBOXHGCMCALLHANDLE hHandle, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    174 {
    175     LogFlowThisFunc(("uClient=%RU32\n", m_uClientID));
     173void Client::SetDeferred(VBOXHGCMCALLHANDLE hHandle, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT
     174{
     175    LogFlowThisFunc(("uClient=%RU32\n", m_idClient));
    176176
    177177#ifndef DEBUG_bird /** r=bird: This bugger triggers in the DnD service when restoring saved state.  Not tested?  */
     
    192192 * @param   uVersion            Version number to set.
    193193 */
    194 void Client::SetProtocolVer(uint32_t uVersion)
     194void Client::SetProtocolVer(uint32_t uVersion) RT_NOEXCEPT
    195195{
    196196    m_uProtocolVer = uVersion;
     
    202202 * @param   SvcCtx              Service context to set.
    203203 */
    204 void Client::SetSvcContext(const VBOXHGCMSVCTX &SvcCtx)
     204void Client::SetSvcContext(const VBOXHGCMSVCTX &SvcCtx) RT_NOEXCEPT
    205205{
    206206    m_SvcCtx = SvcCtx;
     
    216216 * @param   cParms              Number of parameters the message needs.
    217217 */
    218 int Client::SetDeferredMsgInfo(uint32_t uMsg, uint32_t cParms)
     218int Client::SetDeferredMsgInfo(uint32_t uMsg, uint32_t cParms) RT_NOEXCEPT
    219219{
    220220    if (m_fDeferred)
     
    243243 * @param   pMessage            Message to get message type and required parameters from.
    244244 */
    245 int Client::SetDeferredMsgInfo(const Message *pMessage)
     245int Client::SetDeferredMsgInfo(const Message *pMessage) RT_NOEXCEPT
    246246{
    247247    AssertPtrReturn(pMessage, VERR_INVALID_POINTER);
  • trunk/src/VBox/HostServices/common/message.cpp

    r82968 r85318  
    2323    : m_uMsg(0)
    2424    , m_cParms(0)
    25     , m_paParms(NULL) { }
     25    , m_paParms(NULL)
     26{
     27}
    2628
    2729Message::Message(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
     
    4143 * Resets the message by free'ing all allocated parameters and resetting the rest.
    4244 */
    43 void Message::reset(void)
     45void Message::reset(void) RT_NOEXCEPT
    4446{
    4547    if (m_paParms)
     
    6769 * @returns Parameter count.
    6870 */
    69 uint32_t Message::GetParamCount(void) const
     71uint32_t Message::GetParamCount(void) const RT_NOEXCEPT
    7072{
    7173    return m_cParms;
     
    8082 * @param   aParms          Where to store the HGCM parameter data.
    8183 */
    82 int Message::GetData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) const
     84int Message::GetData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) const RT_NOEXCEPT
    8385{
    8486    if (m_uMsg != uMsg)
     
    103105 * @param   pu32Info        Where to store the parameter value.
    104106 */
    105 int Message::GetParmU32(uint32_t uParm, uint32_t *pu32Info) const
     107int Message::GetParmU32(uint32_t uParm, uint32_t *pu32Info) const RT_NOEXCEPT
    106108{
    107109    AssertPtrNullReturn(pu32Info, VERR_INVALID_PARAMETER);
     
    121123 * @param   pu64Info        Where to store the parameter value.
    122124 */
    123 int Message::GetParmU64(uint32_t uParm, uint64_t *pu64Info) const
     125int Message::GetParmU64(uint32_t uParm, uint64_t *pu64Info) const RT_NOEXCEPT
    124126{
    125127    AssertPtrNullReturn(pu64Info, VERR_INVALID_PARAMETER);
     
    142144 * @remarks Does not copy (store) the actual content of the pointer (deep copy).
    143145 */
    144 int Message::GetParmPtr(uint32_t uParm, void **ppvAddr, uint32_t *pcbSize) const
     146int Message::GetParmPtr(uint32_t uParm, void **ppvAddr, uint32_t *pcbSize) const RT_NOEXCEPT
    145147{
    146148    AssertPtrNullReturn(ppvAddr, VERR_INVALID_PARAMETER);
     
    160162 * @returns Message type.
    161163 */
    162 uint32_t Message::GetType(void) const
     164uint32_t Message::GetType(void) const RT_NOEXCEPT
    163165{
    164166    return m_uMsg;
     
    180182int Message::CopyParms(PVBOXHGCMSVCPARM paParmsDst, uint32_t cParmsDst,
    181183                       PVBOXHGCMSVCPARM paParmsSrc, uint32_t cParmsSrc,
    182                        bool fDeepCopy)
     184                       bool fDeepCopy) RT_NOEXCEPT
    183185{
    184186    AssertPtrReturn(paParmsSrc, VERR_INVALID_POINTER);
     
    188190        return VERR_BUFFER_OVERFLOW;
    189191
    190     int rc = VINF_SUCCESS;
    191192    for (uint32_t i = 0; i < cParmsSrc; i++)
    192193    {
     
    215216                        paParmsDst[i].u.pointer.addr = RTMemAlloc(paParmsDst[i].u.pointer.size);
    216217                        if (!paParmsDst[i].u.pointer.addr)
    217                         {
    218                             rc = VERR_NO_MEMORY;
    219                             break;
    220                         }
     218                            return VERR_NO_MEMORY;
    221219                    }
    222220                }
     
    225223                    /* No, but we have to check if there is enough room. */
    226224                    if (paParmsDst[i].u.pointer.size < paParmsSrc[i].u.pointer.size)
    227                     {
    228                         rc = VERR_BUFFER_OVERFLOW;
    229                         break;
    230                     }
     225                        return VERR_BUFFER_OVERFLOW;
    231226                }
    232227
     
    235230                    if (   paParmsDst[i].u.pointer.addr
    236231                        && paParmsDst[i].u.pointer.size)
    237                     {
    238232                        memcpy(paParmsDst[i].u.pointer.addr,
    239233                               paParmsSrc[i].u.pointer.addr,
    240234                               RT_MIN(paParmsDst[i].u.pointer.size, paParmsSrc[i].u.pointer.size));
    241                     }
    242235                    else
    243                         rc = VERR_INVALID_POINTER;
     236                        return VERR_INVALID_POINTER;
    244237                }
    245238                break;
     
    248241            {
    249242                AssertMsgFailed(("Unknown HGCM type %u\n", paParmsSrc[i].type));
    250                 rc = VERR_INVALID_PARAMETER;
    251                 break;
     243                return VERR_INVALID_PARAMETER;
    252244            }
    253245        }
    254         if (RT_FAILURE(rc))
    255             break;
    256     }
    257     return rc;
     246    }
     247    return VINF_SUCCESS;
    258248}
    259249
     
    266256 * @param   aParms          Array of parameters to set.
    267257 */
    268 int Message::initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
    269 {
     258int Message::initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) RT_NOEXCEPT
     259{
     260    /** @todo r=bird: There is a define for the max number of HGCM parameters,
     261     *        it's way smaller than 256, something like 61 IIRC. */
    270262    AssertReturn(cParms < 256, VERR_INVALID_PARAMETER);
    271263    AssertPtrNullReturn(aParms, VERR_INVALID_PARAMETER);
Note: See TracChangeset for help on using the changeset viewer.

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