21#ifndef HEADER_REQUEST_MANAGER_HPP
22#define HEADER_REQUEST_MANAGER_HPP
24#include "online/request.hpp"
25#include "utils/can_be_deleted.hpp"
26#include "utils/synchronised.hpp"
32# define WIN32_LEAN_AND_MEAN
37#include <condition_variable>
94 static bool m_disable_polling;
123 std::shared_ptr<Online::Request>,
124 std::vector<std::shared_ptr<Online::Request> >,
134 void addResult(std::shared_ptr<Online::Request> request);
145 static const int HTTP_MAX_PRIORITY = 9999;
152 if (m_request_manager == NULL)
156 return m_request_manager;
163 void addRequest(std::shared_ptr<Online::Request> request);
168 bool getPaused() {
return m_paused.load(); }
169 void setPaused(
bool val) {
m_paused.store(val); }
A simple class that a adds a function to wait with a timeout for a class to be ready to be deleted.
Definition: can_be_deleted.hpp:38
A class to execute requests in a separate thread.
Definition: request_manager.hpp:80
float m_menu_polling_interval
The polling interval while the menu is shown.
Definition: request_manager.hpp:115
Synchronised< std::priority_queue< std::shared_ptr< Online::Request >, std::vector< std::shared_ptr< Online::Request > >, Online::Request::Compare > > m_request_queue
The list of pointers to all requests that still need to be handled.
Definition: request_manager.hpp:127
float m_game_polling_interval
The polling interval while a game is running.
Definition: request_manager.hpp:112
Synchronised< bool > m_abort
Signal an abort in case that a download is still happening.
Definition: request_manager.hpp:106
std::atomic_bool m_paused
Signal an pause before STK goes into background in iOS.
Definition: request_manager.hpp:109
void addRequest(std::shared_ptr< Online::Request > request)
Inserts a request into the queue of all requests.
Definition: request_manager.cpp:148
void update(float dt)
Should be called every frame and takes care of processing the result queue and polling the database s...
Definition: request_manager.cpp:265
void setGamePollingInterval(float polling_interval)
Sets the interval with which poll requests are send to the server.
Definition: request_manager.hpp:184
void handleResultQueue()
Takes a request out of the result queue, if any is present.
Definition: request_manager.cpp:244
void stopNetworkThread()
This function inserts a high priority request to quit into the request queue of the network thead,...
Definition: request_manager.cpp:118
std::thread m_thread
Thread id of the thread running in this object.
Definition: request_manager.hpp:118
void addResult(std::shared_ptr< Online::Request > request)
Inserts a request into the queue of results.
Definition: request_manager.cpp:231
void setMenuPollingInterval(float polling_interval)
Sets the interval with which poll requests are send to the server.
Definition: request_manager.hpp:176
Synchronised< std::queue< std::shared_ptr< Online::Request > > > m_result_queue
The list of pointers to all requests that are already executed by the networking thread,...
Definition: request_manager.hpp:132
float m_time_since_poll
Time passed since the last poll request.
Definition: request_manager.hpp:97
void startNetworkThread()
Start the actual network thread.
Definition: request_manager.cpp:98
RequestManager()
Constructor.
Definition: request_manager.cpp:71
static void deallocate()
Deletes the http manager.
Definition: request_manager.cpp:51
std::shared_ptr< Online::Request > m_current_request
The current requested being worked on.
Definition: request_manager.hpp:100
std::condition_variable m_condition_variable
A conditional variable to wake up the main loop.
Definition: request_manager.hpp:103
static void mainLoop(void *obj)
The actual main loop, which is started as a separate thread from the constructor.
Definition: request_manager.cpp:173
static bool isRunning()
Checks if the http manager is running.
Definition: request_manager.cpp:63
InternetPermission
If stk has permission to access the internet (for news server etc).
Definition: request_manager.hpp:89
static RequestManager * get()
Singleton access function.
Definition: request_manager.hpp:150
This class is used by the priority queue to sort requests by priority.
Definition: request.hpp:217
A variable that is automatically synchronised using pthreads mutex.
Definition: synchronised.hpp:28
TYPE getAtomic() const
Returns a copy of this variable.
Definition: synchronised.hpp:68