Changeset 8322

Show
Ignore:
Timestamp:
05/14/08 19:03:57
Author:
robert
Message:

Introduced preliminary support for asynchronous file read requests,

ReaderWriter?
ReadResult? now has a FILE_REQUEST enum.
ReaderWriter?
Options now has a s/getAsynchronousFileReadHint() parameter methods.

libcurl based plugin now detects enabing of the AsynchronousFileReadHint?, but
as yet does not handle async requests - handling everything syncronously.


DatabasePager? now by default will enable AsynchronousFileReadHint? for http
based file requests


Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/include/osgDB/ReaderWriter

    r8278 r8322  
    9191                Options(): 
    9292                    osg::Object(true), 
    93                     _objectCacheHint(CACHE_ARCHIVES) {} 
     93                    _objectCacheHint(CACHE_ARCHIVES), 
     94                    _asynchronousFileReadHint(false) {} 
     95                     
    9496                Options(const std::string& str): 
    9597                    osg::Object(true), 
    9698                    _str(str),  
    97                     _objectCacheHint(CACHE_ARCHIVES) {} 
     99                    _objectCacheHint(CACHE_ARCHIVES), 
     100                    _asynchronousFileReadHint(false) {} 
    98101                 
    99102                Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): 
     
    101104                    _str(options._str), 
    102105                    _databasePaths(options._databasePaths), 
    103                     _objectCacheHint(options._objectCacheHint) {} 
     106                    _objectCacheHint(options._objectCacheHint), 
     107                    _asynchronousFileReadHint(options._asynchronousFileReadHint) {} 
    104108 
    105109                META_Object(osgDB,Options); 
     
    120124                const FilePathList& getDatabasePathList() const { return _databasePaths; } 
    121125 
     126 
    122127                /** Set whether the Registry::ObjectCache should be used by default.*/ 
    123128                void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; } 
     
    125130                /** Get whether the Registry::ObjectCache should be used by default.*/ 
    126131                CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; } 
     132 
     133 
     134                /** Set Asynchrnous file read hint.  
     135                  * This hint is used by plugins like the libcurl http reader plugin to inform them that 
     136                  * they should make an internal file read requests to their background threads to load files, 
     137                  * with the plugin returning immediately with a ReadResult::FILE_REQUESTED status.  It is  
     138                  * assumed that calls will continue to be made to the plugin until the background threads 
     139                  * have read or failed to read the request file, at which point the return status which change 
     140                  * to FILE_LOADED and the objects will be returned. 
     141                  * Note, this facility is particular useful when using DatabasePager in conjunction with 
     142                  * internet based databases where file load latency is relatively high.*/ 
     143                void setAsynchronousFileReadHint(bool flag) { _asynchronousFileReadHint = flag; } 
     144 
     145                /** Get Asynchrnous file read hint. */ 
     146                bool getAsynchronousFileReadHint() const { return _asynchronousFileReadHint; } 
     147 
    127148 
    128149                /** Sets a plugindata value PluginData with a string */ 
     
    149170                FilePathList        _databasePaths; 
    150171                CacheHintOptions    _objectCacheHint; 
     172                bool                _asynchronousFileReadHint; 
    151173 
    152174                typedef std::map<std::string,void*> PluginDataMap; 
     
    161183                enum ReadStatus 
    162184                { 
    163                     FILE_NOT_HANDLED, //!< file is not appropriate for this file reader, due to some incompatibility, but *not* a read error 
    164                     FILE_NOT_FOUND, //!< file could not be found or could not be read 
    165                     FILE_LOADED, //!< file successfully found, loaded, and converted into osg 
    166                     FILE_LOADED_FROM_CACHE, //!< file found in cache and returned 
    167                     ERROR_IN_READING_FILE //!< file found, loaded, but an error was encountered during processing 
     185                    FILE_NOT_HANDLED, //!< File is not appropriate for this file reader, due to some incompatibility, but *not* a read error. 
     186                    FILE_NOT_FOUND, //!< File could not be found or could not be read. 
     187                    FILE_LOADED, //!< File successfully found, loaded, and converted into osg. 
     188                    FILE_LOADED_FROM_CACHE, //!< File found in cache and returned. 
     189                    ERROR_IN_READING_FILE, //!< File found, loaded, but an error was encountered during processing. 
     190                    FILE_REQUESTED, //!< Asyncronous file read has been requested, but returning immediatiely, keep polling plugin till file read has been completed. 
    168191                }; 
    169192 
  • OpenSceneGraph/trunk/src/osgDB/DatabasePager.cpp

    r8007 r8322  
    11#include <osgDB/DatabasePager> 
    22#include <osgDB/ReadFile> 
     3#include <osgDB/FileNameUtils> 
    34 
    45#include <osg/Geode> 
     
    420421            databaseRequest->_priorityLastRequest = priority; 
    421422            databaseRequest->_groupForAddingLoadedSubgraph = group; 
    422             databaseRequest->_loadOptions = loadOptions; 
     423 
     424            if ((Registry::instance()->getOptions()==loadOptions) && 
     425                (loadOptions ? !loadOptions->getAsynchronousFileReadHint() : true) && 
     426                osgDB::containsServerAddress(fileName)) 
     427            { 
     428                // we need to enable asynchronous file reading. 
     429                databaseRequest->_loadOptions = loadOptions ?  
     430                        dynamic_cast<osgDB::ReaderWriter::Options*>(loadOptions->clone(osg::CopyOp::SHALLOW_COPY)) : 
     431                        new osgDB::ReaderWriter::Options; 
     432 
     433                databaseRequest->_loadOptions->setAsynchronousFileReadHint(true); 
     434            } 
     435            else 
     436            { 
     437                databaseRequest->_loadOptions = loadOptions; 
     438            } 
    423439 
    424440            _fileRequestList.push_back(databaseRequest); 
  • OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.cpp

    r8321 r8322  
    317317            } 
    318318 
     319            bool asyncFileRead = options ? options->getAsynchronousFileReadHint() : false; 
     320             
     321            osg::notify(osg::INFO)<<"AsynchronousFileReadHint= "<<asyncFileRead<<std::endl; 
     322             
     323            // if (asyncFileRead) return ReadResult::FILE_REQUESTED; 
    319324         
    320325            std::stringstream buffer;