Introduced first iterations of DatabaseRevision classes for managing the revisioning of http hosted databases
This commit is contained in:
76
include/osgDB/DatabaseRevisions
Normal file
76
include/osgDB/DatabaseRevisions
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGDB_DATABASEREVISIONS
|
||||
#define OSGDB_DATABASEREVISIONS 1
|
||||
|
||||
#include <osg/Node>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace osgDB {
|
||||
|
||||
|
||||
class OSGDB_EXPORT DatabaseRevision : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
DatabaseRevision();
|
||||
DatabaseRevision(const DatabaseRevision& revision, const osg::CopyOp=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgDB, DatabaseRevision)
|
||||
|
||||
typedef std::set<std::string> FileNames;
|
||||
|
||||
FileNames& getFilesAdded() { return _filesAdded; }
|
||||
FileNames& getFilesRemoved() { return _filesRemoved; }
|
||||
FileNames& getFilesModified() { return _filesModified; }
|
||||
|
||||
bool isFileBlackListed(const std::string& filename) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DatabaseRevision();
|
||||
|
||||
FileNames _filesAdded;
|
||||
FileNames _filesRemoved;
|
||||
FileNames _filesModified;
|
||||
};
|
||||
|
||||
class OSGDB_EXPORT DatabaseRevisions : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
DatabaseRevisions();
|
||||
DatabaseRevisions(const DatabaseRevisions& revisions, const osg::CopyOp=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgDB, DatabaseRevisions)
|
||||
|
||||
typedef std::vector< osg::ref_ptr<DatabaseRevision> > DatabaseRevisionList;
|
||||
|
||||
DatabaseRevisionList& getDatabaseRevisionList() { return _revisionList; }
|
||||
|
||||
bool isFileBlackListed(const std::string& filename) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DatabaseRevisions();
|
||||
|
||||
DatabaseRevisionList _revisionList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,9 @@
|
||||
#include <osg/Node>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/DatabaseRevisions>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace osgDB {
|
||||
|
||||
@@ -49,12 +52,20 @@ class OSGDB_EXPORT FileCache : public osg::Referenced
|
||||
virtual ReaderWriter::ReadResult readShader(const std::string& originalFileName, const osgDB::Options* options) const;
|
||||
virtual ReaderWriter::WriteResult writeShader(const osg::Shader& shader, const std::string& originalFileName, const osgDB::Options* options) const;
|
||||
|
||||
|
||||
typedef std::list< osg::ref_ptr<DatabaseRevisions> > DatabaseRevisionsList;
|
||||
DatabaseRevisionsList& getDatabaseRevisionsList() { return _databaseRevisionsList; }
|
||||
|
||||
bool isCachedFileBlackListed(const std::string& originalFileName) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~FileCache();
|
||||
|
||||
std::string _fileCachePath;
|
||||
|
||||
DatabaseRevisionsList _databaseRevisionsList;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/Callbacks
|
||||
${HEADER_PATH}/ConvertUTF
|
||||
${HEADER_PATH}/DatabasePager
|
||||
${HEADER_PATH}/DatabaseRevisions
|
||||
${HEADER_PATH}/DotOsgWrapper
|
||||
${HEADER_PATH}/DynamicLibrary
|
||||
${HEADER_PATH}/Export
|
||||
@@ -60,6 +61,7 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
Callbacks.cpp
|
||||
ConvertUTF.cpp
|
||||
DatabasePager.cpp
|
||||
DatabaseRevisions.cpp
|
||||
DotOsgWrapper.cpp
|
||||
DynamicLibrary.cpp
|
||||
Field.cpp
|
||||
|
||||
74
src/osgDB/DatabaseRevisions.cpp
Normal file
74
src/osgDB/DatabaseRevisions.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgDB/DatabaseRevisions>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
using namespace osgDB;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DatabaseRevision
|
||||
//
|
||||
DatabaseRevision::DatabaseRevision()
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseRevision::DatabaseRevision(const DatabaseRevision& revision, const osg::CopyOp):
|
||||
_filesAdded(revision._filesAdded),
|
||||
_filesRemoved(revision._filesRemoved),
|
||||
_filesModified(revision._filesModified)
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseRevision::~DatabaseRevision()
|
||||
{
|
||||
}
|
||||
|
||||
bool DatabaseRevision::isFileBlackListed(const std::string& filename) const
|
||||
{
|
||||
return _filesRemoved.count(filename)!=0 || _filesModified.count(filename)!=0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DatabaseRevisions
|
||||
//
|
||||
DatabaseRevisions::DatabaseRevisions()
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseRevisions::DatabaseRevisions(const DatabaseRevisions& revisions, const osg::CopyOp):
|
||||
_revisionList(revisions._revisionList)
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseRevisions::~DatabaseRevisions()
|
||||
{
|
||||
}
|
||||
|
||||
bool DatabaseRevisions::isFileBlackListed(const std::string& filename) const
|
||||
{
|
||||
for(DatabaseRevisionList::const_iterator itr = _revisionList.begin();
|
||||
itr != _revisionList.end();
|
||||
++itr)
|
||||
{
|
||||
if ((*itr)->isFileBlackListed(filename)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
using namespace osgDB;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FileCache
|
||||
//
|
||||
FileCache::FileCache(const std::string& path):
|
||||
_fileCachePath(path)
|
||||
{
|
||||
@@ -40,15 +44,19 @@ std::string FileCache::createCacheFileName(const std::string& originalFileName)
|
||||
std::string cacheFileName = _fileCachePath + "/" +
|
||||
osgDB::getServerAddress(originalFileName) + "/" +
|
||||
osgDB::getServerFileName(originalFileName);
|
||||
|
||||
|
||||
osg::notify(osg::INFO)<<"FileCache::createCacheFileName("<<originalFileName<<") = "<<cacheFileName<<std::endl;
|
||||
|
||||
|
||||
return cacheFileName;
|
||||
}
|
||||
|
||||
bool FileCache::existsInCache(const std::string& originalFileName) const
|
||||
{
|
||||
return osgDB::fileExists(createCacheFileName(originalFileName));
|
||||
if (osgDB::fileExists(createCacheFileName(originalFileName)))
|
||||
{
|
||||
return !isCachedFileBlackListed(originalFileName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ReaderWriter::ReadResult FileCache::readObject(const std::string& originalFileName, const osgDB::Options* options) const
|
||||
@@ -216,3 +224,15 @@ ReaderWriter::WriteResult FileCache::writeShader(const osg::Shader& shader, cons
|
||||
}
|
||||
return ReaderWriter::WriteResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
bool FileCache::isCachedFileBlackListed(const std::string& originalFileName) const
|
||||
{
|
||||
for(DatabaseRevisionsList::const_iterator itr = _databaseRevisionsList.begin();
|
||||
itr != _databaseRevisionsList.end();
|
||||
++itr)
|
||||
{
|
||||
if ((*itr)->isFileBlackListed(originalFileName)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user