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 token Token to search for.
return OC_STACK_OK;
}
+OCStackResult DeleteObserverUsingResource(OCResource *res)
+{
+ if (!res)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ oc_mutex_lock(g_serverObsListMutex);
+ ResourceObserver *obs = NULL;
+ ResourceObserver *next = NULL;
+ LL_FOREACH_SAFE(g_serverObsList, obs, next)
+ {
+ if (obs->resource == res)
+ {
+ OIC_LOG_V(INFO, TAG, "Deleting observer: id-%u, token-", obs->observeId);
+ OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)obs->token, obs->tokenLength);
+ LL_DELETE(g_serverObsList, obs);
+ FreeObserver(obs);
+ }
+ }
+ oc_mutex_unlock(g_serverObsListMutex);
+ return OC_STACK_OK;
+}
+
void DeleteObserverList()
{
oc_mutex_lock(g_serverObsListMutex);
SendPresenceNotification(resource->rsrcType, OC_PRESENCE_TRIGGER_DELETE);
}
#endif
+ // Delete resource's all observers
+ DeleteObserverUsingResource(resource);
+
// Only resource in list.
if (temp == headResource && temp == tailResource)
{
OCDeleteResourceAttributes(resource->rsrcAttributes);
resource->rsrcAttributes = NULL;
}
+
+ resource->entityHandler = NULL;
resource = NULL;
}