-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathISemanticContext.hpp
281 lines (232 loc) · 11.4 KB
/
ISemanticContext.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
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#ifndef ISEMANTICCONTEXT_HPP
#define ISEMANTICCONTEXT_HPP
#include "EventProperty.hpp"
#include "CommonFields.h"
#include "ctmacros.hpp"
#include "Enums.hpp"
#include <string>
#include <cassert>
namespace MAT_NS_BEGIN
{
/// <summary>
class MATSDK_LIBABI ISemanticContext
{
public:
virtual ~ISemanticContext() {};
/// <summary>
/// Set the application environment context information of telemetry event.
/// </summary>
/// <param name="appEnv">Environment from which this event originated</param>
DECLARE_COMMONFIELD(AppEnv, COMMONFIELDS_APP_ENV);
/// <summary>
/// Set the application identifier context information of telemetry event.
/// </summary>
/// <param name="appId">Id that uniquely identifies the user-facing application from which this event originated</param>
DECLARE_COMMONFIELD(AppId, COMMONFIELDS_APP_ID);
/// <summary>
/// Set the application name context information of telemetry event.
/// </summary>
/// <param name="appName">Application Name</param>
DECLARE_COMMONFIELD(AppName, COMMONFIELDS_APP_NAME);
/// <summary>
/// Set the application version context information of telemetry event.
/// </summary>
/// <param name="appVersion">Version of the application, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(AppVersion, COMMONFIELDS_APP_VERSION);
/// <summary>
/// Set the application language context information of telemetry event.
/// </summary>
DECLARE_COMMONFIELD(AppLanguage, COMMONFIELDS_APP_LANGUAGE);
/// <summary>
/// Set the application's experiment IDs information of telemetry event.
/// The experiment IDs information will be applied to all events unless it is overwritten by that set via SetEventExperimentIds
/// </summary>
/// <param name="appVersion">list of IDs of experimentations into which the application is enlisted</param>
DECLARE_COMMONFIELD(AppExperimentIds, COMMONFIELDS_APP_EXPERIMENTIDS);
/// <summary>
/// Set the application version context information of telemetry event.
/// Removes previously stored experiment ids set by SetAppExperimentIds.
/// </summary>
/// <param name="appVersion">ETAG which is a hash of the set of experimentations into which the application is enlisted</param>
virtual void SetAppExperimentETag(std::string const& appExperimentETag)
{
SetCommonField(COMMONFIELDS_APP_EXPERIMENTETAG, appExperimentETag);
ClearExperimentIds();
};
/// <summary>
/// Set the application experimentation impression id information of telemetry event.
/// </summary>
/// <param name="appExperimentIds">List of expementation IDs which are app/platform specific</param>
DECLARE_COMMONFIELD(AppExperimentImpressionId, SESSION_IMPRESSION_ID);
/// <summary>
/// Set the experiment IDs information of the specified telemetry event.
/// </summary>
/// <param name="appVersion">list of IDs of experimentations into which the application is enlisted</param>
virtual void SetEventExperimentIds(std::string const& /*eventName*/, std::string const& /*experimentIds*/) {};
/// <summary>
/// Clear the experiment IDs information.
/// </summary>
virtual void ClearExperimentIds() {};
/// <summary>
/// Set the device identifier context information of telemetry event.
/// </summary>
/// <param name="deviceId">A unique device identifier, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(DeviceId, COMMONFIELDS_DEVICE_ID);
/// <summary>
/// Set the device manufacturer context information of telemetry event.
/// </summary>
/// <param name="deviceMake">The manufacturer of the device, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(DeviceMake, COMMONFIELDS_DEVICE_MAKE);
/// <summary>
/// Set the device model context information of telemetry event.
/// </summary>
/// <param name="deviceModel">The model of the device, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(DeviceModel, COMMONFIELDS_DEVICE_MODEL);
/// <summary>
/// Set the device class context information of telemetry event.
/// </summary>
/// <param name="deviceClass">Device class.</param>
DECLARE_COMMONFIELD(DeviceClass, COMMONFIELDS_DEVICE_CLASS);
/// <summary>
/// Set the device orgId context information of telemetry event.
/// </summary>
/// <param name="deviceClass">Device orgId</param>
DECLARE_COMMONFIELD(DeviceOrgId, COMMONFIELDS_DEVICE_ORGID);
/// <summary>
/// Set the network cost context information of telemetry event.
/// </summary>
/// <param name="networkCost">The cost of using data traffic on the current network</param>
virtual void SetNetworkCost(NetworkCost networkCost)
{
char const* value;
switch (networkCost) {
case NetworkCost_Unknown:
value = "Unknown";
break;
case NetworkCost_Unmetered:
value = "Unmetered";
break;
case NetworkCost_Metered:
value = "Metered";
break;
case NetworkCost_OverDataLimit:
value = "OverDataLimit";
break;
default:
assert(!"Unknown NetworkCost enum value");
value = "";
break;
}
SetCommonField(COMMONFIELDS_NETWORK_COST, value);
}
/// <summary>
/// Set the network provider context information of telemetry event.
/// </summary>
/// <param name="networkProvider">The provider used to connect to the current network, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(NetworkProvider, COMMONFIELDS_NETWORK_PROVIDER);
/// Set the network type context information of telemetry event.
/// </summary>
/// <param name="networkType">The type of the current network</param>
virtual void SetNetworkType(NetworkType networkType)
{
char const* value;
switch (networkType) {
case NetworkType_Unknown:
value = "Unknown";
break;
case NetworkType_Wired:
value = "Wired";
break;
case NetworkType_Wifi:
value = "Wifi";
break;
case NetworkType_WWAN:
value = "WWAN";
break;
default:
assert(!"Unknown NetworkType enum value");
value = "";
break;
}
SetCommonField(COMMONFIELDS_NETWORK_TYPE, value);
}
/// <summary>
/// Set the system name context information of telemetry event.
/// </summary>
/// <param name="osName">The system anme, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(OsName, COMMONFIELDS_OS_NAME);
/// <summary>
/// Set the system version context information of telemetry event.
/// </summary>
/// <param name="osVersion">The system version, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(OsVersion, COMMONFIELDS_OS_VERSION);
/// <summary>
/// Set the system build number context information of telemetry event.
/// </summary>
/// <param name="osBuild">The system build, retrieved programmatically where possible and is app/platform specific</param>
DECLARE_COMMONFIELD(OsBuild, COMMONFIELDS_OS_BUILD);
/// <summary>
/// Set the userId context information of telemetry event.
/// </summary>
/// <param name="userId">Identifier that uniquely identifies a user in the application-specific user namespace</param>
/// <param name='piiKind'>PIIKind of the userId. Default to PiiKind_Identity, set it to PiiKind_None to denote it as non-PII.</param>
virtual void SetUserId(std::string const& userId, PiiKind piiKind = PiiKind_Identity)
{
EventProperty prop(userId, piiKind);
SetCommonField(COMMONFIELDS_USER_ID, prop);
}
/// <summary>
/// Set the user MsaId context information of telemetry event.
/// </summary>
/// <param name="userMsaId">Msa id that identifies a user in the application-specific user namespace</param>
DECLARE_COMMONFIELD(UserMsaId, COMMONFIELDS_USER_MSAID);
/// <summary>
/// Set the user ANID context information of telemetry event.
/// </summary>
/// <param name="userANID">ANID that identifies a user in in the application-specific user namespace</param>
DECLARE_COMMONFIELD(UserANID, COMMONFIELDS_USER_ANID);
/// <summary>
/// Set the advertising Id context information of telemetry event.
/// </summary>
/// <param name="userAdvertingId">Advertising Id of a user to use in an application-specific user namespace</param>
DECLARE_COMMONFIELD(UserAdvertisingId, COMMONFIELDS_USER_ADVERTISINGID);
/// <summary>
/// Set the user language context information of telemetry event.
/// </summary>
/// <param name="locale">user's language in IETF language tag format, as described in RFC 4646.</param>
DECLARE_COMMONFIELD(UserLanguage, COMMONFIELDS_USER_LANGUAGE);
/// <summary>
/// Set the user time zone context information of telemetry event.
/// </summary>
/// <param name="timeZone">user's time zone relative to UTC, in ISO 8601 time zone format</param>
DECLARE_COMMONFIELD(UserTimeZone, COMMONFIELDS_USER_TIMEZONE);
/// <summary>
/// Set the Commercial Id context information of telemetry event.
/// </summary>
/// <param name="commercialId">CommercialId of a machine</param>
DECLARE_COMMONFIELD(CommercialId, COMMONFIELDS_COMMERCIAL_ID);
/// <summary>
/// Sets the common Part A/B field.
/// </summary>
/// <param name="name">Field name</param>
/// <param name="value">Field value.</param>
virtual void SetCommonField(const std::string &, const EventProperty &) {};
/// <summary>
/// Sets the custom Part C field.
/// </summary>
/// <param name="name">Field name</param>
/// <param name="value">Field value.</param>
virtual void SetCustomField(const std::string &, const EventProperty &) {};
/// <summary>
/// Sets the ticket (device ticket, user id ticket, etc.) for secure token validation.
/// </summary>
/// <param name="type">Ticket type</param>
/// <param name="ticketValue">Ticket value.</param>
virtual void SetTicket(TicketType /*type*/, std::string const& /*ticketValue*/) {};
};
} MAT_NS_END
#endif //ISEMANTICCONTEXT_H