/usr/include/ossim/base/ossimStreamFactoryRegistry.h is in libossim-dev 2.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | //*******************************************************************
//
// License: MIT
//
// See LICENSE.txt file in the top level directory for more details.
//
// Author: Garrett Potts
//
//*******************************************************************
// $Id$
#ifndef ossimStreamFactoryRegistry_HEADER
#define ossimStreamFactoryRegistry_HEADER 1
#include <ossim/base/ossimFactoryListInterface.h>
#include <ossim/base/ossimRefPtr.h>
#include <ossim/base/ossimIoStream.h>
#include <ossim/base/ossimStreamFactoryBase.h>
#include <ossim/base/ossimRegExp.h>
#include <memory>
#include <vector>
#include <mutex>
#include <atomic>
namespace ossim
{
/**
* This is a generic stream registry. We could try to create streams for
* http, https, s3 protocols as well as local file. We have also exposed an
* exists for supporting exists() calls for different stream types.
*
* We have added support for Buffered reads. You can enable buffered
* reads to be block boundary. If it's not block then it will use
* a pubsetbuf for a buffered I/O
* It will read the @see ossimPreferences for the prefix key
* ossim.stream.factory.registry.istream.buffer[0-9]+
* Example key list:
* @code
* ossim.stream.factory.registry.istream.buffer1.enabled: false
* ossim.stream.factory.registry.istream.buffer1.includePattern: ^/
* ossim.stream.factory.registry.istream.buffer1.enableBlocked: true
* ossim.stream.factory.registry.istream.buffer1.size: 65536
* @endcode
*
* The includePattern keyword is a regular expression.
* Examples:
* - ^/ Anything that starts with /
* - ^s3:// Anything starting with s3://
*
* Local file example:
* @code
* ossimString connectionString = "/data/foo.ntf"
* std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->createIstream(connectionString);
* if(in)
* {
* std::vector<char> buf(1024)
* in->seekg(0);
* in->read(&buf.front(), buf.size());
* }
* @endcode
* S3 file example:
* @code
* ossimString connectionString = "s3://foo-bucket/path/foo.ntf"
* std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->createIstream(connectionString);
* if(in)
* {
* std::vector<char> buf(1024)
* in->seekg(0);
* in->read(&buf.front(), buf.size());
* }
* @endcode
* https or https file example:
* @code
* ossimString connectionString = "https://foo-host/path/foo.ntf"
* std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->createIstream(connectionString);
* if(in)
* {
* std::vector<char> buf(1024)
* in->seekg(0);
* in->read(&buf.front(), buf.size());
* }
* @endcode
*/
class OSSIM_DLL StreamFactoryRegistry : public StreamFactoryBase
{
public:
static StreamFactoryRegistry* instance();
virtual ~StreamFactoryRegistry();
/**
* Registers a stream factory. This allows for a pluggable stream
* Please see ossim-plugins and look at curl, aws for example
* stream definitions.
*
* @param factory To be added to the registry
*/
void registerFactory(StreamFactoryBase* factory);
/**
* Removes a factory from the registry.
* @param factory To be removed from the registry
*/
void unregisterFactory(StreamFactoryBase* factory);
/**
* Will try to creates an istream interface to the connectionString
* passed in
*
* @param connectionString Is the connection string used to create
* a stream. Possible examples: s3://<bucket>/path or
* /data/foo.tif or https://<host>/<path>
* @param options If a stream is found then this holds specific options
* for the stream. Defaults to empty options
* @param mode Is the mode to be used. Defaults to a binary input stream.
* @return A shared pointer to an istream if successful.
*/
virtual std::shared_ptr<ossim::istream>
createIstream(const std::string& connectionString,
const ossimKeywordlist& options=ossimKeywordlist(),
std::ios_base::openmode mode=
std::ios_base::in|std::ios_base::binary) const;
/**
* Will try to creates an ostream interface to the connectionString
* passed in
*
* @param connectionString Is the connection string used to create the
* stream
* @param options If a stream is found then this holds specific options
* for the stream. Defaults to empty options
* @param mode Is the mode to be used. Defaults to a binary output
* stream.
* @return A shared pointer to an ostream if successful.
*/
virtual std::shared_ptr<ossim::ostream>
createOstream(const std::string& connectionString,
const ossimKeywordlist& options=ossimKeywordlist(),
std::ios_base::openmode mode=
std::ios_base::out|std::ios_base::binary) const;
/**
* Will try to creates an iostream interface to the connectionString
* passed in
*
* @param connectionString Is the connection string used to create the
* stream
* @param options If a stream is found then this holds specific options
* for the stream. Defaults to empty options
* @param mode Is the mode to be used. Defaults to a binary output
* stream.
* @return A shared pointer to an ostream if successful.
*/
virtual std::shared_ptr<ossim::iostream>
createIOstream(const std::string& connectionString,
const ossimKeywordlist& options=ossimKeywordlist(),
std::ios_base::openmode mode=
std::ios_base::in|std::ios_base::out|std::ios_base::binary) const;
/**
* @brief Methods to test if connection exists.
* @return true on success, false, if not.
*/
bool exists(const std::string& connectionString) const;
/**
* @brief Methods to test if connection exists.
* @param connectionString
* @param continueFlag Initializes by this, if set to true, indicates factory
* handles file/url and no more factory checks are necessary.
* @return true on success, false, if not.
*/
virtual bool exists(const std::string& connectionString,
bool& continueFlag) const;
/**
* This will load the buffer information from the
* preferences.
*/
void loadPreferences();
protected:
StreamFactoryRegistry();
private:
/**
* This is an internal class used to store the buffer information
* loaded from the preferences.
* @see StreamFactoryRegistry
*/
class BufferInfo{
public:
BufferInfo():m_enabled(false),
m_enableBlocked(false),
m_pattern(""),
m_size(4096){}
bool m_enabled;
bool m_enableBlocked;
ossimString m_pattern;
ossim_uint64 m_size;
};
/** @brief copy constructor hidden from use */
StreamFactoryRegistry(const StreamFactoryRegistry&);
/**
* @param bufferInfo Holds the result of the first buffer info
* matching the connection string
* @param connecitonString The connection string
*/
bool getBufferInfo(BufferInfo& bufferInfo,
const ossimString& connectionString)const;
std::vector<StreamFactoryBase*> m_factoryList;
std::vector<BufferInfo> m_bufferInfoList;
static StreamFactoryRegistry* m_instance;
mutable ossimRegExp m_patternMatcher;
mutable std::mutex m_mutex;
};
} // End: namespace ossim
#endif
|