X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fstack%2Finclude%2Focpayload.h;h=992adc8d5a2d0e97818b9b500198592bb64f61e6;hb=00380c6e4145bf0f084b235bc153c9617093efe5;hp=d453621d2c5d4cb58b868ff076db5ab074d12fff;hpb=cc68c51711ac0211b3c29da57ef6f794dd2f6120;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/include/ocpayload.h b/resource/csdk/stack/include/ocpayload.h old mode 100755 new mode 100644 index d453621..992adc8 --- a/resource/csdk/stack/include/ocpayload.h +++ b/resource/csdk/stack/include/ocpayload.h @@ -21,6 +21,12 @@ #ifndef OCPAYLOAD_H_ #define OCPAYLOAD_H_ +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif #include #include #include "octypes.h" @@ -30,6 +36,28 @@ extern "C" { #endif +/** + * Macro to verify the validity of cbor operation. + */ +#define VERIFY_CBOR_SUCCESS(log_tag, err, log_message) \ + if ((CborNoError != (err)) && (CborErrorOutOfMemory != (err))) \ + { \ + if ((log_tag) && (log_message)) \ + { \ + OIC_LOG_V(ERROR, (log_tag), "%s with cbor error: \'%s\'.", \ + (log_message), (cbor_error_string(err))); \ + } \ + goto exit; \ + } \ + +#define VERIFY_PARAM_NON_NULL(log_tag, err, log_message) \ + if (NULL == (err)) \ + { \ + OIC_LOG_V(FATAL, (log_tag), "%s", (log_message)); \ + goto exit;\ + } \ + + typedef struct OCResource OCResource; void OCPayloadDestroy(OCPayload* payload); @@ -47,6 +75,7 @@ bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri); bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType); bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface); +bool OCRepPayloadAddModelVersion(OCRepPayload* payload, const char* dmv); bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType); bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface); @@ -60,6 +89,43 @@ bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value); bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value); +/** + * This function allocates memory for the byte string and sets it in the payload. + * + * @param payload Pointer to the payload to which byte string needs to be added. + * @param name Name of the byte string. + * @param value Byte string and it's length. + * + * @return true on success, false upon failure. + */ +bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value); + +/** + * This function sets the byte string in the payload. + * + * @param payload Pointer to the payload to which byte string needs to be added. + * @param name Name of the byte string. + * @param value Byte string and it's length. + * + * @return true on success, false upon failure. + */ +bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name, + OCByteString* value); + +/** + * This function gets the byte string from the payload. + * + * @param payload Pointer to the payload from which byte string needs to be retrieved. + * @param name Name of the byte string. + * @param value Byte string and it's length. + * + * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string. + * + * @return true on success, false upon failure. + */ +bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name, + OCByteString* value); + bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value); bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value); bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value); @@ -72,6 +138,48 @@ bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name, OCRepPayload* value); bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value); +/** + * This function allocates memory for the byte string array and sets it in the payload. + * + * @param payload Pointer to the payload to which byte string array needs to be added. + * @param name Name of the byte string. + * @param array Byte string array. + * @param dimensions Number of byte strings in above array. + * + * @return true on success, false upon failure. + */ +bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name, + OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]); + +/** + * This function sets the byte string array in the payload. + * + * @param payload Pointer to the payload to which byte string array needs to be added. + * @param name Name of the byte string. + * @param array Byte string array. + * @param dimensions Number of byte strings in above array. + * + * @return true on success, false upon failure. + */ +bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name, + const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]); + +/** + * This function gets the byte string array from the payload. + * + * @param payload Pointer to the payload from which byte string array needs to be retrieved. + * @param name Name of the byte string array. + * @param value Byte string array. + * @param dimensions Number of byte strings in above array. + * + * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is + * finished using the byte string array. + * + * @return true on success, false upon failure. + */ +bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name, + OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]); + bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name, int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]); bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name, @@ -112,29 +220,34 @@ void OCRepPayloadDestroy(OCRepPayload* payload); // Discovery Payload OCDiscoveryPayload* OCDiscoveryPayloadCreate(); -OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData); +OCSecurityPayload* OCSecurityPayloadCreate(const uint8_t* securityData, size_t size); void OCSecurityPayloadDestroy(OCSecurityPayload* payload); +#ifndef TCP_ADAPTER +void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res, + uint16_t securePort); +#else void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res, - uint16_t port); + uint16_t securePort, uint16_t tcpPort); +#endif void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res); -bool OCResourcePayloadAddResourceType(OCResourcePayload* payload, const char* resourceType); -bool OCResourcePayloadAddInterface(OCResourcePayload* payload, const char* interface); +bool OCResourcePayloadAddStringLL(OCStringLL **payload, const char* type); size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload); OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index); +void OCDiscoveryResourceDestroy(OCResourcePayload* payload); void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload); // Device Payload -OCDevicePayload* OCDevicePayloadCreate(const char* uri, const uint8_t* sid, const char* dname, - const char* specVer, const char* dmVer); +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 char* uri, const OCPlatformInfo* platformInfo); -OCPlatformPayload* OCPlatformPayloadCreateAsOwner(char* uri, OCPlatformInfo* platformInfo); - +OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo); +OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo); +void OCPlatformInfoDestroy(OCPlatformInfo *info); void OCPlatformPayloadDestroy(OCPlatformPayload* payload); // Presence Payload @@ -146,6 +259,22 @@ void OCPresencePayloadDestroy(OCPresencePayload* payload); OCStringLL* CloneOCStringLL (OCStringLL* ll); void OCFreeOCStringLL(OCStringLL* ll); +/** + * This function creates a list from a string (with separated contents if several) + * @param text single string or CSV text fields + * @return newly allocated linked list + * @note separator is ',' (according to rfc4180) or ';' + **/ +OCStringLL* OCCreateOCStringLL(const char* text); + +/** + * This function creates a string from a list (with separated contents if several) + * @param ll Pointer to list + * @return newly allocated string + * @note separator is ',' (according to rfc4180) + **/ +char* OCCreateString(const OCStringLL* ll); + #ifdef __cplusplus } #endif