28 #ifndef __OgreWorkQueue_H__
29 #define __OgreWorkQueue_H__
115 RequestID
getID()
const {
return mID; }
228 virtual void startup(
bool forceRestart =
true) = 0;
238 virtual void addRequestHandler(
uint16 channel, RequestHandler* rh) = 0;
240 virtual void removeRequestHandler(
uint16 channel, RequestHandler* rh) = 0;
251 virtual void addResponseHandler(
uint16 channel, ResponseHandler* rh) = 0;
253 virtual void removeResponseHandler(
uint16 channel, ResponseHandler* rh) = 0;
272 virtual RequestID addRequest(
uint16 channel,
uint16 requestType,
const Any& rData,
uint8 retryCount = 0,
273 bool forceSynchronous =
false,
bool idleThread =
false) = 0;
280 virtual void abortRequest(RequestID
id) = 0;
288 virtual void abortRequestsByChannel(
uint16 channel) = 0;
296 virtual void abortPendingRequestsByChannel(
uint16 channel) = 0;
302 virtual void abortAllRequests() = 0;
309 virtual void setPaused(
bool pause) = 0;
311 virtual bool isPaused()
const = 0;
317 virtual void setRequestsAccepted(
bool accept) = 0;
319 virtual bool getRequestsAccepted()
const = 0;
329 virtual void processResponses() = 0;
334 virtual unsigned long getResponseProcessingTimeLimit()
const = 0;
341 virtual void setResponseProcessingTimeLimit(
unsigned long ms) = 0;
345 virtual void shutdown() = 0;
371 const String& getName()
const;
375 virtual size_t getWorkerThreadCount()
const;
382 virtual void setWorkerThreadCount(
size_t c);
393 virtual bool getWorkersCanAccessRenderSystem()
const;
407 virtual void setWorkersCanAccessRenderSystem(
bool access);
416 virtual void _processNextRequest();
419 virtual void _threadMain() = 0;
425 virtual void addRequestHandler(
uint16 channel, RequestHandler* rh);
427 virtual void removeRequestHandler(
uint16 channel, RequestHandler* rh);
429 virtual void addResponseHandler(
uint16 channel, ResponseHandler* rh);
431 virtual void removeResponseHandler(
uint16 channel, ResponseHandler* rh);
434 virtual RequestID addRequest(
uint16 channel,
uint16 requestType,
const Any& rData,
uint8 retryCount = 0,
435 bool forceSynchronous =
false,
bool idleThread =
false);
437 virtual void abortRequest(RequestID
id);
439 virtual void abortRequestsByChannel(
uint16 channel);
441 virtual void abortPendingRequestsByChannel(
uint16 channel);
443 virtual void abortAllRequests();
445 virtual void setPaused(
bool pause);
447 virtual bool isPaused()
const;
449 virtual void setRequestsAccepted(
bool accept);
451 virtual bool getRequestsAccepted()
const;
453 virtual void processResponses();
481 void operator()()
const;
498 : mHandler(handler) {}
524 if (mHandler->canHandleRequest(req, srcQ))
526 response = mHandler->handleRequest(req, srcQ);
559 void processRequestResponse(Request* r,
bool synchronous);
560 Response* processRequest(Request* r);
563 virtual void notifyWorkers() = 0;
565 void addRequestWithRID(RequestID rid,
uint16 channel,
uint16 requestType,
const Any& rData,
uint8 retryCount);
572 bool processIdleRequests();
unsigned long long int RequestID
Numeric identifier for a request.
list< RequestHandlerHolderPtr >::type RequestHandlerList
RequestHandler * getHandler()
Get handler pointer - note, only use this for == comparison or similar, do not attempt to call it as ...
RequestID mID
Identifier (assigned by the system)
const Request * mRequest
Pointer to the request that this response is in relation to.
SharedPtr< RequestHandlerHolder > RequestHandlerHolderPtr
map< uint16, RequestHandlerList >::type RequestHandlerListByChannel
RequestID getID() const
Get the identifier of this request.
virtual bool canHandleResponse(const Response *res, const WorkQueue *srcQ)
Return whether this handler can process a given response.
RequestHandlerHolder(RequestHandler *handler)
RequestQueue mIdleRequestQueue
Interface to a general purpose request / response style background work queue.
const String & getMessages() const
Get any diagnostic messages about the process.
map< String, uint16 >::type ChannelMap
Reference-counted shared pointer, used for objects where implicit destruction is required.
virtual bool canHandleRequest(const Request *req, const WorkQueue *srcQ)
Return whether this handler can process a given request.
deque< Response * >::type ResponseQueue
WorkerFunc(DefaultWorkQueueBase *q)
size_t mWorkerThreadCount
virtual void setResponseProcessingTimeLimit(unsigned long ms)
Set the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
void abortRequest() const
Set the abort flag.
void abortRequest()
Abort the request.
Variant type that can hold Any other type.
uint8 getRetryCount() const
Get the remaining retry count.
uint8 mRetryCount
Retry count - set this to non-zero to have the request try again on failure.
const Request * getRequest() const
Get the request that this is a response to (NB destruction destroys this)
#define OGRE_LOCK_RW_MUTEX_WRITE(name)
const Any & getData() const
Return the response data (user defined, only valid on success)
String mMessages
Any diagnostic messages.
RequestQueue mRequestQueue
virtual unsigned long getResponseProcessingTimeLimit() const
Get the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
bool getAborted() const
Get the abort flag.
General purpose request structure.
bool mWorkerRenderSystemAccess
Any mData
Data associated with the result of the process.
General purpose response structure.
#define OGRE_RW_MUTEX(name)
DefaultWorkQueueBase * mQueue
RequestHandlerListByChannel mRequestHandlers
virtual ~RequestHandler()
uint16 mType
The request type, as an integer within the channel (user can define enumerations on this) ...
deque< Request * >::type RequestQueue
RequestQueue mProcessQueue
const Any & getData() const
Get the user details of this request.
ResponseHandlerListByChannel mResponseHandlers
unsigned long mResposeTimeLimitMS
Base for a general purpose request / response style background work queue.
#define OGRE_LOCK_RW_MUTEX_READ(name)
Response * handleRequest(const Request *req, const WorkQueue *srcQ)
Process a request if possible.
Interface definition for a handler of responses.
uint16 mChannel
The request channel, as an integer.
map< uint16, ResponseHandlerList >::type ResponseHandlerListByChannel
ResponseQueue mResponseQueue
uint16 getChannel() const
Get the request channel (top level categorisation)
bool succeeded() const
Return whether this is a successful response.
RequestHandler * mHandler
Any mData
The details of the request (user defined)
list< ResponseHandler * >::type ResponseHandlerList
uint16 getType() const
Get the type of this request within the given channel.
virtual bool isShuttingDown() const
Returns whether the queue is trying to shut down.
virtual ~ResponseHandler()
Interface definition for a handler of requests.
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
bool mSuccess
Whether the work item succeeded or not.
Intermediate structure to hold a pointer to a request handler which provides insurance against the ha...