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_
30 #define OC_LOG_PAYLOAD(level, tag, payload) OCPayloadLog((level),(tag),(payload))
31 #define UUID_SIZE (16)
32 #define UUID_LENGTH (37)
33 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
34 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
36 static inline void OCPayloadLogRep(LogLevel level, const char* tag, OCRepPayload* payload)
38 OC_LOG(level, tag, PCF("Payload Type: Representation"));
39 OCRepPayload* rep = payload;
43 OC_LOG_V(level, tag, "\tResource #%d", i);
44 OC_LOG_V(level, tag, "\tURI:%s", rep->uri);
45 OC_LOG(level, tag, PCF("\tResource Types:"));
46 OCStringLL* strll = rep->types;
49 OC_LOG_V(level, tag, "\t\t%s", strll->value);
52 OC_LOG(level, tag, PCF("\tInterfaces:"));
53 strll = rep->interfaces;
56 OC_LOG_V(level, tag, "\t\t%s", strll->value);
60 // TODO Finish Logging: Values
61 OCRepPayloadValue* val = rep->values;
63 OC_LOG(level, tag, PCF("\tValues:"));
70 OC_LOG_V(level, tag, "\t\t%s: NULL", val->name);
73 OC_LOG_V(level, tag, "\t\t%s(int):%lld", val->name, val->i);
75 case OCREP_PROP_DOUBLE:
76 OC_LOG_V(level, tag, "\t\t%s(double):%f", val->name, val->d);
79 OC_LOG_V(level, tag, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
81 case OCREP_PROP_STRING:
82 OC_LOG_V(level, tag, "\t\t%s(string):%s", val->name, val->str);
84 case OCREP_PROP_OBJECT:
85 // Note: Only prints the URI (if available), to print further, you'll
86 // need to dig into the object better!
87 OC_LOG_V(level, tag, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
89 case OCREP_PROP_ARRAY:
93 OC_LOG_V(level, tag, "\t\t%s(int array):%lld x %lld x %lld",
95 val->arr.dimensions[0], val->arr.dimensions[1],
96 val->arr.dimensions[2]);
98 case OCREP_PROP_DOUBLE:
99 OC_LOG_V(level, tag, "\t\t%s(double array):%lld x %lld x %lld",
101 val->arr.dimensions[0], val->arr.dimensions[1],
102 val->arr.dimensions[2]);
104 case OCREP_PROP_BOOL:
105 OC_LOG_V(level, tag, "\t\t%s(bool array):%lld x %lld x %lld",
107 val->arr.dimensions[0], val->arr.dimensions[1],
108 val->arr.dimensions[2]);
110 case OCREP_PROP_STRING:
111 OC_LOG_V(level, tag, "\t\t%s(string array):%lld x %lld x %lld",
113 val->arr.dimensions[0], val->arr.dimensions[1],
114 val->arr.dimensions[2]);
116 case OCREP_PROP_OBJECT:
117 OC_LOG_V(level, tag, "\t\t%s(OCRep array):%lld x %lld x %lld",
119 val->arr.dimensions[0], val->arr.dimensions[1],
120 val->arr.dimensions[2]);
123 OC_LOG_V(ERROR, tag, "\t\t%s <-- Unknown/unsupported array type!",
129 OC_LOG_V(ERROR, tag, "\t\t%s <-- Unknown type!", val->name);
141 static inline void OCPayloadLogDiscovery(LogLevel level, const char* tag,
142 OCDiscoveryPayload* payload)
144 OC_LOG(level, tag, PCF("Payload Type: Discovery"));
147 if(!payload->resources)
149 OC_LOG(level, tag, PCF("\tNO Resources"));
153 OCResourcePayload* res = payload->resources;
157 OC_LOG_V(level, tag, "\tResource #%d", i);
158 OC_LOG_V(level, tag, "\tURI:%s", res->uri);
159 OC_LOG(level, tag, PCF("\tSID:"));
160 OC_LOG_BUFFER(level, tag, res->sid, UUID_SIZE);
161 OC_LOG(level, tag, PCF("\tResource Types:"));
162 OCStringLL* strll = res->types;
165 OC_LOG_V(level, tag, "\t\t%s", strll->value);
168 OC_LOG(level, tag, PCF("\tInterfaces:"));
169 strll = res->interfaces;
172 OC_LOG_V(level, tag, "\t\t%s", strll->value);
176 OC_LOG_V(level, tag, "\tBitmap: %u", res->bitmap);
177 OC_LOG_V(level, tag, "\tSecure?: %s", res->secure ? "true" : "false");
178 OC_LOG_V(level, tag, "\tPort: %u", res->port);
179 OC_LOG(level, tag, PCF(""));
185 static inline void OCPayloadLogDevice(LogLevel level, const char* tag, OCDevicePayload* payload)
187 OC_LOG(level, tag, PCF("Payload Type: Device"));
188 OC_LOG_V(level, tag, "\tURI:%s", payload->uri);
189 OC_LOG(level, tag, PCF("\tSID:"));
190 OC_LOG_BUFFER(level, tag, payload->sid, UUID_SIZE);
191 OC_LOG_V(level, tag, "\tDevice Name:%s", payload->deviceName);
192 OC_LOG_V(level, tag, "\tSpec Version%s", payload->specVersion);
193 OC_LOG_V(level, tag, "\tData Model Version:%s", payload->dataModelVersion);
196 static inline void OCPayloadLogPlatform(LogLevel level, const char* tag, OCPlatformPayload* payload)
198 OC_LOG(level, tag, PCF("Payload Type: Platform"));
199 OC_LOG_V(level, tag, "\tURI:%s", payload->uri);
200 OC_LOG_V(level, tag, "\tPlatform ID:%s", payload->info.platformID);
201 OC_LOG_V(level, tag, "\tMfg Name:%s", payload->info.manufacturerName);
202 OC_LOG_V(level, tag, "\tMfg URL:%s", payload->info.manufacturerUrl);
203 OC_LOG_V(level, tag, "\tModel Number:%s", payload->info.modelNumber);
204 OC_LOG_V(level, tag, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
205 OC_LOG_V(level, tag, "\tPlatform Version:%s", payload->info.platformVersion);
206 OC_LOG_V(level, tag, "\tOS Version:%s", payload->info.operatingSystemVersion);
207 OC_LOG_V(level, tag, "\tHardware Version:%s", payload->info.hardwareVersion);
208 OC_LOG_V(level, tag, "\tFirmware Version:%s", payload->info.firmwareVersion);
209 OC_LOG_V(level, tag, "\tSupport URL:%s", payload->info.supportUrl);
210 OC_LOG_V(level, tag, "\tSystem Time:%s", payload->info.systemTime);
213 static inline void OCPayloadLogPresence(LogLevel level, const char* tag, OCPresencePayload* payload)
215 OC_LOG(level, tag, PCF("Payload Type: Presence"));
216 OC_LOG_V(level, tag, "\tSequence Number:%u", payload->sequenceNumber);
217 OC_LOG_V(level, tag, "\tMax Age:%d", payload->maxAge);
218 OC_LOG_V(level, tag, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
219 OC_LOG_V(level, tag, "\tResource Type:%s", payload->resourceType);
222 static inline void OCPayloadLogSecurity(LogLevel level, const char* tag,
223 OCSecurityPayload* payload)
225 OC_LOG(level, tag, PCF("Payload Type: Security"));
226 OC_LOG_V(level, tag, "\tSecurity Data: %s", payload->securityData);
229 static inline void OCPayloadLog(LogLevel level, const char* tag, OCPayload* payload)
233 OC_LOG(level, tag, PCF("NULL Payload"));
236 switch(payload->type)
238 case PAYLOAD_TYPE_REPRESENTATION:
239 OCPayloadLogRep(level, tag, (OCRepPayload*)payload);
241 case PAYLOAD_TYPE_DISCOVERY:
242 OCPayloadLogDiscovery(level, tag, (OCDiscoveryPayload*)payload);
244 case PAYLOAD_TYPE_DEVICE:
245 OCPayloadLogDevice(level, tag, (OCDevicePayload*)payload);
247 case PAYLOAD_TYPE_PLATFORM:
248 OCPayloadLogPlatform(level, tag, (OCPlatformPayload*)payload);
250 case PAYLOAD_TYPE_PRESENCE:
251 OCPayloadLogPresence(level, tag, (OCPresencePayload*)payload);
253 case PAYLOAD_TYPE_SECURITY:
254 OCPayloadLogSecurity(level, tag, (OCSecurityPayload*)payload);
257 OC_LOG_V(level, tag, "Unknown Payload Type: %d", payload->type);
262 #define OC_LOG_PAYLOAD(level, tag, payload)