Add protobuf definitions
Add protobuf definitions for binaryblob store, and change data types
to the generated class.
Signed-off-by: Kun Yi <kunyi@google.com>
Change-Id: I856a000c4a81c10bbbd1983d51712b4999a4e29e
diff --git a/.gitignore b/.gitignore
index dad7ab4..fd23289 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,3 +63,7 @@
*~
.cscope/
build/
+
+# protobuf generated files
+*.pb.h
+*.pb.cc
diff --git a/Makefile.am b/Makefile.am
index 796e385..6d0e426 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,13 +1,30 @@
+PROTOC = protoc
+
+PROTOS_PATH = proto
+vpath %.proto $(PROTOS_PATH)
+
AM_DEFAULT_SOURCE_EXT = .cpp
+SUFFIXES = .proto .pb.cc
libbinarystoredir = ${libdir}/ipmid-providers
libbinarystore_LTLIBRARIES = libbinarystore.la
libbinarystore_la_SOURCES = main.cpp \
handler.cpp \
+ binaryblob.pb.cc \
binarystore.cpp
+
libbinarystore_la_LDFLAGS = $(PHOSPHOR_LOGGING_LIBS) \
- -version-info 0:0:0 -shared
-libbinarystore_la_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS) \
+ -version-info 0:0:0 -shared \
+ -lprotobuf
+
+libbinarystore_la_CXXFLAGS = -I$(srcdir) $(PHOSPHOR_LOGGING_CFLAGS) \
-flto
+binaryblob.pb.h binaryblob.pb.cc: $(srcdir)/$(PROTOS_PATH)/binaryblob.proto
+ $(PROTOC) -I$(srcdir)/$(PROTOS_PATH) --cpp_out=. $<
+
+BUILT_SOURCES = binaryblob.pb.h binaryblob.pb.cc
+
SUBDIRS = . test
+
+ACLOCAL_AMFLAGS = -I m4
diff --git a/binarystore.cpp b/binarystore.cpp
index 10aa449..aa9c0dc 100644
--- a/binarystore.cpp
+++ b/binarystore.cpp
@@ -22,9 +22,9 @@
std::vector<std::string> result;
result.push_back(baseBlobId_);
- for (const auto& blob : blob_.blobs)
+ for (const auto& blob : blob_.blobs())
{
- result.push_back(blob.id);
+ result.push_back(blob.blob_id());
}
return result;
diff --git a/binarystore.hpp b/binarystore.hpp
index a54eaf5..7020cff 100644
--- a/binarystore.hpp
+++ b/binarystore.hpp
@@ -7,6 +7,8 @@
#include <string>
#include <vector>
+#include "binaryblob.pb.h"
+
using std::size_t;
using std::uint16_t;
using std::uint32_t;
@@ -85,19 +87,6 @@
virtual bool stat() = 0;
};
-// TODO: move to protobuf definition
-struct BinaryBlobSingle
-{
- std::string id;
- std::vector<uint8_t> data;
-};
-
-struct BinaryBlob
-{
- std::string baseBlobId;
- std::vector<BinaryBlobSingle> blobs;
-};
-
/**
* @class BinaryStore instantiates a concrete implementation of
* BinaryStoreInterface. The dependency on file is injected through its
@@ -150,7 +139,8 @@
int fd_;
uint32_t offset_;
uint32_t maxSize_;
- BinaryBlob blob_;
+ binaryblobproto::BinaryBlobBase blob_;
+ binaryblobproto::BinaryBlob* currentBlob_;
};
} // namespace binstore
diff --git a/configure.ac b/configure.ac
index c856762..f41f662 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,7 @@
LT_INIT # Required for systemd linking
# Checks for libraries.
+PKG_CHECK_MODULES([PROTOBUF], [protobuf], [], [AC_MSG_ERROR(["protobuf required and not found"])])
PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],, [AC_MSG_ERROR([Could not find phosphor-logging...openbmc/phosphor-logging package required])])
AC_CHECK_HEADER([blobs-ipmid], [AC_MSG_ERROR(["phosphor-ipmi-blobs required and not found."])])
diff --git a/proto/binaryblob.proto b/proto/binaryblob.proto
new file mode 100644
index 0000000..ceb7735
--- /dev/null
+++ b/proto/binaryblob.proto
@@ -0,0 +1,15 @@
+syntax = "proto2";
+
+package binstore.binaryblobproto;
+
+message BinaryBlob {
+ optional string blob_id = 1; // A valid, unique unix path as identifier
+ optional bytes data = 2;
+}
+
+/* BinaryBlobBase is analogous to a directory of BinaryBlobs. */
+message BinaryBlobBase {
+ optional string blob_base_id = 1; // Common parent path of contained blobs
+ repeated BinaryBlob blobs = 2;
+ optional uint32 max_size_bytes = 3;
+}
diff --git a/test/Makefile.am b/test/Makefile.am
index 59325f2..9f41737 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,4 +1,5 @@
AM_CPPFLAGS = -I$(top_srcdir)/ \
+ -I$(builddir)
$(GTEST_CFLAGS) \
$(GMOCK_CFLAGS)
AM_CXXFLAGS = \
@@ -17,15 +18,24 @@
handler_unittest_SOURCES = handler_unittest.cpp
handler_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
- $(top_builddir)/handler.o $(top_builddir)/binarystore.o
+ $(top_builddir)/handler.o \
+ $(top_builddir)/binarystore.o \
+ $(top_builddir)/libbinarystore_la-binaryblob.pb.o \
+ -lprotobuf
handler_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
handler_open_unittest_SOURCES = handler_open_unittest.cpp
handler_open_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
- $(top_builddir)/handler.o $(top_builddir)/binarystore.o
+ $(top_builddir)/handler.o \
+ $(top_builddir)/binarystore.o \
+ $(top_builddir)/libbinarystore_la-binaryblob.pb.o \
+ -lprotobuf
handler_open_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
handler_readwrite_unittest_SOURCES = handler_readwrite_unittest.cpp
handler_readwrite_unittest_LDADD = $(PHOSPHOR_LOGGING_LIBS) \
- $(top_builddir)/handler.o $(top_builddir)/binarystore.o
+ $(top_builddir)/handler.o \
+ $(top_builddir)/binarystore.o \
+ $(top_builddir)/libbinarystore_la-binaryblob.pb.o \
+ -lprotobuf
handler_readwrite_unittest_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
diff --git a/test/handler_unittest.hpp b/test/handler_unittest.hpp
index c35c749..ded13eb 100644
--- a/test/handler_unittest.hpp
+++ b/test/handler_unittest.hpp
@@ -6,6 +6,8 @@
#include <memory>
#include <string>
+#include "binaryblob.pb.h"
+
#include <gtest/gtest.h>
using ::testing::Contains;