OGRE  2.0
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-2014 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 
158  BackgroundProcessTicket addRequest(ResourceRequest& req);
159 
160  public:
162  virtual ~ResourceBackgroundQueue();
163 
167  virtual void initialise(void);
168 
172  virtual void shutdown(void);
173 
182  virtual BackgroundProcessTicket initialiseResourceGroup(
183  const String& name, Listener* listener = 0);
184 
193  virtual BackgroundProcessTicket initialiseAllResourceGroups(
194  Listener* listener = 0);
203  virtual BackgroundProcessTicket prepareResourceGroup(const String& name,
204  Listener* listener = 0);
205 
214  virtual BackgroundProcessTicket loadResourceGroup(const String& name,
215  Listener* listener = 0);
216 
217 
224  virtual BackgroundProcessTicket unload(
225  const String& resType, const String& name,
226  Listener* listener = 0);
227 
234  virtual BackgroundProcessTicket unload(
235  const String& resType, ResourceHandle handle,
236  Listener* listener = 0);
237 
244  virtual BackgroundProcessTicket unloadResourceGroup(const String& name,
245  Listener* listener = 0);
246 
247 
263  virtual BackgroundProcessTicket prepare(
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 
285  virtual BackgroundProcessTicket load(
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);
304  virtual bool isProcessComplete(BackgroundProcessTicket ticket);
305 
308  void abortRequest( BackgroundProcessTicket ticket );
309 
311  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
313  WorkQueue::Response* handleRequest(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 
334  static ResourceBackgroundQueue& getSingleton(void);
350  static ResourceBackgroundQueue* getSingletonPtr(void);
351 
352  };
353 
357 }
358 
359 #include "OgreHeaderSuffix.h"
360 
361 #endif
362 
#define _OgreExport
Definition: OgrePlatform.h:255
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:580
General purpose request structure.
Definition: OgreWorkQueue.h:84
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:498
_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:39
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:80
This abstract listener interface lets you get notifications of completed background processes instead...
_StringBase String
Definition: OgreCommon.h:53
unsigned short uint16
Definition: OgrePlatform.h:421
_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:71
Struct that holds details of queued notifications.
RequestType
Enumerates the type of requests.