SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Attributes | List of all members
Online::Request Class Reference

Stores a request for the HTTP Manager. More...

#include <request.hpp>

Inheritance diagram for Online::Request:
Inheritance graph
[legend]

Classes

class  Compare
 This class is used by the priority queue to sort requests by priority. More...
 

Public Types

enum  RequestType { RT_QUIT = 1 }
 

Public Member Functions

 Request (int priority, int type)
 Creates a request that can be handled by the RequestManager.
 
void execute ()
 Executes the request.
 
void executeNow ()
 Executes the request now, i.e.
 
void queue ()
 Inserts this request into the RequestManager's queue for executing.
 
virtual void callback ()
 Executed when a request has finished.
 
int getType () const
 Returns the type of the request.
 
int getPriority () const
 Returns the priority of this request.
 
void cancel ()
 Signals that this request should be canceled.
 
bool isCancelled () const
 Returns if this request is to be canceled.
 
bool isAbortable () const
 Returns if this request can be aborted.
 
void setAbortable (bool b)
 Sets if this request is abortable or not.
 
void setBusy ()
 Sets the request state to busy.
 
void setExecuted ()
 Sets the request to be completed.
 
void setDone ()
 Should only be called by the manager.
 
bool isDone () const
 Returns if this request is done.
 
bool isPreparing () const
 Returns if this request is being prepared.
 
bool isBusy () const
 Returns if this request is busy.
 
bool hasBeenExecuted () const
 Checks if the request has completed or done (i.e.
 
virtual bool isAllowedToAdd () const
 Virtual method to check if a request has initialized all needed members to a valid value.
 

Protected Member Functions

virtual void operation ()
 The actual operation to be executed.
 
virtual void prepareOperation ()
 Virtual function to be called before an operation.
 
virtual void afterOperation ()
 Virtual function to be called after an operation.
 

Protected Attributes

Synchronised< bool > m_cancel
 Cancel this request if it is active.
 
Synchronised< bool > m_is_abortable
 If this request can be aborted (at the end of STK).
 
Synchronised< Statem_state
 Set to though if the reply of the request is in and callbacks are executed.
 

Private Types

enum  State { S_PREPARING , S_BUSY , S_EXECUTED , S_DONE }
 The different state of the requst: More...
 

Private Attributes

const int m_type
 Type of the request.
 
const int m_priority
 The priority of this request.
 

Detailed Description

Stores a request for the HTTP Manager.

They will be sorted by prioritiy. Requests have four different states they can be in, and this state determines which thread can access it. This allows the use of threading without adding more synchronisation overhead and code to the main thread. The states are:

Member Enumeration Documentation

◆ State

enum Online::Request::State
private

The different state of the requst:

  • S_PREPARING:
    The request is created and can be configured, it is not yet started.
  • S_BUSY:
    The request is added to the execution queue of the request_manager (and potentially executing). This implies that now only the request_manager thread should access the requests's data structures.
  • S_EXECUTED:
    The request was executed, but was not yet marked as finished in the request_manager. This importantly indicates that the main thread should not yet access this request, since the http thread is still executing it.
  • S_DONE:
    The request is finished, and it is marked as finished in the request_manager. This implies that the main stk thread can access its data safely now.

Constructor & Destructor Documentation

◆ Request()

Online::Request::Request ( int  priority,
int  type 
)

Creates a request that can be handled by the RequestManager.

Parameters
priorityby what priority should the RequestManager take care of this request
typeindicates whether the request has a special task for the RequestManager

Member Function Documentation

◆ afterOperation()

virtual void Online::Request::afterOperation ( )
inlineprotectedvirtual

Virtual function to be called after an operation.

Reimplemented in SubmitRankingRequest, Online::HTTPRequest, Online::XMLRequest, and AddonsPackRequest.

◆ callback()

virtual void Online::Request::callback ( )
inlinevirtual

◆ execute()

void Online::Request::execute ( )

Executes the request.

This calles prepareOperation, operation, and afterOperation.

◆ executeNow()

void Online::Request::executeNow ( )

Executes the request now, i.e.

in the main thread and without involving the manager thread.. This calles prepareOperation, operation, and afterOperation.

◆ hasBeenExecuted()

bool Online::Request::hasBeenExecuted ( ) const
inline

Checks if the request has completed or done (i.e.

callbacks were executed).

◆ isAllowedToAdd()

virtual bool Online::Request::isAllowedToAdd ( ) const
inlinevirtual

Virtual method to check if a request has initialized all needed members to a valid value.

Reimplemented in Online::HTTPRequest.

◆ operation()

virtual void Online::Request::operation ( )
inlineprotectedvirtual

The actual operation to be executed.

Empty as default, which allows to create a 'quit' request without any additional code.

Reimplemented in Online::HTTPRequest.

◆ prepareOperation()

virtual void Online::Request::prepareOperation ( )
inlineprotectedvirtual

Virtual function to be called before an operation.

Reimplemented in Online::HTTPRequest.

Member Data Documentation

◆ m_is_abortable

Synchronised<bool> Online::Request::m_is_abortable
protected

If this request can be aborted (at the end of STK).

Most requests can, except the (final) logout and client-quit/signout-request, which must be finished even when STK is quitting.

◆ m_priority

const int Online::Request::m_priority
private

The priority of this request.

The higher the value the more important this request is.

◆ m_type

const int Online::Request::m_type
private

Type of the request.

Has 0 as default value.


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