AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ACurl Class Reference

Easy curl instance. More...

#include <AUI/Curl/ACurl.h>

Classes#

class  Builder
 
struct  ErrorDescription
 
class  Exception
 
struct  Response
 Response struct for Builder::runBlocking() and Builder::runAsync() More...
 

Public Types#

enum class  Http {
  VERSION_NONE , VERSION_1_0 , VERSION_1_1 , VERSION_2_0 ,
  VERSION_2TLS , VERSION_2_PRIOR_KNOWLEDGE , VERSION_3 = 30 , VERSION_LAST
}
 
enum class  ResponseCode {
  HTTP_100_CONTINUE = 100 , HTTP_101_SWITCHING_PROTOCOL = 101 , HTTP_102_PROCESSING = 102 , HTTP_103_EARLY_HINTS = 103 ,
  HTTP_200_OK = 200 , HTTP_201_CREATED = 201 , HTTP_202_ACCEPTED = 202 , HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203 ,
  HTTP_204_NO_CONTENT = 204 , HTTP_205_RESET_CONTENT = 205 , HTTP_206_PARTIAL_CONTENT = 206 , HTTP_300_MULTIPLE_CHOICE = 300 ,
  HTTP_301_MOVED_PERMANENTLY = 301 , HTTP_302_FOUND = 302 , HTTP_303_SEE_OTHER = 303 , HTTP_304_NOT_MODIFIED = 304 ,
  HTTP_305_USE_PROXY = 305 , HTTP_306_SWITCH_PROXY = 306 , HTTP_307_TEMPORARY_REDIRECT = 307 , HTTP_308_PERMANENT_REDIRECT = 308 ,
  HTTP_400_BAD_REQUEST = 400 , HTTP_401_UNAUTHORIZED = 401 , HTTP_402_PAYMENT_REQUIRED = 402 , HTTP_403_FORBIDDEN = 403 ,
  HTTP_404_NOT_FOUND = 404 , HTTP_405_METHOD_NOT_ALLOWED = 405 , HTTP_406_NOT_ACCEPTABLE = 406 , HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407 ,
  HTTP_408_REQUEST_TIMEOUT = 408 , HTTP_409_CONFLICT = 409 , HTTP_410_GONE = 410 , HTTP_411_LENGTH_REQUIRED = 411 ,
  HTTP_412_PRECONDITION_FAILED = 412 , HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413 , HTTP_414_REQUEST_URI_TOO_LONG = 414 , HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415 ,
  HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416 , HTTP_417_EXPECTATION_FAILED = 417 , HTTP_500_INTERNAL_SERVER_ERROR = 500 , HTTP_501_NOT_IMPLEMENTED = 501 ,
  HTTP_502_BAD_GATEWAY = 502 , HTTP_503_SERVICE_UNAVAILABLE = 503 , HTTP_504_GATEWAY_TIMEOUT = 504 , HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505
}
 
enum class  Method { HTTP_GET , HTTP_POST , HTTP_PUT , HTTP_DELETE }
 
using WriteCallback = std::function<size_t(AByteBufferView data)>
 A read callback.
 
using WriteCallbackV2 = std::function<size_t(ACurl& curl, AByteBufferView data)>
 A read callback.
 
using ReadCallback = std::function<std::size_t(char* dst, size_t maxLen)>
 A read callback.
 
using HeaderCallback = std::function<void(AByteBufferView)>
 
using ErrorCallback = std::function<void(const ErrorDescription& description)>
 

Public Member Functions#

 ACurl (Builder &builder)
 
 ACurl (Builder &&builder) noexcept
 
 ACurl (ACurl &&o) noexcept
 
ACurloperator= (Builder &&o) noexcept
 
ACurloperator= (ACurl &&o) noexcept
 
int64_t getContentLength () const
 
int64_t getNumberOfBytesDownloaded () const
 
AString getContentType () const
 
void run ()
 
virtual void close ()
 Breaks curl loop in the run() method, closing underlying curl connection.
 
void * handle () const noexcept
 
ResponseCode getResponseCode () const
 
AString getErrorString () const noexcept
 
- Public Member Functions inherited from AObject
_< AObjectsharedPtr ()
 
_weak< AObjectweakPtr ()
 
template<typename Connectable, ACompatibleSlotFor< Connectable > Function>
decltype(auto) connect (const Connectable &connectable, Function &&function)
 Connects signal or property to slot of "this" object.
 
void setSignalsEnabled (bool enabled)
 
bool isSignalsEnabled () const noexcept
 
template<ASignalInvokable T>
void operator^ (T &&t) noexcept
 
_< AAbstractThreadgetThread () const
 
bool isSlotsCallsOnlyOnMyThread () const noexcept
 
void setSlotsCallsOnlyOnMyThread (bool slotsCallsOnlyOnMyThread)
 
- Public Member Functions inherited from AObjectBase
 AObjectBase (AObjectBase &&rhs) noexcept
 
 AObjectBase (const AObjectBase &rhs) noexcept
 
AObjectBaseoperator= (const AObjectBase &rhs) noexcept
 
AObjectBaseoperator= (AObjectBase &&rhs) noexcept
 
- Public Member Functions inherited from aui::noncopyable
 noncopyable (const noncopyable &)=delete
 
noncopyableoperator= (const noncopyable &)=delete
 

Signals and public fields#

emits< ErrorDescriptionfail
 Emitted on network error.
 
emits success
 Emitted on success.
 
emits closeRequested
 

Additional Inherited Members#

- Static Public Member Functions inherited from AObject
static void disconnect ()
 
template<AAnySignal Signal, aui::derived_from< AObjectBase > Object, ACompatibleSlotFor< Signal > Function>
static decltype(auto) connect (const Signal &signal, Object *object, Function &&function)
 Connects signal to the slot of the specified object.
 
template<AAnyProperty Property, aui::derived_from< AObjectBase > Object, typename Function>
static decltype(auto) connect (const Property &property, Object *object, Function &&function)
 Connects property to the slot of the specified object.
 
template<APropertyReadable PropertySource, APropertyWritable PropertyDestination>
requires requires { { *propertySource } -> aui::convertible_to<std::decay_t<decltype(*propertyDestination)>>; }
static void connect (PropertySource &&propertySource, PropertyDestination &&propertyDestination)
 Connects source property to the destination property.
 
template<APropertyWritable PropertySource, APropertyWritable PropertyDestination>
requires requires { { *propertySource } -> aui::convertible_to<std::decay_t<decltype(*propertyDestination)>>; { *propertyDestination } -> aui::convertible_to<std::decay_t<decltype(*propertySource)>>; }
static void biConnect (PropertySource &&propertySource, PropertyDestination &&propertyDestination)
 Connects source property to the destination property and opposite (bidirectionally).
 
template<AAnySignalOrProperty Connectable, aui::derived_from< AObjectBase > Object, ACompatibleSlotFor< Connectable > Function>
static decltype(auto) connect (const Connectable &connectable, Object &object, Function &&function)
 Connects signal or property to the slot of the specified object.
 
template<AAnySignalOrProperty Connectable, aui::derived_from< AObjectBase > Object, ACompatibleSlotFor< Connectable > Function>
static decltype(auto) connect (const Connectable &connectable, _< Object > object, Function &&function)
 Connects signal or property to the slot of the specified object.
 
template<AAnySignalOrProperty Connectable, aui::derived_from< AObjectBase > Object, typename Function>
static decltype(auto) connect (const Connectable &connectable, ASlotDef< Object *, Function > slotDef)
 Connects signal to the slot of the specified object. Slot is packed to single argument.
 
template<AAnyProperty Property, typename Object, ACompatibleSlotFor< Property > Function>
requires (!aui::derived_from<Object, AObject>)
static void connect (const Property &property, _< Object > object, Function &&function)
 Connects signal or property to the slot of the specified non-AObject type.
 
static void moveToThread (aui::no_escape< AObject > object, _< AAbstractThread > thread)
 
- Static Public Attributes inherited from AObject
static constexpr AObjectBaseGENERIC_OBSERVER = nullptr
 Indicates that a connection should not be explicitly linked to receiver's lifetime.
 
- Static Public Attributes inherited from AObjectBase
static ASpinlockMutex SIGNAL_SLOT_GLOBAL_SYNC
 
- Protected Member Functions inherited from AObject
void setThread (_< AAbstractThread > thread)
 Set thread of the object.
 
- Protected Member Functions inherited from AObjectBase
void clearAllIngoingConnections () noexcept
 
virtual void handleSlotException (std::exception_ptr exception)
 Called then an exception has thrown during slot processing of the signal emitted by this object.
 

Detailed Description#

ACurl::Builder is used to construct ACurl.

Analogous to Qt's QNetworkRequest.

Member Typedef Documentation#

◆ ReadCallback#

using ACurl::ReadCallback = std::function<std::size_t(char* dst, size_t maxLen)>
Parameters
dstdestination buffer you should write to.
maxLendestination buffer size aka max length.
Returns
bytes written to the destination buffer. Zero means data unavailability (but the stream may be continued in the future).

Unlike regular streams, blocking is not allowed. To indicate the data unavailability, return zero. To indicate end of file, throw an AEOFException.

◆ WriteCallback#

using ACurl::WriteCallback = std::function<size_t(AByteBufferView data)>
Parameters
datareceived data
Returns
bytes written to the destination buffer. Zero means buffer does not have enough space to store supplied data (but the stream may be continued in the future), the supplied data is not discarded and being kept in the curl buffers.

Unlike regular streams, blocking is not allowed. To indicate buffer overflow, return zero. To indicate end of file, throw an AEOFException.

◆ WriteCallbackV2#

using ACurl::WriteCallbackV2 = std::function<size_t(ACurl& curl, AByteBufferView data)>
Parameters
curlcurl instance
datareceived data
Returns
bytes written to the destination buffer. Zero means buffer does not have enough space to store supplied data (but the stream may be continued in the future), the supplied data is not discarded and being kept in the curl buffers.

Unlike regular streams, blocking is not allowed. To indicate buffer overflow, return zero. To indicate end of file, throw an AEOFException.

Member Function Documentation#

◆ close()#

virtual void ACurl::close ( )
virtual

curl does not have a function which immediately stops the transfer (see https://curl.se/docs/faq.html#How_do_I_stop_an_ongoing_transfe). The stop functionality is handled in ACurl by returning error code on all callbacks. close() function is non-blocking, and some time would be taken until the run() method finally returns.

After calling close() method, none of the result signals (like fail, success) will be called.

close() is non-blocking function.

close() is thread-safe.

Reimplemented in AWebsocket.

Member Data Documentation#

◆ fail#

emits<ErrorDescription> ACurl::fail
Note
A protocol-level error (like HTTP(S) 404) is not treated as a fail. Check for response code via the getResponseCode() function.

◆ success#

emits ACurl::success
Note
A protocol-level error (like HTTP(S) 404) is not treated as a fail. Check for response code via the getResponseCode() function.