Fix an issue in setPropertyValue for not able to set dmv value.
Return value of getPropertyValue fixed.
BUG:https://jira.iotivity.org/browse/IOT-1724
BUG:https://jira.iotivity.org/browse/IOT-1725
Change-Id: I118c48b70ae6605a8ca19a292411898e7f5fa74d
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16163
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
OCStackResult OCSetDeviceInfo(OCDeviceInfo info)
{
- OCStringLL *dataModelVersion = NULL;
OCResource *resource = FindResourceByUri(OC_RSRVD_DEVICE_URI);
if (!resource)
{
}
VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, info.specVersion ?
info.specVersion: OC_SPEC_VERSION));
+
if (info.dataModelVersions)
{
- VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, info.dataModelVersions));
+ char *dmv = OCCreateString(info.dataModelVersions);
+ VERIFY_PARAM_NON_NULL(TAG, dmv, "Failed allocating dataModelVersions");
+ OCStackResult r = OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dmv);
+ OICFree(dmv);
+ VERIFY_SUCCESS(r);
}
else
{
- dataModelVersion = OCCreateOCStringLL(OC_DATA_MODEL_VERSION);
- VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersion));
+ VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ OC_DATA_MODEL_VERSION));
}
OIC_LOG(INFO, TAG, "Device parameter initialized successfully.");
return OC_STACK_OK;
exit:
- if (dataModelVersion)
- {
- OCFreeOCStringLL(dataModelVersion);
- }
return OC_STACK_ERROR;
}
OCStackResult OCGetPropertyValue(OCPayloadType type, const char *prop, void **value)
{
- if (!prop || *value)
+ if (!prop)
{
return OC_STACK_INVALID_PARAM;
}
{
return OC_STACK_INVALID_PARAM;
}
+ if (*value)
+ {
+ *value = NULL;
+ }
OCStackResult res = OC_STACK_NO_RESOURCE;
if (PAYLOAD_TYPE_DEVICE == type || PAYLOAD_TYPE_PLATFORM == type)
{
// Fill in the new value.
if (0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, attribute))
{
- resAttrib->attrValue = CloneOCStringLL((OCStringLL *)value);
+ resAttrib->attrValue = OCCreateOCStringLL((char *)value);
}
else
{
itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ char invalidId[] = "myDeviceUUID";
OCPlatformInfo info =
{
- "myDeviceUUID",
- gManufacturerName,
- 0, 0, 0, 0, 0, 0, 0, 0, 0
+ invalidId,
+ gManufacturerName,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0
};
EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Sample"));
EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, "specVersion"));
EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, "x.org.iotivity.newproperty", "value"));
- OCStringLL *dataModelVersions = OCCreateOCStringLL("Data Model Version");
- EXPECT_TRUE(dataModelVersions != NULL);
- EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersions));
- OCFreeOCStringLL(dataModelVersions);
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ "Data Model Version"));
OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
EXPECT_TRUE(handle != NULL);
EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Sample"));
EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, "specVersion"));
EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, "x.org.iotivity.newproperty", "value"));
- OCStringLL *dataModelVersions = OCCreateOCStringLL("Data Model Version");
- EXPECT_TRUE(dataModelVersions != NULL);
- EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, dataModelVersions));
- OCFreeOCStringLL(dataModelVersions);
+ EXPECT_EQ(OC_STACK_OK, OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ "Data Model Version"));
OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
EXPECT_TRUE(handle != NULL);
EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
delete[] platformInfo.systemTime;
}
-void DeleteDeviceInfo()
-{
- delete[] deviceInfo.deviceName;
- delete[] deviceInfo.specVersion;
- OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
void DuplicateString(char ** targetString, std::string sourceString)
{
*targetString = new char[sourceString.length() + 1];
return OC_STACK_OK;
}
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
-{
- DuplicateString(&deviceInfo.deviceName, deviceName);
-
- if (!specVersion.empty())
- {
- DuplicateString(&deviceInfo.specVersion, specVersion);
- }
-
- if (!dataModelVersions.empty())
- {
- OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
- }
-
- return OC_STACK_OK;
-}
-
void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequest)
{
// This function handles slow response case
return -1;
}
- result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
- OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
- result = OCPlatform::registerDeviceInfo(deviceInfo);
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+ result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dataModelVersions);
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ if (handle)
+ {
+ OCBindResourceTypeToResource(handle, "oic.wk.tv");
+ }
if (result != OC_STACK_OK)
{
std::cout << "Added Interface and Type" << std::endl;
DeletePlatformInfo();
- DeleteDeviceInfo();
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse) = 0;
- virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value) = 0;
- virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value) = 0;
+ virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::string& value) = 0;
+ virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::string& value) = 0;
+ virtual OCStackResult getPropertyList(OCPayloadType type, const std::string& tag,
+ std::vector<std::string>& value) = 0;
virtual OCStackResult stop() = 0;
virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
- virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
- virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
-
+ virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::string& value);
+ virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::string& value);
+ virtual OCStackResult getPropertyList(OCPayloadType type, const std::string& tag,
+ std::vector<std::string>& value);
virtual OCStackResult stop();
virtual OCStackResult start();
OCConnectivityType connectivityType, FindResListCallback resourceHandler,
FindErrorCallback errorHandler, QualityOfService QoS = QualityOfService::LowQos);
- OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
- OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
- OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
- OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::vector<std::string>& value);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::string& value);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::vector<std::string>& value);
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::string& value);
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::vector<std::string>& value);
/**
* API for Device Discovery
*
OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
FindPlatformCallback platformInfoHandler, QualityOfService QoS);
- OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
- OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
- OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::string& value);
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::vector<std::string>& value);
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::string& value);
+ OCStackResult getPropertyList(OCPayloadType type, const std::string& tag,
+ std::vector<std::string>& value);
/**
* This API registers a resource with the server
#include <OCApi.h>
#include <oic_malloc.h>
+#include <oic_string.h>
#include <OCPlatform.h>
#include <OCUtilities.h>
#include "logger.h"
return result;
}
- OCStackResult InProcServerWrapper::getPropertyValue(OCPayloadType type, const std::string& propName,
- std::string& propValue)
+ OCStackResult InProcServerWrapper::getPropertyValue(OCPayloadType type,
+ const std::string& propName, std::string& propValue)
{
auto cLock = m_csdkLock.lock();
OCStackResult result = OC_STACK_ERROR;
if (cLock)
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
- result = OCGetPropertyValue(type, propName.c_str(), (void **)propValue.c_str());
+ void *value = NULL;
+ result = OCGetPropertyValue(type, propName.c_str(), &value);
+ if (value && OC_STACK_OK == result)
+ {
+ propValue.assign((const char *)value);
+ OICFree(value);
+ }
+ }
+ return result;
+ }
+
+ OCStackResult InProcServerWrapper::getPropertyList(OCPayloadType type,
+ const std::string& propName, std::vector<std::string>& propValue)
+ {
+ auto cLock = m_csdkLock.lock();
+ OCStackResult result = OC_STACK_ERROR;
+ void *value = NULL;
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCGetPropertyValue(type, propName.c_str(), &value);
+ }
+
+ if (OC_STACK_OK == result)
+ {
+ for (OCStringLL *tmp = (OCStringLL *)value; tmp; tmp = tmp->next)
+ {
+ propValue.push_back(tmp->value);
+ }
+ OCFreeOCStringLL((OCStringLL *)value);
}
return result;
}
return OCPlatform_impl::Instance().registerPlatformInfo(platformInfo);
}
- OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value)
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::string& value)
{
return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
}
- OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value)
+ OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::vector<std::string>& value)
{
return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
}
- OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value)
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::string& value)
{
return OCPlatform_impl::Instance().getPropertyValue(type, tag, value);
}
+ OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::vector<std::string>& value)
+ {
+ return OCPlatform_impl::Instance().getPropertyList(type, tag, value);
+ }
+
OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
{
return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
return checked_guard(m_server, &IServerWrapper::registerPlatformInfo, platformInfo);
}
- OCStackResult OCPlatform_impl::setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value)
+ OCStackResult OCPlatform_impl::setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::string& value)
{
-
return checked_guard(m_server, &IServerWrapper::setPropertyValue, type, tag, value);
}
- OCStackResult OCPlatform_impl::setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value)
+ OCStackResult OCPlatform_impl::setPropertyValue(OCPayloadType type, const std::string& tag,
+ const std::vector<std::string>& value)
{
+ std::string concatString = "";
for (const auto& h : value)
{
- OCStackResult r;
-
- if (OC_STACK_OK != (r = result_guard(setPropertyValue(type, tag, h))))
- {
- return r;
- }
+ if (std::string::npos == h.find(","))
+ {
+ concatString += h + ",";
+ }
+ else
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
}
- return OC_STACK_OK;
+ return checked_guard(m_server, &IServerWrapper::setPropertyValue, type, tag, concatString);
}
- OCStackResult OCPlatform_impl::getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value)
+ OCStackResult OCPlatform_impl::getPropertyValue(OCPayloadType type, const std::string& tag,
+ std::string& value)
{
return checked_guard(m_server, &IServerWrapper::getPropertyValue, type, tag, value);
}
+ OCStackResult OCPlatform_impl::getPropertyList(OCPayloadType type, const std::string& tag,
+ std::vector<std::string>& value)
+ {
+ return checked_guard(m_server, &IServerWrapper::getPropertyList, type, tag, value);
+ }
+
OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
const std::shared_ptr< OCResource > resource)
{
BATCH_INTERFACE);
EXPECT_EQ(OC_STACK_OK, result);
}
-
+
#if defined (_MSC_VER)
TEST(BindInterfaceToResourceTest, DISABLED_BindZeroResourceInterface)
#else
"core.brightlight");
EXPECT_EQ(OC_STACK_OK, result);
}
-
+
#if defined (_MSC_VER)
TEST(BindTypeToResourceTest, DISABLED_BindZeroResourceType)
#else
EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
}
+ TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithSetPropertyValue)
+ {
+ std::string deviceName = "myDeviceName";
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ deviceName));
+ std::string specVersion = "mySpecVersion";
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
+ specVersion));
+ std::vector<std::string> dmv;
+ dmv.push_back("myDataModelVersions");
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dmv));
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ ASSERT_TRUE(NULL != handle);
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
+ }
+
+
+ TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithGetPropertyValue)
+ {
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ "myDeviceName"));
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
+ "mySpecVersion"));
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ "myDataModelVersions"));
+ OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+ ASSERT_TRUE(NULL != handle);
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "oic.wk.tv"));
+
+ std::string value;
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::getPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+ value));
+ EXPECT_STREQ("myDeviceName", value.c_str());
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::getPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
+ value));
+ EXPECT_STREQ("mySpecVersion", value.c_str());
+ std::vector<std::string> dmv;
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::getPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+ dmv));
+ EXPECT_STREQ("myDataModelVersions", dmv[0].c_str());
+
+ EXPECT_STREQ("oic.wk.d", OCGetResourceTypeName(handle, 0));
+ EXPECT_STREQ("oic.d.tv", OCGetResourceTypeName(handle, 1));
+ EXPECT_STREQ("oic.wk.tv", OCGetResourceTypeName(handle, 2));
+ }
//SubscribePresence Test
TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
{