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 #define __STDC_FORMAT_MACROS
30 #define __STDC_LIMIT_MACROS
32 #include "rdpayload.h"
39 // PL_TAG is made as generic predefined tag because of build problems in arduino for using logging
40 #define PL_TAG "PayloadLog"
43 #define OC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
44 #define UUID_SIZE (16)
45 #define UUID_LENGTH (37)
46 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
47 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
49 static inline void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
51 OC_LOG(level, (PL_TAG), "Payload Type: Representation");
52 OCRepPayload* rep = payload;
56 OC_LOG_V(level, PL_TAG, "\tResource #%d", i);
57 OC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
58 OC_LOG(level, PL_TAG, "\tResource Types:");
59 OCStringLL* strll = rep->types;
62 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
65 OC_LOG(level, PL_TAG, "\tInterfaces:");
66 strll = rep->interfaces;
69 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
73 // TODO Finish Logging: Values
74 OCRepPayloadValue* val = rep->values;
76 OC_LOG(level, PL_TAG, "\tValues:");
83 OC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
86 OC_LOG_V(level, PL_TAG, "\t\t%s(int):%lld", val->name, val->i);
88 case OCREP_PROP_DOUBLE:
89 OC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
92 OC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
94 case OCREP_PROP_STRING:
95 OC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
97 case OCREP_PROP_OBJECT:
98 // Note: Only prints the URI (if available), to print further, you'll
99 // need to dig into the object better!
100 OC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
102 case OCREP_PROP_ARRAY:
103 switch(val->arr.type)
106 OC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu",
108 val->arr.dimensions[0], val->arr.dimensions[1],
109 val->arr.dimensions[2]);
111 case OCREP_PROP_DOUBLE:
112 OC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu",
114 val->arr.dimensions[0], val->arr.dimensions[1],
115 val->arr.dimensions[2]);
117 case OCREP_PROP_BOOL:
118 OC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
120 val->arr.dimensions[0], val->arr.dimensions[1],
121 val->arr.dimensions[2]);
123 case OCREP_PROP_STRING:
124 OC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu",
126 val->arr.dimensions[0], val->arr.dimensions[1],
127 val->arr.dimensions[2]);
129 case OCREP_PROP_OBJECT:
130 OC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
132 val->arr.dimensions[0], val->arr.dimensions[1],
133 val->arr.dimensions[2]);
136 OC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
142 OC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
154 static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
156 OC_LOG(level, PL_TAG, "Payload Type: Discovery");
159 if(!payload->resources)
161 OC_LOG(level, PL_TAG, "\tNO Resources");
165 OCResourcePayload* res = payload->resources;
169 OC_LOG_V(level, PL_TAG, "\tResource #%d", i);
170 OC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
171 OC_LOG(level, PL_TAG, "\tSID:");
172 OC_LOG_BUFFER(level, PL_TAG, res->sid, UUID_SIZE);
173 OC_LOG(level, PL_TAG, "\tResource Types:");
174 OCStringLL* strll = res->types;
177 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
180 OC_LOG(level, PL_TAG, "\tInterfaces:");
181 strll = res->interfaces;
184 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
188 OC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
189 OC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
190 OC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
191 OC_LOG(level, PL_TAG, "");
197 static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
199 OC_LOG(level, PL_TAG, "Payload Type: Device");
200 OC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
201 OC_LOG(level, PL_TAG, "\tSID:");
202 OC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
203 OC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
204 OC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
205 OC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
208 static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
210 OC_LOG(level, PL_TAG, "Payload Type: Platform");
211 OC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
212 OC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
213 OC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
214 OC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
215 OC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
216 OC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
217 OC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
218 OC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
219 OC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
220 OC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
221 OC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
222 OC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
225 static inline void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
227 OC_LOG(level, PL_TAG, "Payload Type: Presence");
228 OC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
229 OC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
230 OC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
231 OC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
234 static inline void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
236 OC_LOG(level, PL_TAG, "Payload Type: Security");
237 OC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
240 static inline void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
247 if (payload->rdDiscovery)
249 OC_LOG(level, PL_TAG, "RD Discovery");
250 OC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
251 OC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
252 OC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
254 if (payload->rdPublish)
256 OC_LOG(level, PL_TAG, "RD Publish");
257 OCResourceCollectionPayload *rdPublish = payload->rdPublish;
258 OCTagsLog(level, rdPublish->tags);
259 OCLinksLog(level, rdPublish->setLinks);
263 static inline void OCPayloadLog(LogLevel level, OCPayload* payload)
267 OC_LOG(level, PL_TAG, "NULL Payload");
270 switch(payload->type)
272 case PAYLOAD_TYPE_REPRESENTATION:
273 OCPayloadLogRep(level, (OCRepPayload*)payload);
275 case PAYLOAD_TYPE_DISCOVERY:
276 OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
278 case PAYLOAD_TYPE_DEVICE:
279 OCPayloadLogDevice(level, (OCDevicePayload*)payload);
281 case PAYLOAD_TYPE_PLATFORM:
282 OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
284 case PAYLOAD_TYPE_PRESENCE:
285 OCPayloadLogPresence(level, (OCPresencePayload*)payload);
287 case PAYLOAD_TYPE_SECURITY:
288 OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
290 case PAYLOAD_TYPE_RD:
291 OCRDPayloadLog(level, (OCRDPayload*)payload);
294 OC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
299 #define OC_LOG_PAYLOAD(level, payload)