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