28 #ifndef __OgreWorkQueue_H__
29 #define __OgreWorkQueue_H__
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();
ResponseHandlerListByChannel mResponseHandlers
uint16 getChannel() const
Get the request channel (top level categorisation)
const String & getMessages() const
Get any diagnostic messages about the process.
Any mData
The details of the request (user defined)
Variant type that can hold Any other type.
RequestQueue mRequestQueue
RequestHandler * mHandler
uint16 mType
The request type, as an integer within the channel (user can define enumerations on this) ...
virtual void setResponseProcessingTimeLimit(unsigned long ms)
Set the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
General purpose request structure.
bool mSuccess
Whether the work item succeeded or not.
map< uint16, ResponseHandlerList >::type ResponseHandlerListByChannel
RequestID mID
Identifier (assigned by the system)
bool mWorkerRenderSystemAccess
RequestQueue mIdleRequestQueue
General purpose response structure.
unsigned long mResposeTimeLimitMS
map< uint16, RequestHandlerList >::type RequestHandlerListByChannel
list< RequestHandlerHolderPtr >::type RequestHandlerList
Base for a general purpose request / response style background work queue.
ResponseQueue mResponseQueue
RequestHandlerHolder(RequestHandler *handler)
DefaultWorkQueueBase * mQueue
const Any & getData() const
Return the response data (user defined, only valid on success)
virtual bool canHandleResponse(const Response *res, const WorkQueue *srcQ)
Return whether this handler can process a given response.
SharedPtr< RequestHandlerHolder > RequestHandlerHolderPtr
virtual unsigned long getResponseProcessingTimeLimit() const
Get the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
Any mData
Data associated with the result of the process.
WorkerFunc(DefaultWorkQueueBase *q)
RequestHandler * getHandler()
Get handler pointer - note, only use this for == comparison or similar, do not attempt to call it as ...
const Request * mRequest
Pointer to the request that this response is in relation to.
uint16 getType() const
Get the type of this request within the given channel.
virtual bool canHandleRequest(const Request *req, const WorkQueue *srcQ)
Return whether this handler can process a given request.
RequestID getID() const
Get the identifier of this request.
void abortRequest()
Abort the request.
Interface definition for a handler of requests.
Intermediate structure to hold a pointer to a request handler which provides insurance against the ha...
virtual bool isShuttingDown() const
Returns whether the queue is trying to shut down.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
uint8 mRetryCount
Retry count - set this to non-zero to have the request try again on failure.
uint8 getRetryCount() const
Get the remaining retry count.
map< String, uint16 >::type ChannelMap
Interface definition for a handler of responses.
RequestQueue mProcessQueue
deque< Request * >::type RequestQueue
bool getAborted() const
Get the abort flag.
RequestHandlerListByChannel mRequestHandlers
#define OGRE_LOCK_RW_MUTEX_READ(name)
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
#define OGRE_LOCK_RW_MUTEX_WRITE(name)
void abortRequest() const
Set the abort flag.
list< ResponseHandler * >::type ResponseHandlerList
virtual ~RequestHandler()
unsigned long long int RequestID
Numeric identifier for a request.
Response * handleRequest(const Request *req, const WorkQueue *srcQ)
Process a request if possible.
Reference-counted shared pointer, used for objects where implicit destruction is required.
#define OGRE_RW_MUTEX(name)
const Request * getRequest() const
Get the request that this is a response to (NB destruction destroys this)
const Any & getData() const
Get the user details of this request.
size_t mWorkerThreadCount
String mMessages
Any diagnostic messages.
Interface to a general purpose request / response style background work queue.
deque< Response * >::type ResponseQueue
uint16 mChannel
The request channel, as an integer.
virtual ~ResponseHandler()
bool succeeded() const
Return whether this is a successful response.