Commit 4343de79 authored by Morten Ofstad's avatar Morten Ofstad
Browse files

Changed OpenOptions to be a kind of tagged union indicating the connection...

Changed OpenOptions to be a kind of tagged union indicating the connection type to make room for other types than AWS. Still need to create an abstract Connection interface that the VolumeDataPageAccessor and JSON serialize/deserialize methods can use.
parent 635177d5
......@@ -32,8 +32,17 @@ namespace OpenVDS
VDSHandle *open(const OpenOptions &options, Error &error)
{
std::unique_ptr<VDSHandle> ret(new VDSHandle());
if (!downloadAndParseVDSJson(options, *ret.get(), error))
switch(options.connectionType)
{
case OpenOptions::AWS:
{
if (!downloadAndParseVDSJson(static_cast<const AWSOpenOptions &>(options), *ret.get(), error))
{
return nullptr;
}
}
default:
return nullptr;
}
return ret.release();
......@@ -42,8 +51,17 @@ VDSHandle *open(const OpenOptions &options, Error &error)
VDSHandle* create(const OpenOptions& options, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error)
{
std::unique_ptr<VDSHandle> ret(new VDSHandle());
if (!serializeAndUploadVDSJson(options, *ret.get(), error))
switch(options.connectionType)
{
case OpenOptions::AWS:
{
if (!serializeAndUploadVDSJson(static_cast<const AWSOpenOptions &>(options), *ret.get(), error))
{
return nullptr;
}
}
default:
return nullptr;
}
return ret.release();
......
......@@ -33,10 +33,28 @@ class VolumeDataAxisDescriptor;
class VolumeDataChannelDescriptor;
struct OpenOptions
{
enum ConnectionType
{
AWS,
Azure,
File
};
ConnectionType connectionType;
protected:
OpenOptions(ConnectionType connectionType) : connectionType(connectionType) {}
};
struct AWSOpenOptions : OpenOptions
{
std::string bucket;
std::string key;
std::string region;
AWSOpenOptions() : OpenOptions(AWS) {}
AWSOpenOptions(std::string const & bucket, std::string const & key, std::string const & region) : OpenOptions(AWS), bucket(bucket), key(key), region(region) {}
};
struct Error
......
......@@ -488,7 +488,7 @@ main(int argc, char *argv[])
OpenVDS::Error
createError;
auto vds = OpenVDS::create(OpenVDS::OpenOptions(), layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, createError);
auto vds = OpenVDS::create(OpenVDS::AWSOpenOptions(), layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, createError);
return EXIT_SUCCESS;
}
......@@ -669,7 +669,7 @@ static void createVolumeDataLayout(VDSHandle &handle)
}
}
bool downloadAndParseVDSJson(const OpenOptions& options, VDSHandle& handle, Error& error)
bool downloadAndParseVDSJson(const AWSOpenOptions& options, VDSHandle& handle, Error& error)
{
std::string vdsobject_json;
if (!S3::DownloadJson(options.region, options.bucket, options.key, vdsobject_json, error))
......@@ -711,7 +711,7 @@ bool downloadAndParseVDSJson(const OpenOptions& options, VDSHandle& handle, Erro
return true;
}
bool serializeAndUploadVDSJson(const OpenOptions& options, VDSHandle& handle, Error& error)
bool serializeAndUploadVDSJson(const AWSOpenOptions& options, VDSHandle& handle, Error& error)
{
return true;
}
......
......@@ -23,8 +23,8 @@
namespace OpenVDS
{
bool downloadAndParseVDSJson(const OpenOptions &options, VDSHandle &handle, Error &error);
bool serializeAndUploadVDSJson(const OpenOptions &options, VDSHandle &handle, Error &error);
bool downloadAndParseVDSJson(const AWSOpenOptions &options, VDSHandle &handle, Error &error);
bool serializeAndUploadVDSJson(const AWSOpenOptions &options, VDSHandle &handle, Error &error);
}
#endif //PARSEVDSJSON_H
\ No newline at end of file
......@@ -24,7 +24,7 @@
GTEST_TEST(DownloadJson, OpenVDS_integration)
{
OpenVDS::Error error;
OpenVDS::OpenOptions options;
OpenVDS::AWSOpenOptions options;
options.region = getenv("OPENVDS_TEST_AWS_REGION");
options.bucket = getenv("OPENVDS_TEST_AWS_BUCKET");
options.key = getenv("OPENVDS_TEST_AWS_OBJECTID");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment