ArcdpsExtension
 
Loading...
Searching...
No Matches
ArcdpsExtension::SimpleNetworkStack Class Referencefinal

#include <SimpleNetworkStack.h>

Inheritance diagram for ArcdpsExtension::SimpleNetworkStack:
Collaboration diagram for ArcdpsExtension::SimpleNetworkStack:

Classes

struct  Error
 
struct  Response
 

Public Types

enum class  ErrorType {
  PerformError , OptUrlError , OptFollowLocationError , OptWriteFuncError ,
  OptWriteDataError , OptUseragentError
}
 
using Result = std::expected< Response, Error >
 
using ResultFunc = std::function< void(const Result &)>
 
using ResultPromise = std::promise< Result >
 

Public Member Functions

 SimpleNetworkStack ()
 
 ~SimpleNetworkStack () override
 
void QueueGet (const std::string &pUrl, const std::filesystem::path &pFilepath="")
 
void QueueGet (const std::string &pUrl, const ResultFunc &pFunc, const std::filesystem::path &pFilepath="")
 
void QueueGet (const std::string &pUrl, ResultPromise pPromise, const std::filesystem::path &pFilepath="")
 
void SetUserAgent (const std::string &pUserAgent)
 
std::string UrlEncode (std::string_view pStr) const
 
- Public Member Functions inherited from ArcdpsExtension::Singleton< SimpleNetworkStack >
 ~Singleton () override
 
- Public Member Functions inherited from ArcdpsExtension::BaseSingleton
virtual ~BaseSingleton ()=default
 

Additional Inherited Members

- Static Public Member Functions inherited from ArcdpsExtension::Singleton< SimpleNetworkStack >
static T2 & instance ()
 
static T2 & init (Args &&... args)
 
static void f (std::function< void(T2 &)> action)
 
static void f (std::function< void(SimpleNetworkStack &)> action)
 
static void reset ()
 
- Static Protected Member Functions inherited from ArcdpsExtension::BaseSingleton
static BaseSingletonStore (std::unique_ptr< BaseSingleton > &&ptr)
 
static void Clear (BaseSingleton *ptr)
 

Member Typedef Documentation

◆ Result

◆ ResultFunc

using ArcdpsExtension::SimpleNetworkStack::ResultFunc = std::function<void(const Result&)>

◆ ResultPromise

Member Enumeration Documentation

◆ ErrorType

Enumerator
PerformError 
OptUrlError 
OptFollowLocationError 
OptWriteFuncError 
OptWriteDataError 
OptUseragentError 

Constructor & Destructor Documentation

◆ SimpleNetworkStack()

ArcdpsExtension::SimpleNetworkStack::SimpleNetworkStack ( )

◆ ~SimpleNetworkStack()

ArcdpsExtension::SimpleNetworkStack::~SimpleNetworkStack ( )
override

Member Function Documentation

◆ QueueGet() [1/3]

void ArcdpsExtension::SimpleNetworkStack::QueueGet ( const std::string &  pUrl,
const ResultFunc pFunc,
const std::filesystem::path &  pFilepath = "" 
)

Performs a Get-Request and will call pFunc when the response is gathered. If a filepath is provided, the response will be saved in that file and the Result will have an empty string.
Usage:

networkStack.QueueGet("https://example.com/", [](const SimpleNetworkStack::Result& response){
if (response) {
std::cout << response.value().Code << " --> " << response.value().Message << std::endl;
}
});
std::expected< Response, Error > Result
Definition SimpleNetworkStack.h:38
Parameters
pUrlThe URL to call
pFuncThe function that will be called with the response
pFilepathOptional filepath to save the response to

◆ QueueGet() [2/3]

void ArcdpsExtension::SimpleNetworkStack::QueueGet ( const std::string &  pUrl,
const std::filesystem::path &  pFilepath = "" 
)

Performs a Get-Request.
Usage:

networkStack.QueueGet("https://example.com/", [](const SimpleNetworkStack::Result& response){
if (response) {
std::cout << response.value().Code << " --> " << response.value().Message << std::endl;
}
});
Parameters
pUrlThe URL to call
pFilepathOptional filepath to save the response to

◆ QueueGet() [3/3]

void ArcdpsExtension::SimpleNetworkStack::QueueGet ( const std::string &  pUrl,
ResultPromise  pPromise,
const std::filesystem::path &  pFilepath = "" 
)

Performs a Get-Request and will resolve the promise when the response is gathered. If a filepath is provided, the response will be saved in that file and the Result will have an empty string.
Usage:

std::promise<SimpleNetworkStack::Result> promise;
auto future = barrier.get_future();
QueueGet("https://example.com/", std::move(promise));
void QueueGet(const std::string &pUrl, const std::filesystem::path &pFilepath="")
Definition SimpleNetworkStack.cpp:103
Parameters
pUrlThe URL to call
pPromisePromise that will resolved with the response
pFilepathOptional filepath to save the response to

◆ SetUserAgent()

void ArcdpsExtension::SimpleNetworkStack::SetUserAgent ( const std::string &  pUserAgent)
inline

Set a different user-agent instead of the default "ArcdpsExtension/1.0"

Parameters
pUserAgentvalue to set

◆ UrlEncode()

std::string ArcdpsExtension::SimpleNetworkStack::UrlEncode ( std::string_view  pStr) const

URL encode a string. Wrapper for curl_easy_escape.

Parameters
pStrstring to encode
Returns
encoded string

The documentation for this class was generated from the following files: