OGRE: OgreResourceBackgroundQueue.h Source File - OGRE Documentation

# OgreResourceBackgroundQueue.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __ResourceBackgroundQueue_H__
    00029 #define __ResourceBackgroundQueue_H__
    00030
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreCommon.h"
    00034 #include "OgreSingleton.h"
    00035 #include "OgreResource.h"
    00036 #include "OgreWorkQueue.h"
    00037
    00038 namespace Ogre {
    00046
    00047     typedef WorkQueue::RequestID BackgroundProcessTicket;
    00048
    00050     struct BackgroundProcessResult
    00051     {
    00053         bool error;
    00055         String message;
    00056
    00057         BackgroundProcessResult() : error(false) {}
    00058     };
    00059
    00060
    00080     class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>, public ResourceAlloc,
    00081         public WorkQueue::RequestHandler, public WorkQueue::ResponseHandler
    00082     {
    00083     public:
    00092         class _OgreExport Listener
    00093         {
    00094         public:
    00101             virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) = 0;
    00103             virtual ~Listener() {}
    00104
    00105         };
    00106
    00107     protected:
    00108
    00109         uint16 mWorkQueueChannel;
    00111         enum RequestType
    00112         {
    00113             RT_INITIALISE_GROUP = 0,
    00114             RT_INITIALISE_ALL_GROUPS = 1,
    00115             RT_PREPARE_GROUP = 2,
    00116             RT_PREPARE_RESOURCE = 3,
    00117             RT_LOAD_GROUP = 4,
    00118             RT_LOAD_RESOURCE = 5,
    00119             RT_UNLOAD_GROUP = 6,
    00120             RT_UNLOAD_RESOURCE = 7
    00121         };
    00123         struct ResourceRequest
    00124         {
    00125             RequestType type;
    00126             String resourceName;
    00127             ResourceHandle resourceHandle;
    00128             String resourceType;
    00129             String groupName;
    00130             bool isManual;
    00131             ManualResourceLoader* loader;
    00132             NameValuePairList* loadParams;
    00133             Listener* listener;
    00134             BackgroundProcessResult result;
    00135
    00136             _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceRequest& r)
    00137             { (void)r; return o; }
    00138         };
    00139
    00140         typedef set<BackgroundProcessTicket>::type OutstandingRequestSet;
    00141         OutstandingRequestSet mOutstandingRequestSet;
    00142
    00144         struct ResourceResponse
    00145         {
    00146             ResourceResponse(ResourcePtr r, const ResourceRequest& req)
    00147                 : resource(r), request(req)
    00148             {}
    00149
    00150             ResourcePtr resource;
    00151             ResourceRequest request;
    00152
    00153             _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceResponse& r)
    00154             { (void)r; return o; }
    00155         };
    00156
    00157         BackgroundProcessTicket addRequest(ResourceRequest& req);
    00158
    00159     public:
    00160         ResourceBackgroundQueue();
    00161         virtual ~ResourceBackgroundQueue();
    00162
    00166         virtual void initialise(void);
    00167
    00171         virtual void shutdown(void);
    00172
    00181         virtual BackgroundProcessTicket initialiseResourceGroup(
    00182             const String& name, Listener* listener = 0);
    00183
    00192         virtual BackgroundProcessTicket initialiseAllResourceGroups(
    00193             Listener* listener = 0);
    00202         virtual BackgroundProcessTicket prepareResourceGroup(const String& name,
    00203             Listener* listener = 0);
    00204
    00213         virtual BackgroundProcessTicket loadResourceGroup(const String& name,
    00214             Listener* listener = 0);
    00215
    00216
    00223         virtual BackgroundProcessTicket unload(
    00224             const String& resType, const String& name,
    00225             Listener* listener = 0);
    00226
    00233         virtual BackgroundProcessTicket unload(
    00234             const String& resType, ResourceHandle handle,
    00235             Listener* listener = 0);
    00236
    00243         virtual BackgroundProcessTicket unloadResourceGroup(const String& name,
    00244             Listener* listener = 0);
    00245
    00246
    00262         virtual BackgroundProcessTicket prepare(
    00263             const String& resType, const String& name,
    00264             const String& group, bool isManual = false,
    00265             ManualResourceLoader* loader = 0,
    00266             const NameValuePairList* loadParams = 0,
    00267             Listener* listener = 0);
    00268
    00284         virtual BackgroundProcessTicket load(
    00285             const String& resType, const String& name,
    00286             const String& group, bool isManual = false,
    00287             ManualResourceLoader* loader = 0,
    00288             const NameValuePairList* loadParams = 0,
    00289             Listener* listener = 0);
    00303         virtual bool isProcessComplete(BackgroundProcessTicket ticket);
    00304
    00307         void abortRequest( BackgroundProcessTicket ticket );
    00308
    00310         bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
    00312         WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
    00314         bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
    00316         void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
    00317
    00333         static ResourceBackgroundQueue& getSingleton(void);
    00349         static ResourceBackgroundQueue* getSingletonPtr(void);
    00350
    00351     };
    00352
    00356 }
    00357
    00358 #endif
    00359

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52