xoreos  0.0.5
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Events::RequestManager Class Reference

The request manager, handling all requests. More...

#include <requests.h>

Inheritance diagram for Events::RequestManager:
Inheritance graph
[legend]
Collaboration diagram for Events::RequestManager:
Collaboration graph
[legend]

Public Member Functions

 ~RequestManager ()
 
void init ()
 
void deinit ()
 
void dispatch (RequestID request)
 Dispatch a request. More...
 
void waitReply (RequestID request)
 Wait for a request to be answered. More...
 
void forget (RequestID request)
 Ignore any answer we get. More...
 
void dispatchAndWait (RequestID request)
 Dispatch a request and wait for the answer. More...
 
void dispatchAndForget (RequestID request)
 Dispatch a request and ignore the answer. More...
 
void sync ()
 Request a sync, letting all prior requests finish. More...
 
template<typename T >
callInMainThread (const MainThreadFunctor< T > &f)
 Call this function in the main thread. More...
 
RequestID rebuild (Graphics::GLContainer &glContainer)
 Request that a GL container shall be rebuilt. More...
 
RequestID destroy (Graphics::GLContainer &glContainer)
 Request that a GL container shall be destroyed. More...
 
- Public Member Functions inherited from Common::Thread
 Thread ()
 
virtual ~Thread ()
 
bool createThread (const UString &name="")
 
bool destroyThread ()
 

Static Public Member Functions

static void destroy ()
 
- Static Public Member Functions inherited from Common::Singleton< RequestManager >
static RequestManager & instance ()
 
static void destroy ()
 

Private Member Functions

RequestID newRequest (ITCEvent type)
 Create a new, empty request of that type. More...
 
void clearList ()
 
void collectGarbage ()
 
void threadMethod ()
 
void callInMainThread (const MainThreadCallerFunctor &caller)
 

Private Attributes

Common::Mutex _mutexUse
 The mutex locking the use of the manager. More...
 
RequestList _requests
 All currently active requests. More...
 

Additional Inherited Members

- Protected Types inherited from Common::Singleton< RequestManager >
typedef RequestManager SingletonBaseType
 
- Protected Member Functions inherited from Common::Singleton< RequestManager >
 Singleton ()
 
virtual ~Singleton ()
 
- Protected Attributes inherited from Common::Thread
boost::atomic< bool > _killThread
 

Detailed Description

The request manager, handling all requests.

Requests are the main means of communication between the game thread and the main thread, which handles all low-level event and graphics operations.

The idea behind requests is that, as soon as the game thread knows exactly what it needs, it creates and dispatches a specific request. Then it does other things, until it needs what it requested for, issuing a waitReply on the request. That way, the actual fulfilling of the request can happen asynchronously, without it unnecessarily blocking further execution of the game thread.

Note
As soon as waitReply(), forget(), dispatchAndWait() or dispatchAndForget() was called, the RequestID expires.

Definition at line 65 of file requests.h.

Constructor & Destructor Documentation

◆ ~RequestManager()

Events::RequestManager::~RequestManager ( )

Definition at line 38 of file requests.cpp.

References clearList().

Here is the call graph for this function:

Member Function Documentation

◆ callInMainThread() [1/2]

template<typename T >
T Events::RequestManager::callInMainThread ( const MainThreadFunctor< T > &  f)
inline

Call this function in the main thread.

Definition at line 88 of file requests.h.

References Common::StackException::empty(), Events::MainThreadFunctor< T >::getError(), and Events::MainThreadFunctor< T >::getReturnValue().

Here is the call graph for this function:

◆ callInMainThread() [2/2]

void Events::RequestManager::callInMainThread ( const MainThreadCallerFunctor caller)
private

Definition at line 152 of file requests.cpp.

References dispatchAndWait(), Events::kITCEventCallInMainThread, and newRequest().

Here is the call graph for this function:

◆ clearList()

void Events::RequestManager::clearList ( )
private

Definition at line 160 of file requests.cpp.

References _mutexUse, _requests, and Common::PtrList< T, Deallocator >::clear().

Referenced by deinit(), init(), and ~RequestManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collectGarbage()

void Events::RequestManager::collectGarbage ( )
private

Definition at line 170 of file requests.cpp.

References _mutexUse, _requests, Common::PtrList< T, Deallocator >::remove_if(), and Events::requestIsGarbage().

Referenced by threadMethod().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deinit()

void Events::RequestManager::deinit ( )

Definition at line 49 of file requests.cpp.

References clearList(), and Common::Thread::destroyThread().

Here is the call graph for this function:

◆ destroy() [1/2]

RequestID Events::RequestManager::destroy ( Graphics::GLContainer glContainer)

Request that a GL container shall be destroyed.

Definition at line 136 of file requests.cpp.

References Events::kITCEventDestroyGLContainer, and newRequest().

Here is the call graph for this function:

◆ destroy() [2/2]

void Events::RequestManager::destroy ( )
static

Definition at line 183 of file requests.cpp.

References Common::Singleton< T >::destroy().

Referenced by deinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch()

void Events::RequestManager::dispatch ( RequestID  request)

Dispatch a request.

Definition at line 55 of file requests.cpp.

References _mutexUse, EventMan, and Common::isMainThread().

Referenced by dispatchAndForget(), and dispatchAndWait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatchAndForget()

void Events::RequestManager::dispatchAndForget ( RequestID  request)

Dispatch a request and ignore the answer.

Definition at line 117 of file requests.cpp.

References dispatch(), and forget().

Here is the call graph for this function:

◆ dispatchAndWait()

void Events::RequestManager::dispatchAndWait ( RequestID  request)

Dispatch a request and wait for the answer.

Definition at line 112 of file requests.cpp.

References dispatch(), and waitReply().

Referenced by callInMainThread(), and sync().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forget()

void Events::RequestManager::forget ( RequestID  request)

Ignore any answer we get.

Definition at line 106 of file requests.cpp.

References _mutexUse.

Referenced by dispatchAndForget().

Here is the caller graph for this function:

◆ init()

void Events::RequestManager::init ( )

Definition at line 42 of file requests.cpp.

References clearList(), and Common::Thread::createThread().

Here is the call graph for this function:

◆ newRequest()

RequestID Events::RequestManager::newRequest ( ITCEvent  type)
private

Create a new, empty request of that type.

Definition at line 144 of file requests.cpp.

References _mutexUse, and _requests.

Referenced by callInMainThread(), destroy(), rebuild(), and sync().

Here is the caller graph for this function:

◆ rebuild()

RequestID Events::RequestManager::rebuild ( Graphics::GLContainer glContainer)

Request that a GL container shall be rebuilt.

Definition at line 128 of file requests.cpp.

References Events::kITCEventRebuildGLContainer, and newRequest().

Here is the call graph for this function:

◆ sync()

void Events::RequestManager::sync ( )

Request a sync, letting all prior requests finish.

Definition at line 122 of file requests.cpp.

References dispatchAndWait(), Events::kITCEventSync, and newRequest().

Here is the call graph for this function:

◆ threadMethod()

void Events::RequestManager::threadMethod ( )
privatevirtual

Implements Common::Thread.

Definition at line 176 of file requests.cpp.

References Common::Thread::_killThread, collectGarbage(), and EventMan.

Here is the call graph for this function:

◆ waitReply()

void Events::RequestManager::waitReply ( RequestID  request)

Wait for a request to be answered.

Definition at line 74 of file requests.cpp.

References _mutexUse, Common::Mutex::lock(), and Common::Mutex::unlock().

Referenced by dispatchAndWait().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _mutexUse

Common::Mutex Events::RequestManager::_mutexUse
private

The mutex locking the use of the manager.

Definition at line 108 of file requests.h.

Referenced by clearList(), collectGarbage(), dispatch(), forget(), newRequest(), and waitReply().

◆ _requests

RequestList Events::RequestManager::_requests
private

All currently active requests.

Definition at line 110 of file requests.h.

Referenced by clearList(), collectGarbage(), and newRequest().


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