Changeset 9884

Show
Ignore:
Timestamp:
03/10/09 13:21:13 (4 years ago)
Author:
robert
Message:

From Stephan Huber,
"Attached you'll find a proposal for using different
protocols. The idea behind the new code is:

1.) plugins/apps register protocols which they can handle. This is done
via osgDB::Registry::registerProtocol(aProtocolName). Plugins register
supported protocols as usual via ReaderWriter::supportsProtocol(..), the
Registry is updated accordingly.

2.) osgDB::containsServerAddress checks first for an appearance of "://"
in the filename and then checks the protocol against the set of
registered protocols via Registry::isProtocolRegistered(aProtocollName)

3.) the other getServer*-functions changed as well, there's even a
getServerProtocol-function

With these changes filenames/Urls get routed to loaded plugins even with
different protocols than 'http'."

Location:
OpenSceneGraph/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgDB/FileNameUtils

    r8912 r9884  
    4141 
    4242extern OSGDB_EXPORT bool containsServerAddress(const std::string& filename); 
     43extern OSGDB_EXPORT std::string getServerProtocol(const std::string& filename); 
    4344extern OSGDB_EXPORT std::string getServerAddress(const std::string& filename); 
    4445extern OSGDB_EXPORT std::string getServerFileName(const std::string& filename); 
  • OpenSceneGraph/trunk/include/osgDB/Registry

    r9334 r9884  
    479479        /** Add an Archive extension.*/ 
    480480        void addArchiveExtension(const std::string ext); 
    481  
     481         
     482        /** registers a protocol */ 
     483        void registerProtocol(const std::string& protocol); 
     484         
     485        /** returns true, if named protocol is registered */ 
     486        bool isProtocolRegistered(const std::string& protocol); 
     487         
    482488    protected: 
    483489 
     
    492498        typedef std::map<std::string, ObjectTimeStampPair >             ObjectCache; 
    493499        typedef std::map<std::string, osg::ref_ptr<osgDB::Archive> >    ArchiveCache; 
     500         
     501        typedef std::set<std::string>                                   RegisteredProtocolsSet; 
    494502 
    495503        /** constructor is private, as its a singleton, preventing 
     
    509517         
    510518        bool                                        _createNodeFromImage; 
     519         
     520        RegisteredProtocolsSet                      _registeredProtocols; 
    511521 
    512522        osg::Object*       readObject(DotOsgWrapperMap& dowMap,Input& fr); 
  • OpenSceneGraph/trunk/src/osgDB/FileNameUtils.cpp

    r8912 r9884  
    180180} 
    181181 
     182 
     183 
    182184bool osgDB::containsServerAddress(const std::string& filename) 
    183185{ 
    184     // need to check for http:// 
    185     if (filename.size()<7) return false; 
    186     if (filename.compare(0,7,"http://")==0) return true; 
    187     return false; 
     186    // need to check for :// 
     187    std::string::size_type pos(filename.find_first_of("://")); 
     188    if (pos == std::string::npos)  
     189        return false; 
     190    std::string proto(filename.substr(0, pos)); 
     191     
     192    return Registry::instance()->isProtocolRegistered(proto); 
     193} 
     194 
     195std::string osgDB::getServerProtocol(const std::string& filename) 
     196{ 
     197    std::string::size_type pos(filename.find_first_of("://")); 
     198    if (pos != std::string::npos) 
     199        return filename.substr(0,pos); 
     200 
     201    return ""; 
    188202} 
    189203 
    190204std::string osgDB::getServerAddress(const std::string& filename) 
    191205{ 
    192     if (filename.size()>=7 && filename.compare(0,7,"http://")==0) 
    193     { 
    194         std::string::size_type pos_slash = filename.find_first_of('/',7); 
     206    std::string::size_type pos(filename.find_first_of("://")); 
     207     
     208    if (pos != std::string::npos) 
     209    { 
     210        std::string::size_type pos_slash = filename.find_first_of('/',pos+3); 
    195211        if (pos_slash!=std::string::npos) 
    196212        { 
    197             return filename.substr(7,pos_slash-7); 
     213            return filename.substr(pos+3,pos_slash-pos-3); 
    198214        } 
    199215        else 
    200216        { 
    201             return filename.substr(7,std::string::npos); 
     217            return filename.substr(pos+3,std::string::npos); 
    202218        } 
    203219    } 
     
    207223std::string osgDB::getServerFileName(const std::string& filename) 
    208224{ 
    209     if (filename.size()>=7 && filename.compare(0,7,"http://")==0) 
    210     { 
    211         std::string::size_type pos_slash = filename.find_first_of('/',7); 
     225    std::string::size_type pos(filename.find_first_of("://")); 
     226 
     227    if (pos != std::string::npos) 
     228    { 
     229        std::string::size_type pos_slash = filename.find_first_of('/',pos+3); 
    212230        if (pos_slash!=std::string::npos) 
    213231        { 
  • OpenSceneGraph/trunk/src/osgDB/ReaderWriter.cpp

    r8620 r9884  
    4848void ReaderWriter::supportsProtocol(const std::string& fmt, const std::string& description) 
    4949{ 
     50    Registry::instance()->registerProtocol(fmt); 
    5051    _supportedProtocols[convertToLowerCase(fmt)] = description; 
    5152} 
  • OpenSceneGraph/trunk/src/osgDB/Registry.cpp

    r9881 r9884  
    331331    addFileExtensionAlias("pgm", "pnm"); 
    332332    addFileExtensionAlias("ppm", "pnm"); 
     333     
     334    // register http-protocol, so the curl can handle it, if necessary 
     335    registerProtocol("http");  
    333336     
    334337} 
     
    20932096    return _sharedStateManager.get(); 
    20942097} 
     2098 
     2099 
     2100void Registry::registerProtocol(const std::string& protocol)  
     2101 
     2102    _registeredProtocols.insert( convertToLowerCase(protocol) );  
     2103} 
     2104         
     2105bool Registry::isProtocolRegistered(const std::string& protocol)  
     2106{  
     2107    return (_registeredProtocols.find( convertToLowerCase(protocol) ) != _registeredProtocols.end());  
     2108} 
     2109