serialization: add SerializationBackend type 86/246286/3
authorAdrian Szyndela <adrian.s@samsung.com>
Tue, 27 Oct 2020 11:32:03 +0000 (12:32 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 30 Oct 2020 11:17:42 +0000 (12:17 +0100)
Add SerializationBackend type, which is a customization point
for choosing serialization backend. At the moment it is set
to Flatbuffers. It is the place to select another backend, when it shows up.

Change-Id: I2a54f643d5c5bda065fcd193c51ca928f20df203

src/internal/serialization_backend.hpp [new file with mode: 0644]
src/internal/serializer.hpp
src/internal/storage_backend_serialized.hpp

diff --git a/src/internal/serialization_backend.hpp b/src/internal/serialization_backend.hpp
new file mode 100644 (file)
index 0000000..2b3395a
--- /dev/null
@@ -0,0 +1,37 @@
+#pragma once
+
+/*  MIT License
+ *
+ * Copyright (c) 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_flatbuffers.hpp"
+#include "storage_backend_flatbuffers.hpp"
+
+namespace ldp_serialization {
+
+struct SerializationBackendFlatbuffers {
+       typedef ldp_serialized::StorageBackendFlatbuffers Storage;
+       typedef ldp_serializer::SerializerFlatbuffers Serializer;
+};
+
+typedef SerializationBackendFlatbuffers SerializationBackend;
+
+}
index 34c8c9f..e087017 100644 (file)
@@ -21,7 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
-#include "serializer_flatbuffers.hpp"
+#include "serialization_backend.hpp"
 #include <iostream>
 #include <string>
 
@@ -33,7 +33,7 @@ namespace ldp_serializer
 {
 
 class Serializer {
-       SerializerFlatbuffers impl;
+       ldp_serialization::SerializationBackend::Serializer impl;
 public:
        auto serialize(const ldp_xml::StorageBackendXML &db, size_t &size) {
                return impl.serialize(db, size);
index dc3a861..9a498b5 100644 (file)
@@ -22,7 +22,7 @@
  * THE SOFTWARE. */
 
 #include "policy.hpp"
-#include "storage_backend_flatbuffers.hpp"
+#include "serialization_backend.hpp"
 #include "serializer.hpp"
 #include <memory>
 #include <sys/types.h>
@@ -66,7 +66,7 @@ public:
        { return impl.existsPolicyForGroup<MatchItem>(gid); }
 
 private:
-       typedef StorageBackendFlatbuffers Backend;
+       typedef typename ldp_serialization::SerializationBackend::Storage Backend;
        Backend impl;
 
        // Set max size of serialized file to prevent mmap with unexpected memory size.