|
void | addRequest (std::shared_ptr< Online::Request > request) |
| Inserts a request into the queue of all requests.
|
|
void | startNetworkThread () |
| Start the actual network thread.
|
|
void | stopNetworkThread () |
| This function inserts a high priority request to quit into the request queue of the network thead, and also aborts any ongoing download.
|
|
bool | getAbort () |
|
bool | getPaused () |
|
void | setPaused (bool val) |
|
void | update (float dt) |
| Should be called every frame and takes care of processing the result queue and polling the database server if a user is signed in.
|
|
void | setMenuPollingInterval (float polling_interval) |
| Sets the interval with which poll requests are send to the server.
|
|
void | setGamePollingInterval (float polling_interval) |
| Sets the interval with which poll requests are send to the server.
|
|
| CanBeDeleted () |
| Set this instance to be not ready to be deleted.
|
|
void | setCanBeDeleted () |
| Sets this instance to be ready to be deleted.
|
|
void | resetCanBeDeleted () |
|
bool | canBeDeletedNow () |
|
bool | waitForReadyToDeleted (float waiting_time) |
| Waits at most t seconds for this class to be ready to be deleted.
|
|
|
float | m_time_since_poll |
| Time passed since the last poll request.
|
|
std::shared_ptr< Online::Request > | m_current_request |
| The current requested being worked on.
|
|
std::condition_variable | m_condition_variable |
| A conditional variable to wake up the main loop.
|
|
Synchronised< bool > | m_abort |
| Signal an abort in case that a download is still happening.
|
|
std::atomic_bool | m_paused |
| Signal an pause before STK goes into background in iOS.
|
|
float | m_game_polling_interval |
| The polling interval while a game is running.
|
|
float | m_menu_polling_interval |
| The polling interval while the menu is shown.
|
|
std::thread | m_thread |
| Thread id of the thread running in this object.
|
|
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.
|
|
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, but still need to be processed by the main thread.
|
|
A class to execute requests in a separate thread.
Typically the requests involve a http(s) requests to be sent to the stk server, and receive an answer (e.g. to sign in; or to download an addon). The requests are sorted by priority (e.g. sign in and out have higher priority than downloading addon icons). A request is created and initialised from the main thread. When it is moved into the request queue, it must not be handled by the main thread anymore, only the RequestManager thread can handle it. Once the request is finished, it is put in a separate ready queue. The main thread regularly checks the ready queue for any ready request, and executes a callback. So there is no need to protect any functions or data members in requests, since they will either be handled by the main thread, or RequestManager thread, never by both. On exit, if necessary a high priority sign-out or client-quit request is put into the queue, and a flag is set which causes libcurl to abort any ongoing download. Then an additional 'quit' event with same priority as the sign-out is added to the queue (since it will be added later, the sign-out will be executed first, making sure that a logged in user is logged out (or its session saved). Once this is done, most of stk is deleted (except a few objects like the file manager which might be accessed if a download just finished before the abort). On executing the quit request, the request manager will set a flag that it is ready to be deleted (using the CanBeDeleted class). The main thread will wait for a certain amount of time for the RequestManager to be ready to be deleted (i.e. the sign-out and quit request have been processes), before deleting the RequestManager. Typically the RequestManager will finish while the rest of stk is shutting down, so the user will not experience any waiting time. Only on first start of stk (which will trigger downloading of all addon icons) is it possible that actually a download request is running, which might take a bit before it can be deleted.