-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathIECSClient.hpp
361 lines (309 loc) · 21.1 KB
/
IECSClient.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
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#ifndef IECSCLIENT_HPP
#define IECSCLIENT_HPP
#include "ctmacros.hpp"
#include "ILogger.hpp"
#include <string>
#include <vector>
#include <map>
namespace Microsoft {
namespace Applications {
namespace Experimentation {
namespace ECS {
/// <summary>
/// The ECSClientConfiguration structure configures the ECSClient.
/// </summary>
struct ECSClientConfiguration
{
/// <summary>
/// [required]A string that contains the name of the ECS client associated with the configurations.
/// </summary>
std::string clientName;
/// <summary>
/// [required] A string that contains the version of the ECS client associated with the configurations.
/// </summary>
std::string clientVersion;
/// <summary>
/// [required] A string that contains the fully-qualified path name of the file that the ECS client
/// uses to cache the configuration.
/// </summary>
std::string cacheFilePathName;
/// <summary>
/// [optional] An unsigned integer that contains the default time (in minutes) to expire the cached configuration.
/// </summary>
unsigned int defaultExpiryTimeInMin = 0;
/// <summary>
/// [optional] A standard vector of strings that contains the ECS server URIs.
/// If you don't specify a value, then the default value is used.
/// </summary>
std::vector<std::string> serverUrls;
// [optional] enabled ECS telemetry
bool enableECSClientTelemetry = false;
};
/// <summary>
/// The IECSClientCallback class contains the callback interface for the ECS client to
/// notify its listener of events when they occur.
/// </summary>
class IECSClientCallback
{
public:
/// <summary>
/// The ECSClientEventType enumeration contains a set of values that specify the outcome of a configuration update.
/// </summary>
enum ECSClientEventType
{
/// <summary>
/// The configuration update succeeded.
/// </summary>
ET_CONFIG_UPDATE_SUCCEEDED = 0,
/// <summary>
/// The configuration update failed.
/// </summary>
ET_CONFIG_UPDATE_FAILED
};
/// <summary>
/// The ECSClientEventContext structure contains the state of the ECS client event context.
/// </summary>
struct ECSClientEventContext
{
/// <summary>
/// A string that contains the name of the ECS client.
/// </summary>
std::string clientName;
/// <summary>
/// A string that contains the ECS client version.
/// </summary>
std::string clientVersion;
/// <summary>
/// A string that contains the user ID.
/// </summary>
std::string userId;
/// <summary>
/// A string that contains the device ID.
/// </summary>
std::string deviceId;
/// <summary>
/// A key-value map that contains the list of request parameters.
/// </summary>
std::map<std::string, std::string> requestParameters;
/// <summary>
/// An unsigned integer that contains the configured expiry time in seconds.
/// </summary>
unsigned int configExpiryTimeInSec;
/// <summary>
/// A boolean that indicates whether the ECS configuration was updated from ECS.
/// </summary>
bool configUpdateFromECS;
};
/// <summary>
/// A callback method for the ECSClient to notify its listener of configuration changes.
/// </summary>
/// <param name="evtType">The type of the ECSClient event, specified using
/// one of the ECSClientEventType enumeration values.</param>
/// <param name="evtContext">The context information of the ECSClient event, expressed as an ECSClientEventContext object.</param>
virtual void OnECSClientEvent(ECSClientEventType evtType, ECSClientEventContext evtContext) = 0;
};
/// <summary>
/// The IECSClient class is the interface to an ECS client.
/// </summary>
class MATSDK_LIBABI IECSClient
{
public:
/// <summary>
/// Creates a new instance of an IECSClient.
/// </summary>
static IECSClient* MATSDK_LIBABI_CDECL CreateInstance();
/// <summary>
/// Destroys the specified IECSClient instance.
/// </summary>
static void MATSDK_LIBABI_CDECL DestroyInstance(IECSClient** ppECSClient);
/// <summary>
/// Initializes the IECSClient with the specified configuration.
/// </summary>
/// <param name="config">The configuration as an instance of the ECSClientConfiguration structure.</param>
virtual void Initialize(const ECSClientConfiguration& config) = 0;
/// <summary>
/// Adds a listener to the ECS client - to be notified of configuration changes.
/// </summary>
/// <param name="listener">The listener to add to the ECS client.</param>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool AddListener(IECSClientCallback* listener) = 0;
/// <summary>
/// Removes the listener to stop receiving notifications from the ECS client.
/// </summary>
/// <param name="listener">The listener to remove from the ECSClient.</param>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool RemoveListener(IECSClientCallback* listener) = 0;
/// <summary>
/// Registers a logger to auto-tag events sent by the logger,
/// taking a pointer to an ILogger interface, and a string that contains the agent name.
/// </summary>
/// <param name="pLoger">The logger to be registered with the ECS client</param>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool RegisterLogger(MAT::ILogger* pLoger, const std::string& agentName) = 0;
/// <summary>
/// Sets a user ID used as the request parameter for retrieving configurations from the ECS server.
/// The client can optionally pass this in the request so that the configuration can be
/// allocated on a per-user basic. The allocation persists for the user ID,
/// therefore it is good for the allocation to follow the user account.
/// </summary>
/// <param name="userId">A string that contains the login user ID to pass in the request.</param>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool SetUserId(const std::string& userId) = 0;
/// <summary>
/// Sets a device ID used as the request parameter for retrieving configurations from the ECS server.
/// </summary>
/// <param name="deviceId">A string that contains the device ID.</param>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool SetDeviceId(const std::string& deviceId) = 0;
/// <summary>
/// Sets a list of custom parameters for the request to use to retrieve configurations from ECS server
/// </summary>
/// <param name="requestParams"A map that contains the request parameters.</param>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool SetRequestParameters(const std::map<std::string, std::string>& requestParams) = 0;
/// <summary>
/// Starts the ECSClient - to retrieve configurations from the ECS server.
/// </summary>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool Start() = 0;
/// <summary>
/// Stops the ECSClient from retrieving configurations from the ECS server.
/// </summary>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool Stop() = 0;
/// <summary>
/// Suspends the ECSClient from retrieving configuration updates from the ECS server.
/// </summary>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool Suspend() = 0;
/// <summary>
/// Resumes the ECSClient to retrieve configuration updates from the ECS server.
/// </summary>
/// <returns>A boolean value that indicates success (true) or failure (false).</returns>
virtual bool Resume(bool fetchConfig = false) = 0;
/// <summary>
/// Gets the ETag of the currently active ECS configuration.
/// </summary>
/// <returns>A string that contains the ETag.</returns>
virtual std::string GetETag() = 0;
/// <summary>
/// Gets the ETag of the currently active ECS configuration.
/// </summary>
/// <returns>A string that contains the ETag.</returns>
virtual std::string GetConfigs() = 0;
/// <summary>
/// Gets the keys under the specified configuration path, for the specified agent.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="keysPath">A string that contains the configuration path.</param>
/// <returns>list of configuration keys</returns>
virtual std::vector<std::string> GetKeys(const std::string& agentName, const std::string& keysPath) = 0;
/// <summary>
/// Tries to get the setting for the specified agent, from the specified configuration path
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="value">Receives the setting if it is found. Is unchanged if not found.</param>
/// <returns>True if the setting was successfully found.</returns>
virtual bool TryGetSetting(const std::string& agentName, const std::string& settingPath, std::string& value) = 0;
/// <summary>
/// Tries to get the setting for the specified agent, from the specified configuration path
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="value">Receives the setting if it is found. Is unchanged if not found.</param>
/// <returns>True if the setting was successfully found.</returns>
virtual bool TryGetBoolSetting(const std::string& agentName, const std::string& settingPath, bool& value) = 0;
/// <summary>
/// Tries to get the setting for the specified agent, from the specified configuration path
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="value">Receives the setting if it is found. Is unchanged if not found.</param>
/// <returns>True if the setting was successfully found.</returns>
virtual bool TryGetIntSetting(const std::string& agentName, const std::string& settingPath, int& value) = 0;
/// <summary>
/// Tries to get the setting for the specified agent, from the specified configuration path
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="value">Receives the setting if it is found. Is unchanged if not found.</param>
/// <returns>True if the setting was successfully found.</returns>
virtual bool TryGetLongSetting(const std::string& agentName, const std::string& settingPath, long& value) = 0;
/// <summary>
/// Tries to get the setting for the specified agent, from the specified configuration path
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="value">Receives the setting if it is found. Is unchanged if not found.</param>
/// <returns>True if the setting was successfully found.</returns>
virtual bool TryGetDoubleSetting(const std::string& agentName, const std::string& settingPath, double& value) = 0;
/// <summary>
/// Gets the setting for the specified agent, from the specified configuration path, taking a default string value.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="defaultValue">A string that contains the default value to return if no configuration setting can be found.</param>
/// <returns>A string that contains the setting. The default value is returned if no configuration setting can be found.</returns>
virtual std::string GetSetting(const std::string& agentName, const std::string& settingPath, const std::string& defaultValue) = 0;
/// <summary>
/// Gets the setting for the specified agent, from the specified configuration path, taking a default boolean value.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="defaultValue">A boolean that contains the default value to return if no configuration setting can be found.</param>
/// <returns>A boolean value that contains the setting. The default value is returned if no configuration setting can be found.</returns>
virtual bool GetSetting(const std::string& agentName, const std::string& settingPath, const bool defaultValue) = 0;
/// <summary>
/// Gets the setting for the specified agent, from the specified configuration path, taking a default integer value.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="defaultValue">An integer that contains the default value to return if no configuration setting can be found.</param>
/// <returns>An integer that contains the setting. The default value is returned if no configuration setting can be found.</returns>
virtual int GetSetting(const std::string& agentName, const std::string& settingPath, const int defaultValue) = 0;
/// <summary>
/// Gets the setting for the specified agent, from the specified configuration path, taking a default double value.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <param name="defaultValue">A double that contains the default value to return if no configuration setting can be found.</param>
/// <returns>A double that contains the setting. The default value is returned if no configuration setting can be found.</returns>
virtual double GetSetting(const std::string& agentName, const std::string& settingPath, const double defaultValue) = 0;
/// <summary>
/// Gets a collection of settings for the specified agent, from the specified configuration path.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <returns>A standard vector that contains the settings as strings.</returns>
virtual std::vector<std::string> GetSettings(const std::string& agentName, const std::string& settingPath) = 0;
/// <summary>
/// Gets a collection of settings for the specified agent, from the specified configuration path.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <returns>A vector that contains the settings as integers.</returns>
virtual std::vector<int> GetSettingsAsInts(const std::string& agentName, const std::string& settingPath) = 0;
/// <summary>
/// Gets a collection of settings for the specified agent, from the specified configuration path.
/// </summary>
/// <param name="agentName">A string that contains the name of the agent.</param>
/// <param name="settingPath">A string that contains the configuration path.</param>
/// <returns>A vector that contains the settings as doubles.</returns>
virtual std::vector<double> GetSettingsAsDbls(const std::string& agentName, const std::string& settingPath) = 0;
/// <summary>
/// Sets the Time used for retring.
/// </summary>
virtual void SetRetryTimeFactor(int time) = 0;
};
}
}
}
} // namespaces
namespace MAEE = Microsoft::Applications::Experimentation::ECS;
#endif