VirtualBox

Changeset 73900 in vbox


Ignore:
Timestamp:
Aug 26, 2018 8:28:30 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124617
Message:

IPRT/rest: More API code generation bits. bugref:9167

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/restbase.h

    r73895 r73900  
    273273     * @param   a_rDst      The destination for the serialization.
    274274     */
    275     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) = 0;
     275    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const = 0;
    276276
    277277    /**
     
    284284
    285285    /**
     286     * Flags for toString().
     287     *
     288     * The kCollectionFormat_xxx bunch controls multiple values in arrays
     289     * are formatted.  They are ignored by everyone else.
     290     */
     291    enum
     292    {
     293        kCollectionFormat_cvs = 0,  /**< Comma-separated list. */
     294        kCollectionFormat_ssv,      /**< Space-separated list. */
     295        kCollectionFormat_tsv,      /**< Tab-separated list. */
     296        kCollectionFormat_pipes     /**< Pipe-separated list. */
     297    };
     298
     299    /**
    286300     * String conversion.
    287301     *
     
    290304     * @returns IPRT status code.
    291305     * @param   a_pDst      Pointer to the destionation string.
    292      * @param   a_fFlags    For future tricks, MBZ.
    293      */
    294     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0);
     306     * @param   a_fFlags    kCollectionFormat_xxx.
     307     */
     308    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_cvs) const;
    295309
    296310    /**
     
    299313     * @returns String represenation.
    300314     */
    301     RTCString toString();
     315    RTCString toString() const;
    302316
    303317    /**
     
    327341    /* Overridden methods: */
    328342    virtual void resetToDefault() RT_OVERRIDE;
    329     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     343    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    330344    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    331     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     345    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE;
    332346    virtual const char *getType(void) RT_OVERRIDE;
    333347
     
    357371        /* Overridden methods: */
    358372    virtual void resetToDefault() RT_OVERRIDE;
    359     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     373    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    360374    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    361     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     375    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE;
    362376    virtual const char *getType(void) RT_OVERRIDE;
    363377
     
    387401    /* Overridden methods: */
    388402    virtual void resetToDefault() RT_OVERRIDE;
    389     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     403    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    390404    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    391     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     405    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE;
    392406    virtual const char *getType(void) RT_OVERRIDE;
    393407
     
    417431    /* Overridden methods: */
    418432    virtual void resetToDefault() RT_OVERRIDE;
    419     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     433    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    420434    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    421     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     435    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE;
    422436    virtual const char *getType(void) RT_OVERRIDE;
    423437
     
    447461    /* Overridden methods: */
    448462    virtual void resetToDefault() RT_OVERRIDE;
    449     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     463    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    450464    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    451     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     465    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE;
    452466    virtual const char *getType(void) RT_OVERRIDE;
    453467
     
    477491    /* Overridden methods: */
    478492    virtual void resetToDefault() RT_OVERRIDE;
    479     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     493    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    480494    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    481     virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     495    virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE;
    482496    virtual const char *getType(void) RT_OVERRIDE;
    483497};
     
    495509
    496510    virtual void resetToDefault() RT_OVERRIDE;
    497     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     511    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    498512    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE
    499513    {
     
    516530
    517531    virtual void resetToDefault() RT_OVERRIDE;
    518     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     532    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    519533    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE
    520534    {
     
    544558     *
    545559     * @returns IPRT status code.
    546      * @param   a_hHttp     The HTTP handle to prepare for transmitting.
    547      */
    548     virtual int xmitPrepare(RTHTTP a_hHttp) const = 0;
     560     * @param   a_pstrPath  Where to set path parameters.  Will be appended to the base path.
     561     * @param   a_pstrQuery Where to set query parameters.
     562     * @param   a_hHttp     Where to set header parameters and such.
     563     * @param   a_pstrBody  Where to set body parameters.
     564     */
     565    virtual int xmitPrepare(RTCString *a_pStrPath, RTCString *a_pStrQuery, RTHTTP a_hHttp, RTCString *a_pStrBody) const = 0;
    549566
    550567    /**
     
    592609     * @returns IPRT status code.
    593610     * @param   a_hHttp     The HTTP handle to prepare for receiving.
    594      */
    595     virtual int receivePrepare(RTHTTP a_hHttp)
    596     {
    597         RT_NOREF(a_hHttp);
     611     * @param   a_pppvHdr   If a header callback handler is installed, set the value pointed to to NULL.
     612     * @param   a_pppvBody  If a body callback handler is installed, set the value pointed to to NULL.
     613     */
     614    virtual int receivePrepare(RTHTTP a_hHttp, void ***a_pppvHdr, void ***a_pppvBody)
     615    {
     616        RT_NOREF(a_hHttp, a_pppvHdr, a_pppvBody);
    598617        return VINF_SUCCESS;
    599618    }
    600619
    601620    /**
    602      * Callback that consumes HTTP header data from the server.
    603      *
    604      * @returns IPRT status code?
    605      * @param   a_pvData   Body data.
    606      * @param   a_cbData   Amount of body data.
    607      *
    608      * @todo good idea?
    609      */
    610     virtual int consumeHeader(const char *a_pvData, size_t a_cbData)
    611     {
    612         RT_NOREF(a_pvData, a_cbData);
    613         return VINF_SUCCESS;
    614     }
    615 
    616     /**
    617      * Callback that consumes HTTP body data from the server.
    618      *
    619      * @returns IPRT status code?
    620      * @param   a_pvData   Body data.
    621      * @param   a_cbData   Amount of body data.
    622      *
    623      * @todo good idea?
    624      */
    625     virtual int consumeBody(const char *a_pvData, size_t a_cbData)
    626     {
    627         RT_NOREF(a_pvData, a_cbData);
    628         return VINF_SUCCESS;
    629     }
    630 
    631     /**
    632621     * Called when the HTTP request has been completely received.
    633622     *
    634      * @returns IPRT status code?
    635623     * @param   a_rcStatus  Negative numbers are IPRT errors, positive are HTTP status codes.
    636624     * @param   a_hHttp     The HTTP handle the request was performed on.
    637625     *                      This can be NIL_RTHTTP should something fail early, in
    638626     *                      which case it is possible receivePrepare() wasn't called.
    639      */
    640     virtual int receiveComplete(int a_rcStatus, RTHTTP a_hHttp)
     627     *
     628     * @note    Called before consumeHeaders() and consumeBody().
     629     */
     630    virtual void receiveComplete(int a_rcStatus, RTHTTP a_hHttp)
    641631    {
    642632        RT_NOREF_PV(a_hHttp);
    643633        m_rcStatus = a_rcStatus;
    644         return a_rcStatus;
     634    }
     635
     636    /**
     637     * Callback that consumes HTTP header data from the server.
     638     *
     639     * @param   a_pvData   Body data.
     640     * @param   a_cbData   Amount of body data.
     641     *
     642     * @note    Called after receiveComplete()..
     643     */
     644    virtual void consumeHeaders(const char *a_pvData, size_t a_cbData)
     645    {
     646        RT_NOREF(a_pvData, a_cbData);
     647    }
     648
     649    /**
     650     * Callback that consumes HTTP body data from the server.
     651     *
     652     * @param   a_pvData   Body data.
     653     * @param   a_cbData   Amount of body data.
     654     *
     655     * @note    Called after consumeHeaders().
     656     */
     657    virtual void consumeBody(const char *a_pvData, size_t a_cbData)
     658    {
     659        RT_NOREF(a_pvData, a_cbData);
     660    }
     661
     662    /**
     663     * Called after status, headers and body all have been presented.
     664     *
     665     * @returns IPRT status code.
     666     */
     667    virtual void receiveFinal()
     668    {
    645669    }
    646670
  • trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp

    r73898 r73900  
    5656
    5757
    58 int RTCRestObjectBase::toString(RTCString *a_pDst, uint32_t fFlags)
    59 {
    60     Assert(fFlags == 0);
    61     RT_NOREF(fFlags);
     58int RTCRestObjectBase::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     59{
     60    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     61
    6262    /*
    6363     * Just wrap the JSON serialization method.
     
    6969
    7070
    71 RTCString RTCRestObjectBase::toString()
     71RTCString RTCRestObjectBase::toString() const
    7272{
    7373    RTCString strRet;
     
    124124
    125125
    126 RTCRestOutputBase &RTCRestBool::serializeAsJson(RTCRestOutputBase &a_rDst)
     126RTCRestOutputBase &RTCRestBool::serializeAsJson(RTCRestOutputBase &a_rDst) const
    127127{
    128128    a_rDst.printf(m_fValue ? "true" : "false");
     
    156156
    157157
    158 int RTCRestBool::toString(RTCString *a_pDst, uint32_t fFlags /*= 0*/)
    159 {
    160     Assert(!fFlags);
    161     RT_NOREF(fFlags);
     158int RTCRestBool::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     159{
     160    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     161
    162162    /* Be a little careful here to avoid throwing anything. */
    163163    int rc = a_pDst->reserveNoThrow(m_fValue ? sizeof("true") : sizeof("false"));
     
    225225
    226226
    227 RTCRestOutputBase &RTCRestInt64::serializeAsJson(RTCRestOutputBase &a_rDst)
     227RTCRestOutputBase &RTCRestInt64::serializeAsJson(RTCRestOutputBase &a_rDst) const
    228228{
    229229    a_rDst.printf("%RI64", m_iValue);
     
    254254
    255255
    256 int RTCRestInt64::toString(RTCString *a_pDst, uint32_t fFlags /*= 0*/)
    257 {
    258     Assert(!fFlags);
    259     RT_NOREF(fFlags);
     256int RTCRestInt64::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     257{
     258    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     259
    260260    /* Be a little careful here to avoid throwing anything. */
    261261    char   szValue[64];
     
    321321
    322322
    323 RTCRestOutputBase &RTCRestInt32::serializeAsJson(RTCRestOutputBase &a_rDst)
     323RTCRestOutputBase &RTCRestInt32::serializeAsJson(RTCRestOutputBase &a_rDst) const
    324324{
    325325    a_rDst.printf("%RI32", m_iValue);
     
    356356
    357357
    358 int RTCRestInt32::toString(RTCString *a_pDst, uint32_t fFlags /*= 0*/)
    359 {
    360     Assert(!fFlags);
    361     RT_NOREF(fFlags);
     358int RTCRestInt32::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     359{
     360    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     361
    362362    /* Be a little careful here to avoid throwing anything. */
    363363    char   szValue[16];
     
    423423
    424424
    425 RTCRestOutputBase &RTCRestInt16::serializeAsJson(RTCRestOutputBase &a_rDst)
     425RTCRestOutputBase &RTCRestInt16::serializeAsJson(RTCRestOutputBase &a_rDst) const
    426426{
    427427    a_rDst.printf("%RI16", m_iValue);
     
    458458
    459459
    460 int RTCRestInt16::toString(RTCString *a_pDst, uint32_t fFlags /*= 0*/)
    461 {
    462     Assert(!fFlags);
    463     RT_NOREF(fFlags);
     460int RTCRestInt16::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     461{
     462    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     463
    464464    /* Be a little careful here to avoid throwing anything. */
    465465    char   szValue[8];
     
    517517
    518518
    519 RTCRestOutputBase &RTCRestDouble::serializeAsJson(RTCRestOutputBase &a_rDst)
     519RTCRestOutputBase &RTCRestDouble::serializeAsJson(RTCRestOutputBase &a_rDst) const
    520520{
    521521    /* Just a simple approximation here. */
     
    540540
    541541
    542 int RTCRestDouble::toString(RTCString *a_pDst, uint32_t fFlags /*= 0*/)
    543 {
    544     Assert(!fFlags);
    545     RT_NOREF(fFlags);
     542int RTCRestDouble::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     543{
     544    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     545
    546546    /* Just a simple approximation here. */
    547547    /** @todo implement floating point values for json. */
     
    613613
    614614
    615 RTCRestOutputBase &RTCRestString::serializeAsJson(RTCRestOutputBase &a_rDst)
     615RTCRestOutputBase &RTCRestString::serializeAsJson(RTCRestOutputBase &a_rDst) const
    616616{
    617617    a_rDst.printf("%RJs", m_psz);
     
    647647
    648648
    649 int RTCRestString::toString(RTCString *a_pDst, uint32_t fFlags /*= 0*/)
    650 {
    651     Assert(!fFlags);
    652     RT_NOREF(fFlags);
     649int RTCRestString::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const
     650{
     651    Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     652
    653653    /* Careful as always. */
    654654    if (m_cch)
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