OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ossim::AwsStreamFactory Class Reference

#include <ossimAwsStreamFactory.h>

Inheritance diagram for ossim::AwsStreamFactory:
ossim::StreamFactoryBase

Public Member Functions

virtual ~AwsStreamFactory ()
 
virtual std::shared_ptr< ossim::istreamcreateIstream (const std::string &connectionString, const ossimKeywordlist &options, std::ios_base::openmode openMode) const
 
virtual std::shared_ptr< ossim::ostreamcreateOstream (const std::string &connectionString, const ossimKeywordlist &options, std::ios_base::openmode openMode) const
 
virtual std::shared_ptr< ossim::iostreamcreateIOstream (const std::string &connectionString, const ossimKeywordlist &options, std::ios_base::openmode openMode) const
 
bool exists (const std::string &connectionString, bool &continueFlag) const
 Methods to test if connection exists. More...
 
std::shared_ptr< Aws::S3::S3Client > getSharedS3Client () const
 
- Public Member Functions inherited from ossim::StreamFactoryBase
virtual ~StreamFactoryBase ()
 

Static Public Member Functions

static AwsStreamFactoryinstance ()
 

Protected Member Functions

bool isS3Url (const ossimFilename &file) const
 
void initClient () const
 
 AwsStreamFactory ()
 
 AwsStreamFactory (const AwsStreamFactory &)
 

Protected Attributes

std::shared_ptr< Aws::S3::S3Client > m_client
 

Static Protected Attributes

static AwsStreamFactorym_instance = 0
 

Detailed Description

Definition at line 27 of file ossimAwsStreamFactory.h.

Constructor & Destructor Documentation

◆ ~AwsStreamFactory()

ossim::AwsStreamFactory::~AwsStreamFactory ( )
virtual

Definition at line 32 of file ossimAwsStreamFactory.cpp.

33 {
34 }

◆ AwsStreamFactory() [1/2]

ossim::AwsStreamFactory::AwsStreamFactory ( )
protected

Definition at line 168 of file ossimAwsStreamFactory.cpp.

169 {
170  // the stream is now shared so we must allocate here.
171  //
172  initClient();
173 }

◆ AwsStreamFactory() [2/2]

ossim::AwsStreamFactory::AwsStreamFactory ( const AwsStreamFactory )
protected

Definition at line 176 of file ossimAwsStreamFactory.cpp.

177 {
178 }

Member Function Documentation

◆ createIOstream()

std::shared_ptr< ossim::iostream > ossim::AwsStreamFactory::createIOstream ( const std::string &  connectionString,
const ossimKeywordlist options,
std::ios_base::openmode  openMode 
) const
virtual

Implements ossim::StreamFactoryBase.

Definition at line 87 of file ossimAwsStreamFactory.cpp.

91 {
92  return std::shared_ptr<ossim::iostream>(0);
93 }

◆ createIstream()

std::shared_ptr< ossim::istream > ossim::AwsStreamFactory::createIstream ( const std::string &  connectionString,
const ossimKeywordlist options,
std::ios_base::openmode  openMode 
) const
virtual

Implements ossim::StreamFactoryBase.

Definition at line 45 of file ossimAwsStreamFactory.cpp.

49 {
50  std::shared_ptr<ossim::S3IStream> result = std::make_shared<ossim::S3IStream>();
51  if(traceDebug())
52  {
53  ossimNotify(ossimNotifyLevel_WARN) << "ossim::AwsStreamFactory::createIstream: Entered...............\n";
54  }
55 
56  //---
57  // Hack for upstream code calling ossimFilename::convertToNative()
58  // wrecking s3 url.
59  //---
60 #if defined(_WIN32)
61  ossimFilename f = connectionString;
62  result->open( f.string(), options, openMode) ;
63 #else
64  result->open( connectionString, options, openMode );
65 #endif
66 
67  if(!result->good())
68  {
69  result.reset();
70  }
71  if(traceDebug())
72  {
73  ossimNotify(ossimNotifyLevel_WARN) << "ossim::AwsStreamFactory::createIstream: Leaving...............\n";
74  }
75 
76  return result;
77 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
const std::string & string() const
Definition: ossimString.h:414

◆ createOstream()

std::shared_ptr< ossim::ostream > ossim::AwsStreamFactory::createOstream ( const std::string &  connectionString,
const ossimKeywordlist options,
std::ios_base::openmode  openMode 
) const
virtual

Implements ossim::StreamFactoryBase.

Definition at line 79 of file ossimAwsStreamFactory.cpp.

83 {
84  return std::shared_ptr<ossim::ostream>(0);
85 }

◆ exists()

bool ossim::AwsStreamFactory::exists ( const std::string &  connectionString,
bool &  continueFlag 
) const
virtual

Methods to test if connection exists.

Parameters
connectionString
continueFlagInitializes by this, if set to true, indicates factory handles file/url and no more factory checks are necessary.
Returns
true on success, false, if not.

Implements ossim::StreamFactoryBase.

Definition at line 95 of file ossimAwsStreamFactory.cpp.

97 {
98  if(traceDebug())
99  {
101  << "ossim::AwsStreamFactory::exists() DEBUG: entered.....\n";
102 
103  }
104  bool result = false;
105 
106  // ossimTimer::Timer_t startTimer = ossimTimer::instance()->tick();
107 
108  if ( connectionString.size() )
109  {
110  // Check for url string:
111  std::size_t pos = connectionString.find( "://" );
112  if ( pos != std::string::npos )
113  {
114  ossimUrl url(connectionString);
115  if( (url.getProtocol() == "s3") || (url.getProtocol() == "S3") )
116  {
117  continueFlag = false; // Set to false to stop registry search.
118 
119  ossim_int64 filesize;
120  if(ossim::S3HeaderCache::instance()->getCachedFilesize(connectionString, filesize))
121  {
122  if(filesize >=0)
123  {
124  result = true;
125  }
126  }
127  else
128  {
129  std::string bucket = url.getIp().string();
130  std::string key = url.getPath().string();
131  Aws::S3::Model::HeadObjectRequest headObjectRequest;
132  headObjectRequest.WithBucket( bucket.c_str() )
133  .WithKey( key.c_str() );
134  auto headObject = m_client->HeadObject(headObjectRequest);
135  if(headObject.IsSuccess())
136  {
137  result = true;
138  filesize = headObject.GetResult().GetContentLength();
139  ossim::S3HeaderCache::Node_t nodePtr = std::make_shared<ossim::S3HeaderCacheNode>(filesize);
140  ossim::S3HeaderCache::instance()->addHeader(connectionString, nodePtr);
141  }
142  else
143  {
144  result = false;
145  ossim::S3HeaderCache::Node_t nodePtr = std::make_shared<ossim::S3HeaderCacheNode>(-1);
146  ossim::S3HeaderCache::instance()->addHeader(connectionString, nodePtr);
147  }
148  }
149  }
150  }
151  }
152 
153  // ossimTimer::Timer_t endTimer = ossimTimer::instance()->tick();
154  // cout << "time: " << ossimTimer::instance()->delta_s(startTimer, endTimer) << endl;
155 
156  // std::cout << "aws result: " << result << std::endl;
157  if(traceDebug())
158  {
160  << "ossim::AwsStreamFactory::exists() DEBUG: leaving.....\n";
161 
162  }
163 
164  return result;
165 }
std::shared_ptr< S3HeaderCacheNode > Node_t
Definition: S3HeaderCache.h:30
std::shared_ptr< Aws::S3::S3Client > m_client
static std::shared_ptr< S3HeaderCache > instance()
long long ossim_int64
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getSharedS3Client()

std::shared_ptr<Aws::S3::S3Client> ossim::AwsStreamFactory::getSharedS3Client ( ) const
inline

Definition at line 58 of file ossimAwsStreamFactory.h.

References m_client.

Referenced by ossim::S3StreamBuffer::S3StreamBuffer().

58 {return m_client;}
std::shared_ptr< Aws::S3::S3Client > m_client

◆ initClient()

void ossim::AwsStreamFactory::initClient ( ) const
protected

Definition at line 180 of file ossimAwsStreamFactory.cpp.

References ossimPreferences::instance().

181 {
182  Aws::Client::ClientConfiguration config;
183 
184  // Look for AWS S3 region override:
185  std::string region = ossimPreferences::instance()->
186  preferencesKWL().findKey(std::string("ossim.plugins.aws.s3.region"));
187  if ( region.size() )
188  {
189  config.region = region.c_str();
190  }
191 
192  m_client = std::make_shared<Aws::S3::S3Client>(config);
193 //new Aws::S3::S3Client( config );
194 }
static ossimPreferences * instance()
std::shared_ptr< Aws::S3::S3Client > m_client

◆ instance()

ossim::AwsStreamFactory * ossim::AwsStreamFactory::instance ( )
static

◆ isS3Url()

bool ossim::AwsStreamFactory::isS3Url ( const ossimFilename file) const
protected
Returns
true if starts with "s3://" or "S3://"

Member Data Documentation

◆ m_client

std::shared_ptr<Aws::S3::S3Client> ossim::AwsStreamFactory::m_client
mutableprotected

Definition at line 73 of file ossimAwsStreamFactory.h.

Referenced by getSharedS3Client().

◆ m_instance

ossim::AwsStreamFactory * ossim::AwsStreamFactory::m_instance = 0
staticprotected

Definition at line 75 of file ossimAwsStreamFactory.h.


The documentation for this class was generated from the following files: