Equalizer 1.0
|
A thread-safe request handler. More...
#include <requestHandler.h>
Public Member Functions | |
COBASE_API | RequestHandler () |
Construct a new request handler. | |
COBASE_API | ~RequestHandler () |
Destruct the request handler. | |
COBASE_API uint32_t | registerRequest (void *data=0) |
Register a new request. | |
COBASE_API void | unregisterRequest (const uint32_t requestID) |
Unregister a request. | |
COBASE_API bool | waitRequest (const uint32_t requestID, void *&result, const uint32_t timeout=EQ_TIMEOUT_INDEFINITE) |
Wait a given time for the completion of a request. | |
COBASE_API bool | waitRequest (const uint32_t requestID, uint32_t &result, const uint32_t timeout=EQ_TIMEOUT_INDEFINITE) |
Wait for a request with an uint32_t result. | |
COBASE_API bool | waitRequest (const uint32_t requestID, bool &result, const uint32_t timeout=EQ_TIMEOUT_INDEFINITE) |
Wait for a request with a bool result. | |
COBASE_API bool | waitRequest (const uint32_t requestID, uint128_t &result, const uint32_t timeout=EQ_TIMEOUT_INDEFINITE) |
Wait for a request with an uint128_t result. | |
COBASE_API bool | waitRequest (const uint32_t requestID) |
Wait for a request without a result. | |
COBASE_API bool | isRequestServed (const uint32_t requestID) const |
Poll for the completion of a request. | |
COBASE_API void * | getRequestData (const uint32_t requestID) |
Retrieve the user-specific data for a request. | |
COBASE_API void | serveRequest (const uint32_t requestID, void *result=0) |
Serve a request with a void* result. | |
COBASE_API void | serveRequest (const uint32_t requestID, uint32_t result) |
Serve a request with an uint32_t result. | |
COBASE_API void | serveRequest (const uint32_t requestID, bool result) |
Serve a request with a bool result. | |
COBASE_API void | serveRequest (const uint32_t requestID, const uint128_t &result) |
Serve a request with an uint128_t result. | |
bool | hasPendingRequests () const |
Friends | |
COBASE_API std::ostream & | operator<< (std::ostream &, const RequestHandler &) |
A thread-safe request handler.
Different execution threads can synchronize using a request handler. One thread registers a request, and later waits for the request to be served. Another thread can serve the request, providing a result value.
A note on thread-safety: Unless threadSafe is set in the constructor, the functions registerRequest(), unregisterRequest() and waitRequest() are supposed to be called from one 'waiting' thread, and the functions serveRequest() and deleteRequest() are supposed to be called only from one 'serving' thread.
Definition at line 47 of file requestHandler.h.
COBASE_API co::base::RequestHandler::RequestHandler | ( | ) |
Construct a new request handler.
COBASE_API co::base::RequestHandler::~RequestHandler | ( | ) |
Destruct the request handler.
COBASE_API void* co::base::RequestHandler::getRequestData | ( | const uint32_t | requestID | ) |
Retrieve the user-specific data for a request.
requestID | the request identifier. |
bool co::base::RequestHandler::hasPendingRequests | ( | ) | const [inline] |
Definition at line 148 of file requestHandler.h.
COBASE_API bool co::base::RequestHandler::isRequestServed | ( | const uint32_t | requestID | ) | const |
Poll for the completion of a request.
Does not unregister the request.
requestID | the request identifier. |
COBASE_API uint32_t co::base::RequestHandler::registerRequest | ( | void * | data = 0 | ) |
Register a new request.
data | a pointer to user-specific data for the request, can be 0. |
COBASE_API void co::base::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
void * | result = 0 |
||
) |
Serve a request with a void* result.
requestID | the request identifier. |
result | the result of the request. |
COBASE_API void co::base::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
uint32_t | result | ||
) |
Serve a request with an uint32_t result.
COBASE_API void co::base::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
const uint128_t & | result | ||
) |
Serve a request with an uint128_t result.
COBASE_API void co::base::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
bool | result | ||
) |
Serve a request with a bool result.
COBASE_API void co::base::RequestHandler::unregisterRequest | ( | const uint32_t | requestID | ) |
Unregister a request.
Note that waitRequest automatically unregisters the request when it was successful. This method is only used when a waitRequest has timed out and the request will no longer be used.
requestID | the request identifier. |
COBASE_API bool co::base::RequestHandler::waitRequest | ( | const uint32_t | requestID | ) |
Wait for a request without a result.
COBASE_API bool co::base::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
uint128_t & | result, | ||
const uint32_t | timeout = EQ_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with an uint128_t result.
COBASE_API bool co::base::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
bool & | result, | ||
const uint32_t | timeout = EQ_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with a bool result.
COBASE_API bool co::base::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
uint32_t & | result, | ||
const uint32_t | timeout = EQ_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with an uint32_t result.
COBASE_API bool co::base::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
void *& | result, | ||
const uint32_t | timeout = EQ_TIMEOUT_INDEFINITE |
||
) |
Wait a given time for the completion of a request.
The request is unregistered upon successful completion, i.e, the when the method returns true.
requestID | the request identifier. |
result | the result code of the operation. |
timeout | the timeout in milliseconds to wait for the request, or EQ_TIMEOUT_INDEFINITE to wait indefinitely. |