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