28 #ifndef __OgreWorkQueue_H__
29 #define __OgreWorkQueue_H__
228 virtual void startup(
bool forceRestart =
true) = 0;
273 bool forceSynchronous =
false,
bool idleThread =
false) = 0;
435 bool forceSynchronous =
false,
bool idleThread =
false);
498 : mHandler(handler) {}
#define OGRE_LOCK_RW_MUTEX_WRITE(name)
#define OGRE_LOCK_RW_MUTEX_READ(name)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Variant type that can hold Any other type.
Intermediate structure to hold a pointer to a request handler which provides insurance against the ha...
RequestHandler * mHandler
RequestHandler * getHandler()
Get handler pointer - note, only use this for == comparison or similar, do not attempt to call it as ...
Response * handleRequest(const Request *req, const WorkQueue *srcQ)
Process a request if possible.
RequestHandlerHolder(RequestHandler *handler)
Base for a general purpose request / response style background work queue.
ResponseQueue mResponseQueue
virtual void processResponses()
Process the responses in the queue.
virtual void abortAllRequests()
Abort all previously issued requests.
deque< Request * >::type RequestQueue
virtual bool isShuttingDown() const
Returns whether the queue is trying to shut down.
void processResponse(Response *r)
virtual void removeRequestHandler(uint16 channel, RequestHandler *rh)
Remove a request handler.
const String & getName() const
Get the name of the work queue.
virtual void setRequestsAccepted(bool accept)
Set whether to accept new requests or not.
void addRequestWithRID(RequestID rid, uint16 channel, uint16 requestType, const Any &rData, uint8 retryCount)
Put a Request on the queue with a specific RequestID.
virtual ~DefaultWorkQueueBase()
deque< Response * >::type ResponseQueue
DefaultWorkQueueBase(const String &name=StringUtil::BLANK)
Constructor.
void processRequestResponse(Request *r, bool synchronous)
SharedPtr< RequestHandlerHolder > RequestHandlerHolderPtr
virtual void _threadMain()=0
Main function for each thread spawned.
bool processIdleRequests()
RequestQueue mProcessQueue
virtual void setWorkersCanAccessRenderSystem(bool access)
Set whether worker threads will be allowed to access render system resources.
OGRE_MUTEX(mResponseMutex)
virtual void abortRequest(RequestID id)
Abort a previously issued request.
RequestQueue mRequestQueue
virtual void setResponseProcessingTimeLimit(unsigned long ms)
Set the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
map< uint16, ResponseHandlerList >::type ResponseHandlerListByChannel
virtual void setWorkerThreadCount(size_t c)
Set the number of worker threads that this queue will start when startup() is called (default 1).
virtual void setPaused(bool pause)
Set whether to pause further processing of any requests.
virtual void addRequestHandler(uint16 channel, RequestHandler *rh)
Add a request handler instance to the queue.
list< ResponseHandler * >::type ResponseHandlerList
OGRE_MUTEX(mProcessMutex)
OGRE_MUTEX(mRequestMutex)
list< RequestHandlerHolderPtr >::type RequestHandlerList
virtual unsigned long getResponseProcessingTimeLimit() const
Get the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
Response * processRequest(Request *r)
bool mWorkerRenderSystemAccess
virtual void addResponseHandler(uint16 channel, ResponseHandler *rh)
Add a response handler instance to the queue.
virtual void notifyWorkers()=0
Notify workers about a new request.
virtual bool isPaused() const
Return whether the queue is paused ie not sending more work to workers.
RequestQueue mIdleRequestQueue
virtual bool getRequestsAccepted() const
Returns whether requests are being accepted right now.
virtual bool getWorkersCanAccessRenderSystem() const
Get whether worker threads will be allowed to access render system resources.
ResponseHandlerListByChannel mResponseHandlers
virtual size_t getWorkerThreadCount() const
Get the number of worker threads that this queue will start when startup() is called.
virtual void abortPendingRequestsByChannel(uint16 channel)
Abort all previously issued requests in a given channel.
virtual RequestID addRequest(uint16 channel, uint16 requestType, const Any &rData, uint8 retryCount=0, bool forceSynchronous=false, bool idleThread=false)
Add a new request to the queue.
size_t mWorkerThreadCount
RequestHandlerListByChannel mRequestHandlers
unsigned long mResposeTimeLimitMS
virtual void removeResponseHandler(uint16 channel, ResponseHandler *rh)
Remove a Response handler.
map< uint16, RequestHandlerList >::type RequestHandlerListByChannel
virtual void abortRequestsByChannel(uint16 channel)
Abort all previously issued requests in a given channel.
OGRE_RW_MUTEX(mRequestHandlerMutex)
virtual void _processNextRequest()
Process the next request on the queue.
Reference-counted shared pointer, used for objects where implicit destruction is required.
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Interface definition for a handler of requests.
virtual ~RequestHandler()
virtual bool canHandleRequest(const Request *req, const WorkQueue *srcQ)
Return whether this handler can process a given request.
virtual Response * handleRequest(const Request *req, const WorkQueue *srcQ)=0
The handler method every subclass must implement.
General purpose request structure.
uint16 getChannel() const
Get the request channel (top level categorisation)
const Any & getData() const
Get the user details of this request.
uint8 getRetryCount() const
Get the remaining retry count.
uint16 mType
The request type, as an integer within the channel (user can define enumerations on this)
RequestID mID
Identifier (assigned by the system)
uint16 getType() const
Get the type of this request within the given channel.
bool getAborted() const
Get the abort flag.
RequestID getID() const
Get the identifier of this request.
void abortRequest() const
Set the abort flag.
uint16 mChannel
The request channel, as an integer.
uint8 mRetryCount
Retry count - set this to non-zero to have the request try again on failure.
Any mData
The details of the request (user defined)
Request(uint16 channel, uint16 rtype, const Any &rData, uint8 retry, RequestID rid)
Constructor.
Interface definition for a handler of responses.
virtual ~ResponseHandler()
virtual bool canHandleResponse(const Response *res, const WorkQueue *srcQ)
Return whether this handler can process a given response.
virtual void handleResponse(const Response *res, const WorkQueue *srcQ)=0
The handler method every subclass must implement.
Interface to a general purpose request / response style background work queue.
unsigned long long int RequestID
Numeric identifier for a request.
virtual void setRequestsAccepted(bool accept)=0
Set whether to accept new requests or not.
map< String, uint16 >::type ChannelMap
virtual void setPaused(bool pause)=0
Set whether to pause further processing of any requests.
virtual void shutdown()=0
Shut down the queue.
virtual void abortRequest(RequestID id)=0
Abort a previously issued request.
virtual bool isPaused() const =0
Return whether the queue is paused ie not sending more work to workers.
virtual uint16 getChannel(const String &channelName)
Get a channel ID for a given channel name.
virtual unsigned long getResponseProcessingTimeLimit() const =0
Get the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
virtual void setResponseProcessingTimeLimit(unsigned long ms)=0
Set the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indic...
virtual void addRequestHandler(uint16 channel, RequestHandler *rh)=0
Add a request handler instance to the queue.
virtual void processResponses()=0
Process the responses in the queue.
OGRE_MUTEX(mChannelMapMutex)
virtual void removeRequestHandler(uint16 channel, RequestHandler *rh)=0
Remove a request handler.
virtual void abortAllRequests()=0
Abort all previously issued requests.
virtual void removeResponseHandler(uint16 channel, ResponseHandler *rh)=0
Remove a Response handler.
virtual bool getRequestsAccepted() const =0
Returns whether requests are being accepted right now.
virtual void addResponseHandler(uint16 channel, ResponseHandler *rh)=0
Add a response handler instance to the queue.
virtual void abortRequestsByChannel(uint16 channel)=0
Abort all previously issued requests in a given channel.
virtual RequestID addRequest(uint16 channel, uint16 requestType, const Any &rData, uint8 retryCount=0, bool forceSynchronous=false, bool idleThread=false)=0
Add a new request to the queue.
virtual void startup(bool forceRestart=true)=0
Start up the queue with the options that have been set.
virtual void abortPendingRequestsByChannel(uint16 channel)=0
Abort all previously issued requests in a given channel.
DefaultWorkQueueBase * mQueue
WorkerFunc(DefaultWorkQueueBase *q)
General purpose response structure.
Any mData
Data associated with the result of the process.
Response(const Request *rq, bool success, const Any &data, const String &msg=StringUtil::BLANK)
void abortRequest()
Abort the request.
const Request * getRequest() const
Get the request that this is a response to (NB destruction destroys this)
const String & getMessages() const
Get any diagnostic messages about the process.
const Any & getData() const
Return the response data (user defined, only valid on success)
String mMessages
Any diagnostic messages.
bool mSuccess
Whether the work item succeeded or not.
bool succeeded() const
Return whether this is a successful response.
const Request * mRequest
Pointer to the request that this response is in relation to.