VirtualBox

Changeset 74117 in vbox for trunk/include


Ignore:
Timestamp:
Sep 6, 2018 1:30:29 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124884
Message:

IPRT/rest: Started implemented more flexible handling of binary uploads and downloads. bugref:9167

Location:
trunk/include/iprt/cpp
Files:
1 added
1 edited

Legend:

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

    r74096 r74117  
    370370        kTypeClass_Array,               /**< Array (containing any kind of object). */
    371371        kTypeClass_StringMap,           /**< String map (containing any kind of object). */
    372         kTypeClass_StringEnum           /**< String enum. */
     372        kTypeClass_StringEnum,          /**< String enum. */
     373        kTypeClass_BinaryString         /**< Binary string. */
    373374    } kTypeClass;
    374375
     
    741742};
    742743
    743 
    744 /**
    745  * Class for handling strings on the binary format.
    746  *
    747  * This can only be used for body parameters.
    748  */
    749 class RT_DECL_CLASS RTCRestBinaryString : public RTCRestObjectBase
    750 {
    751 public:
    752     /** Default constructor. */
    753     RTCRestBinaryString();
    754     /** Destructor. */
    755     virtual ~RTCRestBinaryString();
    756 
    757     /** Safe copy assignment method. */
    758     int assignCopy(RTCRestBinaryString const &a_rThat);
    759 
    760     /* Overridden methods: */
    761     virtual int resetToDefault() RT_OVERRIDE;
    762     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    763     virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    764     virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const RT_OVERRIDE;
    765     virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
    766                            uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE;
    767     virtual kTypeClass typeClass(void) const RT_OVERRIDE;
    768     virtual const char *typeName(void) const RT_OVERRIDE;
    769 
    770     /** Factory method. */
    771     static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
    772 
    773     /**
    774      * Gets the data size.
    775      *
    776      * This can be used from a consumer callback to get the Content-Length field
    777      * value if available.  Returns UINT64_MAX if not available.
    778      */
    779     uint64_t getDataSize() const { return m_cbData; }
    780 
    781     /**
    782      * Sets the data to upload.
    783      *
    784      * @returns IPRT status code.
    785      * @param   a_pvData    The data buffer.  NULL can be used to actively
    786      *                      deregister previous data.
    787      * @param   a_cbData    The amount of data to upload from that buffer.
    788      * @param   a_fCopy     Whether to make a copy (@a true) or use the
    789      *                      buffer directly (@a false).  In the latter case
    790      *                      the caller must make sure the data remains available
    791      *                      for the entire lifetime of this object (or until
    792      *                      setUploadData is called with NULL parameters).
    793      */
    794     int setUploadData(void const *a_pvData, size_t a_cbData, bool a_fCopy);
    795 
    796     /** @name Data callbacks.
    797      * @{ */
    798     /**
    799      * Callback for producing bytes to upload.
    800      *
    801      * @returns IPRT status code.
    802      * @param   a_pThis     The related string object.
    803      * @param   a_pvDst     Where to put the bytes.
    804      * @param   a_cbDst     Max number of bytes to produce.
    805      * @param   a_pcbActual Where to return the number of bytes actually produced.
    806      * @remarks Use getCallbackData to get the user data.
    807      */
    808     typedef DECLCALLBACK(int) FNPRODUCER(RTCRestBinaryString *a_pThis, void *a_pvDst, size_t a_cbDst, size_t *a_pcbActual);
    809     /** Pointer to a byte producer callback. */
    810     typedef FNPRODUCER *PFNPRODUCER;
    811 
    812     /**
    813      * Callback for consuming downloaded bytes.
    814      *
    815      * @returns IPRT status code.
    816      * @param   a_pThis     The related string object.
    817      * @param   a_pvSrc     Buffer containing the bytes.
    818      * @param   a_cbSrc     The number of bytes in the buffer.
    819      * @remarks Use getCallbackData to get the user data.
    820      */
    821     typedef DECLCALLBACK(int) FNCONSUMER(RTCRestBinaryString *a_pThis, const void *a_pvSrc, size_t a_cbSrc);
    822     /** Pointer to a byte consumer callback. */
    823     typedef FNCONSUMER *PFNCONSUMER;
    824 
    825     /**
    826      * Retrieves the callback data.
    827      */
    828     void *getCallbackData() const  { return m_pvCallbackData; }
    829 
    830     /**
    831      * Sets the consumer callback.
    832      *
    833      * @returns IPRT status code.
    834      * @param   a_pfnConsumer       The callback function for consuming downloaded data.
    835      *                              NULL if data should be stored in m_pbData/m_cbData (the default).
    836      * @param   a_pvCallbackData    Data the can be retrieved from the callback
    837      *                              using getCallbackData().
    838      */
    839     int setConsumerCallback(PFNCONSUMER a_pfnConsumer, void *a_pvCallbackData = NULL);
    840 
    841     /**
    842      * Sets the producer callback.
    843      *
    844      * @returns IPRT status code.
    845      * @param   a_pfnProducer       The callback function for producing data.
    846      * @param   a_pvCallbackData    Data the can be retrieved from the callback
    847      *                              using getCallbackData().
    848      * @param   a_cbData            The amount of data that will be uploaded,
    849      *                              UINT64_MAX if not unknown.
    850      *
    851      * @note    This will drop any buffer previously registered using
    852      *          setUploadData(), unless a_pfnProducer is NULL.
    853      */
    854     int setProducerCallback(PFNPRODUCER a_pfnProducer, void *a_pvCallbackData = NULL, uint64_t a_cbData = UINT64_MAX);
    855     /** @} */
    856 
    857 protected:
    858     /** Pointer to the bytes, if provided directly. */
    859     uint8_t    *m_pbData;
    860     /** Number of bytes.  UINT64_MAX if not known. */
    861     uint64_t    m_cbData;
    862     /** User argument for callbacks. */
    863     void       *m_pvCallbackData;
    864     /** Pointer to user-registered consumer callback function. */
    865     PFNCONSUMER m_pfnConsumer;
    866     /** Pointer to user-registered producer callback function. */
    867     PFNPRODUCER m_pfnProducer;
    868     /** Set if m_pbData must be freed. */
    869     bool        m_fFreeData;
    870     /** Set if it is an upload, clear if download. */
    871     bool        m_fIsUpload;
    872 
    873 private:
    874     /* No copy constructor or copy assignment: */
    875     RTCRestBinaryString(RTCRestBinaryString const &a_rThat);
    876     RTCRestDouble &operator=(RTCRestDouble const &a_rThat);
    877 };
    878 
    879744/** @} */
    880745
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