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 const auto profileRequest = request.get_ProfileSyncRequest();
106 if (!request.get_ProfileSyncRequest().endpointAccessToken.is_null()) {
107 ss <<
KVSTRING(endpointAccessToken, profileRequest.endpointAccessToken.get_string());
109 ss <<
KVSTRING(endpointAccessToken,
"null");
111 if (!profileRequest.endpointPublicKey.is_null()) {
114 ss <<
KVSTRING(endpointPublicKey,
"null");
125 std::ostringstream ss;
126 if (!request.is_null()) {
127 const auto& syncRequest = request.get_SyncRequestMetaData();
129 ss <<
KVSTRING(sdkToken, syncRequest.sdkToken) <<
", ";
131 if (syncRequest.endpointPublicKeyHash.is_null()) {
132 ss <<
KVSTRING(endpointPublicKeyHash,
"null") <<
",";
137 if (syncRequest.profileHash.is_null()) {
138 ss <<
KVSTRING(profileHash,
"null") <<
",";
143 if (syncRequest.timeout.is_null()) {
144 ss <<
KVSTRING(timeout,
"null") <<
",";
146 ss <<
KVSTRING(timeout, syncRequest.timeout.get_long()) <<
",";
155 std::ostringstream ss;
156 if (!request.is_null()) {
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);
177 std::ostringstream ss;
178 if (!request.is_null()) {
189 std::ostringstream ss;
190 if (!response.is_null()) {
191 ss <<
KVSTRING(appStateSeqNumber, response.get_ConfigurationSyncResponse().appStateSeqNumber);
193 (response.get_ConfigurationSyncResponse().confDeltaBody.is_null()
195 :
ByteArrayToString(response.get_ConfigurationSyncResponse().confDeltaBody.get_bytes()))
198 (response.get_ConfigurationSyncResponse().confSchemaBody.is_null()
200 :
ByteArrayToString(response.get_ConfigurationSyncResponse().confSchemaBody.get_bytes()))
210 std::ostringstream ss;
211 if (!response.is_null()) {
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();
226 ss <<
KVSTRING(requestId, bootstrapSync.requestId) <<
", ";
227 ss <<
"supportedChannels: ";
229 if (supportedChannelCount > 0) {
230 for (
const auto& supportedChannel : supportedChannels) {
231 ss <<
"[" << std::hex <<
"accessPointId=0x" << supportedChannel.accessPointId << std::dec <<
",";
233 ss <<
KVSTRING(connectionInfoLen, supportedChannel.connectionInfo.size()) <<
"]";
235 if (--supportedChannelCount > 0) {
249 std::ostringstream ss;
250 if (!response.is_null()) {
261 std::ostringstream ss;
262 if (!response.is_null()) {
264 ss <<
KVSTRING(appStateSeqNumber, response.get_NotificationSyncResponse().appStateSeqNumber) <<
", ";
265 ss <<
KVSTRING(availableTopics,
TopicsToString(response.get_NotificationSyncResponse().availableTopics)) <<
", ";
274 std::ostringstream ss;
275 if (!response.is_null()) {
284 std::ostringstream ss;
285 if (!response.is_null()) {
286 ss <<
KVSTRING(accessToken, response.get_UserDetachNotification().endpointAccessToken);
294 std::ostringstream ss;
295 if (!response.is_null()) {
307 std::ostringstream ss;
308 if (!response.is_null()) {
309 ss << std::hex <<
"accessPointId: 0x" << response.get_RedirectSyncResponse().accessPointId;
317 std::ostringstream ss;
318 ss <<
"(protocol: id=0x" << std::hex << protocolId.
getId() <<
", version=" << std::dec << protocolId.
getVersion() <<
")";
323 std::ostringstream 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) <<
" ";
338 static std::string
ByteArrayToString(
const boost::shared_array<std::uint8_t>& vec,
const size_t&length) {
347 return ByteArrayToString(reinterpret_cast<const std::uint8_t*>(data.data()), data.length());
351 std::string description;
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;
364 std::ostringstream stream;
366 if (!notifications.is_null()) {
367 const auto& container = notifications.get_array();
369 for (
auto it = container.begin(); it != container.end(); ++it) {
371 if ((it + 1) != container.end()) { stream <<
", "; }
382 std::ostringstream stream;
384 if (!states.is_null()) {
385 const auto& container = states.get_array();
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 <<
", "; }
400 std::ostringstream stream;
402 if (!commands.is_null()) {
403 const auto& container = commands.get_array();
405 for (
auto it = container.begin(); it != container.end(); ++it) {
407 if ((it + 1) != container.end()) { stream <<
", "; }
418 std::string description;
421 case ADD: description =
"ADD";
break;
422 case REMOVE: description =
"REMOVE";
break;
423 default: description =
"UNKNOWN";
break;
430 std::ostringstream 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()));
441 std::ostringstream stream;
443 if (!notifications.is_null()) {
444 const auto& container = notifications.get_array();
446 for (
auto it = container.begin(); it != container.end(); ++it) {
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()));
453 if ((it + 1) != container.end()) { stream <<
", "; }
464 std::string description;
467 case SYSTEM: description =
"SYSTEM";
break;
468 case CUSTOM: description =
"CUSTOM";
break;
469 default: description =
"UNKNOWN";
break;
475 static std::string
TopicsToString(
const NotificationSyncResponse::availableTopics_t& topics) {
476 std::ostringstream stream;
478 if (!topics.is_null()) {
479 const auto& container = topics.get_array();
481 for (
auto it = container.begin(); it != container.end(); ++it) {
483 if ((it + 1) != container.end()) { stream <<
", "; }
494 std::string description;
497 case MANDATORY_SUBSCRIPTION: description =
"MANDATORY_SUBSCRIPTION";
break;
498 case OPTIONAL_SUBSCRIPTION: description =
"OPTIONAL_SUBSCRIPTION";
break;
499 default: description =
"UNKNOWN";
break;
506 std::ostringstream stream;
508 if (!attachRequests.is_null()) {
509 const auto& container = attachRequests.get_array();
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 <<
", "; }
524 std::ostringstream stream;
526 if (!detachRequests.is_null()) {
527 const auto& container = detachRequests.get_array();
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 <<
", "; }
542 std::ostringstream stream;
544 if (!attachResponses.is_null()) {
545 const auto& container = attachResponses.get_array();
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()) <<
", ";
551 if ((it + 1) != container.end()) { stream <<
", "; }
562 std::ostringstream stream;
564 if (!detachResponse.is_null()) {
565 const auto& container = detachResponse.get_array();
567 for (
auto it = container.begin(); it != container.end(); ++it) {
568 stream <<
"{id: " << it->requestId <<
", ";
570 if ((it + 1) != container.end()) { stream <<
", "; }
581 std::string description;
587 case SyncResponseResultType::PROFILE_RESYNC: description =
"PROFILE_RESYNC";
break;
588 default: description =
"UNKNOWN";
break;
595 if (!events.is_null()) {
596 return EventsToString(events.get_array());
598 static std::string null(
"null");
603 if (!events.is_null()) {
604 return EventsToString(events.get_array());
606 static std::string null(
"null");
611 std::ostringstream stream;
613 if (!request.is_null()) {
614 const auto& container = request.get_array();
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) {
620 if ((fqnIt + 1) != it->eventClassFQNs.end()) { stream <<
", "; }
623 if ((it + 1) != container.end()) { stream <<
", "; }
634 std::ostringstream stream;
636 if (!response.is_null()) {
637 const auto& container = response.get_array();
639 for (
auto it = container.begin(); it != container.end(); ++it) {
640 stream <<
"{requestId: " << it->requestId <<
", ";
642 stream <<
"listeners: [";
644 if (!it->listeners.is_null()) {
645 const auto& listeners = it->listeners.get_array();
647 for (
auto listenerIt = listeners.begin(); listenerIt != listeners.end(); ++listenerIt) {
648 stream << *listenerIt;
649 if ((listenerIt + 1) != listeners.end()) { stream <<
", "; }
653 if ((it + 1) != container.end()) { stream <<
", "; }
664 std::ostringstream ss;
665 if (!response.is_null()) {
666 ss <<
KVSTRING(sequenceNumber, response.get_EventSequenceNumberResponse().seqNum);
674 std::string description;
684 default: description =
"UNKNOWN";
break;
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 <<
"}";
698 static std::string null(
"null");
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) {
713 stream <<
"{ requestId: " << deliveryStatuses[i].requestId
715 <<
", code: " << (deliveryStatuses[i].errorCode.is_null() ?
"null" :
721 static std::string null(
"null");
728 case LogDeliveryErrorCode::NO_APPENDERS_CONFIGURED:
729 result =
"NO_APPENDERS_CONFIGURED";
731 case LogDeliveryErrorCode::APPENDER_INTERNAL_ERROR:
732 result =
"APPENDER_INTERNAL_ERROR";
734 case LogDeliveryErrorCode::REMOTE_CONNECTION_ERROR:
735 result =
"REMOTE_CONNECTION_ERROR";
737 case LogDeliveryErrorCode::REMOTE_INTERNAL_ERROR:
738 result =
"REMOTE_INTERNAL_ERROR";
748 static std::string EventsToString(
const std::vector<Event>& events) {
749 std::ostringstream 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 <<
", "; }
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 ¬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)