17 #ifndef LOGGINGUTILS_HPP_
18 #define LOGGINGUTILS_HPP_
26 #include <boost/shared_array.hpp>
28 #include "kaa/gen/EndpointGen.hpp"
34 #define KVSTRING(K,V) "\"" #K "\": \"" << V << "\""
39 std::ostringstream ss;
40 if (!request.is_null()) {
41 ss <<
KVSTRING(appStateSeqNumber, request.get_NotificationSyncRequest().appStateSeqNumber) <<
", ";
42 ss <<
KVSTRING(acceptedUnicastNotifications,
46 ss <<
KVSTRING(topicListHash, (request.get_NotificationSyncRequest().topicListHash.is_null() ?
"null" :
47 ByteArrayToString(request.get_NotificationSyncRequest().topicListHash.get_bytes())));
55 std::ostringstream ss;
56 if (!request.is_null()) {
57 ss <<
KVSTRING(appStateSeqNumber, request.get_ConfigurationSyncRequest().appStateSeqNumber);
59 (request.get_ConfigurationSyncRequest().configurationHash.is_null() ?
"null" :
ByteArrayToString(request.get_ConfigurationSyncRequest().configurationHash.get_bytes())));
67 std::ostringstream ss;
69 ss <<
"[" << std::hex <<
"id=0x" << protocolVersion.id << std::dec <<
",";
70 ss <<
KVSTRING(version, protocolVersion.version) <<
"]";
76 std::ostringstream ss;
77 if (!request.is_null()) {
78 const auto& syncRequest = request.get_BootstrapSyncRequest();
79 ss <<
KVSTRING(requestId, syncRequest.requestId) <<
",";
82 const auto& protocols = syncRequest.supportedProtocols;
83 size_t protocolCount = protocols.size();
85 if (protocolCount > 0) {
86 for (
const auto& protocol : protocols) {
88 if (--protocolCount > 0) {
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());
107 ss <<
KVSTRING(endpointAccessToken,
"null");
109 if (!request.get_ProfileSyncRequest().endpointPublicKey.is_null()) {
112 ss <<
KVSTRING(endpointPublicKey,
"null");
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);
131 std::ostringstream ss;
132 if (!request.is_null()) {
133 const auto& syncRequest = request.get_SyncRequestMetaData();
135 ss <<
KVSTRING(applicationToken, syncRequest.applicationToken) <<
", ";
137 if (syncRequest.endpointPublicKeyHash.is_null()) {
138 ss <<
KVSTRING(endpointPublicKeyHash,
"null") <<
",";
143 if (syncRequest.profileHash.is_null()) {
144 ss <<
KVSTRING(profileHash,
"null") <<
",";
149 if (syncRequest.timeout.is_null()) {
150 ss <<
KVSTRING(timeout,
"null") <<
",";
152 ss <<
KVSTRING(timeout, syncRequest.timeout.get_long()) <<
",";
161 std::ostringstream ss;
162 if (!request.is_null()) {
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);
183 std::ostringstream ss;
184 if (!request.is_null()) {
195 std::ostringstream ss;
196 if (!response.is_null()) {
197 ss <<
KVSTRING(appStateSeqNumber, response.get_ConfigurationSyncResponse().appStateSeqNumber);
199 (response.get_ConfigurationSyncResponse().confDeltaBody.is_null()
201 :
ByteArrayToString(response.get_ConfigurationSyncResponse().confDeltaBody.get_bytes()))
204 (response.get_ConfigurationSyncResponse().confSchemaBody.is_null()
206 :
ByteArrayToString(response.get_ConfigurationSyncResponse().confSchemaBody.get_bytes()))
216 std::ostringstream ss;
217 if (!response.is_null()) {
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();
232 ss <<
KVSTRING(requestId, bootstrapSync.requestId) <<
", ";
233 ss <<
"supportedChannels: ";
235 if (supportedChannelCount > 0) {
236 for (
const auto& supportedChannel : supportedChannels) {
237 ss <<
"[" << std::hex <<
"accessPointId=0x" << supportedChannel.accessPointId << std::dec <<
",";
239 ss <<
KVSTRING(connectionInfoLen, supportedChannel.connectionInfo.size()) <<
"]";
241 if (--supportedChannelCount > 0) {
255 std::ostringstream ss;
256 if (!response.is_null()) {
267 std::ostringstream ss;
268 if (!response.is_null()) {
270 ss <<
KVSTRING(appStateSeqNumber, response.get_NotificationSyncResponse().appStateSeqNumber) <<
", ";
271 ss <<
KVSTRING(availableTopics,
TopicsToString(response.get_NotificationSyncResponse().availableTopics)) <<
", ";
280 std::ostringstream ss;
281 if (!response.is_null()) {
290 std::ostringstream ss;
291 if (!response.is_null()) {
292 ss <<
KVSTRING(accessToken, response.get_UserDetachNotification().endpointAccessToken);
300 std::ostringstream ss;
301 if (!response.is_null()) {
313 std::ostringstream ss;
314 if (!response.is_null()) {
315 ss << std::hex <<
"accessPointId: 0x" << response.get_RedirectSyncResponse().accessPointId;
323 std::ostringstream ss;
324 ss <<
"(protocol: id=0x" << std::hex << protocolId.
getId() <<
", version=" << std::dec << protocolId.
getVersion() <<
")";
329 std::ostringstream 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) <<
" ";
344 static std::string
ByteArrayToString(
const boost::shared_array<std::uint8_t>& vec,
const size_t&length) {
353 return ByteArrayToString(reinterpret_cast<const std::uint8_t*>(data.data()), data.length());
357 std::string description;
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;
370 std::ostringstream stream;
372 if (!notifications.is_null()) {
373 const auto& container = notifications.get_array();
375 for (
auto it = container.begin(); it != container.end(); ++it) {
377 if ((it + 1) != container.end()) { stream <<
", "; }
388 std::ostringstream stream;
390 if (!states.is_null()) {
391 const auto& container = states.get_array();
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 <<
", "; }
406 std::ostringstream stream;
408 if (!commands.is_null()) {
409 const auto& container = commands.get_array();
411 for (
auto it = container.begin(); it != container.end(); ++it) {
413 if ((it + 1) != container.end()) { stream <<
", "; }
424 std::string description;
427 case ADD: description =
"ADD";
break;
428 case REMOVE: description =
"REMOVE";
break;
429 default: description =
"UNKNOWN";
break;
436 std::ostringstream 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()));
447 std::ostringstream stream;
449 if (!notifications.is_null()) {
450 const auto& container = notifications.get_array();
452 for (
auto it = container.begin(); it != container.end(); ++it) {
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()));
459 if ((it + 1) != container.end()) { stream <<
", "; }
470 std::string description;
473 case SYSTEM: description =
"SYSTEM";
break;
474 case CUSTOM: description =
"CUSTOM";
break;
475 default: description =
"UNKNOWN";
break;
481 static std::string
TopicsToString(
const NotificationSyncResponse::availableTopics_t& topics) {
482 std::ostringstream stream;
484 if (!topics.is_null()) {
485 const auto& container = topics.get_array();
487 for (
auto it = container.begin(); it != container.end(); ++it) {
489 if ((it + 1) != container.end()) { stream <<
", "; }
500 std::string description;
503 case MANDATORY: description =
"MANDATORY";
break;
504 case OPTIONAL: description =
"OPTIONAL";
break;
505 default: description =
"UNKNOWN";
break;
512 std::ostringstream stream;
514 if (!attachRequests.is_null()) {
515 const auto& container = attachRequests.get_array();
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 <<
", "; }
530 std::ostringstream stream;
532 if (!detachRequests.is_null()) {
533 const auto& container = detachRequests.get_array();
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 <<
", "; }
548 std::ostringstream stream;
550 if (!attachResponses.is_null()) {
551 const auto& container = attachResponses.get_array();
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()) <<
", ";
557 if ((it + 1) != container.end()) { stream <<
", "; }
568 std::ostringstream stream;
570 if (!detachResponse.is_null()) {
571 const auto& container = detachResponse.get_array();
573 for (
auto it = container.begin(); it != container.end(); ++it) {
574 stream <<
"{id: " << it->requestId <<
", ";
576 if ((it + 1) != container.end()) { stream <<
", "; }
587 std::string description;
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;
601 std::ostringstream stream;
603 if (!versions.is_null()) {
604 const auto& container = versions.get_array();
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 <<
", "; }
620 if (!events.is_null()) {
621 return EventsToString(events.get_array());
623 static std::string null(
"null");
628 if (!events.is_null()) {
629 return EventsToString(events.get_array());
631 static std::string null(
"null");
636 std::ostringstream stream;
638 if (!request.is_null()) {
639 const auto& container = request.get_array();
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) {
645 if ((fqnIt + 1) != it->eventClassFQNs.end()) { stream <<
", "; }
648 if ((it + 1) != container.end()) { stream <<
", "; }
659 std::ostringstream stream;
661 if (!response.is_null()) {
662 const auto& container = response.get_array();
664 for (
auto it = container.begin(); it != container.end(); ++it) {
665 stream <<
"{requestId: " << it->requestId <<
", ";
667 stream <<
"listeners: [";
669 if (!it->listeners.is_null()) {
670 const auto& listeners = it->listeners.get_array();
672 for (
auto listenerIt = listeners.begin(); listenerIt != listeners.end(); ++listenerIt) {
673 stream << *listenerIt;
674 if ((listenerIt + 1) != listeners.end()) { stream <<
", "; }
678 if ((it + 1) != container.end()) { stream <<
", "; }
689 std::ostringstream ss;
690 if (!response.is_null()) {
691 ss <<
KVSTRING(sequenceNumber, response.get_EventSequenceNumberResponse().seqNum);
699 std::string description;
709 default: description =
"UNKNOWN";
break;
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 <<
"}";
723 static std::string null(
"null");
728 if (!logSyncResponse.is_null()) {
729 std::ostringstream stream;
731 stream <<
"{ requestId: " << logSyncResponse.get_LogSyncResponse().requestId <<
", result: " << result <<
"}";
734 static std::string null(
"null");
739 static std::string EventsToString(
const std::vector<Event>& events) {
740 std::ostringstream 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 <<
", "; }
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 ¬ifications)
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 ¬ifications)
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)
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 ¬ification)
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)