summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-08-04 11:25:41 -0500
committerDeepak Kodihalli <dkodihal@in.ibm.com>2017-08-21 23:00:57 -0500
commitf7b0399a47e6bc0b03843a7b49445cf8ec675e94 (patch)
tree2a5460f5188aaa5975f3c24ac4ce50573ee4c095
parentef550b1793f51f10bfa5c079dd0ae7a93dfe84a1 (diff)
downloadphosphor-inventory-manager-f7b0399a47e6bc0b03843a7b49445cf8ec675e94.tar.gz
phosphor-inventory-manager-f7b0399a47e6bc0b03843a7b49445cf8ec675e94.zip
pimgen: generate serialization code
Subsequent commits will introduce serialization of inventory properties. Generate the save()/load() functions required by Cereal. Change-Id: I2ce16d205cad9684711c49c32ddae9f69cd8632d Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r--Makefile.am9
-rw-r--r--gen_serialization.mako.hpp47
-rwxr-xr-xpimgen.py12
-rw-r--r--test/Makefile.am5
4 files changed, 70 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 78418a1..769592d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-BUILT_SOURCES=generated.cpp extra_ifaces.cpp
+BUILT_SOURCES=generated.cpp extra_ifaces.cpp gen_serialization.hpp
CLEANFILES=$(BUILT_SOURCES)
@@ -41,7 +41,12 @@ PIMGEN_ARGS=-i $(IFACES_PATH)
endif
generated.cpp:
- $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py $(PIMGEN_ARGS) -d $(base_yamldir) -o $(builddir) generate-cpp
+ $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py $(PIMGEN_ARGS) -d \
+ $(base_yamldir) -o $(builddir) generate-cpp
+
+gen_serialization.hpp:
+ $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py $(PIMGEN_ARGS) -d \
+ $(base_yamldir) -o $(builddir) generate-serialization
SUBDIRS = . test
diff --git a/gen_serialization.mako.hpp b/gen_serialization.mako.hpp
new file mode 100644
index 0000000..f417917
--- /dev/null
+++ b/gen_serialization.mako.hpp
@@ -0,0 +1,47 @@
+## This file is a template. The comment below is emitted
+## into the rendered file; feel free to edit this file.
+// This file was auto generated. Do not edit.
+
+#include <cereal/types/string.hpp>
+#include <cereal/types/vector.hpp>
+% for iface in interfaces:
+#include <${iface.header()}>
+% endfor
+
+namespace cereal
+{
+
+% for iface in interfaces:
+<% properties = interface_composite.names(str(iface)) %>\
+template<class Archive>
+void save(Archive& a,
+ const ${iface.namespace()}& object)
+{
+<%
+ props = ["object." + p[:1].lower() + p[1:] + "()" for p in properties]
+ props = ', '.join(props)
+%>\
+ a(${props});
+}
+
+
+template<class Archive>
+void load(Archive& a,
+ ${iface.namespace()}& object)
+{
+% for p in properties:
+<% t = "object." + p[:1].lower() + p[1:] + "()" %>\
+ decltype(${t}) ${p}{};
+% endfor
+<%
+ props = ', '.join(properties)
+%>\
+ a(${props});
+% for p in properties:
+<% t = "object." + p[:1].lower() + p[1:] + "(" + p + ")" %>\
+ ${t};
+% endfor
+}
+
+% endfor
+} // namespace cereal
diff --git a/pimgen.py b/pimgen.py
index 4f0a566..73d1868 100755
--- a/pimgen.py
+++ b/pimgen.py
@@ -570,11 +570,23 @@ class Everything(Renderer):
interfaces=self.interfaces,
indent=Indent()))
+ def generate_serialization(self, loader):
+ with open(os.path.join(
+ args.outputdir,
+ 'gen_serialization.hpp'), 'w') as fd:
+ fd.write(
+ self.render(
+ loader,
+ 'gen_serialization.mako.hpp',
+ interfaces=self.interfaces,
+ interface_composite=self.interface_composite))
+
if __name__ == '__main__':
script_dir = os.path.dirname(os.path.realpath(__file__))
valid_commands = {
'generate-cpp': 'generate_cpp',
+ 'generate-serialization': 'generate_serialization',
}
parser = argparse.ArgumentParser(
diff --git a/test/Makefile.am b/test/Makefile.am
index deda4ff..98b521a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,4 +1,4 @@
-BUILT_SOURCES=generated.cpp extra_ifaces.cpp
+BUILT_SOURCES=generated.cpp extra_ifaces.cpp gen_serialization.hpp
CLEANFILES=$(BUILT_SOURCES)
AM_CPPFLAGS = -iquote$(top_srcdir)
@@ -31,4 +31,7 @@ clean-local: clean-extra
generated.cpp:
$(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py -d $(extra_yamldir)/.. -o $(builddir) generate-cpp
+gen_serialization.hpp:
+ $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py -d $(extra_yamldir)/.. -o $(builddir) generate-serialization
+
-include Makefile.extra
OpenPOWER on IntegriCloud