SOLA
Loading...
Searching...
No Matches
find_query.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef ALGORITHMS_ESEARCH_FIND_QUERY_H_
8#define ALGORITHMS_ESEARCH_FIND_QUERY_H_
9
10#include <memory>
11
12#include "minhton/algorithms/esearch/boolean_expression.h"
13#include "minhton/algorithms/esearch/distributed_data.h"
14#include "minhton/algorithms/esearch/evaluation_information.h"
15#include "minhton/algorithms/esearch/local_data.h"
16#include "minhton/algorithms/esearch/node_data.h"
17#include "minhton/core/node_info.h"
18#include "solanet/serializer/serialize.h"
19
20namespace minhton {
21class FindQuery {
22public:
23 enum FindQueryScope {
24 kAll,
25 kSome,
26 };
27
28 enum FindQuerySelection {
29 kSelectAll, // every possible attribute -> SELECT * FROM ...
30 kSelectSpecific, // specific list of returns -> SELECT x,y,z FROM ...
31 kSelectUnspecific, // dont care what is being returned, except for NodeInfo
32 };
33
34 FindQuery();
35
36 FindQuery(const std::string &expr_string, const std::string &scope_string);
37
38 std::string serializeBooleanExpression() const;
39 std::string serializeScope() const;
40
41 void deserializeBooleanExpression(const std::string &expr_string);
42 void deserializeScope(const std::string &scope_string);
43
44 FuzzyValue evaluate(NodeData &data, bool all_information_present, const uint64_t &timestamp_now);
45 std::vector<NodeData::Key> evaluateMissingAttributes(NodeData &data,
46 uint64_t const &timestamp_now) const;
47 std::vector<NodeData::Key> getRelevantAttributes() const;
48 std::vector<NodeData::Key> getRelevantTopicAttributes() const;
49
50 FindQueryScope getScope() const;
51 void setScope(const FindQueryScope &scope);
52
53 std::shared_ptr<BooleanExpression> getBooleanExpression() const;
54 void setBooleanExpression(std::shared_ptr<BooleanExpression> expr);
55
56 void setRequestingNode(const NodeInfo &requesting_node);
57 NodeInfo getRequestingNode() const;
58
59 uint64_t getValidityThreshold() const;
60 void setValidityThreshold(const uint64_t &validity_threshold);
61
62 bool getInquireUnknownAttributes() const;
63 void setInquireUnknownAttributes(bool inquire_unknown_attributes);
64
65 bool getInquireOutdatedAttributes() const;
66 void setInquireOutdatedAttributes(bool inquire_outdated_attributes);
67
68 bool getPermissive() const;
69 void setPermissive(bool permissive);
70
71 FindQuerySelection getSelection() const;
72 void setSelection(const FindQuerySelection &selection);
73
74 std::vector<NodeData::Key> getSelectedAttributeKeys() const;
75 void setSelectedAttributeKeys(const std::vector<NodeData::Key> &keys);
76
77 template <class Archive> void save(Archive &archive) const {
78 if (!this->expr_) {
79 throw std::runtime_error("Expression in FindQuery is empty!");
80 }
81 archive(validity_threshold_, serializeBooleanExpression(), scope_, requesting_node_,
82 inquire_unknown_attributes_, inquire_outdated_attributes_, permissive_, selection_,
83 selected_attribute_keys_);
84 }
85
86 template <class Archive> void load(Archive &archive) {
87 std::string expr_string;
88 archive(validity_threshold_, expr_string, scope_, requesting_node_, inquire_unknown_attributes_,
89 inquire_outdated_attributes_, permissive_, selection_, selected_attribute_keys_);
90 deserializeBooleanExpression(expr_string);
91 }
92
93private:
94 EvaluationInformation createEvaluationInformation(bool all_information_present,
95 const uint64_t &timestamp_now) const;
96
97 // LATER change to unique_ptr if possible
98 std::shared_ptr<BooleanExpression> expr_;
99
100 // all, some...
101 FindQueryScope scope_ = FindQuery::FindQueryScope::kAll;
102
104 NodeInfo requesting_node_;
105
107 uint64_t validity_threshold_ = 0; // in ms
108
111 bool inquire_unknown_attributes_;
112
116 bool inquire_outdated_attributes_;
117
118 bool permissive_; // only relevant if inquire_outdated_attributes_=false
119
120 FindQuerySelection selection_;
121
123 std::vector<NodeData::Key> selected_attribute_keys_;
124};
125
126} // namespace minhton
127
128#endif
Definition find_query.h:21
Definition fuzzy_value.h:14
Definition node_data.h:20
Definition node_info.h:24
Definition minhton_watchdog_ns3.cpp:24
Definition evaluation_information.h:12