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

Protected Member Functions

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

Protected Attributes

Synchronised< bool > m_cancel
 Cancel this request if it is active. More...
 
Synchronised< bool > m_is_abortable
 If this request can be aborted (at the end of STK). More...
 
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. More...
 
const int m_priority
 The priority of this request. More...
 

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

◆ cancel()

void Online::Request::cancel ( )
inline

Signals that this request should be canceled.

◆ 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.

◆ getPriority()

int Online::Request::getPriority ( ) const
inline

Returns the priority of this request.

◆ getType()

int Online::Request::getType ( ) const
inline

Returns the type of the request.

◆ hasBeenExecuted()

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

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

callbacks were executed).

◆ isAbortable()

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

Returns if this request can be aborted.

◆ 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.

◆ isBusy()

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

Returns if this request is busy.

◆ isCancelled()

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

Returns if this request is to be canceled.

◆ isDone()

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

Returns if this request is done.

◆ isPreparing()

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

Returns if this request is being prepared.

◆ 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.

◆ setAbortable()

void Online::Request::setAbortable ( bool  b)
inline

Sets if this request is abortable or not.

◆ setBusy()

void Online::Request::setBusy ( )
inline

Sets the request state to busy.

◆ setExecuted()

void Online::Request::setExecuted ( )
inline

Sets the request to be completed.

Member Data Documentation

◆ m_cancel

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

Cancel this request if it is active.

◆ 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: