client-cpp  0.7.4
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  const auto profileRequest = request.get_ProfileSyncRequest();
105 
106  if (!request.get_ProfileSyncRequest().endpointAccessToken.is_null()) {
107  ss << KVSTRING(endpointAccessToken, profileRequest.endpointAccessToken.get_string());
108  } else {
109  ss << KVSTRING(endpointAccessToken, "null");
110  }
111  if (!profileRequest.endpointPublicKey.is_null()) {
112  ss << KVSTRING(endpointPublicKey, ByteArrayToString(profileRequest.endpointPublicKey.get_bytes()));
113  } else {
114  ss << KVSTRING(endpointPublicKey, "null");
115  }
116 
117  ss << KVSTRING(profileBody, ByteArrayToString(profileRequest.profileBody));
118  } else {
119  ss << "null";
120  }
121  return ss.str();
122  }
123 
124  static std::string MetaDataSyncRequestToString(const SyncRequest::syncRequestMetaData_t& request) {
125  std::ostringstream ss;
126  if (!request.is_null()) {
127  const auto& syncRequest = request.get_SyncRequestMetaData();
128 
129  ss << KVSTRING(sdkToken, syncRequest.sdkToken) << ", ";
130 
131  if (syncRequest.endpointPublicKeyHash.is_null()) {
132  ss << KVSTRING(endpointPublicKeyHash, "null") << ",";
133  } else {
134  ss << KVSTRING(endpointPublicKeyHash, ByteArrayToString(syncRequest.endpointPublicKeyHash.get_bytes())) << ",";
135  }
136 
137  if (syncRequest.profileHash.is_null()) {
138  ss << KVSTRING(profileHash, "null") << ",";
139  } else {
140  ss << KVSTRING(profileHash, ByteArrayToString(syncRequest.profileHash.get_bytes())) << ",";
141  }
142 
143  if (syncRequest.timeout.is_null()) {
144  ss << KVSTRING(timeout, "null") << ",";
145  } else {
146  ss << KVSTRING(timeout, syncRequest.timeout.get_long()) << ",";
147  }
148  } else {
149  ss << "null";
150  }
151  return ss.str();
152  }
153 
154  static std::string EventSyncRequestToString(const SyncRequest::eventSyncRequest_t& request) {
155  std::ostringstream ss;
156  if (!request.is_null()) {
157  ss << KVSTRING(events, OutcomingEventsToString(request.get_EventSyncRequest().events));
158  ss << KVSTRING(eventListenersRequest, EventListenersRequestToString(request.get_EventSyncRequest().eventListenersRequests));
159  } else {
160  ss << "null";
161  }
162  return ss.str();
163  }
164 
165  static std::string AttachUserRequestToString(const UserSyncRequest::userAttachRequest_t& request) {
166  std::ostringstream ss;
167  if (!request.is_null()) {
168  ss << KVSTRING(userAccessToken, request.get_UserAttachRequest().userAccessToken);
169  ss << KVSTRING(userExternalId, request.get_UserAttachRequest().userExternalId);
170  } else {
171  ss << "null";
172  }
173  return ss.str();
174  }
175 
176  static std::string UserSyncRequestToString(const SyncRequest::userSyncRequest_t& request) {
177  std::ostringstream ss;
178  if (!request.is_null()) {
179  ss << KVSTRING(endpointAttachRequests, AttachEPRequestsToString(request.get_UserSyncRequest().endpointAttachRequests));
180  ss << KVSTRING(endpointDetachRequests, DetachEPRequestsToString(request.get_UserSyncRequest().endpointDetachRequests));
181  ss << KVSTRING(userAttachRequest, AttachUserRequestToString(request.get_UserSyncRequest().userAttachRequest));
182  } else {
183  ss << "null";
184  }
185  return ss.str();
186  }
187 
188  static std::string ConfigurationSyncResponseToString(const SyncResponse::configurationSyncResponse_t& response) {
189  std::ostringstream ss;
190  if (!response.is_null()) {
191  ss << KVSTRING(appStateSeqNumber, response.get_ConfigurationSyncResponse().appStateSeqNumber);
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(appStateSeqNumber, response.get_NotificationSyncResponse().appStateSeqNumber) << ", ";
265  ss << KVSTRING(availableTopics, TopicsToString(response.get_NotificationSyncResponse().availableTopics)) << ", ";
266  ss << KVSTRING(notifications, NotificationToString(response.get_NotificationSyncResponse().notifications));
267  } else {
268  ss << "null";
269  }
270  return ss.str();
271  }
272 
273  static std::string AttachUserResponseToString(const UserSyncResponse::userAttachResponse_t& response) {
274  std::ostringstream ss;
275  if (!response.is_null()) {
276  ss << KVSTRING(result, SyncResponseResultTypeToString(response.get_UserAttachResponse().result));
277  } else {
278  ss << "null";
279  }
280  return ss.str();
281  }
282 
283  static std::string DetachUserNotificationToString(const UserSyncResponse::userDetachNotification_t& response) {
284  std::ostringstream ss;
285  if (!response.is_null()) {
286  ss << KVSTRING(accessToken, response.get_UserDetachNotification().endpointAccessToken);
287  } else {
288  ss << "null";
289  }
290  return ss.str();
291  }
292 
293  static std::string UserSyncResponseToString(const SyncResponse::userSyncResponse_t& response) {
294  std::ostringstream ss;
295  if (!response.is_null()) {
296  ss << KVSTRING(endpointAttachResponses, AttachEPResponsesToString(response.get_UserSyncResponse().endpointAttachResponses));
297  ss << KVSTRING(endpointDetachResponses, DetachEPResponsesToString(response.get_UserSyncResponse().endpointDetachResponses));
298  ss << KVSTRING(userAttachResponse, AttachUserResponseToString(response.get_UserSyncResponse().userAttachResponse));
299  ss << KVSTRING(userDetachNotification, DetachUserNotificationToString(response.get_UserSyncResponse().userDetachNotification));
300  } else {
301  ss << "null";
302  }
303  return ss.str();
304  }
305 
306  static std::string RedirectSyncResponseToString(const SyncResponse::redirectSyncResponse_t& response) {
307  std::ostringstream ss;
308  if (!response.is_null()) {
309  ss << std::hex << "accessPointId: 0x" << response.get_RedirectSyncResponse().accessPointId;
310  } else {
311  ss << "null";
312  }
313  return ss.str();
314  }
315 
316  static std::string TransportProtocolIdToString(const TransportProtocolId& protocolId) {
317  std::ostringstream ss;
318  ss << "(protocol: id=0x" << std::hex << protocolId.getId() << ", version=" << std::dec << protocolId.getVersion() << ")";
319  return ss.str();
320  }
321 
322  static std::string ByteArrayToString(const std::uint8_t* vec, const size_t& length) {
323  std::ostringstream ss;
324  ss << "[ ";
325  if (vec != nullptr && length > 0) {
326  for (size_t i = 0; i < length; ++i) {
327  ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << (int) *(vec + i) << " ";
328  }
329  }
330  ss << "]";
331  return ss.str();
332  }
333 
334  static std::string ByteArrayToString(const std::vector<std::uint8_t>& vec) {
335  return ByteArrayToString(vec.data(), vec.size());
336  }
337 
338  static std::string ByteArrayToString(const boost::shared_array<std::uint8_t>& vec, const size_t&length) {
339  return ByteArrayToString(vec.get(), length);
340  }
341 
342  static std::string ByteArrayToString(const SharedDataBuffer& buffer) {
343  return ByteArrayToString(buffer.first, buffer.second);
344  }
345 
346  static std::string ByteArrayToString(const std::string& data) {
347  return ByteArrayToString(reinterpret_cast<const std::uint8_t*>(data.data()), data.length());
348  }
349 
350  static std::string SyncResponseStatusToString(SyncResponseStatus status) {
351  std::string description;
352 
353  switch (status) {
354  case NO_DELTA: description = "NO_DELTA"; break;
355  case DELTA: description = "DELTA"; break;
356  case RESYNC: description = "RESYNC"; 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_SUBSCRIPTION: description = "MANDATORY_SUBSCRIPTION"; break;
498  case OPTIONAL_SUBSCRIPTION: description = "OPTIONAL_SUBSCRIPTION"; 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: " << SyncResponseResultTypeToString(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: " << SyncResponseResultTypeToString(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 SyncResponseResultTypeToString(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 OutcomingEventsToString(const EventSyncRequest::events_t& events) {
595  if (!events.is_null()) {
596  return EventsToString(events.get_array());
597  }
598  static std::string null("null");
599  return null;
600  }
601 
602  static std::string IncomingEventsToString(const EventSyncResponse::events_t& events) {
603  if (!events.is_null()) {
604  return EventsToString(events.get_array());
605  }
606  static std::string null("null");
607  return null;
608  }
609 
610  static std::string EventListenersRequestToString(const EventSyncRequest::eventListenersRequests_t& request) {
611  std::ostringstream stream;
612 
613  if (!request.is_null()) {
614  const auto& container = request.get_array();
615  stream << "[";
616  for (auto it = container.begin(); it != container.end(); ++it) {
617  stream << "{requestId: " << it->requestId << ", fqn's: [";
618  for (auto fqnIt = it->eventClassFQNs.begin(); fqnIt != it->eventClassFQNs.end(); ++fqnIt) {
619  stream << *fqnIt;
620  if ((fqnIt + 1) != it->eventClassFQNs.end()) { stream << ", "; }
621  }
622  stream << "]";
623  if ((it + 1) != container.end()) { stream << ", "; }
624  }
625  stream << "]";
626  } else {
627  stream << "null";
628  }
629 
630  return stream.str();
631  }
632 
633  static std::string EventListenersResponseToString(const EventSyncResponse::eventListenersResponses_t& response) {
634  std::ostringstream stream;
635 
636  if (!response.is_null()) {
637  const auto& container = response.get_array();
638  stream << "[";
639  for (auto it = container.begin(); it != container.end(); ++it) {
640  stream << "{requestId: " << it->requestId << ", ";
641  stream << "res: " << SyncResponseResultTypeToString(it->result) << ", ";
642  stream << "listeners: [";
643 
644  if (!it->listeners.is_null()) {
645  const auto& listeners = it->listeners.get_array();
646 
647  for (auto listenerIt = listeners.begin(); listenerIt != listeners.end(); ++listenerIt) {
648  stream << *listenerIt;
649  if ((listenerIt + 1) != listeners.end()) { stream << ", "; }
650  }
651  }
652  stream << "]";
653  if ((it + 1) != container.end()) { stream << ", "; }
654  }
655  stream << "]";
656  } else {
657  stream << "null";
658  }
659 
660  return stream.str();
661  }
662 
663  static std::string EventSequenceNumberResponseToString(const EventSyncResponse::eventSequenceNumberResponse_t& response) {
664  std::ostringstream ss;
665  if (!response.is_null()) {
666  ss << KVSTRING(sequenceNumber, response.get_EventSequenceNumberResponse().seqNum);
667  } else {
668  ss << "null";
669  }
670  return ss.str();
671  }
672 
673  static std::string TransportTypeToString(TransportType type) {
674  std::string description;
675 
676  switch (type) {
677  case TransportType::BOOTSTRAP: description = "BOOTSTRAP"; break;
678  case TransportType::CONFIGURATION: description = "CONFIGURATION"; break;
679  case TransportType::EVENT: description = "EVENT"; break;
680  case TransportType::LOGGING: description = "LOGGING"; break;
681  case TransportType::NOTIFICATION: description = "NOTIFICATION"; break;
682  case TransportType::PROFILE: description = "PROFILE"; break;
683  case TransportType::USER: description = "USER"; break;
684  default: description = "UNKNOWN"; break;
685  }
686 
687  return description;
688  }
689 
690  static std::string LogSyncRequestToString(const SyncRequest::logSyncRequest_t& logSyncRequest) {
691  if (!logSyncRequest.is_null()) {
692  const auto& request = logSyncRequest.get_LogSyncRequest();
693  std::ostringstream stream;
694  size_t entriesCount = request.logEntries.is_null() ? 0 : request.logEntries.get_array().size();
695  stream << "{ requestId: " << request.requestId << ", logEntriesCount: " << entriesCount << "}";
696  return stream.str();
697  }
698  static std::string null("null");
699  return null;
700  }
701 
702  static std::string LogSyncResponseToString(const SyncResponse::logSyncResponse_t& logSyncResponse) {
703  if (!logSyncResponse.is_null()) {
704  const auto& syncResponse = logSyncResponse.get_LogSyncResponse();
705  if (!syncResponse.deliveryStatuses.is_null()) {
706  const auto& deliveryStatuses = syncResponse.deliveryStatuses.get_array();
707  std::ostringstream stream;
708  for (size_t i = 0; i < deliveryStatuses.size(); ++i) {
709  if (i > 0) {
710  stream << ",";
711  }
712 
713  stream << "{ requestId: " << deliveryStatuses[i].requestId
714  << ", result: " << SyncResponseResultTypeToString(deliveryStatuses[i].result)
715  << ", code: " << (deliveryStatuses[i].errorCode.is_null() ? "null" :
716  LogDeliveryErrorCodeToString(deliveryStatuses[i].errorCode.get_LogDeliveryErrorCode())) << "}";
717  }
718  return stream.str();
719  }
720  }
721  static std::string null("null");
722  return null;
723  }
724 
725  static std::string LogDeliveryErrorCodeToString(LogDeliveryErrorCode code) {
726  std::string result;
727  switch (code) {
728  case LogDeliveryErrorCode::NO_APPENDERS_CONFIGURED:
729  result = "NO_APPENDERS_CONFIGURED";
730  break;
731  case LogDeliveryErrorCode::APPENDER_INTERNAL_ERROR:
732  result = "APPENDER_INTERNAL_ERROR";
733  break;
734  case LogDeliveryErrorCode::REMOTE_CONNECTION_ERROR:
735  result = "REMOTE_CONNECTION_ERROR";
736  break;
737  case LogDeliveryErrorCode::REMOTE_INTERNAL_ERROR:
738  result = "REMOTE_INTERNAL_ERROR";
739  break;
740  default:
741  result = "UNKNOWN";
742  break;
743  }
744  return result;
745  }
746 
747 private:
748  static std::string EventsToString(const std::vector<Event>& events) {
749  std::ostringstream stream;
750  stream << "[";
751  for (auto it = events.begin(); it != events.end(); ++it) {
752  stream << "{fqn: " << it->eventClassFQN << ", ";
753  stream << "sn: " << it->seqNum << ", ";
754  stream << "data_size: " << it->eventData.size() << ", ";
755  stream << "source: " << (it->source.is_null() ? "null" : it->source.get_string()) << ", ";
756  stream << "target: " << (it->target.is_null() ? "null" : it->target.get_string()) << "}";
757  if ((it + 1) != events.end()) { stream << ", "; }
758  }
759  stream << "]";
760  return stream.str();
761  }
762 };
763 
764 } // namespace kaa
765 
766 
767 #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)