splits objects into separate headers
The binarystore.(c|h)pp now contains BinaryStore, while
binarystore_interface contains BinaryStoreInterface.
The sys_file.hpp contains SysFile, while sys_file_impl.(c|h)pp contains
SysFileImpl.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ic65792a59809e05e186f7710a27ad6bd0e298c94
diff --git a/Makefile.am b/Makefile.am
index 33d8ac5..b1746be 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,7 @@
binaryblob.pb.cc \
binarystore.cpp \
sys.cpp \
- sys_file.cpp \
+ sys_file_impl.cpp \
handler.cpp
libbinarystore_la_LDFLAGS = $(PHOSPHOR_LOGGING_LIBS) \
diff --git a/binarystore.hpp b/binarystore.hpp
index 9f95539..8185a8a 100644
--- a/binarystore.hpp
+++ b/binarystore.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "binarystore_interface.hpp"
#include "sys_file.hpp"
#include <unistd.h>
@@ -22,80 +23,6 @@
{
/**
- * @class BinaryStoreInterface is an abstraction for a storage location.
- * Each instance would be uniquely identified by a baseId string.
- */
-class BinaryStoreInterface
-{
- public:
- virtual ~BinaryStoreInterface() = default;
-
- /**
- * @returns baseId string of the storage.
- */
- virtual std::string getBaseBlobId() const = 0;
-
- /**
- * @returns List of all open blob IDs, plus the base.
- */
- virtual std::vector<std::string> getBlobIds() const = 0;
-
- /**
- * Opens a blob given its name. If there is no one, create one.
- * @param blobId: The blob id to operate on.
- * @param flags: Either read flag or r/w flag has to be specified.
- * @returns True if open/create successfully.
- */
- virtual bool openOrCreateBlob(const std::string& blobId,
- uint16_t flags) = 0;
-
- /**
- * Deletes a blob given its name. If there is no one,
- * @param blobId: The blob id to operate on.
- * @returns True if deleted.
- */
- virtual bool deleteBlob(const std::string& blobId) = 0;
-
- /**
- * Reads data from the currently opened blob.
- * @param offset: offset into the blob to read
- * @param requestedSize: how many bytes to read
- * @returns Bytes able to read. Returns empty if nothing can be read or
- * if there is no open blob.
- */
- virtual std::vector<uint8_t> read(uint32_t offset,
- uint32_t requestedSize) = 0;
-
- /**
- * Writes data to the currently openend blob.
- * @param offset: offset into the blob to write
- * @param data: bytes to write
- * @returns True if able to write the entire data successfully
- */
- virtual bool write(uint32_t offset, const std::vector<uint8_t>& data) = 0;
-
- /**
- * Commits data to the persistent storage specified during blob init.
- * @returns True if able to write data to sysfile successfully
- */
- virtual bool commit() = 0;
-
- /**
- * Closes blob, which prevents further modifications. Uncommitted data will
- * be lost.
- * @returns True if able to close the blob successfully
- */
- virtual bool close() = 0;
-
- /**
- * Returns blob stat flags.
- * @param meta: output stat flags.
- * @returns True if able to get the stat flags and write to *meta
- */
- virtual bool stat(blobs::BlobMeta* meta) = 0;
-};
-
-/**
* @class BinaryStore instantiates a concrete implementation of
* BinaryStoreInterface. The dependency on file is injected through its
* constructor.
diff --git a/binarystore_interface.hpp b/binarystore_interface.hpp
new file mode 100644
index 0000000..73ce17e
--- /dev/null
+++ b/binarystore_interface.hpp
@@ -0,0 +1,92 @@
+#pragma once
+
+#include <blobs-ipmid/blobs.hpp>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+using std::size_t;
+using std::uint16_t;
+using std::uint32_t;
+using std::uint64_t;
+using std::uint8_t;
+
+namespace binstore
+{
+
+/**
+ * @class BinaryStoreInterface is an abstraction for a storage location.
+ * Each instance would be uniquely identified by a baseId string.
+ */
+class BinaryStoreInterface
+{
+ public:
+ virtual ~BinaryStoreInterface() = default;
+
+ /**
+ * @returns baseId string of the storage.
+ */
+ virtual std::string getBaseBlobId() const = 0;
+
+ /**
+ * @returns List of all open blob IDs, plus the base.
+ */
+ virtual std::vector<std::string> getBlobIds() const = 0;
+
+ /**
+ * Opens a blob given its name. If there is no one, create one.
+ * @param blobId: The blob id to operate on.
+ * @param flags: Either read flag or r/w flag has to be specified.
+ * @returns True if open/create successfully.
+ */
+ virtual bool openOrCreateBlob(const std::string& blobId,
+ uint16_t flags) = 0;
+
+ /**
+ * Deletes a blob given its name. If there is no one,
+ * @param blobId: The blob id to operate on.
+ * @returns True if deleted.
+ */
+ virtual bool deleteBlob(const std::string& blobId) = 0;
+
+ /**
+ * Reads data from the currently opened blob.
+ * @param offset: offset into the blob to read
+ * @param requestedSize: how many bytes to read
+ * @returns Bytes able to read. Returns empty if nothing can be read or
+ * if there is no open blob.
+ */
+ virtual std::vector<uint8_t> read(uint32_t offset,
+ uint32_t requestedSize) = 0;
+
+ /**
+ * Writes data to the currently openend blob.
+ * @param offset: offset into the blob to write
+ * @param data: bytes to write
+ * @returns True if able to write the entire data successfully
+ */
+ virtual bool write(uint32_t offset, const std::vector<uint8_t>& data) = 0;
+
+ /**
+ * Commits data to the persistent storage specified during blob init.
+ * @returns True if able to write data to sysfile successfully
+ */
+ virtual bool commit() = 0;
+
+ /**
+ * Closes blob, which prevents further modifications. Uncommitted data will
+ * be lost.
+ * @returns True if able to close the blob successfully
+ */
+ virtual bool close() = 0;
+
+ /**
+ * Returns blob stat flags.
+ * @param meta: output stat flags.
+ * @returns True if able to get the stat flags and write to *meta
+ */
+ virtual bool stat(blobs::BlobMeta* meta) = 0;
+};
+
+} // namespace binstore
diff --git a/binarystore_mock.hpp b/binarystore_mock.hpp
index 9fa83e6..34f14b8 100644
--- a/binarystore_mock.hpp
+++ b/binarystore_mock.hpp
@@ -1,8 +1,13 @@
#pragma once
#include "binarystore.hpp"
+#include "binarystore_interface.hpp"
#include "sys_file.hpp"
+#include <memory>
+#include <string>
+#include <vector>
+
#include <gmock/gmock.h>
using ::testing::Invoke;
diff --git a/main.cpp b/main.cpp
index b5964b8..ac12fb9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,6 @@
#include "handler.hpp"
#include "parse_config.hpp"
-#include "sys_file.hpp"
+#include "sys_file_impl.hpp"
#include <blobs-ipmid/blobs.hpp>
#include <exception>
diff --git a/sys_file.hpp b/sys_file.hpp
index 63110d2..a45f881 100644
--- a/sys_file.hpp
+++ b/sys_file.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include "sys.hpp"
-
#include <fcntl.h>
#include <unistd.h>
@@ -60,33 +58,4 @@
virtual void writeStr(const std::string& data, size_t pos) = 0;
};
-class SysFileImpl : public SysFile
-{
- public:
- /**
- * @brief Constructs sysFile specified by path and offset
- * @param path The file path
- * @param offset The byte offset relatively. Reading a sysfile at position 0
- * actually reads underlying file at 'offset'
- * @param sys Syscall operation interface
- */
- explicit SysFileImpl(const std::string& path, size_t offset = 0,
- const internal::Sys* sys = &internal::sys_impl);
- ~SysFileImpl();
- SysFileImpl() = delete;
- SysFileImpl(const SysFileImpl&) = delete;
- SysFileImpl& operator=(SysFileImpl) = delete;
-
- size_t readToBuf(size_t pos, size_t count, char* buf) const override;
- std::string readAsStr(size_t pos, size_t count) const override;
- std::string readRemainingAsStr(size_t pos) const override;
- void writeStr(const std::string& data, size_t pos) override;
-
- private:
- int fd_;
- size_t offset_;
- void lseek(size_t pos) const;
- const internal::Sys* sys;
-};
-
} // namespace binstore
diff --git a/sys_file.cpp b/sys_file_impl.cpp
similarity index 98%
rename from sys_file.cpp
rename to sys_file_impl.cpp
index 92d6c85..243d82d 100644
--- a/sys_file.cpp
+++ b/sys_file_impl.cpp
@@ -1,4 +1,4 @@
-#include "sys_file.hpp"
+#include "sys_file_impl.hpp"
#include <system_error>
diff --git a/sys_file_impl.hpp b/sys_file_impl.hpp
new file mode 100644
index 0000000..c74c965
--- /dev/null
+++ b/sys_file_impl.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "sys.hpp"
+#include "sys_file.hpp"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <string>
+
+namespace binstore
+{
+
+class SysFileImpl : public SysFile
+{
+ public:
+ /**
+ * @brief Constructs sysFile specified by path and offset
+ * @param path The file path
+ * @param offset The byte offset relatively. Reading a sysfile at position 0
+ * actually reads underlying file at 'offset'
+ * @param sys Syscall operation interface
+ */
+ explicit SysFileImpl(const std::string& path, size_t offset = 0,
+ const internal::Sys* sys = &internal::sys_impl);
+ ~SysFileImpl();
+ SysFileImpl() = delete;
+ SysFileImpl(const SysFileImpl&) = delete;
+ SysFileImpl& operator=(SysFileImpl) = delete;
+
+ size_t readToBuf(size_t pos, size_t count, char* buf) const override;
+ std::string readAsStr(size_t pos, size_t count) const override;
+ std::string readRemainingAsStr(size_t pos) const override;
+ void writeStr(const std::string& data, size_t pos) override;
+
+ private:
+ int fd_;
+ size_t offset_;
+ void lseek(size_t pos) const;
+ const internal::Sys* sys;
+};
+
+} // namespace binstore
diff --git a/test/Makefile.am b/test/Makefile.am
index 08ef779..742e7e2 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,13 +25,13 @@
parse_config_unittest_SOURCES = parse_config_unittest.cpp
sys_file_unittest_SOURCES = sys_file_unittest.cpp
-sys_file_unittest_LDADD = $(top_builddir)/sys_file.o
+sys_file_unittest_LDADD = $(top_builddir)/sys_file_impl.o
handler_unittest_SOURCES = handler_unittest.cpp
handler_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
$(top_builddir)/handler.o \
$(top_builddir)/binarystore.o \
- $(top_builddir)/sys_file.o \
+ $(top_builddir)/sys_file_impl.o \
$(top_builddir)/libbinarystore_la-binaryblob.pb.o \
-lprotobuf
handler_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
@@ -40,7 +40,7 @@
handler_commit_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
$(top_builddir)/handler.o \
$(top_builddir)/binarystore.o \
- $(top_builddir)/sys_file.o \
+ $(top_builddir)/sys_file_impl.o \
$(top_builddir)/libbinarystore_la-binaryblob.pb.o \
-lprotobuf
handler_commit_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
@@ -49,7 +49,7 @@
handler_stat_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
$(top_builddir)/handler.o \
$(top_builddir)/binarystore.o \
- $(top_builddir)/sys_file.o \
+ $(top_builddir)/sys_file_impl.o \
$(top_builddir)/libbinarystore_la-binaryblob.pb.o \
-lprotobuf
handler_stat_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
@@ -58,7 +58,7 @@
handler_open_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
$(top_builddir)/handler.o \
$(top_builddir)/binarystore.o \
- $(top_builddir)/sys_file.o \
+ $(top_builddir)/sys_file_impl.o \
$(top_builddir)/libbinarystore_la-binaryblob.pb.o \
-lprotobuf
handler_open_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
@@ -67,7 +67,7 @@
handler_readwrite_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
$(top_builddir)/handler.o \
$(top_builddir)/binarystore.o \
- $(top_builddir)/sys_file.o \
+ $(top_builddir)/sys_file_impl.o \
$(top_builddir)/libbinarystore_la-binaryblob.pb.o \
-lprotobuf
handler_readwrite_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
diff --git a/test/sys_file_unittest.cpp b/test/sys_file_unittest.cpp
index f4035cf..f66cefd 100644
--- a/test/sys_file_unittest.cpp
+++ b/test/sys_file_unittest.cpp
@@ -1,4 +1,4 @@
-#include "sys_file.hpp"
+#include "sys_file_impl.hpp"
#include "sys_mock.hpp"
#include <fcntl.h>