]> granicus.if.org Git - icinga2/blob - lib/livestatus/table.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / livestatus / table.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef TABLE_H
4 #define TABLE_H
5
6 #include "livestatus/column.hpp"
7 #include "base/object.hpp"
8 #include "base/dictionary.hpp"
9 #include "base/array.hpp"
10 #include <vector>
11
12 namespace icinga
13 {
14
15 struct LivestatusRowValue {
16         Value Row;
17         LivestatusGroupByType GroupByType;
18         Value GroupByObject;
19 };
20
21 typedef std::function<bool (const Value&, LivestatusGroupByType, const Object::Ptr&)> AddRowFunction;
22
23 class Filter;
24
25 /**
26  * @ingroup livestatus
27  */
28 class Table : public Object
29 {
30 public:
31         DECLARE_PTR_TYPEDEFS(Table);
32
33         static Table::Ptr GetByName(const String& name, const String& compat_log_path = "", const unsigned long& from = 0, const unsigned long& until = 0);
34
35         virtual String GetName() const = 0;
36         virtual String GetPrefix() const = 0;
37
38         std::vector<LivestatusRowValue> FilterRows(const intrusive_ptr<Filter>& filter, int limit = -1);
39
40         void AddColumn(const String& name, const Column& column);
41         Column GetColumn(const String& name) const;
42         std::vector<String> GetColumnNames() const;
43
44         LivestatusGroupByType GetGroupByType() const;
45
46 protected:
47         Table(LivestatusGroupByType type = LivestatusGroupByNone);
48
49         virtual void FetchRows(const AddRowFunction& addRowFn) = 0;
50
51         static Value ZeroAccessor(const Value&);
52         static Value OneAccessor(const Value&);
53         static Value EmptyStringAccessor(const Value&);
54         static Value EmptyArrayAccessor(const Value&);
55         static Value EmptyDictionaryAccessor(const Value&);
56
57         LivestatusGroupByType m_GroupByType;
58         Value m_GroupByObject;
59
60 private:
61         std::map<String, Column> m_Columns;
62
63         bool FilteredAddRow(std::vector<LivestatusRowValue>& rs, const intrusive_ptr<Filter>& filter, int limit, const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject);
64 };
65
66 }
67
68 #endif /* TABLE_H */
69
70 #include "livestatus/filter.hpp"