1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef PAYLOAD_LOGGING_H_
22 #define PAYLOAD_LOGGING_H_
29 #ifndef __STDC_FORMAT_MACROS
30 #define __STDC_FORMAT_MACROS
32 #ifndef __STDC_LIMIT_MACROS
33 #define __STDC_LIMIT_MACROS
36 #include "rdpayload.h"
43 // PL_TAG is made as generic predefined tag because of build problems in arduino for using logging
44 #define PL_TAG "PayloadLog"
47 #define OIC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
48 #define UUID_SIZE (16)
49 OC_EXPORT const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
50 OC_EXPORT OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
52 #if defined(RD_CLIENT) || defined(RD_SERVER)
53 INLINE_API void OCTagsLog(const LogLevel level, const OCTagsPayload *tags)
57 if (tags->n.deviceName)
59 OIC_LOG_V(level, PL_TAG, " Device Name : %s ", tags->n.deviceName);
63 OIC_LOG_V(level, PL_TAG, " Device ID : %s ", tags->di.id);
65 OIC_LOG_V(level, PL_TAG, " lt : %lld ",tags->ttl);
73 INLINE_API void OCLinksLog(const LogLevel level, const OCLinksPayload *links)
84 OIC_LOG_V(level, PL_TAG, " href: %s ",links->href);
86 OIC_LOG(level, PL_TAG, " RT: ");
87 OCStringLL *rt = links->rt;
92 OIC_LOG_V(level, PL_TAG, " %s", rt->value);
96 OIC_LOG(level, PL_TAG, " IF: ");
97 OCStringLL *itf = links->itf;
102 OIC_LOG_V(level, PL_TAG, " %s", itf->value);
106 OIC_LOG(level, PL_TAG, " MT: ");
107 OCStringLL *mt = links->type;
112 OIC_LOG_V(level, PL_TAG, " %s", mt->value);
118 OIC_LOG_V(level, PL_TAG, " %s", links->type);
120 OIC_LOG_V(level, PL_TAG, " INS: %d", links->ins);
121 OIC_LOG_V(level, PL_TAG, " TTL: %d", links->ttl);
122 OIC_LOG_V(level, PL_TAG, " P: %d", links->p);
125 OIC_LOG_V(level, PL_TAG, " REL: %s", links->rel);
129 OIC_LOG_V(level, PL_TAG, " TITLE: %s", links->title);
133 OIC_LOG_V(level, PL_TAG, " URI: %s", links->anchor);
139 INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
141 OIC_LOG(level, (PL_TAG), "Payload Type: Representation");
142 OCRepPayload* rep = payload;
146 OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
147 OIC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
148 OIC_LOG(level, PL_TAG, "\tResource Types:");
149 OCStringLL* strll = rep->types;
152 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
155 OIC_LOG(level, PL_TAG, "\tInterfaces:");
156 strll = rep->interfaces;
159 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
163 // TODO Finish Logging: Values
164 OCRepPayloadValue* val = rep->values;
166 OIC_LOG(level, PL_TAG, "\tValues:");
172 case OCREP_PROP_NULL:
173 OIC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
176 OIC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
178 case OCREP_PROP_DOUBLE:
179 OIC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
181 case OCREP_PROP_BOOL:
182 OIC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
184 case OCREP_PROP_STRING:
185 OIC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
187 case OCREP_PROP_BYTE_STRING:
188 OIC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
189 OIC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
191 case OCREP_PROP_OBJECT:
192 // Note: Only prints the URI (if available), to print further, you'll
193 // need to dig into the object better!
194 OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
196 case OCREP_PROP_ARRAY:
197 switch(val->arr.type)
200 OIC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu",
202 val->arr.dimensions[0], val->arr.dimensions[1],
203 val->arr.dimensions[2]);
205 case OCREP_PROP_DOUBLE:
206 OIC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu",
208 val->arr.dimensions[0], val->arr.dimensions[1],
209 val->arr.dimensions[2]);
211 case OCREP_PROP_BOOL:
212 OIC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
214 val->arr.dimensions[0], val->arr.dimensions[1],
215 val->arr.dimensions[2]);
217 case OCREP_PROP_STRING:
218 OIC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu",
220 val->arr.dimensions[0], val->arr.dimensions[1],
221 val->arr.dimensions[2]);
223 case OCREP_PROP_BYTE_STRING:
224 OIC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu",
226 val->arr.dimensions[0], val->arr.dimensions[1],
227 val->arr.dimensions[2]);
229 case OCREP_PROP_OBJECT:
230 OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
232 val->arr.dimensions[0], val->arr.dimensions[1],
233 val->arr.dimensions[2]);
236 OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
242 OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
254 INLINE_API void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
256 OIC_LOG(level, PL_TAG, "Payload Type: Discovery");
258 while(payload && payload->resources)
260 OIC_LOG_V(level, PL_TAG, "\tSID: %s", payload->sid);
261 if (payload->baseURI)
263 OIC_LOG_V(level, PL_TAG, "\tBase URI:%s", payload->baseURI);
267 OIC_LOG_V(level, PL_TAG, "\tNAME: %s", payload->name);
271 OIC_LOG_V(level, PL_TAG, "\tURI: %s", payload->uri);
275 for (OCStringLL *strll = payload->type; strll; strll = strll->next)
277 OIC_LOG_V(level, PL_TAG, "\tResource Type: %s", strll->value);
280 OIC_LOG(level, PL_TAG, "\tInterface:");
281 for (OCStringLL *itf = payload->iface; itf; itf = itf->next)
283 OIC_LOG_V(level, PL_TAG, "\t\t%s", itf->value);
286 OCResourcePayload* res = payload->resources;
291 OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
292 OIC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
293 OIC_LOG(level, PL_TAG, "\tResource Types:");
294 OCStringLL* strll = res->types;
297 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
300 OIC_LOG(level, PL_TAG, "\tInterfaces:");
301 strll = res->interfaces;
304 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
308 OIC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
309 OIC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
310 OIC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
311 OIC_LOG(level, PL_TAG, "");
315 payload = payload->next;
319 INLINE_API void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
321 OIC_LOG(level, PL_TAG, "Payload Type: Device");
322 OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
323 OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
324 OIC_LOG_V(level, PL_TAG, "\tSpec Version:%s", payload->specVersion);
325 if (payload->dataModelVersions)
327 OIC_LOG(level, PL_TAG, "\tData Model Version:");
328 for (OCStringLL *strll = payload->dataModelVersions; strll; strll = strll->next)
330 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
335 OIC_LOG(level, PL_TAG, "\tResource Type:");
336 for (OCStringLL *strll = payload->types; strll; strll = strll->next)
338 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
341 if (payload->interfaces)
343 OIC_LOG(level, PL_TAG, "\tInterface:");
344 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
346 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
351 INLINE_API void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
353 OIC_LOG(level, PL_TAG, "Payload Type: Platform");
354 OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
355 OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
356 OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
357 OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
358 OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
359 OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
360 OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
361 OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
362 OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
363 OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
364 OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
365 OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
369 OIC_LOG(level, PL_TAG, "\tResource Types:");
370 for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
372 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
375 if (payload->interfaces)
377 OIC_LOG(level, PL_TAG, "\tResource Interfaces:");
378 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
380 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
385 INLINE_API void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
387 OIC_LOG(level, PL_TAG, "Payload Type: Presence");
388 OIC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
389 OIC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
390 OIC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
391 OIC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
394 INLINE_API void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
396 OIC_LOG(level, PL_TAG, "Payload Type: Security");
397 OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
400 #if defined(RD_CLIENT) || defined(RD_SERVER)
401 INLINE_API void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
408 if (payload->rdDiscovery)
410 OIC_LOG(level, PL_TAG, "RD Discovery");
411 OIC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
412 OIC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
413 OIC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
415 if (payload->rdPublish)
417 OIC_LOG(level, PL_TAG, "RD Publish");
418 OCResourceCollectionPayload *rdPublish = payload->rdPublish;
419 OCTagsLog(level, rdPublish->tags);
420 OCLinksLog(level, rdPublish->setLinks);
424 INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
428 OIC_LOG(level, PL_TAG, "NULL Payload");
431 switch(payload->type)
433 case PAYLOAD_TYPE_REPRESENTATION:
434 OCPayloadLogRep(level, (OCRepPayload*)payload);
436 case PAYLOAD_TYPE_DISCOVERY:
437 OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
439 case PAYLOAD_TYPE_DEVICE:
440 OCPayloadLogDevice(level, (OCDevicePayload*)payload);
442 case PAYLOAD_TYPE_PLATFORM:
443 OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
445 case PAYLOAD_TYPE_PRESENCE:
446 OCPayloadLogPresence(level, (OCPresencePayload*)payload);
448 case PAYLOAD_TYPE_SECURITY:
449 OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
451 #if defined(RD_CLIENT) || defined(RD_SERVER)
452 case PAYLOAD_TYPE_RD:
453 OCRDPayloadLog(level, (OCRDPayload*)payload);
457 OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
462 #define OIC_LOG_PAYLOAD(level, payload)