RD query handling
[platform/upstream/iotivity.git] / resource / csdk / stack / include / payload_logging.h
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef PAYLOAD_LOGGING_H_
22 #define PAYLOAD_LOGGING_H_
23
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28
29 #ifdef TB_LOG
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);
35
36 static inline void OCPayloadLogRep(LogLevel level, const char* tag, OCRepPayload* payload)
37 {
38     OC_LOG(level, tag, PCF("Payload Type: Representation"));
39     OCRepPayload* rep = payload;
40     int i = 1;
41     while(rep)
42     {
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;
47         while(strll)
48         {
49             OC_LOG_V(level, tag, "\t\t%s", strll->value);
50             strll = strll->next;
51         }
52         OC_LOG(level, tag, PCF("\tInterfaces:"));
53         strll =  rep->interfaces;
54         while(strll)
55         {
56             OC_LOG_V(level, tag, "\t\t%s", strll->value);
57             strll = strll->next;
58         }
59
60         // TODO Finish Logging: Values
61         OCRepPayloadValue* val = rep->values;
62
63         OC_LOG(level, tag, PCF("\tValues:"));
64
65         while(val)
66         {
67             switch(val->type)
68             {
69                 case OCREP_PROP_NULL:
70                     OC_LOG_V(level, tag, "\t\t%s: NULL", val->name);
71                     break;
72                 case OCREP_PROP_INT:
73                     OC_LOG_V(level, tag, "\t\t%s(int):%lld", val->name, val->i);
74                     break;
75                 case OCREP_PROP_DOUBLE:
76                     OC_LOG_V(level, tag, "\t\t%s(double):%f", val->name, val->d);
77                     break;
78                 case OCREP_PROP_BOOL:
79                     OC_LOG_V(level, tag, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
80                     break;
81                 case OCREP_PROP_STRING:
82                     OC_LOG_V(level, tag, "\t\t%s(string):%s", val->name, val->str);
83                     break;
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);
88                     break;
89                 case OCREP_PROP_ARRAY:
90                     switch(val->arr.type)
91                     {
92                         case OCREP_PROP_INT:
93                             OC_LOG_V(level, tag, "\t\t%s(int array):%lld x %lld x %lld",
94                                     val->name,
95                                     val->arr.dimensions[0], val->arr.dimensions[1],
96                                     val->arr.dimensions[2]);
97                             break;
98                         case OCREP_PROP_DOUBLE:
99                             OC_LOG_V(level, tag, "\t\t%s(double array):%lld x %lld x %lld",
100                                     val->name,
101                                     val->arr.dimensions[0], val->arr.dimensions[1],
102                                     val->arr.dimensions[2]);
103                             break;
104                         case OCREP_PROP_BOOL:
105                             OC_LOG_V(level, tag, "\t\t%s(bool array):%lld x %lld x %lld",
106                                     val->name,
107                                     val->arr.dimensions[0], val->arr.dimensions[1],
108                                     val->arr.dimensions[2]);
109                             break;
110                         case OCREP_PROP_STRING:
111                             OC_LOG_V(level, tag, "\t\t%s(string array):%lld x %lld x %lld",
112                                     val->name,
113                                     val->arr.dimensions[0], val->arr.dimensions[1],
114                                     val->arr.dimensions[2]);
115                             break;
116                         case OCREP_PROP_OBJECT:
117                             OC_LOG_V(level, tag, "\t\t%s(OCRep array):%lld x %lld x %lld",
118                                     val->name,
119                                     val->arr.dimensions[0], val->arr.dimensions[1],
120                                     val->arr.dimensions[2]);
121                             break;
122                         default:
123                             OC_LOG_V(ERROR, tag, "\t\t%s <-- Unknown/unsupported array type!",
124                                     val->name);
125                             break;
126                     }
127                     break;
128                 default:
129                     OC_LOG_V(ERROR, tag, "\t\t%s <-- Unknown type!", val->name);
130                     break;
131             }
132             val = val -> next;
133         }
134
135         ++i;
136         rep = rep->next;
137     }
138
139 }
140
141 static inline void OCPayloadLogDiscovery(LogLevel level, const char* tag,
142         OCDiscoveryPayload* payload)
143 {
144     OC_LOG(level, tag, PCF("Payload Type: Discovery"));
145     int i = 1;
146
147     if(!payload->resources)
148     {
149         OC_LOG(level, tag, PCF("\tNO Resources"));
150         return;
151     }
152
153     OCResourcePayload* res = payload->resources;
154
155     while(res)
156     {
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;
163         while(strll)
164         {
165             OC_LOG_V(level, tag, "\t\t%s", strll->value);
166             strll = strll->next;
167         }
168         OC_LOG(level, tag, PCF("\tInterfaces:"));
169         strll =  res->interfaces;
170         while(strll)
171         {
172             OC_LOG_V(level, tag, "\t\t%s", strll->value);
173             strll = strll->next;
174         }
175
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(""));
180         res = res->next;
181         ++i;
182     }
183 }
184
185 static inline void OCPayloadLogDevice(LogLevel level, const char* tag, OCDevicePayload* payload)
186 {
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);
194 }
195
196 static inline void OCPayloadLogPlatform(LogLevel level, const char* tag, OCPlatformPayload* payload)
197 {
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);
211 }
212
213 static inline void OCPayloadLogPresence(LogLevel level, const char* tag, OCPresencePayload* payload)
214 {
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);
220 }
221
222 static inline void OCPayloadLogSecurity(LogLevel level, const char* tag,
223                                         OCSecurityPayload* payload)
224 {
225     OC_LOG(level, tag, PCF("Payload Type: Security"));
226     OC_LOG_V(level, tag, "\tSecurity Data: %s", payload->securityData);
227 }
228
229 static inline void OCPayloadLog(LogLevel level, const char* tag, OCPayload* payload)
230 {
231     if(!payload)
232     {
233         OC_LOG(level, tag, PCF("NULL Payload"));
234         return;
235     }
236     switch(payload->type)
237     {
238         case PAYLOAD_TYPE_REPRESENTATION:
239             OCPayloadLogRep(level, tag, (OCRepPayload*)payload);
240             break;
241         case PAYLOAD_TYPE_DISCOVERY:
242             OCPayloadLogDiscovery(level, tag, (OCDiscoveryPayload*)payload);
243             break;
244         case PAYLOAD_TYPE_DEVICE:
245             OCPayloadLogDevice(level, tag, (OCDevicePayload*)payload);
246             break;
247         case PAYLOAD_TYPE_PLATFORM:
248             OCPayloadLogPlatform(level, tag, (OCPlatformPayload*)payload);
249             break;
250         case PAYLOAD_TYPE_PRESENCE:
251             OCPayloadLogPresence(level, tag, (OCPresencePayload*)payload);
252             break;
253         case PAYLOAD_TYPE_SECURITY:
254             OCPayloadLogSecurity(level, tag, (OCSecurityPayload*)payload);
255             break;
256 #ifdef WITH_RD
257         case PAYLOAD_TYPE_RD:
258             OCRDPayloadLog(level, tag, (OCRDPayload*)payload);
259             break;
260 #endif
261         default:
262             OC_LOG_V(level, tag, "Unknown Payload Type: %d", payload->type);
263             break;
264     }
265 }
266 #else
267     #define OC_LOG_PAYLOAD(level, tag, payload)
268 #endif
269
270 #ifdef __cplusplus
271 }
272 #endif
273
274 #endif