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(level, PL_TAG, "\tSID:");
178 OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
179 OCResourcePayload* res = payload->resources;
183 OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
184 OIC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
185 OIC_LOG(level, PL_TAG, "\tResource Types:");
186 OCStringLL* strll = res->types;
189 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
192 OIC_LOG(level, PL_TAG, "\tInterfaces:");
193 strll = res->interfaces;
196 OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
200 OIC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
201 OIC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
202 OIC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
203 OIC_LOG(level, PL_TAG, "");
209 static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
211 OIC_LOG(level, PL_TAG, "Payload Type: Device");
212 OIC_LOG(level, PL_TAG, "\tSID:");
213 OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
214 OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
215 OIC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
216 OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
219 static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
221 OIC_LOG(level, PL_TAG, "Payload Type: Platform");
222 OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
223 OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
224 OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
225 OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
226 OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
227 OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
228 OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
229 OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
230 OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
231 OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
232 OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
233 OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
236 static inline void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
238 OIC_LOG(level, PL_TAG, "Payload Type: Presence");
239 OIC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
240 OIC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
241 OIC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
242 OIC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
245 static inline void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
247 OIC_LOG(level, PL_TAG, "Payload Type: Security");
248 OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
251 static inline void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
258 if (payload->rdDiscovery)
260 OIC_LOG(level, PL_TAG, "RD Discovery");
261 OIC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
262 OIC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
263 OIC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
265 if (payload->rdPublish)
267 OIC_LOG(level, PL_TAG, "RD Publish");
268 OCResourceCollectionPayload *rdPublish = payload->rdPublish;
269 OCTagsLog(level, rdPublish->tags);
270 OCLinksLog(level, rdPublish->setLinks);
274 static inline void OCPayloadLog(LogLevel level, OCPayload* payload)
278 OIC_LOG(level, PL_TAG, "NULL Payload");
281 switch(payload->type)
283 case PAYLOAD_TYPE_REPRESENTATION:
284 OCPayloadLogRep(level, (OCRepPayload*)payload);
286 case PAYLOAD_TYPE_DISCOVERY:
287 OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
289 case PAYLOAD_TYPE_DEVICE:
290 OCPayloadLogDevice(level, (OCDevicePayload*)payload);
292 case PAYLOAD_TYPE_PLATFORM:
293 OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
295 case PAYLOAD_TYPE_PRESENCE:
296 OCPayloadLogPresence(level, (OCPresencePayload*)payload);
298 case PAYLOAD_TYPE_SECURITY:
299 OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
301 case PAYLOAD_TYPE_RD:
302 OCRDPayloadLog(level, (OCRDPayload*)payload);
305 OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
310 #define OIC_LOG_PAYLOAD(level, payload)