VirtualBox

Changeset 85318 in vbox for trunk/include


Ignore:
Timestamp:
Jul 13, 2020 9:07:41 PM (5 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

File:
1 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);
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