std::cout << "Destination too long: " << destination << std::endl;
return false;
}
- return static_cast<int>(policy_checker.check(bus_type, user, group, label, matcher, ldp_xml_parser::ItemType::SEND));
+ return static_cast<int>(policy_checker().check(bus_type, user, group, label, matcher, ldp_xml_parser::ItemType::SEND));
}
int __internal_can_send_multi_dest(bool bus_type,
while (destination[i]) {
matcher.addName(destination[i++]);
}
- return static_cast<int>(policy_checker.check(bus_type, user, group, label, matcher, ldp_xml_parser::ItemType::SEND));
+ return static_cast<int>(policy_checker().check(bus_type, user, group, label, matcher, ldp_xml_parser::ItemType::SEND));
}
int __internal_can_recv(bool bus_type,
std::cout << "Sender too long: " << sender << std::endl;
return false;
}
- return static_cast<int>(policy_checker.check(bus_type, user, group, label, matcher, ldp_xml_parser::ItemType::RECEIVE));
+ return static_cast<int>(policy_checker().check(bus_type, user, group, label, matcher, ldp_xml_parser::ItemType::RECEIVE));
}
int __internal_can_own(bool bus_type,
const char* const label,
const char* const service)
{
- return static_cast<int>(policy_checker.check(bus_type, user, group, label, service));
+ return static_cast<int>(policy_checker().check(bus_type, user, group, label, service));
}
using namespace ldp_xml_parser;
-ldp_xml_parser::NaivePolicyChecker policy_checker;
+DEF_NODESTRUCT_GLOBAL(ldp_xml_parser::NaivePolicyChecker, policy_checker)
static void __log_item(const MatchItemSR& item)
{
};
}
-extern ldp_xml_parser::NaivePolicyChecker policy_checker;
+/** Declare a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
+#define DCL_NODESTRUCT_GLOBAL(TYPE,NAME)\
+ namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) extern uint8_t NAME[sizeof(TYPE)]; }\
+ /* awkwardly written to silence gcc's -Wstrict-aliasing because _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") is bugged */\
+ static inline TYPE &NAME() { auto p = static_cast<void*>(&detail_NODESTRUCT_GLOBAL::NAME[0]); return *reinterpret_cast<TYPE*>(p); }\
+ namespace detailInit_NODESTRUCT_GLOBAL { __attribute__((constructor)) static void NAME() { new(&::NAME()) TYPE(); } }
+
+/** Define a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
+#define DEF_NODESTRUCT_GLOBAL(TYPE,NAME)\
+ namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) uint8_t NAME[sizeof(TYPE)]; }
+
+
+DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::NaivePolicyChecker, policy_checker)
#endif
-NaivePolicyDb::~NaivePolicyDb() {
-}
-
NaivePolicyDb::PolicyOwn::PolicyOwn(){
treeRootPtr = new struct TreeNode;
treeRootPtr->__decisionItem = {Decision::ANY, NULL};
}
}
-NaivePolicyDb::PolicyOwn::~PolicyOwn(){
- nodeRemove(&treeRootPtr);
-}
-
void NaivePolicyDb::PolicyOwn::nodeRemove(TreeNode **node){
if (!*node) {
return;
void nodeRemove(TreeNode **node);
public:
PolicyOwn();
- ~PolicyOwn();
/** Adds given item to tree by retrieving its name, decision and checking is it prefix.
* \param[in] item Item to add to policy
*/
const TreeNode* getTreeRoot() const;
};
- ~NaivePolicyDb();
-
/** Gets policy with ownership rules from DB
* \param[in] policy_type Policy type
* \param[in] policy_type_value Policy type value
xmlTraversal(bus, v.second, t, policy_type, policy_type_value, attr, level + 1);
}
if (!pt.empty() && level > 1)
- __builder.generateItem(policy_checker.db(bus), policy_type, policy_type_value);
+ __builder.generateItem(policy_checker().db(bus), policy_type, policy_type_value);
}
}
: names_num(0), interface(i), member(me), path(p), type(t), direction(d) {
}
-MatchItemSR::~MatchItemSR(){
-}
-
void MatchItemSR::addName(const char* name) {
names[names_num++] = NameSR(name, std::strlen(name));
}
MessageType type;
MessageDirection direction;
MatchItemSR(const char* i = NULL, const char* me = NULL, const char* p = NULL, MessageType t = MessageType::ANY, MessageDirection d = MessageDirection::ANY);
- ~MatchItemSR();
void addName(const char* name);
bool addNames(const char* name);
const char* toString(char* str) const;