Moved Registry::ReadFileCallback + WriteFileCallback, and osgDB::ReaderWriter::Options into their own separate Options file and into the osgDB namespace.

Introduced a new callback osgDB::FindFileCallback that overrides the default behavior of findDataFile/findLibraryFile.

Introduced support for assigning ReaderWriter::Options directory to PagedLOD.

Introduced new osgDB::FileLocationCallback for assistancing the DatabasePager to know when a file is hosted on a local or remote file system.
This commit is contained in:
Robert Osfield
2009-05-11 11:39:12 +00:00
parent 67e0abf149
commit f939ea731e
16 changed files with 226 additions and 59 deletions

View File

@@ -58,6 +58,7 @@ PagedLOD::PagedLOD()
PagedLOD::PagedLOD(const PagedLOD& plod,const CopyOp& copyop):
LOD(plod,copyop),
_databaseOptions(plod._databaseOptions),
_databasePath(plod._databasePath),
_frameNumberOfLastTraversal(plod._frameNumberOfLastTraversal),
_numChildrenThatCannotBeExpired(plod._numChildrenThatCannotBeExpired),
@@ -213,16 +214,15 @@ void PagedLOD::traverse(NodeVisitor& nv)
if (_databasePath.empty())
{
nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp(), _perRangeDataList[numChildren]._databaseRequest);
nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp(), _perRangeDataList[numChildren]._databaseRequest, _databaseOptions.get());
}
else
{
// prepend the databasePath to the child's filename.
nv.getDatabaseRequestHandler()->requestNodeFile(_databasePath+_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp(), _perRangeDataList[numChildren]._databaseRequest);
nv.getDatabaseRequestHandler()->requestNodeFile(_databasePath+_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp(), _perRangeDataList[numChildren]._databaseRequest, _databaseOptions.get());
}
}
}

View File

@@ -445,9 +445,7 @@ void DatabasePager::DatabaseThread::run()
read_queue = _pager->_httpRequestQueue;
break;
}
//Getting CURL Environment Variables (If found rewrite OSG Options)
osg::ref_ptr<FileCache> fileCache = osgDB::Registry::instance()->getFileCache();
do
{
@@ -481,9 +479,22 @@ void DatabasePager::DatabaseThread::run()
read_queue->takeFirst(databaseRequest);
bool readFromFileCache = false;
osg::ref_ptr<FileCache> fileCache = osgDB::Registry::instance()->getFileCache();
osg::ref_ptr<FileLocationCallback> fileLocationCallback = osgDB::Registry::instance()->getFileLocationCallback();
if (databaseRequest.valid())
{
if (databaseRequest->_loadOptions.valid())
{
if (databaseRequest->_loadOptions->getFileCache()) fileCache = databaseRequest->_loadOptions->getFileCache();
if (databaseRequest->_loadOptions->getFileLocationCallback()) fileLocationCallback = databaseRequest->_loadOptions->getFileLocationCallback();
}
// disable the FileCache if the fileLocationCallback tells us that it isn't required for this request.
if (fileLocationCallback.valid() && !fileLocationCallback->useFileCache()) fileCache = 0;
// check if databaseRequest is still relevant
if ((_pager->_frameNumber-databaseRequest->_frameNumberLastRequest)<=1)
{
@@ -492,19 +503,32 @@ void DatabasePager::DatabaseThread::run()
switch(_mode)
{
case(HANDLE_ALL_REQUESTS):
{
// do nothing as this thread can handle the load
if (osgDB::containsServerAddress(databaseRequest->_fileName))
if (fileCache.valid() && fileCache->isFileAppropriateForFileCache(databaseRequest->_fileName))
{
if (fileCache.valid() && fileCache->existsInCache(databaseRequest->_fileName))
if (fileCache->existsInCache(databaseRequest->_fileName))
{
readFromFileCache = true;
}
}
break;
}
case(HANDLE_NON_HTTP):
{
// check the cache first
if (osgDB::containsServerAddress(databaseRequest->_fileName))
bool isHighLatencyFileRequest = false;
if (fileLocationCallback.valid())
{
isHighLatencyFileRequest = fileLocationCallback->fileLocation(databaseRequest->_fileName, databaseRequest->_loadOptions.get()) == FileLocationCallback::REMOTE_FILE;
}
else if (fileCache.valid() && fileCache->isFileAppropriateForFileCache(databaseRequest->_fileName))
{
isHighLatencyFileRequest = true;
}
if (isHighLatencyFileRequest)
{
if (fileCache.valid() && fileCache->existsInCache(databaseRequest->_fileName))
{
@@ -518,15 +542,12 @@ void DatabasePager::DatabaseThread::run()
}
}
break;
}
case(HANDLE_ONLY_HTTP):
// make sure the request is a http request
if (!osgDB::containsServerAddress(databaseRequest->_fileName))
{
osg::notify(osg::NOTICE)<<_name<<": Help we have request we shouldn't have "<<databaseRequest->_fileName<<std::endl;
databaseRequest = 0;
}
{
// accept all requests, as we'll assume only high latency requests will have got here.
break;
}
}
}
else
@@ -554,8 +575,8 @@ void DatabasePager::DatabaseThread::run()
if (rr.error()) osg::notify(osg::WARN)<<"Error in reading file "<<databaseRequest->_fileName<<" : "<<rr.message() << std::endl;
if (databaseRequest->_loadedModel.valid() &&
osgDB::containsServerAddress(databaseRequest->_fileName) &&
fileCache.valid() &&
fileCache->isFileAppropriateForFileCache(databaseRequest->_fileName) &&
!readFromFileCache)
{
fileCache->writeNode(*(databaseRequest->_loadedModel), databaseRequest->_fileName, databaseRequest->_loadOptions.get());
@@ -1228,18 +1249,24 @@ bool DatabasePager::getRequestsInProgress() const
}
void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group,
float priority, const osg::FrameStamp* framestamp,
osg::ref_ptr<osg::Referenced>& databaseRequest)
{
requestNodeFile(fileName,group,priority,framestamp,databaseRequest,Registry::instance()->getOptions());
}
void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group,
float priority, const osg::FrameStamp* framestamp,
osg::ref_ptr<osg::Referenced>& databaseRequestRef,
Options* loadOptions)
const osg::Referenced* options)
{
osgDB::Options* loadOptions = dynamic_cast<osgDB::Options*>(const_cast<osg::Referenced*>(options));
if (!loadOptions)
{
loadOptions = Registry::instance()->getOptions();
osg::notify(osg::NOTICE)<<"Using options from Registry "<<std::endl;
}
else
{
osg::notify(osg::NOTICE)<<"options from requestNodeFile "<<std::endl;
}
if (!_acceptNewRequests) return;
osg::Timer_t start_tick = osg::Timer::instance()->tick();

View File

@@ -30,6 +30,11 @@ FileCache::~FileCache()
osg::notify(osg::INFO)<<"Destructed FileCache "<<std::endl;
}
bool FileCache::isFileAppropriateForFileCache(const std::string& originalFileName) const
{
return osgDB::containsServerAddress(originalFileName);
}
std::string FileCache::createCacheFileName(const std::string& originalFileName) const
{
std::string cacheFileName = _fileCachePath + "/" +

View File

@@ -108,4 +108,6 @@ Options::Options(const Options& options,const osg::CopyOp& copyop):
_pluginStringData(options._pluginStringData),
_findFileCallback(options._findFileCallback),
_readFileCallback(options._readFileCallback),
_writeFileCallback(options._writeFileCallback) {}
_writeFileCallback(options._writeFileCallback),
_fileLocationCallback(options._fileLocationCallback),
_fileCache(options._fileCache) {}

View File

@@ -419,11 +419,11 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::NodeVisitor::DatabaseRequestHandler)
I_Constructor0(____DatabaseRequestHandler,
"",
"");
I_Method5(void, requestNodeFile, IN, const std::string &, fileName, IN, osg::Group *, group, IN, float, priority, IN, const osg::FrameStamp *, framestamp, IN, osg::ref_ptr< osg::Referenced > &, databaseRequest,
Properties::PURE_VIRTUAL,
__void__requestNodeFile__C5_std_string_R1__osg_Group_P1__float__C5_FrameStamp_P1__osg_ref_ptrT1_osg_Referenced__R1,
"",
"");
I_MethodWithDefaults6(void, requestNodeFile, IN, const std::string &, fileName, , IN, osg::Group *, group, , IN, float, priority, , IN, const osg::FrameStamp *, framestamp, , IN, osg::ref_ptr< osg::Referenced > &, databaseRequest, , IN, const osg::Referenced *, options, 0,
Properties::PURE_VIRTUAL,
__void__requestNodeFile__C5_std_string_R1__osg_Group_P1__float__C5_FrameStamp_P1__osg_ref_ptrT1_osg_Referenced__R1__C5_osg_Referenced_P1,
"",
"");
END_REFLECTOR
BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::NodeVisitor::ImageRequestHandler)

View File

@@ -93,6 +93,21 @@ BEGIN_OBJECT_REFLECTOR(osg::PagedLOD)
__bool__removeChildren__unsigned_int__unsigned_int,
"Remove children from Group. ",
"Note, must be override by subclasses of Group which add per child attributes. ");
I_Method1(void, setDatabaseOptions, IN, osg::Referenced *, options,
Properties::NON_VIRTUAL,
__void__setDatabaseOptions__osg_Referenced_P1,
"Set the optional database osgDB::Options object to use when loaded children. ",
"");
I_Method0(osg::Referenced *, getDatabaseOptions,
Properties::NON_VIRTUAL,
__osg_Referenced_P1__getDatabaseOptions,
"Get the optional database osgDB::Options object used when loaded children. ",
"");
I_Method0(const osg::Referenced *, getDatabaseOptions,
Properties::NON_VIRTUAL,
__C5_osg_Referenced_P1__getDatabaseOptions,
"Get the optional database osgDB::Options object used when loaded children. ",
"");
I_Method1(void, setDatabasePath, IN, const std::string &, path,
Properties::NON_VIRTUAL,
__void__setDatabasePath__C5_std_string_R1,
@@ -224,6 +239,9 @@ BEGIN_OBJECT_REFLECTOR(osg::PagedLOD)
__void__expandPerRangeDataTo__unsigned_int,
"",
"");
I_SimpleProperty(osg::Referenced *, DatabaseOptions,
__osg_Referenced_P1__getDatabaseOptions,
__void__setDatabaseOptions__osg_Referenced_P1);
I_SimpleProperty(const std::string &, DatabasePath,
__C5_std_string_R1__getDatabasePath,
__void__setDatabasePath__C5_std_string_R1);

View File

@@ -19,7 +19,6 @@
#include <osg/Referenced>
#include <osg/State>
#include <osgDB/DatabasePager>
#include <osgDB/Options>
// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
@@ -69,16 +68,11 @@ BEGIN_OBJECT_REFLECTOR(osgDB::DatabasePager)
__DatabasePager_P1__clone,
"Create a shallow copy on the DatabasePager. ",
"");
I_Method5(void, requestNodeFile, IN, const std::string &, fileName, IN, osg::Group *, group, IN, float, priority, IN, const osg::FrameStamp *, framestamp, IN, osg::ref_ptr< osg::Referenced > &, databaseRequest,
I_Method6(void, requestNodeFile, IN, const std::string &, fileName, IN, osg::Group *, group, IN, float, priority, IN, const osg::FrameStamp *, framestamp, IN, osg::ref_ptr< osg::Referenced > &, databaseRequest, IN, const osg::Referenced *, options,
Properties::VIRTUAL,
__void__requestNodeFile__C5_std_string_R1__osg_Group_P1__float__C5_osg_FrameStamp_P1__osg_ref_ptrT1_osg_Referenced__R1,
__void__requestNodeFile__C5_std_string_R1__osg_Group_P1__float__C5_osg_FrameStamp_P1__osg_ref_ptrT1_osg_Referenced__R1__C5_osg_Referenced_P1,
"Add a request to load a node file to end the the database request list. ",
"");
I_Method6(void, requestNodeFile, IN, const std::string &, fileName, IN, osg::Group *, group, IN, float, priority, IN, const osg::FrameStamp *, framestamp, IN, osg::ref_ptr< osg::Referenced > &, databaseRequest, IN, osgDB::Options *, loadOptions,
Properties::VIRTUAL,
__void__requestNodeFile__C5_std_string_R1__osg_Group_P1__float__C5_osg_FrameStamp_P1__osg_ref_ptrT1_osg_Referenced__R1__Options_P1,
"",
"");
I_Method1(int, setSchedulePriority, IN, OpenThreads::Thread::ThreadPriority, priority,
Properties::NON_VIRTUAL,
__int__setSchedulePriority__OpenThreads_Thread_ThreadPriority,

View File

@@ -17,6 +17,7 @@
#include <osg/Shader>
#include <osg/Shape>
#include <osgDB/AuthenticationMap>
#include <osgDB/FileCache>
#include <osgDB/Options>
#include <osgDB/ReaderWriter>
@@ -28,6 +29,30 @@
#undef OUT
#endif
BEGIN_ENUM_REFLECTOR(osgDB::FileLocationCallback::Location)
I_DeclaringFile("osgDB/Options");
I_EnumLabel(osgDB::FileLocationCallback::LOCAL_FILE);
I_EnumLabel(osgDB::FileLocationCallback::REMOTE_FILE);
END_REFLECTOR
BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgDB::FileLocationCallback)
I_DeclaringFile("osgDB/Options");
I_VirtualBaseType(osg::Referenced);
I_Constructor0(____FileLocationCallback,
"",
"");
I_Method2(osgDB::FileLocationCallback::Location, fileLocation, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::PURE_VIRTUAL,
__Location__fileLocation__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method0(bool, useFileCache,
Properties::PURE_VIRTUAL,
__bool__useFileCache,
"",
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgDB::FindFileCallback)
I_DeclaringFile("osgDB/Options");
I_VirtualBaseType(osg::Referenced);
@@ -223,13 +248,33 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Options)
I_Method1(void, setWriteFileCallback, IN, osgDB::WriteFileCallback *, cb,
Properties::NON_VIRTUAL,
__void__setWriteFileCallback__WriteFileCallback_P1,
"Set the Registry callback to use in place of the default writeFile calls. ",
"Set the callback to use in place of the default writeFile calls. ",
"");
I_Method0(osgDB::WriteFileCallback *, getWriteFileCallback,
Properties::NON_VIRTUAL,
__WriteFileCallback_P1__getWriteFileCallback,
"Get the const writeFile callback. ",
"");
I_Method1(void, setFileLocationCallback, IN, osgDB::FileLocationCallback *, cb,
Properties::NON_VIRTUAL,
__void__setFileLocationCallback__FileLocationCallback_P1,
"Set the callback to use inform the DatabasePager whether a file is located on local or remote file system. ",
"");
I_Method0(osgDB::FileLocationCallback *, getFileLocationCallback,
Properties::NON_VIRTUAL,
__FileLocationCallback_P1__getFileLocationCallback,
"Get the callback to use inform the DatabasePager whether a file is located on local or remote file system. ",
"");
I_Method1(void, setFileCache, IN, osgDB::FileCache *, fileCache,
Properties::NON_VIRTUAL,
__void__setFileCache__FileCache_P1,
"Set the FileCache that is used to manage local storage of files downloaded from the internet. ",
"");
I_Method0(osgDB::FileCache *, getFileCache,
Properties::NON_VIRTUAL,
__FileCache_P1__getFileCache,
"Get the FileCache that is used to manage local storage of files downloaded from the internet. ",
"");
I_SimpleProperty(osgDB::AuthenticationMap *, AuthenticationMap,
0,
__void__setAuthenticationMap__AuthenticationMap_P1);
@@ -242,6 +287,12 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Options)
I_SimpleProperty(osgDB::FilePathList &, DatabasePathList,
__FilePathList_R1__getDatabasePathList,
0);
I_SimpleProperty(osgDB::FileCache *, FileCache,
__FileCache_P1__getFileCache,
__void__setFileCache__FileCache_P1);
I_SimpleProperty(osgDB::FileLocationCallback *, FileLocationCallback,
__FileLocationCallback_P1__getFileLocationCallback,
__void__setFileLocationCallback__FileLocationCallback_P1);
I_SimpleProperty(osgDB::FindFileCallback *, FindFileCallback,
__FindFileCallback_P1__getFindFileCallback,
__void__setFindFileCallback__FindFileCallback_P1);

View File

@@ -85,6 +85,8 @@ TYPE_NAME_ALIAS(class osgDB::ReadFileCallback, osgDB::Registry::ReadFileCallback
TYPE_NAME_ALIAS(class osgDB::WriteFileCallback, osgDB::Registry::WriteFileCallback)
TYPE_NAME_ALIAS(class osgDB::FileLocationCallback, osgDB::Registry::FileLocationCallback)
BEGIN_OBJECT_REFLECTOR(osgDB::Registry)
I_DeclaringFile("osgDB/Registry");
I_BaseType(osg::Referenced);
@@ -412,6 +414,16 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Registry)
__void___buildKdTreeIfRequired__ReaderWriter_ReadResult_R1__C5_Options_P1,
"",
"");
I_Method1(void, setFileLocationCallback, IN, osgDB::Registry::FileLocationCallback *, cb,
Properties::NON_VIRTUAL,
__void__setFileLocationCallback__FileLocationCallback_P1,
"Set the callback to use inform the DatabasePager whether a file is located on local or remote file system. ",
"");
I_Method0(osgDB::Registry::FileLocationCallback *, getFileLocationCallback,
Properties::NON_VIRTUAL,
__FileLocationCallback_P1__getFileLocationCallback,
"Get the callback to use inform the DatabasePager whether a file is located on local or remote file system. ",
"");
I_Method1(void, setBuildKdTreesHint, IN, osgDB::Options::BuildKdTreesHint, hint,
Properties::NON_VIRTUAL,
__void__setBuildKdTreesHint__Options_BuildKdTreesHint,
@@ -666,6 +678,9 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Registry)
I_SimpleProperty(osgDB::FileCache *, FileCache,
__FileCache_P1__getFileCache,
__void__setFileCache__FileCache_P1);
I_SimpleProperty(osgDB::Registry::FileLocationCallback *, FileLocationCallback,
__FileLocationCallback_P1__getFileLocationCallback,
__void__setFileLocationCallback__FileLocationCallback_P1);
I_SimpleProperty(osgDB::Registry::FindFileCallback *, FindFileCallback,
__FindFileCallback_P1__getFindFileCallback,
__void__setFindFileCallback__FindFileCallback_P1);