OCStartPresence comments in header.
authorSashi Penta <sashi.kumar.penta@intel.com>
Mon, 8 Sep 2014 22:14:15 +0000 (15:14 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Mon, 8 Sep 2014 22:34:59 +0000 (15:34 -0700)
Every OCStartPresence sends a random nonce.
C++ Stack cleanup to use unsigned integer for nonce.

Change-Id: If83e0868bbc05fa641cd3a0758e250b59da6393c

csdk/stack/include/ocstack.h
csdk/stack/src/ocstack.c
examples/presenceclient.cpp
include/OCApi.h

index 9b544b5..6b8edc7 100644 (file)
@@ -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
 /**
index b9e28eb..4830784 100644 (file)
@@ -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;
 }
index eefdb39..9ccc9c7 100644 (file)
@@ -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)
     {
index 3f6ae3a..89471e2 100644 (file)
@@ -208,7 +208,7 @@ namespace OC
 
     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
     typedef std::function<void(const std::shared_ptr<OCResourceRequest>, const std::shared_ptr<OCResourceResponse>)> RegisterCallback;
-    typedef std::function<void(OCStackResult, const int)> SubscribeCallback;
+    typedef std::function<void(OCStackResult, const unsigned int)> SubscribeCallback;
     typedef std::function<void(const OCRepresentation&, const int)> GetCallback;
     typedef std::function<void(const OCRepresentation&, const int)> PutCallback;
     typedef std::function<void(const OCRepresentation&, const int, const int)> ObserveCallback;