serialization: implement matching 19/200319/7
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 21 Feb 2019 11:00:33 +0000 (12:00 +0100)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Thu, 7 Mar 2019 07:36:48 +0000 (07:36 +0000)
Change-Id: I2d94b5475939e4ccea92def362fe6cc0b1ec98cf

src/internal/storage_backend_serialized.cpp

index 3a6b207..96b4532 100644 (file)
@@ -20,6 +20,9 @@ using namespace FB;
 
 namespace ldp_serialized {
 
+template <typename T>
+struct type_helper;
+
 class StorageBackendSerialized::StorageBackendSerializedImpl {
        int fd{-1};
        uint8_t *mem{nullptr};
@@ -31,8 +34,8 @@ public:
 
        void printContent() const;
 
-       template <typename T>
-       T *getPolicySet();
+       template <typename T, typename M = typename type_helper<T>::policy_set_type>
+       const M *getPolicySet();
 };
 
 void StorageBackendSerialized::StorageBackendSerializedImpl::release() {
@@ -79,6 +82,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi
                close(fd);
                return;
        }
+// TODO: decide - do we need verification?
 // for verification:
 //
 //     if (!VerifyFileBuffer(Verifier(mem, length)))
@@ -92,18 +96,16 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::printContent() cons
 }
 
 /*************************************************/
-template <typename T>
-struct type_helper;
 
 #define TYPE_HELPER(T, t) \
        template <> \
-       struct type_helper<const ldp_xml_parser::MatchItem##T> { \
+       struct type_helper<ldp_xml_parser::MatchItem##T> { \
                typedef FB::T##Set policy_set_type; \
                typedef FB::Policy##T policy_type; \
        }; \
        template <> \
-       auto StorageBackendSerialized::StorageBackendSerializedImpl::getPolicySet() \
-               -> const typename type_helper<const ldp_xml_parser::MatchItem##T>::policy_set_type * { \
+       auto StorageBackendSerialized::StorageBackendSerializedImpl::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(); \
        }
@@ -126,9 +128,13 @@ void StorageBackendSerialized::printContent() const {
 }
 
 template <typename T, typename I>
-bool match(const T &t, const I *i) {
-       // TODO!!!!
-       return true;
+bool match(const T &match, const I *i) {
+       return match.match(makeMessageType(i->type()), i->interface()->c_str(), i->path()->c_str(),
+                       i->member()->c_str(), i->name()->c_str(), i->is_name_prefix());
+}
+
+template <> bool match(const ldp_xml_parser::MatchItemAccess &match, const FB::ItemAccess *item) {
+       return match.match(makeBusAccessType(item->type()), item->uid(), item->gid());
 }
 
 template <typename T, typename P = typename type_helper<T>::policy_type>
@@ -183,10 +189,10 @@ template <> ldp_xml_parser::DecisionItem getDecisionItem(const ldp_xml_parser::M
 }
 
 template <typename T, typename P = typename type_helper<T>::policy_type>
-ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *policy) {
-       if (nullptr == policy)
+ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *policyPair) {
+       if (nullptr == policyPair)
                return ldp_xml_parser::Decision::ANY;
-       return getDecisionItem(item, policy);
+       return getDecisionItem(item, policyPair->policy());
 }
 
 template <typename T>
@@ -210,23 +216,24 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_
 }
 
 #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 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;
 
 T_INSTANTIATION(Own)
 T_INSTANTIATION(Send)
 T_INSTANTIATION(Receive)
 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 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;
 
 T_INSTANTIATION2(Own)
 T_INSTANTIATION2(Send)
 T_INSTANTIATION2(Receive)
 
-#undef T_INSTANTIATION
 #undef T_INSTANTIATION2
 
 StorageBackendSerialized::StorageBackendSerialized()