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 // PL_TAG is made as generic predefined tag because of build problems in arduino for using logging
30 #define PL_TAG "PayloadLog"
33 #define OC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
34 #define UUID_SIZE (16)
35 #define UUID_LENGTH (37)
36 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
37 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
39 static inline void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
41 OC_LOG(level, (PL_TAG), "Payload Type: Representation");
42 OCRepPayload* rep = payload;
46 OC_LOG_V(level, PL_TAG, "\tResource #%d", i);
47 OC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
48 OC_LOG(level, PL_TAG, "\tResource Types:");
49 OCStringLL* strll = rep->types;
52 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
55 OC_LOG(level, PL_TAG, "\tInterfaces:");
56 strll = rep->interfaces;
59 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
63 // TODO Finish Logging: Values
64 OCRepPayloadValue* val = rep->values;
66 OC_LOG(level, PL_TAG, "\tValues:");
73 OC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
76 OC_LOG_V(level, PL_TAG, "\t\t%s(int):%lld", val->name, val->i);
78 case OCREP_PROP_DOUBLE:
79 OC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
82 OC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
84 case OCREP_PROP_STRING:
85 OC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
87 case OCREP_PROP_OBJECT:
88 // Note: Only prints the URI (if available), to print further, you'll
89 // need to dig into the object better!
90 OC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
92 case OCREP_PROP_ARRAY:
96 OC_LOG_V(level, PL_TAG, "\t\t%s(int array):%lld x %lld x %lld",
98 val->arr.dimensions[0], val->arr.dimensions[1],
99 val->arr.dimensions[2]);
101 case OCREP_PROP_DOUBLE:
102 OC_LOG_V(level, PL_TAG, "\t\t%s(double array):%lld x %lld x %lld",
104 val->arr.dimensions[0], val->arr.dimensions[1],
105 val->arr.dimensions[2]);
107 case OCREP_PROP_BOOL:
108 OC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%lld x %lld x %lld",
110 val->arr.dimensions[0], val->arr.dimensions[1],
111 val->arr.dimensions[2]);
113 case OCREP_PROP_STRING:
114 OC_LOG_V(level, PL_TAG, "\t\t%s(string array):%lld x %lld x %lld",
116 val->arr.dimensions[0], val->arr.dimensions[1],
117 val->arr.dimensions[2]);
119 case OCREP_PROP_OBJECT:
120 OC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%lld x %lld x %lld",
122 val->arr.dimensions[0], val->arr.dimensions[1],
123 val->arr.dimensions[2]);
126 OC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
132 OC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
144 static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
146 OC_LOG(level, PL_TAG, "Payload Type: Discovery");
149 if(!payload->resources)
151 OC_LOG(level, PL_TAG, "\tNO Resources");
155 OCResourcePayload* res = payload->resources;
159 OC_LOG_V(level, PL_TAG, "\tResource #%d", i);
160 OC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
161 OC_LOG(level, PL_TAG, "\tSID:");
162 OC_LOG_BUFFER(level, PL_TAG, res->sid, UUID_SIZE);
163 OC_LOG(level, PL_TAG, "\tResource Types:");
164 OCStringLL* strll = res->types;
167 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
170 OC_LOG(level, PL_TAG, "\tInterfaces:");
171 strll = res->interfaces;
174 OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
178 OC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
179 OC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
180 OC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
181 OC_LOG(level, PL_TAG, "");
187 static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
189 OC_LOG(level, PL_TAG, "Payload Type: Device");
190 OC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
191 OC_LOG(level, PL_TAG, "\tSID:");
192 OC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
193 OC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
194 OC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
195 OC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
198 static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
200 OC_LOG(level, PL_TAG, "Payload Type: Platform");
201 OC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
202 OC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
203 OC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
204 OC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
205 OC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
206 OC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
207 OC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
208 OC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
209 OC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
210 OC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
211 OC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
212 OC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
215 static inline void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
217 OC_LOG(level, PL_TAG, "Payload Type: Presence");
218 OC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
219 OC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
220 OC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
221 OC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
224 static inline void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
226 OC_LOG(level, PL_TAG, "Payload Type: Security");
227 OC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
230 static inline void OCPayloadLog(LogLevel level, OCPayload* payload)
234 OC_LOG(level, PL_TAG, "NULL Payload");
237 switch(payload->type)
239 case PAYLOAD_TYPE_REPRESENTATION:
240 OCPayloadLogRep(level, (OCRepPayload*)payload);
242 case PAYLOAD_TYPE_DISCOVERY:
243 OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
245 case PAYLOAD_TYPE_DEVICE:
246 OCPayloadLogDevice(level, (OCDevicePayload*)payload);
248 case PAYLOAD_TYPE_PLATFORM:
249 OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
251 case PAYLOAD_TYPE_PRESENCE:
252 OCPayloadLogPresence(level, (OCPresencePayload*)payload);
254 case PAYLOAD_TYPE_SECURITY:
255 OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
258 OC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
263 #define OC_LOG_PAYLOAD(level, payload)