19
19
#include " AnalyticsImplementation.h"
20
20
#include " Backend/AnalyticsBackend.h"
21
21
#include " UtilsLogging.h"
22
+ #include " SystemTime.h"
22
23
23
24
#include < fstream>
24
25
#include < streambuf>
@@ -36,7 +37,7 @@ namespace Plugin {
36
37
mQueueCondition (),
37
38
mActionQueue (),
38
39
mEventQueue (),
39
- mBackends (IAnalyticsBackendAdministrator::Instances ()),
40
+ mBackends (IAnalyticsBackendAdministrator::Create ()),
40
41
mSysTimeValid (false ),
41
42
mShell (nullptr )
42
43
{
@@ -45,20 +46,21 @@ namespace Plugin {
45
46
46
47
AnalyticsImplementation::~AnalyticsImplementation ()
47
48
{
49
+ LOGINFO (" AnalyticsImplementation::~AnalyticsImplementation()" );
48
50
std::unique_lock<std::mutex> lock (mQueueMutex );
49
51
mActionQueue .push ({ACTION_TYPE_SHUTDOWN, nullptr });
50
52
lock.unlock ();
51
53
mQueueCondition .notify_one ();
52
54
mThread .join ();
53
55
}
54
56
55
- /* virtual */ uint32_t AnalyticsImplementation::SendEvent (const string& eventName,
57
+ /* virtual */ Core::hresult AnalyticsImplementation::SendEvent (const string& eventName,
56
58
const string& eventVersion,
57
59
const string& eventSource,
58
60
const string& eventSourceVersion,
59
- RPC:: IStringIterator* const & cetList,
60
- const uint64_t & epochTimestamp,
61
- const uint64_t & uptimeTimestamp,
61
+ IStringIterator* const & cetList,
62
+ const uint64_t epochTimestamp,
63
+ const uint64_t uptimeTimestamp,
62
64
const string& eventPayload)
63
65
{
64
66
std::shared_ptr<Event> event = std::make_shared<Event>();
@@ -98,39 +100,23 @@ namespace Plugin {
98
100
return Core::ERROR_NONE;
99
101
}
100
102
101
- uint32_t AnalyticsImplementation::SetSessionId (const string& id)
102
- {
103
- uint32_t ret = Core::ERROR_GENERAL;
104
- // set session id in sift backend
105
- if (mBackends .find (IAnalyticsBackend::SIFT) != mBackends .end ())
106
- {
107
- ret = mBackends .at (IAnalyticsBackend::SIFT).SetSessionId (id);
108
- }
109
-
110
- return ret;
111
- }
112
-
113
- uint32_t AnalyticsImplementation::SetTimeReady ()
114
- {
115
- // set time ready action
116
- std::unique_lock<std::mutex> lock (mQueueMutex );
117
- mActionQueue .push ({ACTION_TYPE_SET_TIME_READY, nullptr });
118
- lock.unlock ();
119
- mQueueCondition .notify_one ();
120
- return Core::ERROR_NONE;
121
- }
122
-
123
103
uint32_t AnalyticsImplementation::Configure (PluginHost::IShell* shell)
124
104
{
125
105
LOGINFO (" Configuring Analytics" );
126
106
uint32_t result = Core::ERROR_NONE;
127
107
ASSERT (shell != nullptr );
128
108
mShell = shell;
129
109
110
+ mSysTime = std::make_shared<SystemTime>(shell);
111
+ if (mSysTime == nullptr )
112
+ {
113
+ LOGERR (" Failed to create SystemTime instance" );
114
+ }
115
+
130
116
for (auto &backend : mBackends )
131
117
{
132
118
LOGINFO (" Configuring backend: %s" , backend.first .c_str ());
133
- backend.second . Configure (shell);
119
+ backend.second -> Configure (shell, mSysTime );
134
120
}
135
121
136
122
return result;
@@ -177,7 +163,7 @@ namespace Plugin {
177
163
switch (action.type ) {
178
164
case ACTION_POPULATE_TIME_INFO:
179
165
180
- // mSysTimeValid = IsSysTimeValid();
166
+ mSysTimeValid = IsSysTimeValid ();
181
167
182
168
if ( mSysTimeValid )
183
169
{
@@ -225,24 +211,8 @@ namespace Plugin {
225
211
}
226
212
break ;
227
213
case ACTION_TYPE_SHUTDOWN:
214
+ LOGINFO (" Shutting down Analytics" );
228
215
return ;
229
- case ACTION_TYPE_SET_TIME_READY:
230
- {
231
- mSysTimeValid = true ;
232
- // Send the events from the queue, if there are any.
233
- while ( !mEventQueue .empty () )
234
- {
235
- AnalyticsImplementation::Event event = mEventQueue .front ();
236
- // convert uptime to epoch timestamp
237
- if (event.epochTimestamp == 0 )
238
- {
239
- event.epochTimestamp = ConvertUptimeToTimestampInMs (event.uptimeTimestamp );
240
- }
241
-
242
- SendEventToBackend ( event );
243
- mEventQueue .pop ();
244
- }
245
- }break ;
246
216
default :
247
217
break ;
248
218
}
@@ -254,8 +224,10 @@ namespace Plugin {
254
224
bool AnalyticsImplementation::IsSysTimeValid ()
255
225
{
256
226
bool ret = false ;
257
- // TODO: Add system time validationm
258
- // For now, relay on setTimeReady call
227
+ if (mSysTime != nullptr )
228
+ {
229
+ ret = mSysTime ->IsSystemTimeAvailable ();
230
+ }
259
231
260
232
return ret;
261
233
}
@@ -279,7 +251,7 @@ namespace Plugin {
279
251
else if (mBackends .find (IAnalyticsBackend::SIFT) != mBackends .end ())
280
252
{
281
253
LOGINFO (" Sending event to Sift backend: %s" , event.eventName .c_str ());
282
- mBackends .at (IAnalyticsBackend::SIFT). SendEvent (backendEvent);
254
+ mBackends .at (IAnalyticsBackend::SIFT)-> SendEvent (backendEvent);
283
255
}
284
256
}
285
257
0 commit comments