17 #ifndef LOGGINGUTILS_HPP_
18 #define LOGGINGUTILS_HPP_
26 #include <boost/shared_array.hpp>
28 #include "kaa/gen/BootstrapGen.hpp"
29 #include "kaa/gen/EndpointGen.hpp"
35 #define KVSTRING(K,V) "\"" #K "\": \"" << V << "\""
40 std::ostringstream ss;
41 if (!request.is_null()) {
42 ss <<
KVSTRING(appStateSeqNumber, request.get_NotificationSyncRequest().appStateSeqNumber) <<
", ";
43 ss <<
KVSTRING(acceptedUnicastNotifications,
47 ss <<
KVSTRING(topicListHash, (request.get_NotificationSyncRequest().topicListHash.is_null() ?
"null" :
48 ByteArrayToString(request.get_NotificationSyncRequest().topicListHash.get_bytes())));
56 std::ostringstream ss;
57 if (!request.is_null()) {
58 ss <<
KVSTRING(appStateSeqNumber, request.get_ConfigurationSyncRequest().appStateSeqNumber);
60 (request.get_ConfigurationSyncRequest().configurationHash.is_null() ?
"null" :
ByteArrayToString(request.get_ConfigurationSyncRequest().configurationHash.get_bytes())));
68 std::ostringstream ss;
69 if (!request.is_null()) {
70 if (!request.get_ProfileSyncRequest().endpointAccessToken.is_null()) {
71 ss <<
KVSTRING(endpointAccessToken, request.get_ProfileSyncRequest().endpointAccessToken.get_string());
73 ss <<
KVSTRING(endpointAccessToken,
"null");
75 if (!request.get_ProfileSyncRequest().endpointPublicKey.is_null()) {
78 ss <<
KVSTRING(endpointPublicKey,
"null");
83 ss <<
KVSTRING(configVersion, request.get_ProfileSyncRequest().versionInfo.configVersion);
84 ss <<
KVSTRING(profileVersion, request.get_ProfileSyncRequest().versionInfo.profileVersion);
85 ss <<
KVSTRING(systemNfVersion, request.get_ProfileSyncRequest().versionInfo.systemNfVersion);
86 ss <<
KVSTRING(userNfVersion, request.get_ProfileSyncRequest().versionInfo.userNfVersion);
87 ss <<
KVSTRING(logSchemaVersion, request.get_ProfileSyncRequest().versionInfo.logSchemaVersion);
97 std::ostringstream ss;
98 if (!request.is_null()) {
99 ss <<
KVSTRING(applicationToken, request.get_SyncRequestMetaData().applicationToken) <<
", ";
100 ss <<
KVSTRING(endpointPublicKeyHash,
ByteArrayToString(request.get_SyncRequestMetaData().endpointPublicKeyHash)) <<
", ";
101 if (request.get_SyncRequestMetaData().profileHash.is_null()) {
102 ss <<
KVSTRING(profileHash,
"null") <<
",";
106 ss <<
KVSTRING(timeout, request.get_SyncRequestMetaData().timeout);
114 std::ostringstream ss;
115 if (!request.is_null()) {
125 std::ostringstream ss;
126 if (!request.is_null()) {
127 ss <<
KVSTRING(userAccessToken, request.get_UserAttachRequest().userAccessToken);
128 ss <<
KVSTRING(userExternalId, request.get_UserAttachRequest().userExternalId);
136 std::ostringstream ss;
137 if (!request.is_null()) {
148 std::ostringstream ss;
149 if (!response.is_null()) {
150 ss <<
KVSTRING(appStateSeqNumber, response.get_ConfigurationSyncResponse().appStateSeqNumber);
152 (response.get_ConfigurationSyncResponse().confDeltaBody.is_null()
154 :
ByteArrayToString(response.get_ConfigurationSyncResponse().confDeltaBody.get_bytes()))
157 (response.get_ConfigurationSyncResponse().confSchemaBody.is_null()
159 :
ByteArrayToString(response.get_ConfigurationSyncResponse().confSchemaBody.get_bytes()))
169 std::ostringstream ss;
170 if (!response.is_null()) {
179 std::ostringstream ss;
180 if (!response.is_null()) {
190 std::ostringstream ss;
191 if (!response.is_null()) {
193 ss <<
KVSTRING(appStateSeqNumber, response.get_NotificationSyncResponse().appStateSeqNumber) <<
", ";
194 ss <<
KVSTRING(availableTopics,
TopicsToString(response.get_NotificationSyncResponse().availableTopics)) <<
", ";
203 std::ostringstream ss;
204 if (!response.is_null()) {
213 std::ostringstream ss;
214 if (!response.is_null()) {
225 std::ostringstream ss;
226 if (!response.is_null()) {
227 ss <<
KVSTRING(dnsName, response.get_RedirectSyncResponse().dnsName);
236 std::stringstream ss;
237 ss <<
"{ " <<
KVSTRING(name, ops.name)
238 <<
", " <<
KVSTRING(priority, ops.priority)
246 std::stringstream ss;
248 for (
const OperationsServer& ops : opsList.operationsServerArray) {
256 std::stringstream ss;
258 for (
const OperationsServer& ops : opsList) {
267 case ChannelType::HTTP:
269 case ChannelType::HTTP_LP:
273 case ChannelType::KAATCP:
280 std::stringstream ss;
281 ss <<
"{ " <<
KVSTRING(hostName, params.get_HTTPComunicationParameters().hostName)
282 <<
", " <<
KVSTRING(port, params.get_HTTPComunicationParameters().port)
288 std::stringstream ss;
289 ss <<
"{ " <<
KVSTRING(hostName, params.get_HTTPLPComunicationParameters().hostName)
290 <<
", " <<
KVSTRING(port, params.get_HTTPLPComunicationParameters().port)
296 std::stringstream ss;
298 <<
", " <<
KVSTRING(communicationParameters,
299 (supportedChannel.channelType == ChannelType::HTTP
301 : (supportedChannel.channelType == ChannelType::HTTP_LP
311 std::stringstream ss;
313 for (
const SupportedChannel& channel : supportedChannels) {
321 std::stringstream ss;
323 if (vec !=
nullptr && length > 0) {
324 for (
size_t i = 0; i < length; ++i) {
325 ss << std::setw(2) << std::uppercase << std::setfill(
'0') << std::hex << (int) *(vec + i) <<
" ";
336 static std::string
ByteArrayToString(
const boost::shared_array<std::uint8_t>& vec,
const size_t&length) {
345 return ByteArrayToString(reinterpret_cast<const std::uint8_t*>(data.data()), data.length());
349 std::string description;
352 case NO_DELTA: description =
"NO_DELTA";
break;
353 case DELTA: description =
"DELTA";
break;
354 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: description =
"MANDATORY";
break;
498 case OPTIONAL: description =
"OPTIONAL";
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;
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;
595 std::ostringstream stream;
597 if (!versions.is_null()) {
598 const auto& container = versions.get_array();
600 for (
auto it = container.begin(); it != container.end(); ++it) {
601 stream <<
"{name: " << it->name <<
", ";
602 stream <<
"version: " << it->version <<
"}";
603 if ((it + 1) != container.end()) { stream <<
", "; }
614 if (!events.is_null()) {
615 return EventsToString(events.get_array());
617 static std::string null(
"null");
622 if (!events.is_null()) {
623 return EventsToString(events.get_array());
625 static std::string null(
"null");
630 std::ostringstream stream;
632 if (!request.is_null()) {
633 const auto& container = request.get_array();
635 for (
auto it = container.begin(); it != container.end(); ++it) {
636 stream <<
"{requestId: " << it->requestId <<
", fqn's: [";
637 for (
auto fqnIt = it->eventClassFQNs.begin(); fqnIt != it->eventClassFQNs.end(); ++fqnIt) {
639 if ((fqnIt + 1) != it->eventClassFQNs.end()) { stream <<
", "; }
642 if ((it + 1) != container.end()) { stream <<
", "; }
653 std::ostringstream stream;
655 if (!response.is_null()) {
656 const auto& container = response.get_array();
658 for (
auto it = container.begin(); it != container.end(); ++it) {
659 stream <<
"{requestId: " << it->requestId <<
", ";
661 stream <<
"listeners: [";
663 if (!it->listeners.is_null()) {
664 const auto& listeners = it->listeners.get_array();
666 for (
auto listenerIt = listeners.begin(); listenerIt != listeners.end(); ++listenerIt) {
667 stream << *listenerIt;
668 if ((listenerIt + 1) != listeners.end()) { stream <<
", "; }
672 if ((it + 1) != container.end()) { stream <<
", "; }
684 std::string description;
694 default: description =
"UNKNOWN";
break;
701 if (!logSyncRequest.is_null()) {
702 const auto& request = logSyncRequest.get_LogSyncRequest();
703 std::ostringstream stream;
704 std::string requestId = request.requestId.is_null() ?
"null" : request.requestId.get_string();
705 size_t entriesCount = request.logEntries.is_null() ? 0 : request.logEntries.get_array().size();
706 stream <<
"{ requestId: " << requestId <<
", logEntriesCount: " << entriesCount <<
"}";
709 static std::string null(
"null");
714 if (!logSyncResponse.is_null()) {
715 std::ostringstream stream;
716 std::string requestId = logSyncResponse.get_LogSyncResponse().requestId;
718 stream <<
"{ requestId: " << requestId <<
", result: " << result <<
"}";
721 static std::string null(
"null");
726 static std::string EventsToString(
const std::vector<Event>& events) {
727 std::ostringstream stream;
729 for (
auto it = events.begin(); it != events.end(); ++it) {
730 stream <<
"{fqn: " << it->eventClassFQN <<
", ";
731 stream <<
"sn: " << it->seqNum <<
", ";
732 stream <<
"data_size: " << it->eventData.size() <<
", ";
733 stream <<
"source: " << (it->source.is_null() ?
"null" : it->source.get_string()) <<
", ";
734 stream <<
"target: " << (it->target.is_null() ?
"null" : it->target.get_string()) <<
"}";
735 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 UserSyncRequestToString(const SyncRequest::userSyncRequest_t &request)
static std::string HTTPLPParametersToString(const SupportedChannel::communicationParameters_t ¶ms)
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 HTTPParametersToString(const SupportedChannel::communicationParameters_t ¶ms)
static std::string OperationServerToString(const OperationsServer &ops)
static std::string AcceptedUnicastNotificationsToString(const NotificationSyncRequest::acceptedUnicastNotifications_t ¬ifications)
static std::string ChannelTypeToString(ChannelType type)
static std::string UserSyncResponseToString(const SyncResponse::userSyncResponse_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 NotificationSyncResponseToString(const SyncResponse::notificationSyncResponse_t &response)
static std::string ConfigurationSyncResponseToString(const SyncResponse::configurationSyncResponse_t &response)
static std::string ProfileSyncResponseToString(const SyncResponse::profileSyncResponse_t &response)
static std::string EventSyncResponseToString(const SyncResponse::eventSyncResponse_t &response)
static std::string SupportedChannelArrayToString(const std::vector< SupportedChannel > &supportedChannels)
static std::string ConfigurationSyncRequestToString(const SyncRequest::configurationSyncRequest_t &request)
static std::string ProfileSyncRequestToString(const SyncRequest::profileSyncRequest_t &request)
static std::string OperationServerArrayToString(const std::vector< OperationsServer > &opsList)
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 EventSyncRequestToString(const SyncRequest::eventSyncRequest_t &request)
static std::string SupportedChannelToString(const SupportedChannel &supportedChannel)
static std::string LogSyncRequestToString(const SyncRequest::logSyncRequest_t &logSyncRequest)
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 OperationServerListToString(const OperationsServerList &opsList)
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)