client-cpp  0.6.1
LoggingUtils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LOGGINGUTILS_HPP_
18 #define LOGGINGUTILS_HPP_
19 
20 #include <iomanip>
21 #include <vector>
22 #include <string>
23 #include <sstream>
24 #include <cstdint>
25 
26 #include <boost/shared_array.hpp>
27 
28 #include "kaa/gen/BootstrapGen.hpp"
29 #include "kaa/gen/EndpointGen.hpp"
32 
33 namespace kaa {
34 
35 #define KVSTRING(K,V) "\"" #K "\": \"" << V << "\""
36 
37 class LoggingUtils {
38 public:
39  static std::string NotificationSyncRequestToString(const SyncRequest::notificationSyncRequest_t& request) {
40  std::ostringstream ss;
41  if (!request.is_null()) {
42  ss << KVSTRING(appStateSeqNumber, request.get_NotificationSyncRequest().appStateSeqNumber) << ", ";
43  ss << KVSTRING(acceptedUnicastNotifications,
44  AcceptedUnicastNotificationsToString(request.get_NotificationSyncRequest().acceptedUnicastNotifications)) << ", ";
45  ss << KVSTRING(subscriptionCommands, SubscriptionCommandsToString(request.get_NotificationSyncRequest().subscriptionCommands)) << ", ";
46  ss << KVSTRING(topicStates, TopicStatesToString(request.get_NotificationSyncRequest().topicStates)) << ", ";
47  ss << KVSTRING(topicListHash, (request.get_NotificationSyncRequest().topicListHash.is_null() ? "null" :
48  ByteArrayToString(request.get_NotificationSyncRequest().topicListHash.get_bytes())));
49  } else {
50  ss << "null";
51  }
52  return ss.str();
53  }
54 
55  static std::string ConfigurationSyncRequestToString(const SyncRequest::configurationSyncRequest_t& request) {
56  std::ostringstream ss;
57  if (!request.is_null()) {
58  ss << KVSTRING(appStateSeqNumber, request.get_ConfigurationSyncRequest().appStateSeqNumber);
59  ss << KVSTRING(configurationHash,
60  (request.get_ConfigurationSyncRequest().configurationHash.is_null() ? "null" : ByteArrayToString(request.get_ConfigurationSyncRequest().configurationHash.get_bytes())));
61  } else {
62  ss << "null";
63  }
64  return ss.str();
65  }
66 
67  static std::string ProfileSyncRequestToString(const SyncRequest::profileSyncRequest_t& request) {
68  std::ostringstream ss;
69  if (!request.is_null()) {
70  if (!request.get_ProfileSyncRequest().endpointAccessToken.is_null()) {
71  ss << KVSTRING(endpointAccessToken, request.get_ProfileSyncRequest().endpointAccessToken.get_string());
72  } else {
73  ss << KVSTRING(endpointAccessToken, "null");
74  }
75  if (!request.get_ProfileSyncRequest().endpointPublicKey.is_null()) {
76  ss << KVSTRING(endpointPublicKey, ByteArrayToString(request.get_ProfileSyncRequest().endpointPublicKey.get_bytes()));
77  } else {
78  ss << KVSTRING(endpointPublicKey, "null");
79  }
80 
81  ss << KVSTRING(profileBody, ByteArrayToString(request.get_ProfileSyncRequest().profileBody));
82 
83  ss << KVSTRING(configVersion, request.get_ProfileSyncRequest().versionInfo.configVersion);
84  ss << KVSTRING(profileVersion, request.get_ProfileSyncRequest().versionInfo.profileVersion);
85  ss << KVSTRING(systemNfVersion, request.get_ProfileSyncRequest().versionInfo.systemNfVersion);
86  ss << KVSTRING(userNfVersion, request.get_ProfileSyncRequest().versionInfo.userNfVersion);
87  ss << KVSTRING(logSchemaVersion, request.get_ProfileSyncRequest().versionInfo.logSchemaVersion);
88 
89  ss << KVSTRING(eventFamilyVersions, EventFamilyVersionsToString(request.get_ProfileSyncRequest().versionInfo.eventFamilyVersions));
90  } else {
91  ss << "null";
92  }
93  return ss.str();
94  }
95 
96  static std::string MetaDataSyncRequestToString(const SyncRequest::syncRequestMetaData_t& request) {
97  std::ostringstream ss;
98  if (!request.is_null()) {
99  ss << KVSTRING(applicationToken, request.get_SyncRequestMetaData().applicationToken) << ", ";
100  ss << KVSTRING(endpointPublicKeyHash, ByteArrayToString(request.get_SyncRequestMetaData().endpointPublicKeyHash)) << ", ";
101  if (request.get_SyncRequestMetaData().profileHash.is_null()) {
102  ss << KVSTRING(profileHash, "null") << ",";
103  } else {
104  ss << KVSTRING(profileHash, ByteArrayToString(request.get_SyncRequestMetaData().profileHash.get_bytes())) << ",";
105  }
106  ss << KVSTRING(timeout, request.get_SyncRequestMetaData().timeout);
107  } else {
108  ss << "null";
109  }
110  return ss.str();
111  }
112 
113  static std::string EventSyncRequestToString(const SyncRequest::eventSyncRequest_t& request) {
114  std::ostringstream ss;
115  if (!request.is_null()) {
116  ss << KVSTRING(events, OutcomingEventsToString(request.get_EventSyncRequest().events));
117  ss << KVSTRING(eventListenersRequest, EventListenersRequestToString(request.get_EventSyncRequest().eventListenersRequests));
118  } else {
119  ss << "null";
120  }
121  return ss.str();
122  }
123 
124  static std::string AttachUserRequestToString(const UserSyncRequest::userAttachRequest_t& request) {
125  std::ostringstream ss;
126  if (!request.is_null()) {
127  ss << KVSTRING(userAccessToken, request.get_UserAttachRequest().userAccessToken);
128  ss << KVSTRING(userExternalId, request.get_UserAttachRequest().userExternalId);
129  } else {
130  ss << "null";
131  }
132  return ss.str();
133  }
134 
135  static std::string UserSyncRequestToString(const SyncRequest::userSyncRequest_t& request) {
136  std::ostringstream ss;
137  if (!request.is_null()) {
138  ss << KVSTRING(endpointAttachRequests, AttachEPRequestsToString(request.get_UserSyncRequest().endpointAttachRequests));
139  ss << KVSTRING(endpointDetachRequests, DetachEPRequestsToString(request.get_UserSyncRequest().endpointDetachRequests));
140  ss << KVSTRING(userAttachRequest, AttachUserRequestToString(request.get_UserSyncRequest().userAttachRequest));
141  } else {
142  ss << "null";
143  }
144  return ss.str();
145  }
146 
147  static std::string ConfigurationSyncResponseToString(const SyncResponse::configurationSyncResponse_t& response) {
148  std::ostringstream ss;
149  if (!response.is_null()) {
150  ss << KVSTRING(appStateSeqNumber, response.get_ConfigurationSyncResponse().appStateSeqNumber);
151  ss << KVSTRING(confDeltaBody,
152  (response.get_ConfigurationSyncResponse().confDeltaBody.is_null()
153  ? "null"
154  : ByteArrayToString(response.get_ConfigurationSyncResponse().confDeltaBody.get_bytes()))
155  );
156  ss << KVSTRING(confSchemaBody,
157  (response.get_ConfigurationSyncResponse().confSchemaBody.is_null()
158  ? "null"
159  : ByteArrayToString(response.get_ConfigurationSyncResponse().confSchemaBody.get_bytes()))
160  );
161  ss << KVSTRING(responseStatus, SyncResponseStatusToString(response.get_ConfigurationSyncResponse().responseStatus));
162  } else {
163  ss << "null";
164  }
165  return ss.str();
166  }
167 
168  static std::string ProfileSyncResponseToString(const SyncResponse::profileSyncResponse_t& response) {
169  std::ostringstream ss;
170  if (!response.is_null()) {
171  ss << KVSTRING(profileBody, SyncResponseStatusToString(response.get_ProfileSyncResponse().responseStatus));
172  } else {
173  ss << "null";
174  }
175  return ss.str();
176  }
177 
178  static std::string EventSyncResponseToString(const SyncResponse::eventSyncResponse_t& response) {
179  std::ostringstream ss;
180  if (!response.is_null()) {
181  ss << KVSTRING(events, IncomingEventsToString(response.get_EventSyncResponse().events));
182  ss << KVSTRING(eventListenersResponse, EventListenersResponseToString(response.get_EventSyncResponse().eventListenersResponses));
183  } else {
184  ss << "null";
185  }
186  return ss.str();
187  }
188 
189  static std::string NotificationSyncResponseToString(const SyncResponse::notificationSyncResponse_t& response) {
190  std::ostringstream ss;
191  if (!response.is_null()) {
192  ss << KVSTRING(responseStatus, SyncResponseStatusToString(response.get_NotificationSyncResponse().responseStatus)) << ", ";
193  ss << KVSTRING(appStateSeqNumber, response.get_NotificationSyncResponse().appStateSeqNumber) << ", ";
194  ss << KVSTRING(availableTopics, TopicsToString(response.get_NotificationSyncResponse().availableTopics)) << ", ";
195  ss << KVSTRING(notifications, NotificationToString(response.get_NotificationSyncResponse().notifications));
196  } else {
197  ss << "null";
198  }
199  return ss.str();
200  }
201 
202  static std::string AttachUserResponseToString(const UserSyncResponse::userAttachResponse_t& response) {
203  std::ostringstream ss;
204  if (!response.is_null()) {
205  ss << KVSTRING(result, RequestResultTypeToString(response.get_UserAttachResponse().result));
206  } else {
207  ss << "null";
208  }
209  return ss.str();
210  }
211 
212  static std::string UserSyncResponseToString(const SyncResponse::userSyncResponse_t& response) {
213  std::ostringstream ss;
214  if (!response.is_null()) {
215  ss << KVSTRING(endpointAttachResponses, AttachEPResponsesToString(response.get_UserSyncResponse().endpointAttachResponses));
216  ss << KVSTRING(endpointDetachResponses, DetachEPResponsesToString(response.get_UserSyncResponse().endpointDetachResponses));
217  ss << KVSTRING(userAttachResponse, AttachUserResponseToString(response.get_UserSyncResponse().userAttachResponse));
218  } else {
219  ss << "null";
220  }
221  return ss.str();
222  }
223 
224  static std::string RedirectSyncResponseToString(const SyncResponse::redirectSyncResponse_t& response) {
225  std::ostringstream ss;
226  if (!response.is_null()) {
227  ss << KVSTRING(dnsName, response.get_RedirectSyncResponse().dnsName);
228  } else {
229  ss << "null";
230  }
231  return ss.str();
232  }
233 
234 
235  static std::string OperationServerToString(const OperationsServer &ops) {
236  std::stringstream ss;
237  ss << "{ " << KVSTRING(name, ops.name)
238  << ", " << KVSTRING(priority, ops.priority)
239  << ", " << KVSTRING(publicKey, ByteArrayToString(ops.publicKey))
240  << ", " << KVSTRING(supportedChannels, SupportedChannelArrayToString(ops.supportedChannelsArray))
241  << "}";
242  return ss.str();
243  }
244 
245  static std::string OperationServerListToString(const OperationsServerList &opsList) {
246  std::stringstream ss;
247  ss << "[ ";
248  for (const OperationsServer& ops : opsList.operationsServerArray) {
249  ss << OperationServerToString(ops) << ", ";
250  }
251  ss << "]";
252  return ss.str();
253  }
254 
255  static std::string OperationServerArrayToString(const std::vector<OperationsServer > &opsList) {
256  std::stringstream ss;
257  ss << "[ ";
258  for (const OperationsServer& ops : opsList) {
259  ss << OperationServerToString(ops) << ", ";
260  }
261  ss << "]";
262  return ss.str();
263  }
264 
265  static std::string ChannelTypeToString(ChannelType type) {
266  switch (type) {
267  case ChannelType::HTTP:
268  return "HTTP";
269  case ChannelType::HTTP_LP:
270  return "HTTP_LP";
272  return "BOOTSTRAP";
273  case ChannelType::KAATCP:
274  return "KAATCP";
275  }
276  return "null";
277  }
278 
279  static std::string HTTPParametersToString(const SupportedChannel::communicationParameters_t& params) {
280  std::stringstream ss;
281  ss << "{ " << KVSTRING(hostName, params.get_HTTPComunicationParameters().hostName)
282  << ", " << KVSTRING(port, params.get_HTTPComunicationParameters().port)
283  << "}";
284  return ss.str();
285  }
286 
287  static std::string HTTPLPParametersToString(const SupportedChannel::communicationParameters_t& params) {
288  std::stringstream ss;
289  ss << "{ " << KVSTRING(hostName, params.get_HTTPLPComunicationParameters().hostName)
290  << ", " << KVSTRING(port, params.get_HTTPLPComunicationParameters().port)
291  << "}";
292  return ss.str();
293  }
294 
295  static std::string SupportedChannelToString(const SupportedChannel& supportedChannel) {
296  std::stringstream ss;
297  ss << "{ " << KVSTRING(channelType, ChannelTypeToString(supportedChannel.channelType))
298  << ", " << KVSTRING(communicationParameters,
299  (supportedChannel.channelType == ChannelType::HTTP
300  ? HTTPParametersToString(supportedChannel.communicationParameters)
301  : (supportedChannel.channelType == ChannelType::HTTP_LP
302  ? HTTPLPParametersToString(supportedChannel.communicationParameters)
303  : "null")
304  )
305  )
306  << "}";
307  return ss.str();
308  }
309 
310  static std::string SupportedChannelArrayToString(const std::vector<SupportedChannel > &supportedChannels) {
311  std::stringstream ss;
312  ss << "[ ";
313  for (const SupportedChannel& channel : supportedChannels) {
314  ss << SupportedChannelToString(channel) << ", ";
315  }
316  ss << "]";
317  return ss.str();
318  }
319 
320  static std::string ByteArrayToString(const std::uint8_t* vec, const size_t& length) {
321  std::stringstream ss;
322  ss << "[ ";
323  if (vec != nullptr && length > 0) {
324  for (size_t i = 0; i < length; ++i) {
325  ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << (int) *(vec + i) << " ";
326  }
327  }
328  ss << "]";
329  return ss.str();
330  }
331 
332  static std::string ByteArrayToString(const std::vector<std::uint8_t>& vec) {
333  return ByteArrayToString(vec.data(), vec.size());
334  }
335 
336  static std::string ByteArrayToString(const boost::shared_array<std::uint8_t>& vec, const size_t&length) {
337  return ByteArrayToString(vec.get(), length);
338  }
339 
340  static std::string ByteArrayToString(const SharedDataBuffer& buffer) {
341  return ByteArrayToString(buffer.first, buffer.second);
342  }
343 
344  static std::string ByteArrayToString(const std::string& data) {
345  return ByteArrayToString(reinterpret_cast<const std::uint8_t*>(data.data()), data.length());
346  }
347 
348  static std::string SyncResponseStatusToString(SyncResponseStatus status) {
349  std::string description;
350 
351  switch (status) {
352  case NO_DELTA: description = "NO_DELTA"; break;
353  case DELTA: description = "DELTA"; break;
354  case RESYNC: description = "RESYNC"; break;
355 // case CONF_RESYNC: description = "CONF_RESYNC"; break;
356 // case REDIRECT: description = "REDIRECT"; break;
357  default: description = "UNKNOWN"; break;
358  }
359 
360  return description;
361  }
362 
363  static std::string AcceptedUnicastNotificationsToString(const NotificationSyncRequest::acceptedUnicastNotifications_t& notifications) {
364  std::ostringstream stream;
365 
366  if (!notifications.is_null()) {
367  const auto& container = notifications.get_array();
368  stream << "[";
369  for (auto it = container.begin(); it != container.end(); ++it) {
370  stream << *it;
371  if ((it + 1) != container.end()) { stream << ", "; }
372  }
373  stream << "]";
374  } else {
375  stream << "null";
376  }
377 
378  return stream.str();
379  }
380 
381  static std::string TopicStatesToString(const NotificationSyncRequest::topicStates_t& states) {
382  std::ostringstream stream;
383 
384  if (!states.is_null()) {
385  const auto& container = states.get_array();
386  stream << "[";
387  for (auto it = container.begin(); it != container.end(); ++it) {
388  stream << "{id: " << it->topicId << ", sn: " << it->seqNumber << "}";
389  if ((it + 1) != container.end()) { stream << ", "; }
390  }
391  stream << "]";
392  } else {
393  stream << "null";
394  }
395 
396  return stream.str();
397  }
398 
399  static std::string SubscriptionCommandsToString(const NotificationSyncRequest::subscriptionCommands_t& commands) {
400  std::ostringstream stream;
401 
402  if (!commands.is_null()) {
403  const auto& container = commands.get_array();
404  stream << "[";
405  for (auto it = container.begin(); it != container.end(); ++it) {
406  stream << "{id: " << it->topicId << ", cmd: " << SubscriptionCommandToString(it->command) << "}";
407  if ((it + 1) != container.end()) { stream << ", "; }
408  }
409  stream << "]";
410  } else {
411  stream << "null";
412  }
413 
414  return stream.str();
415  }
416 
417  static std::string SubscriptionCommandToString(SubscriptionCommandType type) {
418  std::string description;
419 
420  switch (type) {
421  case ADD: description = "ADD"; break;
422  case REMOVE: description = "REMOVE"; break;
423  default: description = "UNKNOWN"; break;
424  }
425 
426  return description;
427  }
428 
429  static std::string SingleNotificationToString(const Notification& notification) {
430  std::ostringstream stream;
431  stream << "{";
432  stream << KVSTRING(id, notification.topicId) << ", ";
433  stream << KVSTRING(type, notification.type) << ", ";
434  stream << KVSTRING(sn, (notification.seqNumber.is_null() ? 0 : notification.seqNumber.get_int())) << ", ";
435  stream << KVSTRING(uid, (notification.uid.is_null() ? "null" : notification.uid.get_string()));
436  stream << "}";
437  return stream.str();
438  }
439 
440  static std::string NotificationToString(const NotificationSyncResponse::notifications_t& notifications) {
441  std::ostringstream stream;
442 
443  if (!notifications.is_null()) {
444  const auto& container = notifications.get_array();
445  stream << "[";
446  for (auto it = container.begin(); it != container.end(); ++it) {
447  stream << "{";
448  stream << KVSTRING(id, it->topicId) << ", ";
449  stream << KVSTRING(type, it->type) << ", ";
450  stream << KVSTRING(sn, (it->seqNumber.is_null() ? 0 : it->seqNumber.get_int())) << ", ";
451  stream << KVSTRING(uid, (it->uid.is_null() ? "null" : it->uid.get_string()));
452  stream << "}";
453  if ((it + 1) != container.end()) { stream << ", "; }
454  }
455  stream << "]";
456  } else {
457  stream << "null";
458  }
459 
460  return stream.str();
461  }
462 
463  static std::string NotificationTypeToString(NotificationType type) {
464  std::string description;
465 
466  switch (type) {
467  case SYSTEM: description = "SYSTEM"; break;
468  case CUSTOM: description = "CUSTOM"; break;
469  default: description = "UNKNOWN"; break;
470  }
471 
472  return description;
473  }
474 
475  static std::string TopicsToString(const NotificationSyncResponse::availableTopics_t& topics) {
476  std::ostringstream stream;
477 
478  if (!topics.is_null()) {
479  const auto& container = topics.get_array();
480  stream << "[";
481  for (auto it = container.begin(); it != container.end(); ++it) {
482  stream << "{id: " << it->id << ", type: " << TopicSubscriptionTypeToString(it->subscriptionType) << "}";
483  if ((it + 1) != container.end()) { stream << ", "; }
484  }
485  stream << "]";
486  } else {
487  stream << "null";
488  }
489 
490  return stream.str();
491  }
492 
493  static std::string TopicSubscriptionTypeToString(SubscriptionType type) {
494  std::string description;
495 
496  switch (type) {
497  case MANDATORY: description = "MANDATORY"; break;
498  case OPTIONAL: description = "OPTIONAL"; break;
499  default: description = "UNKNOWN"; break;
500  }
501 
502  return description;
503  }
504 
505  static std::string AttachEPRequestsToString(const UserSyncRequest::endpointAttachRequests_t& attachRequests) {
506  std::ostringstream stream;
507 
508  if (!attachRequests.is_null()) {
509  const auto& container = attachRequests.get_array();
510  stream << "[";
511  for (auto it = container.begin(); it != container.end(); ++it) {
512  stream << "{id: " << it->requestId << ", token: " << it->endpointAccessToken << "}";
513  if ((it + 1) != container.end()) { stream << ", "; }
514  }
515  stream << "]";
516  } else {
517  stream << "null";
518  }
519 
520  return stream.str();
521  }
522 
523  static std::string DetachEPRequestsToString(const UserSyncRequest::endpointDetachRequests_t& detachRequests) {
524  std::ostringstream stream;
525 
526  if (!detachRequests.is_null()) {
527  const auto& container = detachRequests.get_array();
528  stream << "[";
529  for (auto it = container.begin(); it != container.end(); ++it) {
530  stream << "{id: " << it->requestId << ", epHash: " << it->endpointKeyHash << "}";
531  if ((it + 1) != container.end()) { stream << ", "; }
532  }
533  stream << "]";
534  } else {
535  stream << "null";
536  }
537 
538  return stream.str();
539  }
540 
541  static std::string AttachEPResponsesToString(const UserSyncResponse::endpointAttachResponses_t& attachResponses) {
542  std::ostringstream stream;
543 
544  if (!attachResponses.is_null()) {
545  const auto& container = attachResponses.get_array();
546  stream << "[";
547  for (auto it = container.begin(); it != container.end(); ++it) {
548  stream << "{id: " << it->requestId << ", ";
549  stream << "token: " << (it->endpointKeyHash.is_null() ? "null" : it->endpointKeyHash.get_string()) << ", ";
550  stream << "type: " << RequestResultTypeToString(it->result) << "}";
551  if ((it + 1) != container.end()) { stream << ", "; }
552  }
553  stream << "]";
554  } else {
555  stream << "null";
556  }
557 
558  return stream.str();
559  }
560 
561  static std::string DetachEPResponsesToString(const UserSyncResponse::endpointDetachResponses_t& detachResponse) {
562  std::ostringstream stream;
563 
564  if (!detachResponse.is_null()) {
565  const auto& container = detachResponse.get_array();
566  stream << "[";
567  for (auto it = container.begin(); it != container.end(); ++it) {
568  stream << "{id: " << it->requestId << ", ";
569  stream << "epHash: " << RequestResultTypeToString(it->result) << "}";
570  if ((it + 1) != container.end()) { stream << ", "; }
571  }
572  stream << "]";
573  } else {
574  stream << "null";
575  }
576 
577  return stream.str();
578  }
579 
580  static std::string RequestResultTypeToString(SyncResponseResultType type) {
581  std::string description;
582 
583  switch (type) {
584  case SyncResponseResultType::SUCCESS: description = "SUCCESS"; break;
585  case SyncResponseResultType::FAILURE: description = "FAILURE"; break;
586  case SyncResponseResultType::REDIRECT: description = "REDIRECT"; break;
587  case SyncResponseResultType::PROFILE_RESYNC: description = "PROFILE_RESYNC"; break;
588  default: description = "UNKNOWN"; break;
589  }
590 
591  return description;
592  }
593 
594  static std::string EventFamilyVersionsToString(const EndpointVersionInfo::eventFamilyVersions_t& versions) {
595  std::ostringstream stream;
596 
597  if (!versions.is_null()) {
598  const auto& container = versions.get_array();
599  stream << "[";
600  for (auto it = container.begin(); it != container.end(); ++it) {
601  stream << "{name: " << it->name << ", ";
602  stream << "version: " << it->version << "}";
603  if ((it + 1) != container.end()) { stream << ", "; }
604  }
605  stream << "]";
606  } else {
607  stream << "null";
608  }
609 
610  return stream.str();
611  }
612 
613  static std::string OutcomingEventsToString(const EventSyncRequest::events_t& events) {
614  if (!events.is_null()) {
615  return EventsToString(events.get_array());
616  }
617  static std::string null("null");
618  return null;
619  }
620 
621  static std::string IncomingEventsToString(const EventSyncResponse::events_t& events) {
622  if (!events.is_null()) {
623  return EventsToString(events.get_array());
624  }
625  static std::string null("null");
626  return null;
627  }
628 
629  static std::string EventListenersRequestToString(const EventSyncRequest::eventListenersRequests_t& request) {
630  std::ostringstream stream;
631 
632  if (!request.is_null()) {
633  const auto& container = request.get_array();
634  stream << "[";
635  for (auto it = container.begin(); it != container.end(); ++it) {
636  stream << "{requestId: " << it->requestId << ", fqn's: [";
637  for (auto fqnIt = it->eventClassFQNs.begin(); fqnIt != it->eventClassFQNs.end(); ++fqnIt) {
638  stream << *fqnIt;
639  if ((fqnIt + 1) != it->eventClassFQNs.end()) { stream << ", "; }
640  }
641  stream << "]";
642  if ((it + 1) != container.end()) { stream << ", "; }
643  }
644  stream << "]";
645  } else {
646  stream << "null";
647  }
648 
649  return stream.str();
650  }
651 
652  static std::string EventListenersResponseToString(const EventSyncResponse::eventListenersResponses_t& response) {
653  std::ostringstream stream;
654 
655  if (!response.is_null()) {
656  const auto& container = response.get_array();
657  stream << "[";
658  for (auto it = container.begin(); it != container.end(); ++it) {
659  stream << "{requestId: " << it->requestId << ", ";
660  stream << "res: " << RequestResultTypeToString(it->result) << ", ";
661  stream << "listeners: [";
662 
663  if (!it->listeners.is_null()) {
664  const auto& listeners = it->listeners.get_array();
665 
666  for (auto listenerIt = listeners.begin(); listenerIt != listeners.end(); ++listenerIt) {
667  stream << *listenerIt;
668  if ((listenerIt + 1) != listeners.end()) { stream << ", "; }
669  }
670  }
671  stream << "]";
672  if ((it + 1) != container.end()) { stream << ", "; }
673  }
674  stream << "]";
675  } else {
676  stream << "null";
677  }
678 
679  return stream.str();
680  }
681 
682 
683  static std::string TransportTypeToString(TransportType type) {
684  std::string description;
685 
686  switch (type) {
687  case TransportType::BOOTSTRAP: description = "BOOTSTRAP"; break;
688  case TransportType::CONFIGURATION: description = "CONFIGURATION"; break;
689  case TransportType::EVENT: description = "EVENT"; break;
690  case TransportType::LOGGING: description = "LOGGING"; break;
691  case TransportType::NOTIFICATION: description = "NOTIFICATION"; break;
692  case TransportType::PROFILE: description = "PROFILE"; break;
693  case TransportType::USER: description = "USER"; break;
694  default: description = "UNKNOWN"; break;
695  }
696 
697  return description;
698  }
699 
700  static std::string LogSyncRequestToString(const SyncRequest::logSyncRequest_t& logSyncRequest) {
701  if (!logSyncRequest.is_null()) {
702  const auto& request = logSyncRequest.get_LogSyncRequest();
703  std::ostringstream stream;
704  std::string requestId = request.requestId.is_null() ? "null" : request.requestId.get_string();
705  size_t entriesCount = request.logEntries.is_null() ? 0 : request.logEntries.get_array().size();
706  stream << "{ requestId: " << requestId << ", logEntriesCount: " << entriesCount << "}";
707  return stream.str();
708  }
709  static std::string null("null");
710  return null;
711  }
712 
713  static std::string LogSyncResponseToString(const SyncResponse::logSyncResponse_t& logSyncResponse) {
714  if (!logSyncResponse.is_null()) {
715  std::ostringstream stream;
716  std::string requestId = logSyncResponse.get_LogSyncResponse().requestId;
717  std::string result = RequestResultTypeToString(logSyncResponse.get_LogSyncResponse().result);
718  stream << "{ requestId: " << requestId << ", result: " << result << "}";
719  return stream.str();
720  }
721  static std::string null("null");
722  return null;
723  }
724 
725 private:
726  static std::string EventsToString(const std::vector<Event>& events) {
727  std::ostringstream stream;
728  stream << "[";
729  for (auto it = events.begin(); it != events.end(); ++it) {
730  stream << "{fqn: " << it->eventClassFQN << ", ";
731  stream << "sn: " << it->seqNum << ", ";
732  stream << "data_size: " << it->eventData.size() << ", ";
733  stream << "source: " << (it->source.is_null() ? "null" : it->source.get_string()) << ", ";
734  stream << "target: " << (it->target.is_null() ? "null" : it->target.get_string()) << "}";
735  if ((it + 1) != events.end()) { stream << ", "; }
736  }
737  stream << "]";
738  return stream.str();
739  }
740 };
741 
742 } // namespace kaa
743 
744 
745 #endif /* LOGGINGUTILS_HPP_ */
static std::string LogSyncResponseToString(const SyncResponse::logSyncResponse_t &logSyncResponse)
static std::string DetachEPResponsesToString(const UserSyncResponse::endpointDetachResponses_t &detachResponse)
static std::string DetachEPRequestsToString(const UserSyncRequest::endpointDetachRequests_t &detachRequests)
static std::string RequestResultTypeToString(SyncResponseResultType type)
static std::string EventFamilyVersionsToString(const EndpointVersionInfo::eventFamilyVersions_t &versions)
static std::string UserSyncRequestToString(const SyncRequest::userSyncRequest_t &request)
static std::string HTTPLPParametersToString(const SupportedChannel::communicationParameters_t &params)
static std::string ByteArrayToString(const std::uint8_t *vec, const size_t &length)
static std::string IncomingEventsToString(const EventSyncResponse::events_t &events)
static std::string HTTPParametersToString(const SupportedChannel::communicationParameters_t &params)
static std::string OperationServerToString(const OperationsServer &ops)
static std::string AcceptedUnicastNotificationsToString(const NotificationSyncRequest::acceptedUnicastNotifications_t &notifications)
static std::string ChannelTypeToString(ChannelType type)
static std::string UserSyncResponseToString(const SyncResponse::userSyncResponse_t &response)
static std::string RedirectSyncResponseToString(const SyncResponse::redirectSyncResponse_t &response)
static std::string SubscriptionCommandToString(SubscriptionCommandType type)
static std::string SubscriptionCommandsToString(const NotificationSyncRequest::subscriptionCommands_t &commands)
static std::string NotificationSyncResponseToString(const SyncResponse::notificationSyncResponse_t &response)
static std::string ConfigurationSyncResponseToString(const SyncResponse::configurationSyncResponse_t &response)
static std::string ProfileSyncResponseToString(const SyncResponse::profileSyncResponse_t &response)
static std::string EventSyncResponseToString(const SyncResponse::eventSyncResponse_t &response)
static std::string SupportedChannelArrayToString(const std::vector< SupportedChannel > &supportedChannels)
static std::string ConfigurationSyncRequestToString(const SyncRequest::configurationSyncRequest_t &request)
static std::string ProfileSyncRequestToString(const SyncRequest::profileSyncRequest_t &request)
static std::string OperationServerArrayToString(const std::vector< OperationsServer > &opsList)
static std::string AttachUserResponseToString(const UserSyncResponse::userAttachResponse_t &response)
static std::string MetaDataSyncRequestToString(const SyncRequest::syncRequestMetaData_t &request)
static std::string NotificationSyncRequestToString(const SyncRequest::notificationSyncRequest_t &request)
static std::string SyncResponseStatusToString(SyncResponseStatus status)
static std::string ByteArrayToString(const boost::shared_array< std::uint8_t > &vec, const size_t &length)
static std::string NotificationToString(const NotificationSyncResponse::notifications_t &notifications)
static std::string EventSyncRequestToString(const SyncRequest::eventSyncRequest_t &request)
static std::string SupportedChannelToString(const SupportedChannel &supportedChannel)
#define KVSTRING(K, V)
static std::string LogSyncRequestToString(const SyncRequest::logSyncRequest_t &logSyncRequest)
static std::string ByteArrayToString(const std::vector< std::uint8_t > &vec)
static std::string TopicStatesToString(const NotificationSyncRequest::topicStates_t &states)
static std::string TopicsToString(const NotificationSyncResponse::availableTopics_t &topics)
static std::string NotificationTypeToString(NotificationType type)
static std::string SingleNotificationToString(const Notification &notification)
static std::string TopicSubscriptionTypeToString(SubscriptionType type)
static std::string OperationServerListToString(const OperationsServerList &opsList)
static std::string TransportTypeToString(TransportType type)
static std::string AttachEPResponsesToString(const UserSyncResponse::endpointAttachResponses_t &attachResponses)
static std::string ByteArrayToString(const SharedDataBuffer &buffer)
std::pair< boost::shared_array< std::uint8_t >, std::uint32_t > SharedDataBuffer
static std::string ByteArrayToString(const std::string &data)
static std::string AttachEPRequestsToString(const UserSyncRequest::endpointAttachRequests_t &attachRequests)
static std::string EventListenersResponseToString(const EventSyncResponse::eventListenersResponses_t &response)
static std::string AttachUserRequestToString(const UserSyncRequest::userAttachRequest_t &request)
static std::string EventListenersRequestToString(const EventSyncRequest::eventListenersRequests_t &request)
static std::string OutcomingEventsToString(const EventSyncRequest::events_t &events)