OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
38 namespace Ogre {
48 
51  {
53  bool error;
56 
58  };
59 
60 
80  class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>, public ResourceAlloc,
82  {
83  public:
93  {
94  public:
101  virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) = 0;
103  virtual ~Listener() {}
104 
105  };
106 
107  protected:
108 
112  {
113  RT_INITIALISE_GROUP = 0,
114  RT_INITIALISE_ALL_GROUPS = 1,
115  RT_PREPARE_GROUP = 2,
116  RT_PREPARE_RESOURCE = 3,
117  RT_LOAD_GROUP = 4,
118  RT_LOAD_RESOURCE = 5,
119  RT_UNLOAD_GROUP = 6,
120  RT_UNLOAD_RESOURCE = 7
121  };
124  {
130  bool isManual;
135 
136  _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceRequest& r)
137  { (void)r; return o; }
138  };
139 
142 
145  {
147  : resource(r), request(req)
148  {}
149 
152 
153  _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceResponse& r)
154  { (void)r; return o; }
155  };
156 
157  BackgroundProcessTicket addRequest(ResourceRequest& req);
158 
159  public:
161  virtual ~ResourceBackgroundQueue();
162 
166  virtual void initialise(void);
167 
171  virtual void shutdown(void);
172 
181  virtual BackgroundProcessTicket initialiseResourceGroup(
182  const String& name, Listener* listener = 0);
183 
192  virtual BackgroundProcessTicket initialiseAllResourceGroups(
193  Listener* listener = 0);
202  virtual BackgroundProcessTicket prepareResourceGroup(const String& name,
203  Listener* listener = 0);
204 
213  virtual BackgroundProcessTicket loadResourceGroup(const String& name,
214  Listener* listener = 0);
215 
216 
223  virtual BackgroundProcessTicket unload(
224  const String& resType, const String& name,
225  Listener* listener = 0);
226 
233  virtual BackgroundProcessTicket unload(
234  const String& resType, ResourceHandle handle,
235  Listener* listener = 0);
236 
243  virtual BackgroundProcessTicket unloadResourceGroup(const String& name,
244  Listener* listener = 0);
245 
246 
262  virtual BackgroundProcessTicket prepare(
263  const String& resType, const String& name,
264  const String& group, bool isManual = false,
265  ManualResourceLoader* loader = 0,
266  const NameValuePairList* loadParams = 0,
267  Listener* listener = 0);
268 
284  virtual BackgroundProcessTicket load(
285  const String& resType, const String& name,
286  const String& group, bool isManual = false,
287  ManualResourceLoader* loader = 0,
288  const NameValuePairList* loadParams = 0,
289  Listener* listener = 0);
303  virtual bool isProcessComplete(BackgroundProcessTicket ticket);
304 
307  void abortRequest( BackgroundProcessTicket ticket );
308 
310  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
312  WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
314  bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
316  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
317 
333  static ResourceBackgroundQueue& getSingleton(void);
349  static ResourceBackgroundQueue* getSingletonPtr(void);
350 
351  };
352 
356 }
357 
358 #endif
359 
#define _OgreExport
Definition: OgrePlatform.h:233
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:553
General purpose request structure.
Definition: OgreWorkQueue.h:82
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:64
General purpose response structure.
Encapsulates the result of a background queue request.
Interface describing a manual resource loader.
Definition: OgreResource.h:513
_OgreExport friend std::ostream & operator<<(std::ostream &o, const ResourceRequest &r)
ResourceResponse(ResourcePtr r, const ResourceRequest &req)
Encapsulates a queued request for the background queue.
Interface definition for a handler of requests.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
virtual ~Listener()
Need virtual destructor in case subclasses use it.
bool error
Whether an error occurred.
String message
Any messages from the process.
Interface definition for a handler of responses.
WorkQueue::RequestID BackgroundProcessTicket
Identifier of a background process.
unsigned long long int ResourceHandle
Definition: OgreResource.h:40
This class is used to perform Resource operations in a background thread.
unsigned long long int RequestID
Numeric identifier for a request.
Definition: OgreWorkQueue.h:78
This abstract listener interface lets you get notifications of completed background processes instead...
_StringBase String
unsigned short uint16
Definition: OgrePlatform.h:271
_OgreExport friend std::ostream & operator<<(std::ostream &o, const ResourceResponse &r)
set< BackgroundProcessTicket >::type OutstandingRequestSet
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:69
Struct that holds details of queued notifications.
RequestType
Enumerates the type of requests.