From 166e909b4ecccf4d0fc98f372e542b189425eb97 Mon Sep 17 00:00:00 2001 From: Sashi Penta Date: Mon, 8 Sep 2014 15:14:15 -0700 Subject: [PATCH] OCStartPresence comments in header. Every OCStartPresence sends a random nonce. C++ Stack cleanup to use unsigned integer for nonce. Change-Id: If83e0868bbc05fa641cd3a0758e250b59da6393c --- csdk/stack/include/ocstack.h | 12 ++++++++---- csdk/stack/src/ocstack.c | 9 ++++----- examples/presenceclient.cpp | 2 +- include/OCApi.h | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/csdk/stack/include/ocstack.h b/csdk/stack/include/ocstack.h index 9b544b5..6b8edc7 100644 --- a/csdk/stack/include/ocstack.h +++ b/csdk/stack/include/ocstack.h @@ -299,12 +299,14 @@ OCStackResult OCCancel(OCDoHandle handle); * presence notifications to clients via multicast. Once this API has been called with a success, * clients may query for this server's presence and this server's stack will respond via multicast. * - * @param ttl (Time To Live in seconds) - Used to set the time a server + * Server can call this function when it comes online for the first time, or when it comes back + * online from offline mode, or when it re enters network. + * + * @param ttl - Time To Live in seconds * Note: If ttl is '0', then the default stack value will be used (60 Seconds). * * @return * OC_STACK_OK - No errors; Success - * OC_STACK_ERROR - @ref OCStartPresence has already been called. */ OCStackResult OCStartPresence(const uint32_t ttl); @@ -313,11 +315,13 @@ OCStackResult OCStartPresence(const uint32_t ttl); * presence notifications to clients via multicast. Once this API has been called with a success, * this server's stack will not respond to clients querying for this server's presence. * + * Server can call this function when it is terminating, going offline, or when going + * away from network. + * * @return * OC_STACK_OK - No errors; Success - * OC_STACK_ERROR - @ref OCStartPresence has never been called or @ref OCStopPresence has - * already been called. */ + OCStackResult OCStopPresence(); #endif /** diff --git a/csdk/stack/src/ocstack.c b/csdk/stack/src/ocstack.c index b9e28eb..4830784 100644 --- a/csdk/stack/src/ocstack.c +++ b/csdk/stack/src/ocstack.c @@ -561,7 +561,6 @@ OCStackResult OCProcess() { * * @return * OC_STACK_OK - No errors; Success - * OC_STACK_ERROR - @ref OCStartPresence has already been called. */ OCStackResult OCStartPresence(const uint32_t ttl) { @@ -586,6 +585,10 @@ OCStackResult OCStartPresence(const uint32_t ttl) (OCResource *)presenceResource.handle, OC_NON_CONFIRMABLE); } + // Each time OCStartPresence is called + // a different random 32-bit integer number is used + ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom(); + return OCNotifyObservers(presenceResource.handle); } @@ -599,8 +602,6 @@ OCStackResult OCStartPresence(const uint32_t ttl) * * @return * OC_STACK_OK - No errors; Success - * OC_STACK_ERROR - @ref OCStartPresence has never been called or @ref OCStopPresence has - * already been called. */ OCStackResult OCStopPresence() { @@ -1392,8 +1393,6 @@ OCStackResult initResources() { result = OCChangeResourceProperty( &(((OCResource *) presenceResource.handle)->resourceProperties), OC_ACTIVE, 0); - //initialize the sequence number as a random 32-bit integer - ((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom(); #endif return result; } diff --git a/examples/presenceclient.cpp b/examples/presenceclient.cpp index eefdb39..9ccc9c7 100644 --- a/examples/presenceclient.cpp +++ b/examples/presenceclient.cpp @@ -35,7 +35,7 @@ static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe; OCPlatform* platformPtr; // Callback to presence -void presenceHandler(OCStackResult result, const int& nonce) +void presenceHandler(OCStackResult result, const unsigned int nonce) { switch(result) { diff --git a/include/OCApi.h b/include/OCApi.h index 3f6ae3a..89471e2 100644 --- a/include/OCApi.h +++ b/include/OCApi.h @@ -208,7 +208,7 @@ namespace OC typedef std::function)> FindCallback; typedef std::function, const std::shared_ptr)> RegisterCallback; - typedef std::function SubscribeCallback; + typedef std::function SubscribeCallback; typedef std::function GetCallback; typedef std::function PutCallback; typedef std::function ObserveCallback; -- 2.7.4