-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathEventProperties.hpp
374 lines (315 loc) · 16.3 KB
/
EventProperties.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#ifndef EVENTPROPERTIES_HPP
#define EVENTPROPERTIES_HPP
#define MAT_C_API
#include "Enums.hpp"
#include "EventProperty.hpp"
#include "ctmacros.hpp"
#include <map>
#include <stdint.h>
#include <string>
#include <tuple>
#ifdef MAT_C_API
#include "mat.h"
#endif
namespace MAT_NS_BEGIN
{
struct EventPropertiesStorage;
/// <summary>
/// The EventProperties class encapsulates event properties.
/// </summary>
class MATSDK_LIBABI EventProperties
{
public:
/// <summary>
/// Constructs an EventProperties object, taking a string for the property name and a diagnostic level.
/// You must supply a non-empty name whenever you supply any custom properties for the event via <b>EventProperties</b>.
/// </summary>
EventProperties(const std::string& name, uint8_t diagnosticLevel);
/// <summary>
/// Constructs an EventProperties object, taking a string for the property name.
/// Sets the diagnostic level of the event to DIAG_LEVEL_OPTIONAL
/// You must supply a non-empty name whenever you supply any custom properties for the event via <b>EventProperties</b>.
/// </summary>
EventProperties(const std::string& name);
/// <summary>
/// Constructs an EventProperties object (the default constructor).
/// Sets the diagnostic level of the event to DIAG_LEVEL_OPTIONAL
/// You must supply a non-empty name whenever you supply any custom properties for the event via <b>EventProperties</b>.
/// </summary>
EventProperties();
/// <summary>
/// The EventProperties copy constructor.
/// </summary>
EventProperties(EventProperties const& copy);
/// <summary>
/// The EventProperties equals operator overload.
/// </summary>
EventProperties& operator=(EventProperties const& copy);
/// <summary>
/// Constructs an EventProperties object from a map of string to EventProperty.<br>
/// You must supply a non-empty name whenever you supply any custom properties for the event via <b>EventProperties</b>.
/// </summary>
EventProperties(const std::string& name, const std::map<std::string, EventProperty>& properties);
/// <summary>
/// Adds a map of <string, EventProperty> to EventProperties.
/// </summary>
EventProperties& operator+=(const std::map<std::string, EventProperty>& properties);
/// <summary>
/// Assigns a map of <string, EventProperty> to EventProperties.
/// </summary>
EventProperties& operator=(const std::map<std::string, EventProperty>& properties);
/// <summary>
/// An EventProperties constructor using a C++11 initializer list.
/// </summary>
EventProperties(const std::string& name, std::initializer_list<std::pair<std::string const, EventProperty>> properties);
/// <summary>
/// An EventProperties assignment operator using C++11 initializer list.
/// </summary>
EventProperties& operator=(std::initializer_list<std::pair<std::string const, EventProperty>> properties);
/// <summary>
/// Sets the name of an event, given a string for the event name.
/// You must supply a non-empty name whenever you supply any custom properties for the event via <b>EventProperties</b>.
/// </summary>
/// <param name="name">A string that contains the name of the event.</param>
bool SetName(const std::string& name);
/// <summary>
/// Gets the name of an event. An empty string is returned if the name was never set.
/// </summary>
/// <returns>Name of the event</returns>
const std::string& GetName() const;
/// <summary>
/// Sets the base type of an event.
/// </summary>
/// <param name="recordType">Base Type of event record.</param>
bool SetType(const std::string& recordType);
/// <summary>
/// Gets the Base Type of an event.
/// </summary>
/// <returns>A string that contains the type of the event.</returns>
const std::string& GetType() const;
/// <summary>
/// [optional] Sets the timestamp of an event, in milliseconds.
/// <b>Note:</b> This method overrides the default timestamp generated by the telemetry system.
/// </summary>
/// <param name="timestampInEpochMillis">The UNIX timestamp in milliseconds. This is the amount of time since 00:00:00
/// Coordinated Universal Time (UTC), January, 1, 1970 (not counting leap seconds).</param>
void SetTimestamp(int64_t timestampInEpochMillis);
/// <summary>
/// Gets the timestamp of an event, in milliseconds.
/// Zero is returned when the time stamp was not specified with SetTimestamp().
/// </summary>
/// <returns>The timestamp of the event, specified in milliseconds.</returns>
int64_t GetTimestamp() const;
/// <summary>
/// [optional] Sets the transmit priority of an event.
/// <b>Note:</b> If you don't specify a value, then the default priority is used.
/// </summary>
/// <param name="priority">The transmit priority.</param>
void SetPriority(EventPriority priority);
/// <summary>
/// Gets the transmit priority of the event.
/// </summary>
/// <returns>The transmit priority.<returns>
EventPriority GetPriority() const;
/// <summary>
/// [optional] Sets the transmit Latency of the event.
/// </summary>
/// <param name="latency">Event latency.</param>
void SetLatency(EventLatency latency);
/// <summary>
/// Get the transmit Latency of the event.
/// </summary>
/// <returns>Transmit Latency of the event<returns>
EventLatency GetLatency() const;
/// <summary>
/// [optional] Specify Persistence priority of an event.
/// Default Persistence priority will be used for persisting the event if none was specified.
/// </summary>
/// <param name="priority">Persistence of the event</param>
void SetPersistence(EventPersistence persistence);
/// <summary>
/// Get the transmit Latency of the event.
/// </summary>
/// <returns>Transmit Latency of the event<returns>
EventPersistence GetPersistence() const;
/// <summary>
/// [optional] Specify popSample of an event.
/// </summary>
/// <param name="priority">popSample of the event</param>
void SetPopsample(double popSample);
/// <summary>
/// Get the popSample of the event.
/// </summary>
/// <returns>popSample of the event<returns>
double GetPopSample() const;
/// <summary>
/// [optional] Specify Policy Bit flags for UTC usage of an event.
/// Default values will be used for transmitting the event if none was specified.
/// </summary>
/// <param name="priority">Transmit priority of the event</param>
void SetPolicyBitFlags(uint64_t policyBitFlags);
/// <summary>
/// Get the Policy bit flags for UTC usage of the event.
/// </summary>
/// <returns>Transmit priority of the event<returns>
uint64_t GetPolicyBitFlags() const;
/// <summary>
/// Sets the diagnostic level of an event. This is equivalent to:
/// ...
/// SetProperty(COMMONFIELDS_EVENT_LEVEL, level);
/// ...
/// </summary>
void SetLevel(uint8_t level)
{
SetProperty(COMMONFIELDS_EVENT_LEVEL, level);
}
///
/// TODO: [MG] - can we revisit this, do we need a tuple?
///
/// <summary>
/// Attempts to get the diagnostic level for an event.
/// <return>True and the level, or false if unset, set to the wrong type, or the value is out of bounds.</return>
/// </summary>
std::tuple<bool, uint8_t> TryGetLevel() const;
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
/// <param name='name'>Name of the property</param>
/// <param name='value'>Value of the property</param>
/// <param name='piiKind'>PIIKind of the property</param>
void SetProperty(const std::string& name, EventProperty value);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, char const* value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, const std::string& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, double value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, int64_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, bool value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, time_ticks_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, GUID_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
/// </summary>
void SetProperty(const std::string& name, int8_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
void SetProperty(const std::string& name, int16_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
void SetProperty(const std::string& name, int32_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
void SetProperty(const std::string& name, uint8_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
void SetProperty(const std::string& name, uint16_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
void SetProperty(const std::string& name, uint32_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event. It either creates a new property if none exists or overwrites the existing one.<br>
/// All integer types are currently being converted to int64_t.
void SetProperty(const std::string& name, uint64_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC)
{
SetProperty(name, static_cast<int64_t>(value), piiKind, category);
}
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, std::vector<std::string>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, std::vector<GUID_t>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, std::vector<double>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Specify a property for an event.
/// It either creates a new property if none exists or overwrites the existing one.
/// </summary>
void SetProperty(const std::string& name, std::vector<int64_t>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Get the properties bag of an event.
/// </summary>
/// <returns>Properties bag of the event</returns>
const std::map<std::string, EventProperty>& GetProperties(DataCategory category = DataCategory_PartC) const;
/// <summary>
/// Get the Pii properties bag of an event.
/// </summary>
/// <returns>Pii Properties bag of the event</returns>
const std::map<std::string, std::pair<std::string, PiiKind>> GetPiiProperties(DataCategory category = DataCategory_PartC) const;
/// <summary>
/// Erase property from event.
/// </summary>
size_t erase(const std::string& key, DataCategory category = DataCategory_PartC);
virtual ~EventProperties() noexcept;
#ifdef MAT_C_API
/// Implementation of ABI-safe packing of EventProperties object
evt_prop* pack();
bool unpack(const evt_prop* packed, size_t size);
#endif
private:
EventPropertiesStorage* m_storage;
};
} MAT_NS_END
#endif