Build fix: g++ 4.8 incorrectly disambiguates enum and member
[lttng-tools.git] / src / bin / lttng / utils.hpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef _LTTNG_UTILS_H
9 #define _LTTNG_UTILS_H
10
11 #include <common/argpar/argpar.h>
12 #include <common/dynamic-array.hpp>
13 #include <common/make-unique-wrapper.hpp>
14
15 #include <lttng/lttng.h>
16
17 #include <iterator>
18 #include <memory>
19 #include <popt.h>
20
21 extern char *opt_relayd_path;
22 extern int opt_no_sessiond;
23 extern char *opt_sessiond_path;
24 extern pid_t sessiond_pid;
25
26 struct cmd_struct;
27
28 struct session_spec {
29 enum class type {
30 NAME,
31 GLOB_PATTERN,
32 ALL,
33 };
34
35 explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
36 type_(spec_type), value(name_or_pattern)
37 {
38 }
39
40 /* Disambiguate type enum from the member for buggy g++ versions. */
41 type type_;
42 const char *value;
43 };
44
45 /*
46 * We don't use a std::vector here because it would make a copy of the C array.
47 */
48 class session_list {
49 template <typename ContainerType, typename DereferenceReturnType>
50 class _iterator
51 : public std::iterator<std::random_access_iterator_tag, std::size_t> {
52 public:
53 explicit _iterator(ContainerType& list, std::size_t k) :
54 _list(list), _index(k)
55 {
56 }
57
58 _iterator& operator++() noexcept
59 {
60 ++_index;
61 return *this;
62 }
63
64 _iterator& operator--() noexcept
65 {
66 --_index;
67 return *this;
68 }
69
70 _iterator& operator++(int) noexcept
71 {
72 _index++;
73 return *this;
74 }
75
76 _iterator& operator--(int) noexcept
77 {
78 _index--;
79 return *this;
80 }
81
82 bool operator==(_iterator other) const noexcept
83 {
84 return _index == other._index;
85 }
86
87 bool operator!=(_iterator other) const noexcept
88 {
89 return !(*this == other);
90 }
91
92 DereferenceReturnType& operator*() const noexcept
93 {
94 return _list[_index];
95 }
96
97 private:
98 ContainerType& _list;
99 std::size_t _index;
100 };
101
102 using iterator = _iterator<session_list, lttng_session>;
103 using const_iterator = _iterator<const session_list, const lttng_session>;
104
105 public:
106 session_list() : _sessions_count(0), _sessions(nullptr)
107 {
108 }
109
110 session_list(session_list&& original, std::size_t new_count)
111 {
112 _sessions_count = new_count;
113 _sessions = std::move(original._sessions);
114 }
115
116 session_list(struct lttng_session *raw_sessions, std::size_t raw_sessions_count)
117 {
118 _sessions_count = raw_sessions_count;
119 _sessions.reset(raw_sessions);
120 }
121
122 iterator begin() noexcept
123 {
124 return iterator(*this, 0);
125 }
126
127 iterator end() noexcept
128 {
129 return iterator(*this, _sessions_count);
130 }
131
132 const_iterator begin() const noexcept
133 {
134 return const_iterator(*this, 0);
135 }
136
137 const_iterator end() const noexcept
138 {
139 return const_iterator(*this, _sessions_count);
140 }
141
142 std::size_t size() const noexcept
143 {
144 return _sessions_count;
145 }
146
147 void resize(std::size_t new_size) noexcept
148 {
149 _sessions_count = new_size;
150 }
151
152 lttng_session& operator[](std::size_t index)
153 {
154 LTTNG_ASSERT(index < _sessions_count);
155 return _sessions.get()[index];
156 }
157
158 const lttng_session& operator[](std::size_t index) const
159 {
160 LTTNG_ASSERT(index < _sessions_count);
161 return _sessions.get()[index];
162 }
163
164 private:
165 std::size_t _sessions_count;
166 std::unique_ptr<lttng_session,
167 lttng::memory::create_deleter_class<lttng_session, lttng::free>::deleter>
168 _sessions;
169 };
170
171 char *get_session_name(void);
172 char *get_session_name_quiet(void);
173 void list_commands(struct cmd_struct *commands, FILE *ofp);
174 void list_cmd_options(FILE *ofp, struct poptOption *options);
175 void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options);
176
177 /*
178 * Return the minimum order for which x <= (1UL << order).
179 * Return -1 if x is 0.
180 */
181 int get_count_order_u32(uint32_t x);
182
183 /*
184 * Return the minimum order for which x <= (1UL << order).
185 * Return -1 if x is 0.
186 */
187 int get_count_order_u64(uint64_t x);
188
189 /*
190 * Return the minimum order for which x <= (1UL << order).
191 * Return -1 if x is 0.
192 */
193 int get_count_order_ulong(unsigned long x);
194
195 const char *get_event_type_str(enum lttng_event_type event_type);
196
197 int print_missing_or_multiple_domains(unsigned int domain_count, bool include_agent_domains);
198
199 int spawn_relayd(const char *pathname, int port);
200 int check_relayd(void);
201 void print_session_stats(const char *session_name);
202 int get_session_stats_str(const char *session_name, char **str);
203 int show_cmd_help(const char *cmd_name, const char *help_msg);
204
205 int print_trace_archive_location(const struct lttng_trace_archive_location *location,
206 const char *session_name);
207
208 int validate_exclusion_list(const char *event_name,
209 const struct lttng_dynamic_pointer_array *exclusions);
210
211 session_list list_sessions(const struct session_spec& spec);
212
213 #endif /* _LTTNG_UTILS_H */
This page took 0.03375 seconds and 4 git commands to generate.