cpp Rest API master
C++ library for REST API access with Qt, Curl and cpp-httplib backends
 
Loading...
Searching...
No Matches
threaded_connection.hpp
Go to the documentation of this file.
1#ifndef THREADED_CONNECTION_HPP_INCLUDED
2#define THREADED_CONNECTION_HPP_INCLUDED
3
4#include <condition_variable>
5#include <mutex>
6
7#include "base_connection.hpp"
8#include "cpp_restapi_export.h"
9
10
11namespace cpp_restapi
12{
24 class CPP_RESTAPI_EXPORT ThreadedConnection : public BaseConnection
25 {
26 public:
27 using BaseConnection::BaseConnection;
28 using BaseConnection::fetch;
29
31
32 protected:
33 void fetchAsync(const std::string& fullUrl,
34 CancellationToken cancel,
35 FetchCallback onSuccess,
36 ErrorCallback onError) override;
37
42
43 private:
44 std::mutex m_mutex;
45 std::condition_variable m_cv;
46 unsigned m_activeCount = 0;
47 };
48}
49
50#endif
base class with common parts for backend specific implementations
Definition base_connection.hpp:18
BaseConnection subclass that implements fetch(url, cb) via a background std::thread.
Definition threaded_connection.hpp:25
void fetchAsync(const std::string &fullUrl, CancellationToken cancel, FetchCallback onSuccess, ErrorCallback onError) override
Definition base_connection.hpp:13
std::shared_ptr< std::atomic< bool > > CancellationToken
Token returned by asynchronous fetch(); set it to true to cancel the request.
Definition iconnection.hpp:33
std::function< void(Response)> FetchCallback
Definition iconnection.hpp:42
std::function< void(HttpError)> ErrorCallback
Definition iconnection.hpp:44