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 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
50 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
52 static inline 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 static inline 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->interface; 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 static inline 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);
247 static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
249 OIC_LOG(level, PL_TAG, "Payload Type: Platform");
250 OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
251 OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
252 OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
253 OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
254 OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
255 OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
256 OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
257 OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
258 OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
259 OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
260 OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
261 OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
264 static inline void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
266 OIC_LOG(level, PL_TAG, "Payload Type: Presence");
267 OIC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
268 OIC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
269 OIC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
270 OIC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
273 static inline void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
275 OIC_LOG(level, PL_TAG, "Payload Type: Security");
276 OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
279 static inline void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
286 if (payload->rdDiscovery)
288 OIC_LOG(level, PL_TAG, "RD Discovery");
289 OIC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
290 OIC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
291 OIC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
293 if (payload->rdPublish)
295 OIC_LOG(level, PL_TAG, "RD Publish");
296 OCResourceCollectionPayload *rdPublish = payload->rdPublish;
297 OCTagsLog(level, rdPublish->tags);
298 OCLinksLog(level, rdPublish->setLinks);
302 static inline void OCPayloadLog(LogLevel level, OCPayload* payload)
306 OIC_LOG(level, PL_TAG, "NULL Payload");
309 switch(payload->type)
311 case PAYLOAD_TYPE_REPRESENTATION:
312 OCPayloadLogRep(level, (OCRepPayload*)payload);
314 case PAYLOAD_TYPE_DISCOVERY:
315 OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
317 case PAYLOAD_TYPE_DEVICE:
318 OCPayloadLogDevice(level, (OCDevicePayload*)payload);
320 case PAYLOAD_TYPE_PLATFORM:
321 OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
323 case PAYLOAD_TYPE_PRESENCE:
324 OCPayloadLogPresence(level, (OCPresencePayload*)payload);
326 case PAYLOAD_TYPE_SECURITY:
327 OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
329 case PAYLOAD_TYPE_RD:
330 OCRDPayloadLog(level, (OCRDPayload*)payload);
333 OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
338 #define OIC_LOG_PAYLOAD(level, payload)