libzypp 17.37.10

networkrequestdispatcher_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPP_NG_MEDIA_CURL_PRIVATE_CURL_P_H_INCLUDED
15#define ZYPP_NG_MEDIA_CURL_PRIVATE_CURL_P_H_INCLUDED
16
17#include <zypp-curl/ng/network/networkrequestdispatcher.h>
18#include <zypp-core/zyppng/base/private/base_p.h>
19#include <curl/curl.h>
20#include <deque>
21#include <set>
22#include <unordered_map>
23
24 namespace zyppng {
25
26 class Timer;
27 class SocketNotifier;
28
29 class NetworkRequestDispatcherPrivate : public BasePrivate
30{
31 ZYPP_DECLARE_PUBLIC(NetworkRequestDispatcher)
32 public:
33 NetworkRequestDispatcherPrivate ( NetworkRequestDispatcher &p );
34 ~NetworkRequestDispatcherPrivate() override;
35
36 int _maxConnections = 10;
37
38 std::deque< std::shared_ptr<NetworkRequest> > _pendingDownloads;
39 std::vector< std::shared_ptr<NetworkRequest> > _runningDownloads;
40
41 std::shared_ptr<Timer> _timer;
42 std::map< curl_socket_t, std::shared_ptr<SocketNotifier> > _socketHandler;
43
44 bool _isRunning = false;
45 bool _locked = false; //if set to true, no new requests will be dequeued
46 CURLM *_multi = nullptr;
47
48 NetworkRequestError _lastError;
49
50 std::string _userAgent;
51 std::unordered_map< std::string, std::unordered_map<std::string, std::string> > _customHeaders;
52
53 //signals
54 Signal< void ( NetworkRequestDispatcher &, NetworkRequest & )> _sigDownloadStarted;
55 Signal< void ( NetworkRequestDispatcher &, NetworkRequest & )> _sigDownloadFinished;
56 Signal< void ( NetworkRequestDispatcher & )> _sigQueueFinished;
57 Signal< void ( NetworkRequestDispatcher & )> _sigError;
58
59 private:
60 static int multi_timer_cb ( CURLM *multi, long timeout_ms, void *g );
61 static int static_socket_callback(CURL *easy, curl_socket_t s, int what, void *userp, SocketNotifier *socketp );
62
63 void multiTimerTimout ( const Timer &t );
64 int socketCallback(CURL *easy, curl_socket_t s, int what, void * );
65
66 void cancelAll ( const NetworkRequestError& result );
67 bool addRequestToMultiHandle ( NetworkRequest &req );
68 void setFinished( NetworkRequest &req , NetworkRequestError result );
69
70 void onSocketActivated ( const SocketNotifier &listener, int events );
71
72 void handleMultiSocketAction ( curl_socket_t nativeSocket, int evBitmask );
73 void dequeuePending ();
74};
75}
76
77#endif
base_p.h
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::NetworkRequestDispatcherPrivate::NetworkRequestDispatcherPrivate
NetworkRequestDispatcherPrivate(NetworkRequestDispatcher &p)
Definition networkrequestdispatcher.cc:47
zyppng::NetworkRequestDispatcherPrivate::static_socket_callback
static int static_socket_callback(CURL *easy, curl_socket_t s, int what, void *userp, SocketNotifier *socketp)
Definition networkrequestdispatcher.cc:94
zyppng::NetworkRequestDispatcherPrivate::socketCallback
int socketCallback(CURL *easy, curl_socket_t s, int what, void *)
Definition networkrequestdispatcher.cc:101
zyppng::NetworkRequestDispatcherPrivate::_sigError
Signal< void(NetworkRequestDispatcher &)> _sigError
Definition networkrequestdispatcher_p.h:57
zyppng::NetworkRequestDispatcherPrivate::_sigQueueFinished
Signal< void(NetworkRequestDispatcher &)> _sigQueueFinished
Definition networkrequestdispatcher_p.h:56
zyppng::NetworkRequestDispatcherPrivate::dequeuePending
void dequeuePending()
Definition networkrequestdispatcher.cc:343
zyppng::NetworkRequestDispatcherPrivate::_customHeaders
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > _customHeaders
Definition networkrequestdispatcher_p.h:51
zyppng::NetworkRequestDispatcherPrivate::setFinished
void setFinished(NetworkRequest &req, NetworkRequestError result)
Definition networkrequestdispatcher.cc:279
zyppng::NetworkRequestDispatcherPrivate::_isRunning
bool _isRunning
Definition networkrequestdispatcher_p.h:44
zyppng::NetworkRequestDispatcherPrivate::multiTimerTimout
void multiTimerTimout(const Timer &t)
Definition networkrequestdispatcher.cc:89
zyppng::NetworkRequestDispatcherPrivate::_lastError
NetworkRequestError _lastError
Definition networkrequestdispatcher_p.h:48
zyppng::NetworkRequestDispatcherPrivate::handleMultiSocketAction
void handleMultiSocketAction(curl_socket_t nativeSocket, int evBitmask)
Definition networkrequestdispatcher.cc:176
zyppng::NetworkRequestDispatcherPrivate::_multi
CURLM * _multi
Definition networkrequestdispatcher_p.h:46
zyppng::NetworkRequestDispatcherPrivate::~NetworkRequestDispatcherPrivate
~NetworkRequestDispatcherPrivate() override
Definition networkrequestdispatcher.cc:68
zyppng::NetworkRequestDispatcherPrivate::_sigDownloadFinished
Signal< void(NetworkRequestDispatcher &, NetworkRequest &)> _sigDownloadFinished
Definition networkrequestdispatcher_p.h:55
zyppng::NetworkRequestDispatcherPrivate::_timer
std::shared_ptr< Timer > _timer
Definition networkrequestdispatcher_p.h:41
zyppng::NetworkRequestDispatcherPrivate::_maxConnections
int _maxConnections
Definition networkrequestdispatcher_p.h:36
zyppng::NetworkRequestDispatcherPrivate::_socketHandler
std::map< curl_socket_t, std::shared_ptr< SocketNotifier > > _socketHandler
Definition networkrequestdispatcher_p.h:42
zyppng::NetworkRequestDispatcherPrivate::addRequestToMultiHandle
bool addRequestToMultiHandle(NetworkRequest &req)
Definition networkrequestdispatcher.cc:329
zyppng::NetworkRequestDispatcherPrivate::_userAgent
std::string _userAgent
Definition networkrequestdispatcher_p.h:50
zyppng::NetworkRequestDispatcherPrivate::onSocketActivated
void onSocketActivated(const SocketNotifier &listener, int events)
Definition networkrequestdispatcher.cc:163
zyppng::NetworkRequestDispatcherPrivate::_sigDownloadStarted
Signal< void(NetworkRequestDispatcher &, NetworkRequest &)> _sigDownloadStarted
Definition networkrequestdispatcher_p.h:54
zyppng::NetworkRequestDispatcherPrivate::_pendingDownloads
std::deque< std::shared_ptr< NetworkRequest > > _pendingDownloads
Definition networkrequestdispatcher_p.h:38
zyppng::NetworkRequestDispatcherPrivate::multi_timer_cb
static int multi_timer_cb(CURLM *multi, long timeout_ms, void *g)
Definition networkrequestdispatcher.cc:75
zyppng::NetworkRequestDispatcherPrivate::_locked
bool _locked
Definition networkrequestdispatcher_p.h:45
zyppng::NetworkRequestDispatcherPrivate::cancelAll
void cancelAll(const NetworkRequestError &result)
Definition networkrequestdispatcher.cc:263
zyppng::NetworkRequestDispatcherPrivate::_runningDownloads
std::vector< std::shared_ptr< NetworkRequest > > _runningDownloads
Definition networkrequestdispatcher_p.h:39
zyppng::NetworkRequestError
The NetworkRequestError class Represents a error that occured in.
Definition networkrequesterror.h:24
zyppng::NetworkRequest
Definition request.h:43
zyppng::Signal
Definition signals.h:151
zyppng::SocketNotifier
Definition socketnotifier.h:69
zyppng::Timer
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
zyppng
Definition MediaNetworkRequestExecutor.h:16
networkrequestdispatcher.h
ZYPP_DECLARE_PUBLIC
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:98