- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.h
r12906 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 29 29 NODE 30 30 }; 31 31 32 32 class EasyCurl : public osg::Referenced 33 33 { 34 34 public: 35 35 36 36 struct StreamObject 37 37 { 38 38 StreamObject(std::ostream* outputStream, std::istream* inputStream, const std::string& cacheFileName); 39 39 40 40 void write(const char* ptr, size_t realsize); 41 41 size_t read(char* ptr, size_t maxsize); 42 42 43 43 std::ostream* _outputStream; 44 44 std::istream* _inputStream; 45 45 46 46 bool _foutOpened; 47 47 std::string _cacheFileName; … … 49 49 std::string _resultMimeType; 50 50 }; 51 51 52 52 static size_t StreamMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data); 53 53 … … 62 62 inline void setTimeout(long val) { _timeout = val; } 63 63 64 // Perform HTTP GET to download data from web server. 64 // Perform HTTP GET to download data from web server. 65 65 osgDB::ReaderWriter::ReadResult read(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp, const osgDB::ReaderWriter::Options *options); 66 66 … … 85 85 void setOptions(const std::string& proxyAddress, const std::string& fileName, StreamObject& sp, const osgDB::ReaderWriter::Options *options); 86 86 osgDB::ReaderWriter::ReadResult processResponse(CURLcode responseCode, const std::string& proxyAddress, const std::string& fileName, StreamObject& sp); 87 87 88 88 CURL* _curl; 89 89 90 90 std::string _previousPassword; 91 91 long _previousHttpAuthentication; … … 98 98 { 99 99 public: 100 100 101 101 ReaderWriterCURL(); 102 102 103 103 ~ReaderWriterCURL(); 104 104 105 105 virtual const char* className() const { return "HTTP Protocol Model Reader"; } 106 106 107 107 virtual bool acceptsExtension(const std::string& extension) const 108 108 { … … 122 122 return readFile(OBJECT,fileName,options); 123 123 } 124 124 125 125 virtual ReadResult readImage(const std::string& fileName, const Options *options) const 126 126 { … … 138 138 } 139 139 140 virtual WriteResult writeObject(const osg::Object& obj, const std::string& fileName, const Options* options) const 140 virtual WriteResult writeObject(const osg::Object& obj, const std::string& fileName, const Options* options) const 141 141 { 142 142 return writeFile(obj,fileName,options); 143 143 } 144 144 145 virtual WriteResult writeImage(const osg::Image& image, const std::string& fileName, const Options* options) const 145 virtual WriteResult writeImage(const osg::Image& image, const std::string& fileName, const Options* options) const 146 146 { 147 147 return writeFile(image,fileName,options); 148 148 } 149 149 150 virtual WriteResult writeHeightField(const osg::HeightField& heightField, const std::string& fileName, const Options* options) const 150 virtual WriteResult writeHeightField(const osg::HeightField& heightField, const std::string& fileName, const Options* options) const 151 151 { 152 152 return writeFile(heightField,fileName,options); 153 153 } 154 154 155 virtual WriteResult writeNode(const osg::Node& node, const std::string& fileName, const Options* options) const 156 { 155 virtual WriteResult writeNode(const osg::Node& node, const std::string& fileName, const Options* options) const 156 { 157 157 return writeFile(node,fileName,options); 158 158 } … … 160 160 ReadResult readFile(ObjectType objectType, osgDB::ReaderWriter* rw, std::istream& fin, const Options *options) const; 161 161 WriteResult writeFile(const osg::Object& obj, osgDB::ReaderWriter* rw, std::ostream& fout, const Options *options) const; 162 162 163 163 virtual ReadResult readFile(ObjectType objectType, const std::string& fullFileName, const Options *options) const; 164 164 virtual WriteResult writeFile(const osg::Object& obj, const std::string& fullFileName, const Options *options) const; 165 165 166 166 EasyCurl& getEasyCurl() const 167 167 { … … 170 170 osg::ref_ptr<EasyCurl>& ec = _threadCurlMap[OpenThreads::Thread::CurrentThread()]; 171 171 if (!ec) ec = new EasyCurl; 172 172 173 173 return *ec; 174 174 } … … 178 178 protected: 179 179 void getConnectionOptions(const osgDB::ReaderWriter::Options *options, std::string& proxyAddress, long& connectTimeout, long& timeout) const; 180 180 181 181 typedef std::map< OpenThreads::Thread*, osg::ref_ptr<EasyCurl> > ThreadCurlMap; 182 182 183 183 mutable OpenThreads::Mutex _threadCurlMapMutex; 184 184 mutable ThreadCurlMap _threadCurlMap;
