#ifndef OC_OBSERVE_H
#define OC_OBSERVE_H
-/** Sequence number is a 24 bit field, per https://tools.ietf.org/html/draft-ietf-core-observe-16.*/
-#define MAX_SEQUENCE_NUMBER (0xFFFFFF)
-
/** Maximum number of observers to reach */
#define MAX_OBSERVER_FAILED_COMM (2)
#define MAX_OBSERVER_NON_COUNT (3)
/**
+ * MAX_OBSERVER_TTL_SECONDS sets the maximum time to live (TTL) for notification.
+ * 60 sec/min * 60 min/hr * 24 hr/day
+ */
+#define MAX_OBSERVER_TTL_SECONDS (60 * 60 * 24)
+
+#define MILLISECONDS_PER_SECOND (1000)
+
+/**
* Data structure to hold informations for each registered observer.
*/
typedef struct ResourceObserver
/** force the qos value to CON.*/
uint8_t forceHighQos;
+ /** The TTL for this callback. TTL is set to 24 hours.
+ * A server send a notification in a confirmable message every 24 hours.
+ * This prevents a client that went away or is no logger interested
+ * from remaining in the list of observers indefinitely.*/
+ uint32_t TTL;
+
/** next node in this list.*/
struct ResourceObserver *next;
+
+ /** requested payload encoding format. */
+ OCPayloadFormat acceptFormat;
+
} ResourceObserver;
+/**
+ * Initialize observer list.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult InitializeObserverList();
+
+/**
+ * Terminate observer list.
+ */
+void TerminateObserverList();
+
#ifdef WITH_PRESENCE
/**
* Create an observe response and send to all observers in the observe list.
uint8_t tokenLength,
OCResource *resHandle,
OCQualityOfService qos,
+ OCPayloadFormat acceptFormat,
const OCDevAddr *devAddr);
/**
*/
OCStackResult DeleteObserverUsingToken (CAToken_t token, uint8_t tokenLength);
+ /**
+ * Delete observer with device address from list of observers.
+ * Free memory that was allocated for the observer in the list.
+ *
+ * @param devAddr Device's address.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult DeleteObserverUsingDevAddr(const OCDevAddr *devAddr);
+
+/**
+ * Delete all observers of a resource.
+ *
+ * @param resource Handle of resource whose observers needs to be deleted.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult DeleteObserverUsingResource(OCResource *res);
+
/**
* Search the list of observers for the specified token.
*
* @param tokenLength Length of token.
*
* @return Pointer to found observer.
+ * This is copy of observer, caller must release its memory using FreeObserver().
*/
ResourceObserver* GetObserverUsingToken (const CAToken_t token, uint8_t tokenLength);
* @param observeId Observer ID to search for.
*
* @return Pointer to found observer.
+ * This is copy of observer, caller must release its memory using FreeObserver().
*/
ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
/**
+ * Search the list of observers for the specified observe ID.
+ *
+ * @param observeId Observer ID to search for.
+ *
+ * @return true if observer found matched with observer ID, otherwise false.
+ */
+bool IsObserverAvailable (const OCObservationId observeId);
+
+/**
* Add observe header option to a request.
*
* @param caHdrOpt Target request CA header option.
CAHeaderOption_t *options,
uint8_t * numOptions);
+/**
+ * Free memory associated with observer.
+ *
+ * @param obsNode Observer to be freed.
+ */
+void FreeObserver (ResourceObserver* obsNode);
+
#endif //OC_OBSERVE_H