-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathEventProperty.hpp
559 lines (467 loc) · 20.4 KB
/
EventProperty.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#ifndef MAT_EVENTPROPERTY_HPP
#define MAT_EVENTPROPERTY_HPP
#include "ctmacros.hpp"
#include "Enums.hpp"
#include "CommonFields.h"
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
#include <ctime>
#include <cstdlib>
#include <cstdint>
#ifdef _WIN32
/* Required for GUID type helper function on Windows */
#include <ObjBase.h>
#else
#include <string.h>
#ifndef LONG_IS_INT64_T
#define LONG_IS_INT64_T
#endif
#endif
namespace MAT_NS_BEGIN
{
/// <summary>
/// The number of ticks per second.
/// </summary>
const uint64_t ticksPerSecond = 10000000UL;
/// <summary>
/// The UNIX epoch: Thursday, January, 01, 1970, 12:00:00 AM.
/// </summary>
const uint64_t ticksUnixEpoch = 0x089f7ff5f7b58000;
/// <summary>
/// The time_ticks_t structure encapsulates time in .NET ticks.
/// </summary>
/// <remarks>
/// A single tick represents one hundred nanoseconds, or one ten-millionth of a second.
/// There are 10,000 ticks in a millisecond, or 10 million ticks in a second.
/// The value of this property represents the number of 100 nanosecond intervals that have
/// elapsed since 12:00 AM, January, 1, 0001 (0:00 : 00 UTC on January 1, 0001, in
/// the Gregorian calendar), which represents DateTime.MinValue.
/// <b>Note:</b> This does not include the number of ticks that are attributable to leap seconds.
/// </remarks>
struct MATSDK_LIBABI time_ticks_t {
/// <summary>
/// A raw 64-bit unsigned integer that represents the number of .NET ticks.
/// </summary>
uint64_t ticks;
/// <summary>
/// The default constructor for instantiating an empty time_ticks_t object.
/// </summary>
time_ticks_t();
/// <summary>
/// Converts the number of .NET ticks into an instance of the time_ticks_t structure.
/// </summary>
time_ticks_t(uint64_t raw);
/// <summary>
/// Constructs a time_ticks_t object from a pointer to a time_t object from the standard library.
/// <b>Note:</b> time_t time must contain a timestamp in UTC time.
/// </summary>
time_ticks_t(const std::time_t* time);
/// <summary>
/// The time_ticks_t copy constructor.
/// </summary>
time_ticks_t(const time_ticks_t& t);
/// <summary>
/// The time_ticks_t move constructor.
/// </summary>
time_ticks_t(time_ticks_t&& t) noexcept;
/// <summary>
/// The time_ticks_t copy assignment operator.
/// </summary>
time_ticks_t& operator=(const time_ticks_t& t) noexcept;
/// <summary>
/// The time_ticks_t move assignment operator.
/// </summary>
time_ticks_t& operator=(time_ticks_t&& t) noexcept;
};
/// <summary>
/// The GUID_t structure represents the portable cross-platform implementation of a GUID (Globally Unique ID).
/// </summary>
/// <remarks>
/// GUIDs identify objects such as interfaces, manager entry-point vectors (EPVs), and class objects.
/// A GUID is a 128-bit value consisting of one group of eight hexadecimal digits, followed
/// by three groups of four hexadecimal digits, each followed by one group of 12 hexadecimal digits.
///
/// The definition of this structure is the cross-platform equivalent to the
/// [Windows RPC GUID definition](https://msdn.microsoft.com/en-us/library/windows/desktop/aa373931%28v=vs.85%29.aspx).
///
/// <b>Note:</b> You must provide your own converter to convert from a <b>Windows RPC GUID</b> to a GUID_t.
/// </remarks>
struct MATSDK_LIBABI GUID_t {
/// <summary>
/// Specifies the first eight hexadecimal digits of the GUID.
/// </summary>
uint32_t Data1;
/// <summary>
/// Specifies the first group of four hexadecimal digits.
///</summary>
uint16_t Data2;
/// <summary>
/// Specifies the second group of four hexadecimal digits.
/// </summary>
uint16_t Data3;
/// <summary>
/// An array of eight bytes.
/// The first two bytes contain the third group of four hexadecimal digits.
/// The remaining six bytes contain the final 12 hexadecimal digits.
/// </summary>
uint8_t Data4[8];
/// <summary>
/// The default GUID_t constructor.
/// Creates a null instance of the GUID_t object (initialized to all zeros).
/// {00000000-0000-0000-0000-000000000000}.
/// </summary>
GUID_t();
/// <summary>
/// A constructor that creates a GUID_t object from a hyphenated string.
/// </summary>
/// <param name="guid_string">A hyphenated string that contains the GUID (curly braces optional).</param>
GUID_t(const char* guid_string);
/// <summary>
/// A constructor that creates a GUID_t object from a byte array.
/// </summary>
/// <param name="guid_bytes">A byte array.</param>
/// <param name="bigEndian">
/// A boolean value that specifies the byte order.<br>
/// A value of <i>true</i> specifies the more natural human-readable order.<br>
/// A value of <i>false</i> (the default) specifies the same order as the .NET GUID constructor.
/// </param>
GUID_t(const uint8_t guid_bytes[16], bool bigEndian = false);
/// <summary>
/// A constructor that creates a GUID_t object from three integers and a byte array.
/// </summary>
/// <param name="d1">An integer that specifies the first eight hexadecimal digits of the GUID.</param>
/// <param name="d2">An integer that specifies the first group of four hexadecimal digits.</param>
/// <param name="d3">An integer that specifies the second group of four hexadecimal digits.</param>
/// <param name="v">A reference to an array of eight bytes.
/// The first two bytes contain the third group of four hexadecimal digits.
/// The remaining six bytes contain the final 12 hexadecimal digits.
/// </param>
GUID_t(int d1, int d2, int d3, const std::initializer_list<uint8_t> &v);
/// <summary>
/// The GUID_t copy constructor.
/// </summary>
/// <param name="guid">A GUID_t object.</param>
GUID_t(const GUID_t& guid);
/// <summary>
/// The GUID_t move constructor.
/// </summary>
/// <param name="guid">A GUID_t object.</param>
GUID_t(GUID_t&& guid) noexcept;
/// <summary>
/// The GUID_t copy-assignment operator.
/// </summary>
/// <param name="guid">A GUID_t object.</param>
GUID_t& operator=(const GUID_t& guid) noexcept;
/// <summary>
/// The GUID_t move assignment operator.
/// </summary>
/// <param name="guid">A GUID_t object.</param>
GUID_t& operator=(GUID_t&& guid) noexcept;
#ifdef _WIN32
/// <summary>
/// A constructor that creates a GUID_t object from a Windows GUID object.
/// </summary>
/// <param name="guid">A Windows GUID object.</param>
GUID_t(GUID guid);
/// <summary>
/// Converts a standard vector of bytes into a Windows GUID object.
/// </summary>
/// <param name="bytes">A standard vector of bytes.</param>
/// <returns>A GUID.</returns>
static GUID convertUintVectorToGUID(std::vector<uint8_t> const& bytes);
#endif
/// <summary>
/// Converts this GUID_t to an array of bytes.
/// </summary>
/// <param name="guid_bytes">A uint8_t array of 16 bytes.</param>
void to_bytes(uint8_t(&guid_bytes)[16]) const;
/// <summary>
/// Convert this GUID_t object to a string.
/// </summary>
/// <returns>This GUID_t object in a string.</returns>
std::string to_string() const;
/// <summary>
/// Calculates the size of this GUID_t object.
/// The output from this method is compatible with std::unordered_map.
/// </summary>
/// <returns>The size of the GUID_t object in bytes.</returns>
std::size_t Hash() const;
/// <summary>
/// Tests to determine whether two GUID_t objects are equivalent (needed for maps).
/// </summary>
/// <returns>A boolean value that indicates success or failure.</returns>
bool operator==(GUID_t const& other) const;
/// <summary>
/// Tests to determine how to sort 2 GUID_t objects
/// </summary>
/// <returns>A boolean value that indicates success or failure.</returns>
bool operator<(GUID_t const& other) const;
};
/// @cond INTERNAL_DOCS
/// Excluded from public docs
/// <summary>
/// Declare GuidComparer as the Comparer when using GUID_t as a key in a map or set
/// </summary>
struct GuidComparer : std::less<GUID_t>
{
inline std::size_t operator()(GUID_t const& key) const
{
return key.Hash();
}
inline bool operator()(GUID_t const& lhs, GUID_t const& rhs) const
{
return lhs.Hash() < rhs.Hash();
}
};
/// @endcond
/// <summary>
/// The EventProperty structure represents a C++11 variant object that holds an event property type
/// and an event property value.
/// </summary>
struct MATSDK_LIBABI EventProperty
{
// <remarks>
// With the concept of EventProperty value object we allow users implementing their
// own type conversion system, which may subclass and provides an implementation of
// to_string method
// </remarks>
public:
/// <summary>
/// This anonymous enumeration contains a set of values that specify the types
/// that are supported by events collector.
///
/// <b>Note:</b> These enum values should be in sync with Java enum com.microsoft.applications.events.EventPropertyType
/// </summary>
enum
{
/// <summary>
/// A string.
/// </summary>
TYPE_STRING = 0,
/// <summary>
/// A 64-bit signed integer.
/// </summary>
TYPE_INT64 = 1,
/// <summary>
/// A double.
/// </summary>
TYPE_DOUBLE = 2,
/// <summary>
/// A date/time object represented in .NET ticks.
/// </summary>
TYPE_TIME = 3,
/// <summary>
/// A boolean.
/// </summary>
TYPE_BOOLEAN = 4,
/// <summary>
/// A GUID.
/// </summary>
TYPE_GUID = 5,
/// <summary>String</summary>
TYPE_STRING_ARRAY = 6,
/// <summary>64-bit signed integer</summary>
TYPE_INT64_ARRAY = 7,
/// <summary>double</summary>
TYPE_DOUBLE_ARRAY = 8,
/// <summary>GUID</summary>
TYPE_GUID_ARRAY = 9,
} type;
/// <summary>
/// The kind of PII (Personal Identifiable Information) for an event.
/// </summary>
PiiKind piiKind;
/// <summary>
DataCategory dataCategory = DataCategory_PartC;
/// <summary>
/// Variant object value
/// </summary>
union
{
char* as_string;
int64_t as_int64;
double as_double;
bool as_bool;
GUID_t as_guid;
time_ticks_t as_time_ticks;
std::vector<int64_t>* as_longArray;
std::vector<double>* as_doubleArray;
std::vector<GUID_t>* as_guidArray;
std::vector<std::string>* as_stringArray;
};
/// <summary>Debug routine that returns string representation of type name</summary>
static const char *type_name(unsigned typeId);
/// <summary>
/// EventProperty copy constructor
/// </summary>
/// <param name="source">Right-hand side value of object</param>
EventProperty(const EventProperty& source);
/// <summary>
/// The EventProperty move constructor.
/// </summary>
/// <param name="source">The EventProperty object to move.</param>
EventProperty(EventProperty&& source);
/// <summary>
/// The EventProperty equalto operator.
/// </summary>
bool operator==(const EventProperty& source) const;
/// <summary>
/// An EventProperty assignment operator that takes an EventProperty object.
/// </summary>
EventProperty& operator=(const EventProperty& source);
/// <summary>
/// An EventProperty assignment operator that takes a string value.
/// </summary>
EventProperty& operator=(const std::string& value);
/// <summary>
/// An EventProperty assignment operator that takes a character pointer to a string.
/// </summary>
EventProperty& operator=(const char *value);
/// <summary>
/// An EventProperty assignment operator that takes an int64_t value.
/// </summary>
EventProperty& operator=(int64_t value);
// All other integer types get converted to int64_t
#ifndef LONG_IS_INT64_T
EventProperty& operator=(long value);
#endif
/// <summary>
/// An EventProperty assignment operator that takes an int8_t value.
/// </summary>
EventProperty& operator=(int8_t value);
/// <summary>
/// An EventProperty assignment operator that takes an int16_t value.
/// </summary>
EventProperty& operator=(int16_t value);
/// <summary>
/// An EventProperty assignment operator that takes an int32_t value.
/// </summary>
EventProperty& operator=(int32_t value);
/// <summary>
/// An EventProperty assignment operator that takes a uint8_t value.
/// </summary>
EventProperty& operator=(uint8_t value);
/// <summary>
/// An EventProperty assignment operator that takes a uint16_t value.
/// </summary>
EventProperty& operator=(uint16_t value);
/// <summary>
/// An EventProperty assignment operator that takes a uint32_t value.
/// </summary>
EventProperty& operator=(uint32_t value);
/// <summary>
/// An EventProperty assignment operator that takes a uint64_t value.
/// </summary>
EventProperty& operator=(uint64_t value);
EventProperty& operator=(const std::vector<int64_t>& value);
EventProperty& operator=(const std::vector<double>& value);
EventProperty& operator=(const std::vector<GUID_t>& value);
EventProperty& operator=(const std::vector<std::string>& value);
/// <summary>
/// An EventProperty assignment operator that takes a double.
/// </summary>
EventProperty& operator=(double value);
/// <summary>
/// An EventProperty assignment operator that takes a boolean value.
/// </summary>
EventProperty& operator=(bool value);
/// <summary>
/// An EventProperty assignment operator that takes a time_ticks_t value.
/// </summary>
EventProperty& operator=(time_ticks_t value);
/// <summary>
/// An EventProperty assignment operator that takes a GUID_t value.
/// </summary>
EventProperty& operator=(GUID_t value);
/// <summary>
/// Clears the object values, deallocating memory when needed.
/// </summary>
void clear();
/// <summary>
/// The EventProperty destructor.
/// </summary>
virtual ~EventProperty();
/// <summary>
/// The EventProperty default constructor.
/// </summary>
EventProperty();
/// <summary>
/// The EventProperty constructor, taking a character pointer to a string, and the kind of personal identifiable information.
/// </summary>
/// <param name="value">A constant character pointer to a string.</param>
/// <param name="piiKind">The kind of personal identifiable information.</param>
/// EventProperty constructor for string value
/// </summary>
/// <param name="value">string value</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(const char* value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// EventProperty constructor for string value
/// </summary>
/// <param name="value">string value</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(const std::string& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// EventProperty constructor for int64 value
/// </summary>
/// <param name="value">int64_t value</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(int64_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// EventProperty constructor for double value
/// </summary>
/// <param name="value">double value</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(double value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// EventProperty constructor for time in .NET ticks
/// </summary>
/// <param name="value">time_ticks_t value - time in .NET ticks</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(time_ticks_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// EventProperty constructor for boolean value
/// </summary>
/// <param name="value">boolean value</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(bool value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// EventProperty constructor for GUID
/// </summary>
/// <param name="value">GUID_t value</param>
/// <param name="piiKind">Pii kind</param>
EventProperty(GUID_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
// All other integer types get converted to int64_t
#ifndef LONG_IS_INT64_T
EventProperty(long value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
#endif
EventProperty(int8_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(int16_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(int32_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(uint8_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(uint16_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(uint32_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(uint64_t value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(std::vector<int64_t>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(std::vector<double>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(std::vector<GUID_t>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
EventProperty(std::vector<std::string>& value, PiiKind piiKind = PiiKind_None, DataCategory category = DataCategory_PartC);
/// <summary>
/// Returns <i>true</i> when the type is string AND the value is empty.
/// </summary>
bool empty();
/// <summary>
/// Returns a string representation of this object.
/// </summary>
virtual std::string to_string() const;
private:
void copydata(EventProperty const* source);
};
} MAT_NS_END
#endif