summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Szyndela <adrian.s@samsung.com>2020-10-27 10:58:05 +0100
committerAdrian Szyndela <adrian.s@samsung.com>2020-10-30 12:16:57 +0100
commit020f8a37aab9f0c0e36c3395c613b26fd35f96b3 (patch)
tree56786191612e4588abdc894e2a19fbc73be189a5
parent47987ac30e2edaf1a1415d56dcb47ab87481a9ec (diff)
downloadlibdbuspolicy-020f8a37aab9f0c0e36c3395c613b26fd35f96b3.tar.gz
libdbuspolicy-020f8a37aab9f0c0e36c3395c613b26fd35f96b3.tar.bz2
libdbuspolicy-020f8a37aab9f0c0e36c3395c613b26fd35f96b3.zip
refactoring: extract common file operations to Serializer
Change-Id: I87e8dd9daa91a35c2748001fba71178d608d2024
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac2
-rw-r--r--src/internal/serializer.cpp47
-rw-r--r--src/internal/serializer.hpp21
-rw-r--r--src/internal/serializer_flatbuffers.cpp20
-rw-r--r--src/internal/serializer_flatbuffers.hpp2
6 files changed, 68 insertions, 25 deletions
diff --git a/Makefile.am b/Makefile.am
index b52237d..0c88727 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -62,6 +62,7 @@ COMMON_SRC =\
src/internal/own_tree.cpp \
src/internal/xml_parser.cpp \
src/internal/tslog.cpp \
+ src/internal/serializer.cpp \
src/internal/serializer_flatbuffers.cpp \
src/internal/print_content.cpp \
src/internal/storage_backend_flatbuffers.cpp \
diff --git a/configure.ac b/configure.ac
index febecd2..9a69a05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,7 +84,7 @@ my_CXXFLAGS="\
-Wall \
-Wextra \
-Werror \
--std=c++11 \
+-std=c++14 \
"
AC_SUBST([my_CXXFLAGS])
diff --git a/src/internal/serializer.cpp b/src/internal/serializer.cpp
new file mode 100644
index 0000000..f965045
--- /dev/null
+++ b/src/internal/serializer.cpp
@@ -0,0 +1,47 @@
+/* MIT License
+ *
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#include "serializer.hpp"
+#include "storage_backend_xml.hpp"
+#include "tslog.hpp"
+#include <iostream>
+
+using namespace ldp_serializer;
+
+const uint8_t *Serializer::serialize(const std::string &config_path, size_t &size) {
+ tslog::init(tslog::ldp_log_level::DEFAULT);
+ ldp_xml::StorageBackendXML xmlStorage;
+
+ if (!xmlStorage.init(config_path.c_str())) {
+ std::cout << "xmlStorage init error" << std::endl;
+ return nullptr;
+ }
+
+ return serialize(xmlStorage, size);
+}
+const uint8_t *Serializer::serialize(const std::string &config_path, std::ostream &output) {
+ size_t size = 0;
+ auto buf = serialize(config_path, size);
+
+ output.write(reinterpret_cast<const char *>(buf), size);
+ return buf;
+}
diff --git a/src/internal/serializer.hpp b/src/internal/serializer.hpp
index dfa9d7a..34c8c9f 100644
--- a/src/internal/serializer.hpp
+++ b/src/internal/serializer.hpp
@@ -22,7 +22,24 @@
* THE SOFTWARE. */
#include "serializer_flatbuffers.hpp"
+#include <iostream>
+#include <string>
+
+namespace ldp_xml {
+class StorageBackendXML;
+};
+
+namespace ldp_serializer
+{
+
+class Serializer {
+ SerializerFlatbuffers impl;
+public:
+ auto serialize(const ldp_xml::StorageBackendXML &db, size_t &size) {
+ return impl.serialize(db, size);
+ }
+ const uint8_t *serialize(const std::string &config_path, size_t &size);
+ const uint8_t *serialize(const std::string &config_path, std::ostream &output);
+};
-namespace ldp_serializer {
-using Serializer = SerializerFlatbuffers;
}
diff --git a/src/internal/serializer_flatbuffers.cpp b/src/internal/serializer_flatbuffers.cpp
index b79558a..dc38275 100644
--- a/src/internal/serializer_flatbuffers.cpp
+++ b/src/internal/serializer_flatbuffers.cpp
@@ -115,26 +115,6 @@ const uint8_t* SerializerFlatbuffers::serialize(const ldp_xml::StorageBackendXML
return buf;
}
-const uint8_t* SerializerFlatbuffers::serialize(const std::string config_path, size_t &size) {
- tslog::init(tslog::ldp_log_level::DEFAULT);
- ldp_xml::StorageBackendXML xmlStorage;
-
- if (!xmlStorage.init(config_path.c_str())) {
- std::cout << "xmlStorage init error" << std::endl;
- return nullptr;
- }
-
- return serialize(xmlStorage, size);
-}
-
-const uint8_t *SerializerFlatbuffers::serialize(const std::string config_path, std::ostream &output) {
- size_t size = 0;
- auto buf = serialize(config_path, size);
-
- output.write(reinterpret_cast<const char *>(buf), size);
- return buf;
-}
-
template <typename T>
auto SerializerFlatbuffers::get_create_set() -> decltype(type_helper<T>::create_set) {
return type_helper<T>::create_set;
diff --git a/src/internal/serializer_flatbuffers.hpp b/src/internal/serializer_flatbuffers.hpp
index 10f0c12..62847fe 100644
--- a/src/internal/serializer_flatbuffers.hpp
+++ b/src/internal/serializer_flatbuffers.hpp
@@ -76,8 +76,6 @@ namespace ldp_serializer
public:
SerializerFlatbuffers() : m_db(nullptr) {}
const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size);
- const uint8_t *serialize(const std::string config_path, size_t &size);
- const uint8_t *serialize(const std::string config_path, std::ostream &output);
friend class SerializerTests;
};
}