OgreResourceBackgroundQueue.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __ResourceBackgroundQueue_H__
29 #define __ResourceBackgroundQueue_H__
30 
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreCommon.h"
34 #include "OgreSingleton.h"
35 #include "OgreResource.h"
36 #include "OgreWorkQueue.h"
37 #include "OgreHeaderPrefix.h"
38 
39 namespace Ogre {
49 
52  {
54  bool error;
57 
59  };
60 
61 
81  class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>, public ResourceAlloc,
83  {
84  public:
94  {
95  public:
102  virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) = 0;
104  virtual ~Listener() {}
105 
106  };
107 
108  protected:
109 
113  {
114  RT_INITIALISE_GROUP = 0,
115  RT_INITIALISE_ALL_GROUPS = 1,
116  RT_PREPARE_GROUP = 2,
117  RT_PREPARE_RESOURCE = 3,
118  RT_LOAD_GROUP = 4,
119  RT_LOAD_RESOURCE = 5,
120  RT_UNLOAD_GROUP = 6,
121  RT_UNLOAD_RESOURCE = 7
122  };
125  {
131  bool isManual;
136 
137  _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceRequest& r)
138  { (void)r; return o; }
139  };
140 
143 
146  {
148  : resource(r), request(req)
149  {}
150 
153 
154  _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceResponse& r)
155  { (void)r; return o; }
156  };
157 
159 
160  public:
163 
167  virtual void initialise(void);
168 
172  virtual void shutdown(void);
173 
183  const String& name, Listener* listener = 0);
184 
194  Listener* listener = 0);
204  Listener* listener = 0);
205 
215  Listener* listener = 0);
216 
217 
225  const String& resType, const String& name,
226  Listener* listener = 0);
227 
235  const String& resType, ResourceHandle handle,
236  Listener* listener = 0);
237 
245  Listener* listener = 0);
246 
247 
264  const String& resType, const String& name,
265  const String& group, bool isManual = false,
266  ManualResourceLoader* loader = 0,
267  const NameValuePairList* loadParams = 0,
268  Listener* listener = 0);
269 
286  const String& resType, const String& name,
287  const String& group, bool isManual = false,
288  ManualResourceLoader* loader = 0,
289  const NameValuePairList* loadParams = 0,
290  Listener* listener = 0);
305 
309 
311  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
315  bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
317  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
318 
351 
352  };
353 
357 }
358 
359 #include "OgreHeaderSuffix.h"
360 
361 #endif
362 
#define _OgreExport
Definition: OgrePlatform.h:257
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Interface describing a manual resource loader.
Definition: OgreResource.h:515
This abstract listener interface lets you get notifications of completed background processes instead...
virtual ~Listener()
Need virtual destructor in case subclasses use it.
virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult &result)=0
Called when a requested operation completes, queued into main thread.
This class is used to perform Resource operations in a background thread.
virtual BackgroundProcessTicket initialiseResourceGroup(const String &name, Listener *listener=0)
Initialise a resource group in the background.
set< BackgroundProcessTicket >::type OutstandingRequestSet
virtual BackgroundProcessTicket prepare(const String &resType, const String &name, const String &group, bool isManual=false, ManualResourceLoader *loader=0, const NameValuePairList *loadParams=0, Listener *listener=0)
Prepare a single resource in the background.
void abortRequest(BackgroundProcessTicket ticket)
Aborts background process.
bool canHandleResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
Implementation for WorkQueue::ResponseHandler.
virtual BackgroundProcessTicket unloadResourceGroup(const String &name, Listener *listener=0)
Unloads a resource group in the background.
virtual bool isProcessComplete(BackgroundProcessTicket ticket)
Returns whether a previously queued process has completed or not.
void handleResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
Implementation for WorkQueue::ResponseHandler.
static ResourceBackgroundQueue * getSingletonPtr(void)
Override standard Singleton retrieval.
static ResourceBackgroundQueue & getSingleton(void)
Override standard Singleton retrieval.
virtual void initialise(void)
Initialise the background queue system.
virtual BackgroundProcessTicket loadResourceGroup(const String &name, Listener *listener=0)
Loads a resource group in the background.
virtual BackgroundProcessTicket unload(const String &resType, ResourceHandle handle, Listener *listener=0)
Unload a single resource in the background.
virtual BackgroundProcessTicket prepareResourceGroup(const String &name, Listener *listener=0)
Prepares a resource group in the background.
virtual BackgroundProcessTicket load(const String &resType, const String &name, const String &group, bool isManual=false, ManualResourceLoader *loader=0, const NameValuePairList *loadParams=0, Listener *listener=0)
Load a single resource in the background.
WorkQueue::Response * handleRequest(const WorkQueue::Request *req, const WorkQueue *srcQ)
Implementation for WorkQueue::RequestHandler.
virtual BackgroundProcessTicket initialiseAllResourceGroups(Listener *listener=0)
Initialise all resource groups which are yet to be initialised in the background.
bool canHandleRequest(const WorkQueue::Request *req, const WorkQueue *srcQ)
Implementation for WorkQueue::RequestHandler.
virtual BackgroundProcessTicket unload(const String &resType, const String &name, Listener *listener=0)
Unload a single resource in the background.
virtual void shutdown(void)
Shut down the background queue system.
BackgroundProcessTicket addRequest(ResourceRequest &req)
RequestType
Enumerates the type of requests.
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:65
Interface definition for a handler of requests.
General purpose request structure.
Definition: OgreWorkQueue.h:84
Interface definition for a handler of responses.
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:71
unsigned long long int RequestID
Numeric identifier for a request.
Definition: OgreWorkQueue.h:79
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:550
WorkQueue::RequestID BackgroundProcessTicket
Identifier of a background process.
unsigned short uint16
Definition: OgrePlatform.h:360
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
_StringBase String
Encapsulates the result of a background queue request.
String message
Any messages from the process.
bool error
Whether an error occurred.
Encapsulates a queued request for the background queue.
_OgreExport friend std::ostream & operator<<(std::ostream &o, const ResourceRequest &r)
Struct that holds details of queued notifications.
ResourceResponse(ResourcePtr r, const ResourceRequest &req)
_OgreExport friend std::ostream & operator<<(std::ostream &o, const ResourceResponse &r)
General purpose response structure.

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.