OgreResourceBackgroundQueue.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __ResourceBackgroundQueue_H__
#define __ResourceBackgroundQueue_H__
#include "OgrePrerequisites.h"
#include "OgreCommon.h"
#include "OgreSingleton.h"
#include "OgreResource.h"
#include "OgreWorkQueue.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
typedef WorkQueue::RequestID BackgroundProcessTicket;
struct BackgroundProcessResult
{
bool error;
String message;
BackgroundProcessResult() : error(false) {}
};
class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>, public ResourceAlloc,
public WorkQueue::RequestHandler, public WorkQueue::ResponseHandler
{
public:
class _OgreExport Listener
{
public:
virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) = 0;
virtual ~Listener() {}
};
protected:
uint16 mWorkQueueChannel;
enum RequestType
{
RT_INITIALISE_GROUP = 0,
RT_INITIALISE_ALL_GROUPS = 1,
RT_PREPARE_GROUP = 2,
RT_PREPARE_RESOURCE = 3,
RT_LOAD_GROUP = 4,
RT_LOAD_RESOURCE = 5,
RT_UNLOAD_GROUP = 6,
RT_UNLOAD_RESOURCE = 7
};
struct ResourceRequest
{
RequestType type;
String resourceName;
ResourceHandle resourceHandle;
String resourceType;
String groupName;
bool isManual;
ManualResourceLoader* loader;
NameValuePairList* loadParams;
Listener* listener;
BackgroundProcessResult result;
_OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceRequest& r)
{ (void)r; return o; }
};
typedef set<BackgroundProcessTicket>::type OutstandingRequestSet;
OutstandingRequestSet mOutstandingRequestSet;
struct ResourceResponse
{
ResourceResponse(ResourcePtr r, const ResourceRequest& req)
: resource(r), request(req)
{}
ResourcePtr resource;
ResourceRequest request;
_OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceResponse& r)
{ (void)r; return o; }
};
BackgroundProcessTicket addRequest(ResourceRequest& req);
public:
ResourceBackgroundQueue();
virtual ~ResourceBackgroundQueue();
virtual void initialise(void);
virtual void shutdown(void);
virtual BackgroundProcessTicket initialiseResourceGroup(
const String& name, Listener* listener = 0);
virtual BackgroundProcessTicket initialiseAllResourceGroups(
Listener* listener = 0);
virtual BackgroundProcessTicket prepareResourceGroup(const String& name,
Listener* listener = 0);
virtual BackgroundProcessTicket loadResourceGroup(const String& name,
Listener* listener = 0);
virtual BackgroundProcessTicket unload(
const String& resType, const String& name,
Listener* listener = 0);
virtual BackgroundProcessTicket unload(
const String& resType, ResourceHandle handle,
Listener* listener = 0);
virtual BackgroundProcessTicket unloadResourceGroup(const String& name,
Listener* listener = 0);
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);
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);
virtual bool isProcessComplete(BackgroundProcessTicket ticket);
void abortRequest( BackgroundProcessTicket ticket );
bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
static ResourceBackgroundQueue& getSingleton(void);
static ResourceBackgroundQueue* getSingletonPtr(void);
};
}
#include "OgreHeaderSuffix.h"
#endif
OgreWorkQueue.h
Ogre::ResourceBackgroundQueue::ResourceRequest::listener
Listener * listener
Definition: OgreResourceBackgroundQueue.h:134
Ogre::WorkQueue::RequestID
unsigned long long int RequestID
Numeric identifier for a request.
Definition: OgreWorkQueue.h:79
Ogre::ResourceBackgroundQueue::Listener
This abstract listener interface lets you get notifications of completed background processes instead...
Definition: OgreResourceBackgroundQueue.h:93
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::BackgroundProcessResult
Encapsulates the result of a background queue request.
Definition: OgreResourceBackgroundQueue.h:51
OgreResource.h
Ogre::ResourceBackgroundQueue::ResourceRequest::groupName
String groupName
Definition: OgreResourceBackgroundQueue.h:130
Ogre::WorkQueue
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:70
Ogre::ResourceBackgroundQueue::ResourceRequest::loader
ManualResourceLoader * loader
Definition: OgreResourceBackgroundQueue.h:132
Ogre::BackgroundProcessResult::message
String message
Any messages from the process.
Definition: OgreResourceBackgroundQueue.h:56
Ogre::ResourceBackgroundQueue::OutstandingRequestSet
set< BackgroundProcessTicket >::type OutstandingRequestSet
Definition: OgreResourceBackgroundQueue.h:141
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
Ogre::ResourceBackgroundQueue::ResourceResponse::ResourceResponse
ResourceResponse(ResourcePtr r, const ResourceRequest &req)
Definition: OgreResourceBackgroundQueue.h:147
Ogre::ResourceBackgroundQueue::mOutstandingRequestSet
OutstandingRequestSet mOutstandingRequestSet
Definition: OgreResourceBackgroundQueue.h:142
OgreCommon.h
Ogre::ResourceBackgroundQueue::mWorkQueueChannel
uint16 mWorkQueueChannel
Definition: OgreResourceBackgroundQueue.h:110
Ogre::BackgroundProcessResult::BackgroundProcessResult
BackgroundProcessResult()
Definition: OgreResourceBackgroundQueue.h:58
OgreSingleton.h
Ogre::WorkQueue::Request
General purpose request structure.
Definition: OgreWorkQueue.h:83
OgrePrerequisites.h
Ogre::ResourceBackgroundQueue::ResourceResponse::request
ResourceRequest request
Definition: OgreResourceBackgroundQueue.h:152
Ogre::ResourceBackgroundQueue::Listener::~Listener
virtual ~Listener()
Need virtual destructor in case subclasses use it.
Definition: OgreResourceBackgroundQueue.h:104
Ogre::BackgroundProcessResult::error
bool error
Whether an error occurred.
Definition: OgreResourceBackgroundQueue.h:54
Ogre::WorkQueue::Response
General purpose response structure.
Definition: OgreWorkQueue.h:122
Ogre::ResourceBackgroundQueue::ResourceRequest::result
BackgroundProcessResult result
Definition: OgreResourceBackgroundQueue.h:135
Ogre::ResourceBackgroundQueue::ResourceRequest::isManual
bool isManual
Definition: OgreResourceBackgroundQueue.h:131
Ogre::NameValuePairList
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:550
Ogre::ResourceBackgroundQueue::ResourceRequest
Encapsulates a queued request for the background queue.
Definition: OgreResourceBackgroundQueue.h:124
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::BackgroundProcessTicket
WorkQueue::RequestID BackgroundProcessTicket
Identifier of a background process.
Definition: OgreResourceBackgroundQueue.h:48
Ogre::ResourceBackgroundQueue
This class is used to perform Resource operations in a background thread.
Definition: OgreResourceBackgroundQueue.h:81
Ogre::set
Definition: OgrePrerequisites.h:519
Ogre::ResourceBackgroundQueue::RequestType
RequestType
Enumerates the type of requests.
Definition: OgreResourceBackgroundQueue.h:112
OgreHeaderSuffix.h
Ogre::ResourceBackgroundQueue::ResourceRequest::resourceHandle
ResourceHandle resourceHandle
Definition: OgreResourceBackgroundQueue.h:128
Ogre::ResourceBackgroundQueue::ResourceResponse::operator<<
_OgreExport friend std::ostream & operator<<(std::ostream &o, const ResourceResponse &r)
Definition: OgreResourceBackgroundQueue.h:154
Ogre::ResourceBackgroundQueue::ResourceResponse
Struct that holds details of queued notifications.
Definition: OgreResourceBackgroundQueue.h:145
Ogre::WorkQueue::ResponseHandler
Interface definition for a handler of responses.
Definition: OgreWorkQueue.h:196
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::ResourceBackgroundQueue::ResourceRequest::type
RequestType type
Definition: OgreResourceBackgroundQueue.h:126
Ogre::SharedPtr< Resource >
Ogre::ResourceBackgroundQueue::ResourceRequest::loadParams
NameValuePairList * loadParams
Definition: OgreResourceBackgroundQueue.h:133
OgreHeaderPrefix.h
Ogre::ResourceBackgroundQueue::ResourceRequest::operator<<
_OgreExport friend std::ostream & operator<<(std::ostream &o, const ResourceRequest &r)
Definition: OgreResourceBackgroundQueue.h:137
Ogre::Singleton
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:64
Ogre::ResourceBackgroundQueue::ResourceRequest::resourceName
String resourceName
Definition: OgreResourceBackgroundQueue.h:127
Ogre::ResourceBackgroundQueue::ResourceResponse::resource
ResourcePtr resource
Definition: OgreResourceBackgroundQueue.h:151
Ogre::ResourceBackgroundQueue::ResourceRequest::resourceType
String resourceType
Definition: OgreResourceBackgroundQueue.h:129
Ogre::WorkQueue::RequestHandler
Interface definition for a handler of requests.
Definition: OgreWorkQueue.h:161
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58

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