refactoring: rename StorageBackendSerialized to StorageBackendFlatbuffers 82/246282/1
authorAdrian Szyndela <adrian.s@samsung.com>
Tue, 27 Oct 2020 09:18:52 +0000 (10:18 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Tue, 27 Oct 2020 15:26:22 +0000 (16:26 +0100)
Change-Id: I1d6a8e089b31730e7a8e2f54ea0a3b2fe8548401

Makefile.am
src/internal/storage_backend_flatbuffers.cpp [moved from src/internal/storage_backend_serialized.cpp with 78% similarity]
src/internal/storage_backend_flatbuffers.hpp [new file with mode: 0644]
src/internal/storage_backend_serialized.hpp

index 3388f17..b52237d 100644 (file)
@@ -64,7 +64,7 @@ COMMON_SRC =\
        src/internal/tslog.cpp \
        src/internal/serializer_flatbuffers.cpp \
        src/internal/print_content.cpp \
-       src/internal/storage_backend_serialized.cpp \
+       src/internal/storage_backend_flatbuffers.cpp \
        src/internal/storage_backend_xml.cpp
 
 src_libdbuspolicy1_la_SOURCES =\
similarity index 78%
rename from src/internal/storage_backend_serialized.cpp
rename to src/internal/storage_backend_flatbuffers.cpp
index a099a1e..b0c6933 100644 (file)
@@ -17,7 +17,7 @@
 #include "print_content.hpp"
 #include "serialized_convert.hpp"
 #include "serializer.hpp"
-#include "storage_backend_serialized.hpp"
+#include "storage_backend_flatbuffers.hpp"
 #include "transaction_guard.hpp"
 #include "tslog.hpp"
 #include <boost/tokenizer.hpp>
@@ -123,7 +123,7 @@ ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *po
 
 } // anonymous namespace
 
-class StorageBackendSerialized::StorageBackendSerializedImpl {
+class StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl {
        int fd{-1};
        uint8_t *mem{static_cast<decltype(mem)>(MAP_FAILED)};
        size_t length{0};
@@ -148,7 +148,7 @@ public:
        const M *getPolicySet();
 };
 
-ldp_xml_parser::DecisionItem StorageBackendSerialized::StorageBackendSerializedImpl::getDecisionFromSendIndex(const MatchItemSend &item,
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::getDecisionFromSendIndex(const MatchItemSend &item,
                const FB::PolicySend *policy) {
 
        const auto *index = policy->index();
@@ -217,7 +217,7 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::StorageBackendSerializedI
        return ldp_xml_parser::DecisionItem(ldp_xml_parser::Decision::ANY);
 }
 
-void StorageBackendSerialized::StorageBackendSerializedImpl::releaseMMap() {
+void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::releaseMMap() {
        assert(MAP_FAILED != mem);
        assert(0 != length);
 
@@ -228,7 +228,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::releaseMMap() {
        length = 0;
 }
 
-void StorageBackendSerialized::StorageBackendSerializedImpl::releaseFD() {
+void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::releaseFD() {
        assert(-1 != fd);
 
        if (close(fd) != 0)
@@ -237,7 +237,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::releaseFD() {
        fd = -1;
 }
 
-void StorageBackendSerialized::StorageBackendSerializedImpl::release() {
+void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::release() {
        if (-1 != fd) {         // we need to check it, because we may have initialized the storage directly from File *
                releaseMMap();
                releaseFD();
@@ -250,7 +250,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::release() {
        file = nullptr;
 }
 
-bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *filename, bool verify) {
+bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::init(const char *filename, bool verify) {
        assert(nullptr == file);
 
        auto err = [filename] (const char *what) {
@@ -290,7 +290,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi
        return true;
 }
 
-bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const uint8_t *mem, size_t size, bool verify) {
+bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::initFromData(const uint8_t *mem, size_t size, bool verify) {
        assert(nullptr == file);
 
        if (verify) {
@@ -314,7 +314,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const
        return file != nullptr;
 }
 
-bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const char *config_name) {
+bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::initFromXML(const char *config_name) {
        assert(nullptr == file);
        assert(nullptr == serializer.get());
 
@@ -328,7 +328,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const c
        return initFromData(data, serialized_size, false);
 }
 
-void StorageBackendSerialized::StorageBackendSerializedImpl::printContent(const bool xml_format) const {
+void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::printContent(const bool xml_format) const {
        print_content::use_xml_format(xml_format);
        std::cerr << *file;
 }
@@ -342,7 +342,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::printContent(const
                typedef FB::Policy##T policy_type; \
        }; \
        template <> \
-       auto StorageBackendSerialized::StorageBackendSerializedImpl::getPolicySet<ldp_xml_parser::MatchItem##T>() \
+       auto StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::getPolicySet<ldp_xml_parser::MatchItem##T>() \
                -> const typename type_helper<ldp_xml_parser::MatchItem##T>::policy_set_type * { \
                assert(file); \
                return file->m_##t##_set(); \
@@ -353,43 +353,43 @@ TYPE_HELPER(Send, send)
 TYPE_HELPER(Receive, receive)
 TYPE_HELPER(Access, access)
 
-bool StorageBackendSerialized::init(const char *filename, bool verify) {
+bool StorageBackendFlatbuffers::init(const char *filename, bool verify) {
        return pimpl->init(filename, verify);
 }
 
-bool StorageBackendSerialized::initFromData(const uint8_t *serialized_data, size_t length, bool verify) {
+bool StorageBackendFlatbuffers::initFromData(const uint8_t *serialized_data, size_t length, bool verify) {
        return pimpl->initFromData(serialized_data, length, verify);
 }
 
-bool StorageBackendSerialized::initFromXML(const char *config_name) {
+bool StorageBackendFlatbuffers::initFromXML(const char *config_name) {
        return pimpl->initFromXML(config_name);
 }
 
-void StorageBackendSerialized::release() {
+void StorageBackendFlatbuffers::release() {
        pimpl->release();
 }
 
-void StorageBackendSerialized::printContent(const bool xml_format) const {
+void StorageBackendFlatbuffers::printContent(const bool xml_format) const {
        pimpl->printContent(xml_format);
 }
 
 template <typename T>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const T &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const T &item) const {
        return getDecisionItem(item, pimpl->getPolicySet<T>()->context_mandatory());
 }
 
 template <>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const MatchItemSend &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const MatchItemSend &item) const {
        return pimpl->getDecisionFromSendIndex(item, pimpl->getPolicySet<MatchItemSend>()->context_mandatory());
 }
 
 template <>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const MatchItemSend &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const MatchItemSend &item) const {
        return pimpl->getDecisionFromSendIndex(item, pimpl->getPolicySet<MatchItemSend>()->context_default());
 }
 
 template <>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const MatchItemSend &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const MatchItemSend &item) const {
        auto *policyPair = pimpl->getPolicySet<MatchItemSend>()->user()->LookupByKey(uid);
        if (nullptr == policyPair)
                return ldp_xml_parser::Decision::ANY;
@@ -397,28 +397,28 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t
 }
 
 template <typename T>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const T &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const T &item) const {
        return getDecisionItem(item, pimpl->getPolicySet<T>()->context_default());
 }
 
 template <typename T>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const T &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const T &item) const {
        return getDecisionItemMaybeNull(item, pimpl->getPolicySet<T>()->user()->LookupByKey(uid));
 }
 
 template <typename T>
-ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_t gid, const T &item) const {
+ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemGroup(gid_t gid, const T &item) const {
        return getDecisionItemMaybeNull(item, pimpl->getPolicySet<T>()->group()->LookupByKey(gid));
 }
 
 template <typename T>
-bool StorageBackendSerialized::existsPolicyForGroup(gid_t gid) const {
+bool StorageBackendFlatbuffers::existsPolicyForGroup(gid_t gid) const {
        return pimpl->getPolicySet<T>()->group()->LookupByKey(gid) != nullptr;
 }
 
 #define T_INSTANTIATION(T) \
-       template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const ldp_xml_parser::MatchItem##T &item) const; \
-       template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const ldp_xml_parser::MatchItem##T &item) const;
+       template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const ldp_xml_parser::MatchItem##T &item) const; \
+       template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const ldp_xml_parser::MatchItem##T &item) const;
 
 T_INSTANTIATION(Own)
 T_INSTANTIATION(Send)
@@ -428,9 +428,9 @@ T_INSTANTIATION(Access)
 #undef T_INSTANTIATION
 
 #define T_INSTANTIATION2(T) \
-       template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const ldp_xml_parser::MatchItem##T &item) const; \
-       template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_t gid, const ldp_xml_parser::MatchItem##T &item) const; \
-       template bool StorageBackendSerialized::existsPolicyForGroup<ldp_xml_parser::MatchItem##T>(gid_t) const;
+       template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const ldp_xml_parser::MatchItem##T &item) const; \
+       template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemGroup(gid_t gid, const ldp_xml_parser::MatchItem##T &item) const; \
+       template bool StorageBackendFlatbuffers::existsPolicyForGroup<ldp_xml_parser::MatchItem##T>(gid_t) const;
 
 T_INSTANTIATION2(Own)
 T_INSTANTIATION2(Send)
@@ -438,11 +438,11 @@ T_INSTANTIATION2(Receive)
 
 #undef T_INSTANTIATION2
 
-StorageBackendSerialized::StorageBackendSerialized()
-       : pimpl{new StorageBackendSerializedImpl} {
+StorageBackendFlatbuffers::StorageBackendFlatbuffers()
+       : pimpl{new StorageBackendFlatbuffersImpl} {
 }
 
-StorageBackendSerialized::~StorageBackendSerialized() {
+StorageBackendFlatbuffers::~StorageBackendFlatbuffers() {
        pimpl->release();
 }
 
diff --git a/src/internal/storage_backend_flatbuffers.hpp b/src/internal/storage_backend_flatbuffers.hpp
new file mode 100644 (file)
index 0000000..aaba006
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+#pragma once
+
+#include "policy.hpp"
+
+#include <memory>
+
+namespace ldp_serialized {
+
+class StorageBackendFlatbuffers {
+       class StorageBackendFlatbuffersImpl;
+       std::unique_ptr<StorageBackendFlatbuffersImpl> pimpl;
+public:
+       StorageBackendFlatbuffers();
+       ~StorageBackendFlatbuffers();
+
+       bool init(const char *filename, bool verify = false);
+       bool initFromData(const uint8_t *serialized_data, size_t length, bool verify = false);
+       bool initFromXML(const char *config_name);
+       void release();
+
+       void printContent(const bool xml_format = false) const;
+
+       // Supported template parameters are:
+       // MatchPolicyOwn, MatchPolicySend, MatchPolicyReceive
+       // and - only for Contexts - MatchPolicyAccess
+       template <typename T>
+       ldp_xml_parser::DecisionItem getDecisionItemContextMandatory(const T &item) const;
+       template <typename T>
+       ldp_xml_parser::DecisionItem getDecisionItemContextDefault(const T &item) const;
+       template <typename T>
+       ldp_xml_parser::DecisionItem getDecisionItemUser(uid_t uid, const T &item) const;
+       template <typename T>
+       ldp_xml_parser::DecisionItem getDecisionItemGroup(gid_t gid, const T &item) const;
+
+       // This works with T set to MatchItemOwn, MatchItemSend or MatchItemReceive
+       // This is needed for filtering mapGroups. Check NaivePolicyChecker.
+       template <typename T>
+       bool existsPolicyForGroup(gid_t gid) const;
+
+};
+
+}
index 4781b87..7755dd3 100644 (file)
@@ -1,57 +1,7 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
 #pragma once
 
-#include "policy.hpp"
-
-#include <memory>
+#include "storage_backend_flatbuffers.hpp"
 
 namespace ldp_serialized {
-
-class StorageBackendSerialized {
-       class StorageBackendSerializedImpl;
-       std::unique_ptr<StorageBackendSerializedImpl> pimpl;
-public:
-       StorageBackendSerialized();
-       ~StorageBackendSerialized();
-
-       bool init(const char *filename, bool verify = false);
-       bool initFromData(const uint8_t *serialized_data, size_t length, bool verify = false);
-       bool initFromXML(const char *config_name);
-       void release();
-
-       void printContent(const bool xml_format = false) const;
-
-       // Supported template parameters are:
-       // MatchPolicyOwn, MatchPolicySend, MatchPolicyReceive
-       // and - only for Contexts - MatchPolicyAccess
-       template <typename T>
-       ldp_xml_parser::DecisionItem getDecisionItemContextMandatory(const T &item) const;
-       template <typename T>
-       ldp_xml_parser::DecisionItem getDecisionItemContextDefault(const T &item) const;
-       template <typename T>
-       ldp_xml_parser::DecisionItem getDecisionItemUser(uid_t uid, const T &item) const;
-       template <typename T>
-       ldp_xml_parser::DecisionItem getDecisionItemGroup(gid_t gid, const T &item) const;
-
-       // This works with T set to MatchItemOwn, MatchItemSend or MatchItemReceive
-       // This is needed for filtering mapGroups. Check NaivePolicyChecker.
-       template <typename T>
-       bool existsPolicyForGroup(gid_t gid) const;
-
-};
-
+using StorageBackendSerialized = StorageBackendFlatbuffers;
 }