static OCDeviceInfo deviceInfo =
{
.deviceName = "IoTivity/Zigbee Server Sample",
+ .specVersion = "IoTivity/Zigbee Device Spec Version",
+ .dataModleVersion = "IoTivity/Zigbee Data Model Version",
};
char *dup = OICStrdup("oic.wk.d");
deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
char *deviceName;
/** Pointer to the types.*/
OCStringLL *types;
+ /** Pointer to the device specification version.*/
+ char *specVersion;
+ /** Pointer to the device data model version.*/
+ char *dataModleVersion;
} OCDeviceInfo;
#ifdef RA_ADAPTER
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, "\tSpec Version:%s", payload->specVersion);
OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
if (payload->types)
{
const char *supportUrl = "mySupportUrl";
const char *version = "myVersion";
const char *systemTime = "2015-05-15T11.04";
+const char *specVersion = "myDeviceSpecVersion";
+const char* dataModleVersion = "myDeviceModleVersion";
// Entity handler should check for resourceTypeName and ResourceInterface in order to GET
// the existence of a known resource
void DeleteDeviceInfo()
{
free (deviceInfo.deviceName);
+ free (deviceInfo.specVersion);
+ free (deviceInfo.dataModleVersion);
}
bool DuplicateString(char** targetString, const char* sourceString)
return OC_STACK_ERROR;
}
-OCStackResult SetDeviceInfo(const char* deviceName)
+OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModleVersion)
{
if(!DuplicateString(&deviceInfo.deviceName, deviceName))
{
return OC_STACK_ERROR;
}
+ if(!DuplicateString(&deviceInfo.specVersion, specVersion))
+ {
+ return OC_STACK_ERROR;
+ }
+ if(!DuplicateString(&deviceInfo.dataModleVersion, dataModleVersion))
+ {
+ return OC_STACK_ERROR;
+ }
return OC_STACK_OK;
}
exit (EXIT_FAILURE);
}
- registrationResult = SetDeviceInfo(deviceName);
+ registrationResult = SetDeviceInfo(deviceName, specVersion, dataModleVersion);
if (registrationResult != OC_STACK_OK)
{
const char *supportUrl = "mySupportUrl";
const char *version = "myVersion";
const char *systemTime = "2015-05-15T11.04";
+const char *specVersion = "myDeviceSpecVersion";
+const char* dataModleVersion = "myDeviceModleVersion";
// Entity handler should check for resourceTypeName and ResourceInterface in order to GET
// the existence of a known resource
void DeleteDeviceInfo()
{
free (deviceInfo.deviceName);
+ free (deviceInfo.specVersion);
+ free (deviceInfo.dataModleVersion);
}
bool DuplicateString(char** targetString, const char* sourceString)
return OC_STACK_ERROR;
}
-OCStackResult SetDeviceInfo(const char* deviceName)
+OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModleVersion)
{
if(!DuplicateString(&deviceInfo.deviceName, deviceName))
{
return OC_STACK_ERROR;
}
+ if(!DuplicateString(&deviceInfo.specVersion, specVersion))
+ {
+ return OC_STACK_ERROR;
+ }
+ if(!DuplicateString(&deviceInfo.dataModleVersion, dataModleVersion))
+ {
+ return OC_STACK_ERROR;
+ }
return OC_STACK_OK;
}
exit (EXIT_FAILURE);
}
- registrationResult = SetDeviceInfo(deviceName);
+ registrationResult = SetDeviceInfo(deviceName, specVersion, dataModleVersion);
if (registrationResult != OC_STACK_OK)
{
else
{
payload = (OCPayload*) OCDevicePayloadCreate(deviceId, savedDeviceInfo.deviceName,
- savedDeviceInfo.types, OC_SPEC_VERSION, OC_DATA_MODEL_VERSION);
+ savedDeviceInfo.types, savedDeviceInfo.specVersion, savedDeviceInfo.dataModleVersion);
if (!payload)
{
discoveryResult = OC_STACK_NO_MEMORY;
OICFree(savedDeviceInfo.deviceName);
OCFreeOCStringLL(savedDeviceInfo.types);
+ OICFree(savedDeviceInfo.specVersion);
+ OICFree(savedDeviceInfo.dataModleVersion);
savedDeviceInfo.deviceName = NULL;
-
+ savedDeviceInfo.specVersion = NULL;
+ savedDeviceInfo.dataModleVersion = NULL;
}
static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
return OC_STACK_NO_MEMORY;
}
}
+
+ if (info.specVersion)
+ {
+ savedDeviceInfo.specVersion = OICStrdup(info.specVersion);
+ if(!savedDeviceInfo.specVersion && info.specVersion)
+ {
+ DeleteDeviceInfo();
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+ else
+ {
+ savedDeviceInfo.specVersion = OICStrdup(OC_SPEC_VERSION);
+ if(!savedDeviceInfo.specVersion && OC_SPEC_VERSION)
+ {
+ DeleteDeviceInfo();
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+
+ if (info.dataModleVersion)
+ {
+ savedDeviceInfo.dataModleVersion = OICStrdup(info.dataModleVersion);
+ if(!savedDeviceInfo.dataModleVersion && info.dataModleVersion)
+ {
+ DeleteDeviceInfo();
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+ else
+ {
+ savedDeviceInfo.dataModleVersion = OICStrdup(OC_DATA_MODEL_VERSION);
+ if(!savedDeviceInfo.dataModleVersion && OC_DATA_MODEL_VERSION)
+ {
+ DeleteDeviceInfo();
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+
return OC_STACK_OK;
}
using namespace OC;
-//Set of strings for each of deviceInfo fields
+//Set of strings for each of platform Info fields
std::string dateOfManufacture = "myDateOfManufacture";
std::string firmwareVersion = "my.Firmware.Version";
std::string manufacturerName = "myName";
std::string supportUrl = "www.mysupporturl.com";
std::string systemTime = "mySystemTime";
-//Set of strings for each of platform info fields
+//Set of strings for each of device info fields
std::string deviceName = "Bill's Battlestar";
+std::string specVersion = "myDeviceSpecVersion";
+std::string dataModleVersion = "myDeviceModleVersion";
//OCPlatformInfo Contains all the platform info to be stored
OCPlatformInfo platformInfo;
void DeleteDeviceInfo()
{
delete[] deviceInfo.deviceName;
+ delete[] deviceInfo.specVersion;
+ delete[] deviceInfo.dataModleVersion;
}
void DuplicateString(char ** targetString, std::string sourceString)
}
-OCStackResult SetDeviceInfo(std::string deviceName)
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModleVersion)
{
DuplicateString(&deviceInfo.deviceName, deviceName);
+
+ if (!specVersion.empty())
+ DuplicateString(&deviceInfo.specVersion, specVersion);
+
+ if (!dataModleVersion.empty())
+ DuplicateString(&deviceInfo.dataModleVersion, dataModleVersion);
+
return OC_STACK_OK;
}
}
- result = SetDeviceInfo(deviceName);
+ result = SetDeviceInfo(deviceName, specVersion, dataModleVersion);
OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
{
delete[] deviceInfo.deviceName;
DeleteStringLL(deviceInfo.types);
-
+ delete[] deviceInfo.specVersion;
+ delete[] deviceInfo.dataModleVersion;
}
void DuplicateString(char ** targetString, std::string sourceString)
deviceInfo.types = NULL;
OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
+ DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
+ DuplicateString(&deviceInfo.dataModleVersion, "myDataModleVersion");
EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
}
TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
{
- OCDeviceInfo di = {0, 0};
+ OCDeviceInfo di = {0, 0, 0, 0};
EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
}