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(topicListHash, ((request.get_NotificationSyncRequest().topicListHash == 0) ? 0 :
42 request.get_NotificationSyncRequest().topicListHash));
43 ss <<
KVSTRING(acceptedUnicastNotifications,
54 std::ostringstream ss;
55 if (!request.is_null()) {
56 std::stringstream hashStream;
57 for (
auto &byte : request.get_ConfigurationSyncRequest().configurationHash) {
60 ss <<
KVSTRING(configurationHash, (std::string(hashStream.str()).empty() ?
"null" : hashStream.str()));
68 std::ostringstream ss;
70 ss <<
"[" << std::hex <<
"id=0x" << protocolVersion.id << std::dec <<
",";
71 ss <<
KVSTRING(version, protocolVersion.version) <<
"]";
77 std::ostringstream ss;
78 if (!request.is_null()) {
79 const auto& syncRequest = request.get_BootstrapSyncRequest();
80 ss <<
KVSTRING(requestId, syncRequest.requestId) <<
",";
83 const auto& protocols = syncRequest.supportedProtocols;
84 size_t protocolCount = protocols.size();
86 if (protocolCount > 0) {
87 for (
const auto& protocol : protocols) {
89 if (--protocolCount > 0) {
103 std::ostringstream ss;
104 if (!request.is_null()) {
105 const auto profileRequest = request.get_ProfileSyncRequest();
107 if (!request.get_ProfileSyncRequest().endpointAccessToken.is_null()) {
108 ss <<
KVSTRING(endpointAccessToken, profileRequest.endpointAccessToken.get_string());
110 ss <<
KVSTRING(endpointAccessToken,
"null");
112 if (!profileRequest.endpointPublicKey.is_null()) {
115 ss <<
KVSTRING(endpointPublicKey,
"null");
126 std::ostringstream ss;
127 if (!request.is_null()) {
128 const auto& syncRequest = request.get_SyncRequestMetaData();
130 ss <<
KVSTRING(sdkToken, syncRequest.sdkToken) <<
", ";
132 if (syncRequest.endpointPublicKeyHash.is_null()) {
133 ss <<
KVSTRING(endpointPublicKeyHash,
"null") <<
",";
138 if (syncRequest.profileHash.is_null()) {
139 ss <<
KVSTRING(profileHash,
"null") <<
",";
144 if (syncRequest.timeout.is_null()) {
145 ss <<
KVSTRING(timeout,
"null") <<
",";
147 ss <<
KVSTRING(timeout, syncRequest.timeout.get_long()) <<
",";
156 std::ostringstream ss;
157 if (!request.is_null()) {
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);
178 std::ostringstream ss;
179 if (!request.is_null()) {
190 std::ostringstream ss;
191 if (!response.is_null()) {
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(availableTopics,
TopicsToString(response.get_NotificationSyncResponse().availableTopics)) <<
", ";
273 std::ostringstream ss;
274 if (!response.is_null()) {
283 std::ostringstream ss;
284 if (!response.is_null()) {
285 ss <<
KVSTRING(accessToken, response.get_UserDetachNotification().endpointAccessToken);
293 std::ostringstream ss;
294 if (!response.is_null()) {
306 std::ostringstream ss;
307 if (!response.is_null()) {
308 ss << std::hex <<
"accessPointId: 0x" << response.get_RedirectSyncResponse().accessPointId;
316 std::ostringstream ss;
317 ss <<
"(protocol: id=0x" << std::hex << protocolId.
getId() <<
", version=" << std::dec << protocolId.
getVersion() <<
")";
322 std::ostringstream 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) <<
" ";
337 static std::string
ByteArrayToString(
const boost::shared_array<std::uint8_t>& vec,
const size_t&length) {
346 return ByteArrayToString(reinterpret_cast<const std::uint8_t*>(data.data()), data.length());
350 std::string description;
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;
363 std::ostringstream stream;
365 if (!notifications.is_null()) {
366 const auto& container = notifications.get_array();
368 for (
auto it = container.begin(); it != container.end(); ++it) {
370 if ((it + 1) != container.end()) { stream <<
", "; }
381 std::ostringstream stream;
383 if (!states.is_null()) {
384 const auto& container = states.get_array();
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 <<
", "; }
399 std::ostringstream stream;
401 if (!commands.is_null()) {
402 const auto& container = commands.get_array();
404 for (
auto it = container.begin(); it != container.end(); ++it) {
406 if ((it + 1) != container.end()) { stream <<
", "; }
417 std::string description;
420 case ADD: description =
"ADD";
break;
421 case REMOVE: description =
"REMOVE";
break;
422 default: description =
"UNKNOWN";
break;
429 std::ostringstream 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()));
440 std::ostringstream stream;
442 if (!notifications.is_null()) {
443 const auto& container = notifications.get_array();
445 for (
auto it = container.begin(); it != container.end(); ++it) {
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()));
452 if ((it + 1) != container.end()) { stream <<
", "; }
463 std::string description;
466 case SYSTEM: description =
"SYSTEM";
break;
467 case CUSTOM: description =
"CUSTOM";
break;
468 default: description =
"UNKNOWN";
break;
474 static std::string
TopicsToString(
const NotificationSyncResponse::availableTopics_t& topics) {
475 std::ostringstream stream;
477 if (!topics.is_null()) {
478 const auto& container = topics.get_array();
480 for (
auto it = container.begin(); it != container.end(); ++it) {
482 if ((it + 1) != container.end()) { stream <<
", "; }
493 std::string description;
496 case MANDATORY_SUBSCRIPTION: description =
"MANDATORY_SUBSCRIPTION";
break;
497 case OPTIONAL_SUBSCRIPTION: description =
"OPTIONAL_SUBSCRIPTION";
break;
498 default: description =
"UNKNOWN";
break;
505 std::ostringstream stream;
507 if (!attachRequests.is_null()) {
508 const auto& container = attachRequests.get_array();
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 <<
", "; }
523 std::ostringstream stream;
525 if (!detachRequests.is_null()) {
526 const auto& container = detachRequests.get_array();
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 <<
", "; }
541 std::ostringstream stream;
543 if (!attachResponses.is_null()) {
544 const auto& container = attachResponses.get_array();
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()) <<
", ";
550 if ((it + 1) != container.end()) { stream <<
", "; }
561 std::ostringstream stream;
563 if (!detachResponse.is_null()) {
564 const auto& container = detachResponse.get_array();
566 for (
auto it = container.begin(); it != container.end(); ++it) {
567 stream <<
"{id: " << it->requestId <<
", ";
569 if ((it + 1) != container.end()) { stream <<
", "; }
580 std::string description;
586 case SyncResponseResultType::PROFILE_RESYNC: description =
"PROFILE_RESYNC";
break;
587 default: description =
"UNKNOWN";
break;
594 if (!events.is_null()) {
595 return EventsToString(events.get_array());
597 static std::string null(
"null");
602 if (!events.is_null()) {
603 return EventsToString(events.get_array());
605 static std::string null(
"null");
610 std::ostringstream stream;
612 if (!request.is_null()) {
613 const auto& container = request.get_array();
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) {
619 if ((fqnIt + 1) != it->eventClassFQNs.end()) { stream <<
", "; }
622 if ((it + 1) != container.end()) { stream <<
", "; }
633 std::ostringstream stream;
635 if (!response.is_null()) {
636 const auto& container = response.get_array();
638 for (
auto it = container.begin(); it != container.end(); ++it) {
639 stream <<
"{requestId: " << it->requestId <<
", ";
641 stream <<
"listeners: [";
643 if (!it->listeners.is_null()) {
644 const auto& listeners = it->listeners.get_array();
646 for (
auto listenerIt = listeners.begin(); listenerIt != listeners.end(); ++listenerIt) {
647 stream << *listenerIt;
648 if ((listenerIt + 1) != listeners.end()) { stream <<
", "; }
652 if ((it + 1) != container.end()) { stream <<
", "; }
663 std::ostringstream ss;
664 if (!response.is_null()) {
665 ss <<
KVSTRING(sequenceNumber, response.get_EventSequenceNumberResponse().seqNum);
673 std::string description;
683 default: description =
"UNKNOWN";
break;
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 <<
"}";
697 static std::string null(
"null");
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) {
712 stream <<
"{ requestId: " << deliveryStatuses[i].requestId
714 <<
", code: " << (deliveryStatuses[i].errorCode.is_null() ?
"null" :
720 static std::string null(
"null");
727 case LogDeliveryErrorCode::NO_APPENDERS_CONFIGURED:
728 result =
"NO_APPENDERS_CONFIGURED";
730 case LogDeliveryErrorCode::APPENDER_INTERNAL_ERROR:
731 result =
"APPENDER_INTERNAL_ERROR";
733 case LogDeliveryErrorCode::REMOTE_CONNECTION_ERROR:
734 result =
"REMOTE_CONNECTION_ERROR";
736 case LogDeliveryErrorCode::REMOTE_INTERNAL_ERROR:
737 result =
"REMOTE_INTERNAL_ERROR";
747 static std::string EventsToString(
const std::vector<Event>& events) {
748 std::ostringstream 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 <<
", "; }
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)