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 INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
54 OIC_LOG(level, (PL_TAG), "Payload Type: Representation");
55 OCRepPayload* rep = payload;
59 OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
60 OIC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
61 OIC_LOG(level, PL_TAG, "\tResource Types:");
62 OCStringLL* strll = rep->types;
65 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
68 OIC_LOG(level, PL_TAG, "\tInterfaces:");
69 strll = rep->interfaces;
72 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
76 // TODO Finish Logging: Values
77 OCRepPayloadValue* val = rep->values;
79 OIC_LOG(level, PL_TAG, "\tValues:");
86 OIC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
89 OIC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
91 case OCREP_PROP_DOUBLE:
92 OIC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
95 OIC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
97 case OCREP_PROP_STRING:
98 OIC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
100 case OCREP_PROP_BYTE_STRING:
101 OIC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
102 OIC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
104 case OCREP_PROP_OBJECT:
105 // Note: Only prints the URI (if available), to print further, you'll
106 // need to dig into the object better!
107 OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
109 case OCREP_PROP_ARRAY:
110 switch(val->arr.type)
113 OIC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu",
115 val->arr.dimensions[0], val->arr.dimensions[1],
116 val->arr.dimensions[2]);
118 case OCREP_PROP_DOUBLE:
119 OIC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu",
121 val->arr.dimensions[0], val->arr.dimensions[1],
122 val->arr.dimensions[2]);
124 case OCREP_PROP_BOOL:
125 OIC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
127 val->arr.dimensions[0], val->arr.dimensions[1],
128 val->arr.dimensions[2]);
130 case OCREP_PROP_STRING:
131 OIC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu",
133 val->arr.dimensions[0], val->arr.dimensions[1],
134 val->arr.dimensions[2]);
136 case OCREP_PROP_BYTE_STRING:
137 OIC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu",
139 val->arr.dimensions[0], val->arr.dimensions[1],
140 val->arr.dimensions[2]);
142 case OCREP_PROP_OBJECT:
143 OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
145 val->arr.dimensions[0], val->arr.dimensions[1],
146 val->arr.dimensions[2]);
149 OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
155 OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
167 INLINE_API void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
169 OIC_LOG(level, PL_TAG, "Payload Type: Discovery");
172 if(!payload->resources)
174 OIC_LOG(level, PL_TAG, "\tNO Resources");
177 OIC_LOG_V(level, PL_TAG, "\tSID: %s", payload->sid);
178 if (payload->baseURI)
180 OIC_LOG_V(level, PL_TAG, "\tBase URI:%s", payload->baseURI);
184 OIC_LOG_V(level, PL_TAG, "\tNAME: %s", payload->name);
188 OIC_LOG_V(level, PL_TAG, "\tURI: %s", payload->uri);
192 OIC_LOG_V(level, PL_TAG, "\tResource Type: %s", payload->type);
194 OIC_LOG(level, PL_TAG, "\tInterface:");
195 for (OCStringLL *itf = payload->iface; itf; itf = itf->next)
197 OIC_LOG_V(level, PL_TAG, "\t\t%s", itf->value);
200 OCResourcePayload* res = payload->resources;
204 OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
205 OIC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
206 OIC_LOG(level, PL_TAG, "\tResource Types:");
207 OCStringLL* strll = res->types;
210 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
213 OIC_LOG(level, PL_TAG, "\tInterfaces:");
214 strll = res->interfaces;
217 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
221 OIC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
222 OIC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
223 OIC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
224 OIC_LOG(level, PL_TAG, "");
230 INLINE_API void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
232 OIC_LOG(level, PL_TAG, "Payload Type: Device");
233 OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
234 OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
235 OIC_LOG_V(level, PL_TAG, "\tSpec Version:%s", payload->specVersion);
236 OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
239 OIC_LOG(level, PL_TAG, "\tResource Type:");
240 for (OCStringLL *strll = payload->types; strll; strll = strll->next)
242 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
245 if (payload->interfaces)
247 OIC_LOG(level, PL_TAG, "\tInterface:");
248 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
250 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
255 INLINE_API void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
257 OIC_LOG(level, PL_TAG, "Payload Type: Platform");
258 OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
259 OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
260 OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
261 OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
262 OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
263 OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
264 OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
265 OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
266 OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
267 OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
268 OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
269 OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
273 OIC_LOG(level, PL_TAG, "\tResource Types:");
274 OIC_LOG_V(level, PL_TAG, "\t\t%s", payload->rt);
276 if (payload->interfaces)
278 OIC_LOG(level, PL_TAG, "\tResource Interfaces:");
279 for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
281 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
286 INLINE_API void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
288 OIC_LOG(level, PL_TAG, "Payload Type: Presence");
289 OIC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
290 OIC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
291 OIC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
292 OIC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
295 INLINE_API void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
297 OIC_LOG(level, PL_TAG, "Payload Type: Security");
298 OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
301 INLINE_API void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
308 if (payload->rdDiscovery)
310 OIC_LOG(level, PL_TAG, "RD Discovery");
311 OIC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
312 OIC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
313 OIC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
315 if (payload->rdPublish)
317 OIC_LOG(level, PL_TAG, "RD Publish");
318 OCResourceCollectionPayload *rdPublish = payload->rdPublish;
319 OCTagsLog(level, rdPublish->tags);
320 OCLinksLog(level, rdPublish->setLinks);
324 INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
328 OIC_LOG(level, PL_TAG, "NULL Payload");
331 switch(payload->type)
333 case PAYLOAD_TYPE_REPRESENTATION:
334 OCPayloadLogRep(level, (OCRepPayload*)payload);
336 case PAYLOAD_TYPE_DISCOVERY:
337 OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
339 case PAYLOAD_TYPE_DEVICE:
340 OCPayloadLogDevice(level, (OCDevicePayload*)payload);
342 case PAYLOAD_TYPE_PLATFORM:
343 OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
345 case PAYLOAD_TYPE_PRESENCE:
346 OCPayloadLogPresence(level, (OCPresencePayload*)payload);
348 case PAYLOAD_TYPE_SECURITY:
349 OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
351 case PAYLOAD_TYPE_RD:
352 OCRDPayloadLog(level, (OCRDPayload*)payload);
355 OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
360 #define OIC_LOG_PAYLOAD(level, payload)