Commit 0fb2a2b2 authored by Morten Ofstad's avatar Morten Ofstad
Browse files

Refactored the Open/Close methods so there are alternate versions that take an...

Refactored the Open/Close methods so there are alternate versions that take an IOManager instead of OpenOptions. This is meant to make it easier to test the code by creating IOManagers that e.g. store everything in memory instead of in an object store. Renamed the Destroy(handle) method to Close(handle) and added documentation for Open/Create/Close calls.
parent f96b1732
......@@ -34,13 +34,12 @@
namespace OpenVDS
{
VDSHandle *Open(const OpenOptions &options, Error &error)
VDSHandle* Open(IOManager *ioManager, Error& error)
{
error = Error();
std::unique_ptr<VDSHandle> ret(new VDSHandle(options, error));
if (error.Code)
return nullptr;
std::unique_ptr<VDSHandle> ret(new VDSHandle(ioManager));
error = Error();
if (!downloadAndParseVolumeDataLayoutAndLayerStatus(*ret.get(), error))
{
return nullptr;
......@@ -50,6 +49,16 @@ VDSHandle *Open(const OpenOptions &options, Error &error)
return ret.release();
}
VDSHandle *Open(const OpenOptions &options, Error &error)
{
error = Error();
IOManager* ioManager = IOManager::createIOManager(options, error);
if (error.Code)
return nullptr;
return Open(ioManager, error);
}
VolumeDataLayout *GetLayout(VDSHandle *handle)
{
if (!handle)
......@@ -167,10 +176,10 @@ void createVolumeDataLayout(VDSHandle &handle)
}
}
VDSHandle* Create(const OpenOptions& options, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error)
VDSHandle* Create(IOManager *ioManager, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error)
{
error = Error();
std::unique_ptr<VDSHandle> handle(new VDSHandle(options, error));
std::unique_ptr<VDSHandle> handle(new VDSHandle(ioManager));
handle->layoutDescriptor = layoutDescriptor;
......@@ -217,7 +226,17 @@ VDSHandle* Create(const OpenOptions& options, VolumeDataLayoutDescriptor const &
return handle.release();
}
void Destroy(VDSHandle *handle)
VDSHandle* Create(const OpenOptions& options, VolumeDataLayoutDescriptor const& layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const& axisDescriptors, std::vector<VolumeDataChannelDescriptor> const& channelDescriptors, MetadataContainer const& metadataContainer, Error& error)
{
error = Error();
IOManager* ioManager = IOManager::createIOManager(options, error);
if (error.Code)
return nullptr;
return Create(ioManager, layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, error);
}
void Close(VDSHandle *handle)
{
delete handle;
}
......
......@@ -31,6 +31,7 @@ namespace OpenVDS
class VolumeDataLayoutDescriptor;
class VolumeDataAxisDescriptor;
class VolumeDataChannelDescriptor;
class IOManager;
struct OpenOptions
{
......@@ -73,9 +74,69 @@ class VolumeDataLayout;
class VolumeDataAccessManager;
class VolumeDataPageAccessor;
OPENVDS_EXPORT VDSHandle* Open(const OpenOptions& options, Error &error);
OPENVDS_EXPORT VDSHandle* Create(const OpenOptions& options, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error);
OPENVDS_EXPORT void Destroy(VDSHandle *handle);
/// <summary>
/// Open an existing VDS
/// </summary>
/// <param name="options">
/// The options for the connection
/// </param>
/// <param name="error">
/// If an error occured, the error code and message will be written to this output parameter
/// </param>
/// <returns>
/// The VDS handle that can be used to get the VolumeDataLayout and the VolumeDataAccessManager
/// </returns>
OPENVDS_EXPORT VDSHandle* Open(const OpenOptions& options, Error& error);
/// <summary>
/// Open an existing VDS
/// </summary>
/// <param name="ioManager">
/// The IOManager for the connection, it will be deleted automatically when the VDS handle is closed
/// </param>
/// <param name="error">
/// If an error occured, the error code and message will be written to this output parameter
/// </param>
/// <returns>
/// The VDS handle that can be used to get the VolumeDataLayout and the VolumeDataAccessManager
/// </returns>
OPENVDS_EXPORT VDSHandle* Open(IOManager*ioManager, Error &error);
/// <summary>
/// Create a new VDS
/// </summary>
/// <param name="options">
/// The options for the connection
/// </param>
/// <param name="error">
/// If an error occured, the error code and message will be written to this output parameter
/// </param>
/// <returns>
/// The VDS handle that can be used to get the VolumeDataLayout and the VolumeDataAccessManager
/// </returns>
OPENVDS_EXPORT VDSHandle* Create(const OpenOptions& options, VolumeDataLayoutDescriptor const& layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const& axisDescriptors, std::vector<VolumeDataChannelDescriptor> const& channelDescriptors, MetadataContainer const& metadataContainer, Error& error);
/// <summary>
/// Create a new VDS
/// </summary>
/// <param name="ioManager">
/// The IOManager for the connection, it will be deleted automatically when the VDS handle is closed
/// </param>
/// <param name="error">
/// If an error occured, the error code and message will be written to this output parameter
/// </param>
/// <returns>
/// The VDS handle that can be used to get the VolumeDataLayout and the VolumeDataAccessManager
/// </returns>
OPENVDS_EXPORT VDSHandle* Create(IOManager* ioManager, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error);
/// <summary>
/// Close a VDS and free up all associated resources
/// </summary>
/// <param name="handle">
/// The handle to close
/// </param>
OPENVDS_EXPORT void Close(VDSHandle *handle);
OPENVDS_EXPORT VolumeDataLayout *GetLayout(VDSHandle *handle);
OPENVDS_EXPORT VolumeDataAccessManager *GetDataAccessManager(VDSHandle *handle);
......
......@@ -48,8 +48,8 @@ public:
struct VDSHandle
{
VDSHandle(const OpenOptions &openOptions, Error &error)
: ioManager(IOManager::createIOManager(openOptions, error))
VDSHandle(IOManager *ioManager)
: ioManager(ioManager)
{
}
VolumeDataLayoutDescriptor
......
......@@ -79,7 +79,7 @@ main(int argc, char *argv[])
std::string
key = !prefix.empty() ? prefix + "/" + persistentID : persistentID;
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> vds(OpenVDS::Open(OpenVDS::AWSOpenOptions(bucket, key, region), openError), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> vds(OpenVDS::Open(OpenVDS::AWSOpenOptions(bucket, key, region), openError), &OpenVDS::Close);
if(openError.Code != 0)
{
......
......@@ -857,7 +857,7 @@ main(int argc, char *argv[])
std::string
key = !prefix.empty() ? prefix + "/" + persistentID : persistentID;
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> vds(OpenVDS::Create(OpenVDS::AWSOpenOptions(bucket, key, region), layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, createError), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> vds(OpenVDS::Create(OpenVDS::AWSOpenOptions(bucket, key, region), layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, createError), &OpenVDS::Close);
if(createError.Code != 0)
{
......
......@@ -41,7 +41,7 @@ GTEST_TEST(OpenVDS_integration, SimpleVolumeDataPageRead)
}
ASSERT_TRUE(options.Region.size() && options.Bucket.size() && options.Key.size());
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> handle(OpenVDS::Open(options, error), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> handle(OpenVDS::Open(options, error), &OpenVDS::Close);
ASSERT_TRUE(handle);
OpenVDS::VolumeDataAccessManager *dataAccessManager = OpenVDS::GetDataAccessManager(handle.get());
......@@ -92,7 +92,7 @@ GTEST_TEST(OpenVDS_integration, SimpleRequestVolumeSubset)
}
ASSERT_TRUE(options.Region.size() && options.Bucket.size() && options.Key.size());
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> handle(OpenVDS::Open(options, error), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> handle(OpenVDS::Open(options, error), &OpenVDS::Close);
ASSERT_TRUE(handle);
OpenVDS::VolumeDataAccessManager *dataAccessManager = OpenVDS::GetDataAccessManager(handle.get());
......
......@@ -49,7 +49,7 @@ GTEST_TEST(OpenVDS_integration, SimpleRequestVolumeSamples)
}
ASSERT_TRUE(options.Region.size() && options.Bucket.size() && options.Key.size());
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> handle(OpenVDS::Open(options, error), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> handle(OpenVDS::Open(options, error), &OpenVDS::Close);
ASSERT_TRUE(handle);
OpenVDS::VolumeDataAccessManager *dataAccessManager = OpenVDS::GetDataAccessManager(handle.get());
......
......@@ -43,7 +43,7 @@ GTEST_TEST(OpenVDS_integration, SimpleRequestVolumeTraces)
}
ASSERT_TRUE(options.Region.size() && options.Bucket.size() && options.Key.size());
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> handle(OpenVDS::Open(options, error), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> handle(OpenVDS::Open(options, error), &OpenVDS::Close);
ASSERT_TRUE(handle);
OpenVDS::VolumeDataAccessManager *dataAccessManager = OpenVDS::GetDataAccessManager(handle.get());
......
......@@ -37,12 +37,6 @@ namespace OpenVDS
std::vector<uint8_t> writeJson(Json::Value root);
}
struct TestOpenOptions : OpenVDS::OpenOptions
{
TestOpenOptions() : OpenVDS::OpenOptions(OpenVDS::OpenOptions::File) {}
};
GTEST_TEST(VDS_integration, ParseVolumeDataLayoutAndLayerStatus)
{
std::vector<uint8_t>
......@@ -91,7 +85,7 @@ GTEST_TEST(VDS_integration, ParseVolumeDataLayoutAndLayerStatus)
error;
OpenVDS::VDSHandle
handle(TestOpenOptions(), error);
handle(nullptr);
// Clear error
error = OpenVDS::Error();
......
......@@ -36,6 +36,6 @@ GTEST_TEST(OpenVDS_integration, DownloadJson)
}
ASSERT_TRUE(options.Region.size() && options.Bucket.size() && options.Key.size());
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Destroy)> handle(OpenVDS::Open(options, error), &OpenVDS::Destroy);
std::unique_ptr<OpenVDS::VDSHandle, decltype(&OpenVDS::Close)> handle(OpenVDS::Open(options, error), &OpenVDS::Close);
ASSERT_TRUE(handle);
}
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