#include <dlog.h>
#endif
+#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
+#endif
+#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
+#endif
#include <inttypes.h>
#include "rdpayload.h"
#define PL_TAG "PayloadLog"
#ifdef TB_LOG
- #define OC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
+ #define OIC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
#define UUID_SIZE (16)
const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
static inline void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
{
- OC_LOG(level, (PL_TAG), "Payload Type: Representation");
+ OIC_LOG(level, (PL_TAG), "Payload Type: Representation");
OCRepPayload* rep = payload;
int i = 1;
while(rep)
{
- OC_LOG_V(level, PL_TAG, "\tResource #%d", i);
- OC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
- OC_LOG(level, PL_TAG, "\tResource Types:");
+ OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
+ OIC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
+ OIC_LOG(level, PL_TAG, "\tResource Types:");
OCStringLL* strll = rep->types;
while(strll)
{
- OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
strll = strll->next;
}
- OC_LOG(level, PL_TAG, "\tInterfaces:");
+ OIC_LOG(level, PL_TAG, "\tInterfaces:");
strll = rep->interfaces;
while(strll)
{
- OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
strll = strll->next;
}
// TODO Finish Logging: Values
OCRepPayloadValue* val = rep->values;
- OC_LOG(level, PL_TAG, "\tValues:");
+ OIC_LOG(level, PL_TAG, "\tValues:");
while(val)
{
switch(val->type)
{
case OCREP_PROP_NULL:
- OC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
break;
case OCREP_PROP_INT:
- OC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
break;
case OCREP_PROP_DOUBLE:
- OC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
break;
case OCREP_PROP_BOOL:
- OC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
break;
case OCREP_PROP_STRING:
- OC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
break;
case OCREP_PROP_BYTE_STRING:
- OC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
- OC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
+ OIC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
break;
case OCREP_PROP_OBJECT:
// Note: Only prints the URI (if available), to print further, you'll
// need to dig into the object better!
- OC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
break;
case OCREP_PROP_ARRAY:
switch(val->arr.type)
{
case OCREP_PROP_INT:
- OC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu",
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu",
val->name,
val->arr.dimensions[0], val->arr.dimensions[1],
val->arr.dimensions[2]);
break;
case OCREP_PROP_DOUBLE:
- OC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu",
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu",
val->name,
val->arr.dimensions[0], val->arr.dimensions[1],
val->arr.dimensions[2]);
break;
case OCREP_PROP_BOOL:
- OC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
val->name,
val->arr.dimensions[0], val->arr.dimensions[1],
val->arr.dimensions[2]);
break;
case OCREP_PROP_STRING:
- OC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu",
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu",
val->name,
val->arr.dimensions[0], val->arr.dimensions[1],
val->arr.dimensions[2]);
break;
case OCREP_PROP_BYTE_STRING:
- OC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu",
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu",
val->name,
val->arr.dimensions[0], val->arr.dimensions[1],
val->arr.dimensions[2]);
break;
case OCREP_PROP_OBJECT:
- OC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
val->name,
val->arr.dimensions[0], val->arr.dimensions[1],
val->arr.dimensions[2]);
break;
default:
- OC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
+ OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
val->name);
break;
}
break;
default:
- OC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
+ OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
break;
}
val = val -> next;
static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
{
- OC_LOG(level, PL_TAG, "Payload Type: Discovery");
+ OIC_LOG(level, PL_TAG, "Payload Type: Discovery");
int i = 1;
if(!payload->resources)
{
- OC_LOG(level, PL_TAG, "\tNO Resources");
+ OIC_LOG(level, PL_TAG, "\tNO Resources");
return;
}
- OC_LOG(level, PL_TAG, "\tSID:");
- OC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
+ OIC_LOG_V(level, PL_TAG, "\tSID: %s", payload->sid);
+ if (payload->baseURI)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tBase URI:%s", payload->baseURI);
+ }
+ if (payload->name)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tNAME: %s", payload->name);
+ }
+ if (payload->uri)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tURI: %s", payload->uri);
+ }
+ if (payload->type)
+ {
+ for (OCStringLL *strll = payload->type; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tResource Type: %s", strll->value);
+ }
+ }
+ OIC_LOG(level, PL_TAG, "\tInterface:");
+ for (OCStringLL *itf = payload->interface; itf; itf = itf->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", itf->value);
+ }
+
OCResourcePayload* res = payload->resources;
while(res)
{
- OC_LOG_V(level, PL_TAG, "\tResource #%d", i);
- OC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
- OC_LOG(level, PL_TAG, "\tResource Types:");
+ OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
+ OIC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
+ OIC_LOG(level, PL_TAG, "\tResource Types:");
OCStringLL* strll = res->types;
while(strll)
{
- OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
strll = strll->next;
}
- OC_LOG(level, PL_TAG, "\tInterfaces:");
+ OIC_LOG(level, PL_TAG, "\tInterfaces:");
strll = res->interfaces;
while(strll)
{
- OC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
strll = strll->next;
}
- OC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
- OC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
- OC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
- OC_LOG(level, PL_TAG, "");
+ OIC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
+ OIC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
+ OIC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
+ OIC_LOG(level, PL_TAG, "");
res = res->next;
++i;
}
static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
{
- OC_LOG(level, PL_TAG, "Payload Type: Device");
- OC_LOG(level, PL_TAG, "\tSID:");
- OC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
- OC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
- OC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
- OC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
+ OIC_LOG(level, PL_TAG, "Payload Type: Device");
+ OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
+ OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
+ OIC_LOG_V(level, PL_TAG, "\tSpec Version:%s", payload->specVersion);
+ OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
+ if (payload->types)
+ {
+ OIC_LOG(level, PL_TAG, "\tResource Type:");
+ for (OCStringLL *strll = payload->types; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ }
+ }
+ if (payload->interfaces)
+ {
+ OIC_LOG(level, PL_TAG, "\tInterface:");
+ for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ }
+ }
}
static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
{
- OC_LOG(level, PL_TAG, "Payload Type: Platform");
- OC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
- OC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
- OC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
- OC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
- OC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
- OC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
- OC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
- OC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
- OC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
- OC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
- OC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
- OC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
+ OIC_LOG(level, PL_TAG, "Payload Type: Platform");
+ OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
+ OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
+ OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
+ OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
+ OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
+ OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
+ OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
+ OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
+ OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
+ OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
+ OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
+ OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
+
+ if (payload->rt)
+ {
+ OIC_LOG(level, PL_TAG, "\tResource Types:");
+ for (OCStringLL *strll = payload->rt; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ }
+ }
+ if (payload->interfaces)
+ {
+ OIC_LOG(level, PL_TAG, "\tResource Interfaces:");
+ for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ }
+ }
}
static inline void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
{
- OC_LOG(level, PL_TAG, "Payload Type: Presence");
- OC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
- OC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
- OC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
- OC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
+ OIC_LOG(level, PL_TAG, "Payload Type: Presence");
+ OIC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
+ OIC_LOG_V(level, PL_TAG, "\tMax Age:%d", payload->maxAge);
+ OIC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
+ OIC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
}
static inline void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
{
- OC_LOG(level, PL_TAG, "Payload Type: Security");
- OC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
+ OIC_LOG(level, PL_TAG, "Payload Type: Security");
+ OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
}
static inline void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
if (payload->rdDiscovery)
{
- OC_LOG(level, PL_TAG, "RD Discovery");
- OC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
- OC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
- OC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
+ OIC_LOG(level, PL_TAG, "RD Discovery");
+ OIC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
+ OIC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
+ OIC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
}
if (payload->rdPublish)
{
- OC_LOG(level, PL_TAG, "RD Publish");
+ OIC_LOG(level, PL_TAG, "RD Publish");
OCResourceCollectionPayload *rdPublish = payload->rdPublish;
OCTagsLog(level, rdPublish->tags);
OCLinksLog(level, rdPublish->setLinks);
{
if(!payload)
{
- OC_LOG(level, PL_TAG, "NULL Payload");
+ OIC_LOG(level, PL_TAG, "NULL Payload");
return;
}
switch(payload->type)
OCRDPayloadLog(level, (OCRDPayload*)payload);
break;
default:
- OC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
+ OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
break;
}
}
#else
- #define OC_LOG_PAYLOAD(level, payload)
+ #define OIC_LOG_PAYLOAD(level, payload)
#endif
#ifdef __cplusplus