Commit 9705d8cb authored by Habib Virji's avatar Habib Virji

Add generic API for setting and getting defined tag values

- Uses the resource attribute of OCResource for storing and retrieving device and platform values.
- Removed global savedDeviceInfo and savedPlatformInfo. The information passed via
OCSetDeviceInfo and OCSetPlatformInfo is stored in rsrcAttributes.
- OCAttribute type change from char * to void * to store generic value, this was part of OCResource but was not used.
- Payload type PAYLOAD_TYPE_DEVICE and PAYLOAD_TYPE_PLATFORM is removed from PAYLOAD_TYPE as this was used only internally.
- Payload convert and parse for payload type device and platform is removed, as device and payload uri uses
OCRepresentation payload type.
- Delete function to delete resource attributes.
- OCDevicePayloadCreate and OCPlatformCreate is removed as this was only used internally, all values are now stored in
resource attributes.
- Moves OCSetDeviceInfo and OCSetPlatformInfo from ocstack to ocresource to avoid duplicate checking.
- Add set and get API to set parameter for /oic/d and /oic/p.
- OCGetResourceHandleAtUri accesible without ifdef RD_CLIENT.
- Updated Unit test to test the functionality.
- Add the OCSSetParam and OCGetParam in C++ and Java

Change-Id: If822ae95a70e681121528679de8da1375718de0c
Signed-off-by: default avatarHabib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14377Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
parent 9aac67cc
......@@ -1644,6 +1644,104 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0(
}
}
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue0
(JNIEnv *env, jclass clazz, jint jType, jstring jPropName, jobjectArray jPropValue)
{
try
{
OCPayloadType type = (OCPayloadType)jType;
std::string propName;
std::vector<std::string> propValue;
if (jPropName)
{
propName = env->GetStringUTFChars(jPropName, nullptr);
}
if (jPropValue)
{
JniUtils::convertJavaStrArrToStrVector(env, jPropValue, propValue);
}
OCStackResult result = OCPlatform::setPropertyValue(type, propName, propValue);
if (OC_STACK_OK != result)
{
ThrowOcException(result, "Failed to set property");
return;
}
}
catch (OCException& e)
{
LOGE("Error is due to %s", e.reason().c_str());
ThrowOcException(e.code(), e.reason().c_str());
}
}
/*
* Class: org_iotivity_base_OcPlatform
* Method: setPropertyValue0
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue1
(JNIEnv *env, jclass clazz, jint jType, jstring jPropName, jstring jPropValue)
{
try
{
OCPayloadType type = (OCPayloadType)jType;
std::string propName;
std::string propValue;
if (jPropName)
{
propName = env->GetStringUTFChars(jPropName, nullptr);
}
if (jPropValue)
{
propValue = env->GetStringUTFChars(jPropValue, nullptr);
}
OCStackResult result = OCPlatform::setPropertyValue(type, propName, propValue);
if (OC_STACK_OK != result)
{
ThrowOcException(result, "Failed to set property");
return;
}
}
catch (OCException& e)
{
LOGE("Error is due to %s", e.reason().c_str());
ThrowOcException(e.code(), e.reason().c_str());
}
}
/*
* Class: org_iotivity_base_OcPlatform
* Method: getPropertyValue
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPropertyValue0
(JNIEnv *env, jclass clazz, jint jType, jstring jPropName, jstring jPropValue)
{
try
{
OCPayloadType type = (OCPayloadType) jType;
std::string propName;
std::string propValue;
if (jPropName)
{
propName = env->GetStringUTFChars(jPropName, nullptr);
}
OCStackResult result = OCPlatform::getPropertyValue(type, propName, propValue);
if (OC_STACK_OK != result)
{
ThrowOcException(result, "Failed to get property value.");
return;
}
}
catch (OCException& e)
{
LOGE("Error is due to %s", e.reason().c_str());
ThrowOcException(e.code(), e.reason().c_str());
}
}
/*
* Class: org_iotivity_base_OcPlatform
* Method: unregisterResource0
......
......@@ -195,6 +195,30 @@ extern "C" {
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0
(JNIEnv *, jclass, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring);
/*
* Class: org_iotivity_base_OcPlatform
* Method: setPropertyValue0
* Signature: (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue0
(JNIEnv *, jclass, jint, jstring, jobjectArray);
/*
* Class: org_iotivity_base_OcPlatform
* Method: setPropertyValue1
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setPropertyValue1
(JNIEnv *, jclass, jint, jstring, jstring);
/*
* Class: org_iotivity_base_OcPlatform
* Method: getPropertyValue0
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPropertyValue0
(JNIEnv *, jint, jstring, jstring);
/*
* Class: org_iotivity_base_OcPlatform
* Method: unregisterResource0
......
......@@ -562,6 +562,49 @@ public final class OcPlatform {
String[] deviceTypes
) throws OcException;
/**
* Set param Info
*
* @param ocDeviceInfo object containing all the device specific information
* @throws OcException if failure
*/
public static void setPropertyValue(
int path, String propName, String propValue) throws OcException {
OcPlatform.initCheck();
OcPlatform.setPropertyValue0(path, propName, propValue);
}
public static void setPropertyValue(
int path, String propName, List<String> propValue) throws OcException {
OcPlatform.initCheck();
OcPlatform.setPropertyValue1(path, propName, propValue.toArray(new String[propValue.size()]));
}
public static void getPropertyValue(
int path, String propName, String propValue) throws OcException {
OcPlatform.initCheck();
OcPlatform.getPropertyValue0(path, propName, propValue);
}
private static native void setPropertyValue0(
int path,
String propName,
String propValue
) throws OcException;
private static native void setPropertyValue1(
int path,
String propName,
String[] propValue
) throws OcException;
private static native void getPropertyValue0(
int path,
String propName,
String propValue
) throws OcException;
/**
* Register Platform Info
*
......
......@@ -29,6 +29,7 @@ calcDimTotal
ConvertStrToUuid
convertTriggerEnumToString
FindResourceByUri
OCBindResource
OCBindResourceHandler
OCBindResourceInsToResource
......@@ -48,10 +49,13 @@ OCDoResource
OCDoResponse
OCEncodeAddressForRFC6874
OCFreeOCStringLL
OCGetDeviceId
OCGetDirectPairedDevices
OCGetHeaderOption
OCGetNumberOfResources
OCGetNumberOfResourceInterfaces
OCGetNumberOfResourceTypes
OCGetPropertyValue
OCGetResourceHandle
OCGetResourceHandleAtUri
OCGetResourceHandleFromCollection
......@@ -67,7 +71,6 @@ OCInit1
OCNotifyAllObservers
OCNotifyListOfObservers
OCPayloadDestroy
OCPlatformPayloadCreate
OCPresencePayloadCreate
OCProcess
OCRegisterPersistentStorageHandler
......@@ -104,15 +107,13 @@ OCRepPayloadSetUri
OCResourcePayloadAddStringLL
OCSecurityPayloadCreate
OCSetDefaultDeviceEntityHandler
OCSetDeviceId
OCSetDeviceInfo
OCSetHeaderOption
OCSetPlatformInfo
OCSetPropertyValue
OCStartPresence
OCStop
OCStopPresence
OCStopMulticastServer
OCUnBindResource
OCSetHeaderOption
OCGetHeaderOption
OCGetDeviceId
OCSetDeviceId
FindResourceByUri
......@@ -155,10 +155,10 @@ typedef struct attr_t {
/** The name of the attribute; used to look up the attribute in list.
* for a given attribute SHOULD not be changed once assigned.
*/
const char *attrName;
char *attrName;
/** value of the attribute as string.*/
char *attrValue;
/** value of the attribute as void. To support both string and @OCStringLL value*/
void *attrValue;
} OCAttribute;
/**
......
......@@ -309,6 +309,13 @@ OCStackResult OCUpdateResourceInsWithResponse(const char *requestUri,
const OCClientResponse *response);
#endif
/**
* Delete all of the dynamically allocated elements that were created for the resource attributes.
*
* @param resourceAttr Specified resource attribute.
*/
void OCDeleteResourceAttributes(OCAttribute *rsrcAttributes);
#ifdef __cplusplus
}
#endif // __cplusplus
......
......@@ -249,17 +249,6 @@ OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, si
void OCDiscoveryResourceDestroy(OCResourcePayload* payload);
void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
// Device Payload
OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
const OCStringLL *types, const char* specVer, const char* dmVer);
void OCDevicePayloadDestroy(OCDevicePayload* payload);
// Platform Payload
OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
void OCPlatformInfoDestroy(OCPlatformInfo *info);
void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
// Presence Payload
OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
OCPresenceTrigger trigger, const char* resourceType);
......
......@@ -586,17 +586,17 @@ OCStackResult OCBindResourceInsToResource(OCResourceHandle handle, uint8_t ins);
*/
OCStackResult OCGetResourceIns(OCResourceHandle handle, uint8_t *ins);
#endif
/**
* This function gets a resource handle by resource uri.
*
* @param uri Uri of Resource to get Resource handle.
*
* @return Found resource handle or NULL if not found.
*/
* This function gets a resource handle by resource uri.
*
* @param uri Uri of Resource to get Resource handle.
*
* @return Found resource handle or NULL if not found.
*/
OCResourceHandle OCGetResourceHandleAtUri(const char *uri);
#endif
#ifdef RD_SERVER
/**
* Search the RD database for queries.
......@@ -702,6 +702,31 @@ OCStackResult OCDecodeAddressForRFC6874(char* outputAddress,
size_t outputSize,
const char* inputAddress,
const char* end);
/**
* Set the value of /oic/d and /oic/p properties. This function is a generic function that sets for
* all OCF defined properties.
*
* @param type the payload type for device and platform as defined in @ref OCPayloadType.
* @param propName the pre-defined property as per OCF spec.
* @param value the value of the property to be set.
*
* @return ::OC_STACK_OK on success and other value otherwise.
*/
OCStackResult OCSetPropertyValue(OCPayloadType type, const char *propName, const void *value);
/**
* Get the value of /oic/d and /oic/p properties. This function is a generic function that get value
* for all OCF defined properties.
*
* @param type the payload type for device and platform as defined in @ref OCPayloadType.
* @param propName the pre-defined as per OCF spec.
* @param value this holds the return value. In case of error will be set to NULL.
*
* @return ::OC_STACK_OK on success and other value otherwise.
*/
OCStackResult OCGetPropertyValue(OCPayloadType type, const char *propName, void **value);
#ifdef __cplusplus
}
#endif // __cplusplus
......
......@@ -49,17 +49,32 @@
#define MAX_QUERY_LENGTH (256)
#endif
/**
* Maximum length of the Manufacturer name supported by the server
* for manufacturer name.
* @deprecated use MAX_PLATFORM_NAME_LENGTH instead.
*/
#define MAX_MANUFACTURER_NAME_LENGTH (16)
#define MAX_MANUFACTURER_NAME_LENGTH (64)
/**
* Maximum length of the URL to the Manufacturer details supported by
* the server.
* @deprecated use MAX_PLATFORM_URL_LENGTH instead.
*/
#define MAX_MANUFACTURER_URL_LENGTH (256)
/**
* Maximum length of the value supported by the server
* for platform property of type string.
*/
#define MAX_PLATFORM_NAME_LENGTH (64)
/**
* Maximum length of the URL supported by the server
* for platform property of type url.
*/
#define MAX_MANUFACTURER_URL_LENGTH (32)
#define MAX_PLATFORM_URL_LENGTH (256)
/**
* Maximum number of resources which can be contained inside collection
......
......@@ -270,6 +270,8 @@ extern "C" {
/** System time for the platform. */
#define OC_RSRVD_SYSTEM_TIME "st"
/** VID for the platform. */
#define OC_RSRVD_VID "vid"
/**
* Device.
*/
......@@ -290,8 +292,7 @@ extern "C" {
#define OC_SPEC_VERSION "core.1.1.0"
/** Device Data Model version.*/
#define OC_DATA_MODEL_VERSION "res.1.1.0"
#define OC_DATA_MODEL_VERSION "res.1.1.0,sh.1.1.0"
/**
* These provide backward compatibility - their use is deprecated.
*/
......@@ -1160,6 +1161,7 @@ typedef struct OCHeaderOption
/**
* This structure describes the platform properties. All non-Null properties will be
* included in a platform discovery request.
* @deprecated: Use OCSetPropertyValue to set platform value.
*/
typedef struct
{
......@@ -1202,6 +1204,7 @@ typedef struct
* This structure is expected as input for device properties.
* device name is mandatory and expected from the application.
* device id of type UUID will be generated by the stack.
* @deprecated: Use OCSetPropertyValue to set device value.
*/
typedef struct
{
......@@ -1282,9 +1285,9 @@ typedef enum
PAYLOAD_TYPE_INVALID,
/** The payload is an OCDiscoveryPayload */
PAYLOAD_TYPE_DISCOVERY,
/** The payload is an OCDevicePayload */
/** The payload of the device */
PAYLOAD_TYPE_DEVICE,
/** The payload is an OCPlatformPayload */
/** The payload type of the platform */
PAYLOAD_TYPE_PLATFORM,
/** The payload is an OCRepPayload */
PAYLOAD_TYPE_REPRESENTATION,
......@@ -1437,26 +1440,6 @@ typedef struct OCDiscoveryPayload
} OCDiscoveryPayload;
typedef struct
{
OCPayload base;
char *sid;
char* deviceName;
char* specVersion;
OCStringLL *dataModelVersions;
OCStringLL *interfaces;
OCStringLL *types;
} OCDevicePayload;
typedef struct
{
OCPayload base;
char* uri;
OCPlatformInfo info;
OCStringLL* rt;
OCStringLL* interfaces;
} OCPlatformPayload;
typedef struct
{
OCPayload base;
......
......@@ -268,72 +268,6 @@ INLINE_API void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payloa
}
}
INLINE_API void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
{
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);
if (payload->dataModelVersions)
{
OIC_LOG(level, PL_TAG, "\tData Model Version:");
for (OCStringLL *strll = payload->dataModelVersions; strll; strll = strll->next)
{
OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
}
}
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);
}
}
}
INLINE_API void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
{
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);
}
}
}
INLINE_API void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
{
OIC_LOG(level, PL_TAG, "Payload Type: Presence");
......@@ -379,12 +313,6 @@ INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
case PAYLOAD_TYPE_DISCOVERY:
OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
break;
case PAYLOAD_TYPE_DEVICE:
OCPayloadLogDevice(level, (OCDevicePayload*)payload);
break;
case PAYLOAD_TYPE_PLATFORM:
OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
break;
case PAYLOAD_TYPE_PRESENCE:
OCPayloadLogPresence(level, (OCPresencePayload*)payload);
break;
......
......@@ -888,12 +888,12 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
bool success = true;
if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_PLATFORM_NAME_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_PLATFORM_URL_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
......
......@@ -841,12 +841,12 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
bool success = true;
if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_PLATFORM_NAME_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_PLATFORM_URL_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
......
......@@ -52,12 +52,6 @@ void OCPayloadDestroy(OCPayload* payload)
case PAYLOAD_TYPE_DISCOVERY:
OCDiscoveryPayloadDestroy((OCDiscoveryPayload*)payload);
break;
case PAYLOAD_TYPE_DEVICE:
OCDevicePayloadDestroy((OCDevicePayload*)payload);
break;
case PAYLOAD_TYPE_PLATFORM:
OCPlatformPayloadDestroy((OCPlatformPayload*)payload);
break;
case PAYLOAD_TYPE_PRESENCE:
OCPresencePayloadDestroy((OCPresencePayload*)payload);
break;
......@@ -70,6 +64,7 @@ void OCPayloadDestroy(OCPayload* payload)
break;
}
}
OCRepPayload* OCRepPayloadCreate()
{
OCRepPayload* payload = (OCRepPayload*)OICCalloc(1, sizeof(OCRepPayload));
......@@ -1804,9 +1799,10 @@ void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource
bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, const char *value)
{
char *dup = OICStrdup(value);
VERIFY_PARAM_NON_NULL(TAG, dup, "Failed copying string");
char *dup = NULL;
VERIFY_PARAM_NON_NULL(TAG, value, "Invalid Parameters");
dup = OICStrdup(value);
VERIFY_PARAM_NON_NULL(TAG, dup, "Failed copying string");
if (!*stringLL)
{
......@@ -1885,169 +1881,6 @@ void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload)
OICFree(payload);
}
OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
const OCStringLL *types, const char* specVer, const char* dmVer)
{
OCDevicePayload* payload = (OCDevicePayload*)OICCalloc(1, sizeof(OCDevicePayload));
if (!payload)
{
return NULL;
}
payload->base.type = PAYLOAD_TYPE_DEVICE;
payload->sid = OICStrdup(sid);
if (sid && !payload->sid)
{
goto exit;