Equalizer  1.2.1
Public Member Functions | Friends
co::base::RequestHandler Class Reference

A thread-safe request handler. More...

#include <requestHandler.h>

+ Inheritance diagram for co::base::RequestHandler:
+ Collaboration diagram for co::base::RequestHandler:

List of all members.

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 &)

Detailed Description

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.


Constructor & Destructor Documentation

Construct a new request handler.

Version:
1.0

Destruct the request handler.


Member Function Documentation

COBASE_API void* co::base::RequestHandler::getRequestData ( const uint32_t  requestID)

Retrieve the user-specific data for a request.

Parameters:
requestIDthe request identifier.
Returns:
the user-specific data for the request.
Version:
1.0
Returns:
true if this request handler has pending requests.
Version:
1.0

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.

Parameters:
requestIDthe request identifier.
Returns:
true if the request has been served, false if it is pending.
Version:
1.0
COBASE_API uint32_t co::base::RequestHandler::registerRequest ( void *  data = 0)

Register a new request.

Parameters:
dataa pointer to user-specific data for the request, can be 0.
Returns:
the request identifier.
Version:
1.0
COBASE_API void co::base::RequestHandler::serveRequest ( const uint32_t  requestID,
void *  result = 0 
)

Serve a request with a void* result.

Parameters:
requestIDthe request identifier.
resultthe result of the request.
Version:
1.0
COBASE_API void co::base::RequestHandler::serveRequest ( const uint32_t  requestID,
uint32_t  result 
)

Serve a request with an uint32_t result.

Version:
1.0
COBASE_API void co::base::RequestHandler::serveRequest ( const uint32_t  requestID,
bool  result 
)

Serve a request with a bool result.

Version:
1.0
COBASE_API void co::base::RequestHandler::serveRequest ( const uint32_t  requestID,
const uint128_t result 
)

Serve a request with an uint128_t result.

Version:
1.0
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.

Parameters:
requestIDthe request identifier.
Version:
1.0
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.

Parameters:
requestIDthe request identifier.
resultthe result code of the operation.
timeoutthe timeout in milliseconds to wait for the request, or EQ_TIMEOUT_INDEFINITE to wait indefinitely.
Returns:
true if the request was served, false if not.
Version:
1.0
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.

Version:
1.0
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.

Version:
1.0
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.

Version:
1.0
COBASE_API bool co::base::RequestHandler::waitRequest ( const uint32_t  requestID)

Wait for a request without a result.

Version:
1.0

The documentation for this class was generated from the following file:
Generated on Fri Jun 8 2012 15:44:34 for Equalizer 1.2.1 by  doxygen 1.8.0