Commit 22932f7a authored by hekra's avatar hekra Committed by Habib Virji

[IOT-972] add type and interface to platform representation

Change-Id: Ie02a201507ffcc0c6a640846dc57341832ea3158
Signed-off-by: default avatarHugues Ekra <hekra@cisco.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5655Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarHabib Virji <habib.virji@samsung.com>
parent d96fb8be
......@@ -1185,6 +1185,8 @@ typedef struct
OCPayload base;
char* uri;
OCPlatformInfo info;
char* rt;
OCStringLL* interfaces;
} OCPlatformPayload;
typedef struct
......
......@@ -229,6 +229,20 @@ static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* paylo
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:");
OIC_LOG_V(level, PL_TAG, "\t\t%s", payload->rt);
}
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)
......
......@@ -1612,6 +1612,14 @@ OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo)
}
payload->base.type = PAYLOAD_TYPE_PLATFORM;
payload->interfaces = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
if (!payload->interfaces)
{
return NULL;
}
payload->interfaces->value = OICStrdup(OC_RSRVD_INTERFACE_READ);
payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
payload->info = *platformInfo;
return payload;
......@@ -1627,6 +1635,14 @@ OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo)
}
payload->base.type = PAYLOAD_TYPE_PLATFORM;
payload->interfaces = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
if (!payload->interfaces)
{
return NULL;
}
payload->interfaces->value = OICStrdup(OC_RSRVD_INTERFACE_READ);
payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
OCCopyPlatformInfo(platformInfo, payload);
return payload;
......@@ -1655,6 +1671,8 @@ void OCPlatformPayloadDestroy(OCPlatformPayload* payload)
}
OICFree(payload->uri);
OCPlatformInfoDestroy(&payload->info);
OICFree(payload->rt);
OCFreeOCStringLL(payload->interfaces);
OICFree(payload);
}
......
......@@ -482,6 +482,27 @@ static int64_t OCConvertPlatformPayload(OCPlatformPayload *payload, uint8_t *out
sizeof(OC_RSRVD_SYSTEM_TIME) - 1, payload->info.systemTime);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding system time");
// Resource type
if (payload->rt)
{
err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_RESOURCE_TYPE,
sizeof(OC_RSRVD_RESOURCE_TYPE) - 1, payload->rt);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding resource type");
}
// Resource interfaces
if (payload->interfaces)
{
err |= cbor_encode_text_string(&repMap, OC_RSRVD_INTERFACE,
sizeof(OC_RSRVD_INTERFACE) - 1);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding platform interface tag");
char* joinedInterfaces = OCStringLLJoin(payload->interfaces);
VERIFY_PARAM_NON_NULL(TAG, joinedInterfaces, "Failed creating joined string");
err |= cbor_encode_text_string(&repMap, joinedInterfaces, strlen(joinedInterfaces));
OICFree(joinedInterfaces);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding platform interface value");
}
// Close Map
err |= cbor_encoder_close_container(&encoder, &repMap);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed closing rep map");
......
......@@ -389,6 +389,9 @@ static OCStackResult OCParsePlatformPayload(OCPayload **outPayload, CborValue *r
OCStackResult ret = OC_STACK_INVALID_PARAM;
CborError err = CborNoError;
OCPlatformInfo info = {0};
char* rt = NULL;
OCStringLL* interfaces = NULL;
OCPlatformPayload* out = NULL;
VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid Parameter outPayload");
......@@ -476,11 +479,30 @@ static OCStackResult OCParsePlatformPayload(OCPayload **outPayload, CborValue *r
VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find systemTume in the platform payload");
}
// Resource type
err = cbor_value_map_find_value(rootValue, OC_RSRVD_RESOURCE_TYPE, &repVal);
if(cbor_value_is_valid(&repVal))
{
err = cbor_value_dup_text_string(&repVal, &rt, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find resource type in the platform payload");
}
// Interface Types
err = cbor_value_map_find_value(rootValue, OC_RSRVD_INTERFACE, &repVal);
if(cbor_value_is_valid(&repVal))
{
err = OCParseStringLL(rootValue, OC_RSRVD_INTERFACE, &interfaces);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find interfaces tag/value");
}
err = cbor_value_advance(rootValue);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed to find supportUrl in the platform payload");
*outPayload = (OCPayload *)OCPlatformPayloadCreateAsOwner(&info);
return OC_STACK_OK;
out = (OCPlatformPayload *)OCPlatformPayloadCreateAsOwner(&info);
out->rt = rt;
out->interfaces = interfaces;
*outPayload = (OCPayload *)out;
return OC_STACK_OK;
}
exit:
......
......@@ -130,6 +130,15 @@ namespace OC
std::string(payload->info.systemTime) :
std::string();
if (payload->rt)
{
rep.addResourceType(payload->rt);
}
for (OCStringLL *strll = payload->interfaces; strll; strll = strll->next)
{
rep.addResourceInterface(strll->value);
}
m_reps.push_back(std::move(rep));
}
......
......@@ -126,6 +126,8 @@ namespace OCRepresentationEncodingTest
EXPECT_STREQ(fwver1, platform->info.firmwareVersion);
EXPECT_STREQ(url1, platform->info.supportUrl);
EXPECT_STREQ(time1, platform->info.systemTime);
EXPECT_STREQ(OC_RSRVD_INTERFACE_READ, platform->interfaces->value);
EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt);
uint8_t* cborData;
size_t cborSize;
......@@ -148,6 +150,8 @@ namespace OCRepresentationEncodingTest
EXPECT_STREQ(platform->info.firmwareVersion, platform->info.firmwareVersion);
EXPECT_STREQ(platform->info.supportUrl, platform->info.supportUrl);
EXPECT_STREQ(platform->info.systemTime, platform2->info.systemTime);
EXPECT_STREQ(platform->interfaces->value, platform2->interfaces->value);
EXPECT_STREQ(platform->rt, platform2->rt);
OCPayloadDestroy((OCPayload*)platform);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment