X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fstack%2Fsamples%2Flinux%2FSimpleClientServer%2Focserver.cpp;h=2acfc24367cf3d30896076475edd967bc984fb23;hb=e3d2458136a675d733533424eabb6ee1f77444c4;hp=970565a7fe865362790a9c615afeb5ce93fad611;hpb=43ddc2883a11ca19291776fa12e63ccc24ac0729;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp index 970565a..2acfc24 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp @@ -19,6 +19,7 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "iotivity_config.h" #include #include #include @@ -41,7 +42,6 @@ #include "ocpayload.h" #include "ocserver.h" #include "common.h" -#include "platform_features.h" //string length of "/a/light/" + std::numeric_limits::digits10 + '\0'" // 9 + 9 + 1 = 19 @@ -618,17 +618,48 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag, MAX_HEADER_OPTION_DATA_LENGTH); } } - OCHeaderOption * sendOptions = response.sendVendorSpecificHeaderOptions; - uint8_t option2[] = {21,22,23,24,25,26,27,28,29,30}; - uint8_t option3[] = {31,32,33,34,35,36,37,38,39,40}; - sendOptions[0].protocolID = OC_COAP_ID; - sendOptions[0].optionID = 2248; - memcpy(sendOptions[0].optionData, option2, sizeof(option2)); - sendOptions[0].optionLength = 10; - sendOptions[1].protocolID = OC_COAP_ID; - sendOptions[1].optionID = 2600; - memcpy(sendOptions[1].optionData, option3, sizeof(option3)); - sendOptions[1].optionLength = 10; + + OCHeaderOption* sendOptions = response.sendVendorSpecificHeaderOptions; + size_t numOptions = response.numSendVendorSpecificHeaderOptions; + // Check if the option header has already existed before adding it in. + uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH]; + size_t optionDataSize = sizeof(optionData); + uint16_t actualDataSize = 0; + OCGetHeaderOption(response.sendVendorSpecificHeaderOptions, + response.numSendVendorSpecificHeaderOptions, + 2248, + optionData, + optionDataSize, + &actualDataSize); + if (actualDataSize == 0) + { + uint8_t option2[] = {21,22,23,24,25,26,27,28,29,30}; + uint16_t optionID2 = 2248; + size_t optionDataSize2 = sizeof(option2); + OCSetHeaderOption(sendOptions, + &numOptions, + optionID2, + option2, + optionDataSize2); + } + + OCGetHeaderOption(response.sendVendorSpecificHeaderOptions, + response.numSendVendorSpecificHeaderOptions, + 2600, + optionData, + optionDataSize, + &actualDataSize); + if (actualDataSize == 0) + { + uint8_t option3[] = {31,32,33,34,35,36,37,38,39,40}; + uint16_t optionID3 = 2600; + size_t optionDataSize3 = sizeof(option3); + OCSetHeaderOption(sendOptions, + &numOptions, + optionID3, + option3, + optionDataSize3); + } response.numSendVendorSpecificHeaderOptions = 2; }