#define VERIFY_NON_NULL(arg) { if (!arg) {OIC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
+#define MAX_OBSERVERS 3840
+
static struct ResourceObserver * g_serverObsList = NULL;
static oc_mutex g_serverObsListMutex = NULL;
+static int observer_count = 0;
+
static ResourceObserver* GetObserverUsingIdAsOwner (const OCObservationId observeId);
static ResourceObserver* CloneObserverNode (ResourceObserver* observer)
OCStackResult result = OC_STACK_ERROR;
ResourceObserver * resourceObserver = NULL;
- uint8_t numObs = 0;
+ uint16_t numObs = 0;
OCServerRequest * request = NULL;
bool observeErrorFlag = false;
}
OCStackResult SendListObserverNotification (OCResource * resource,
- OCObservationId *obsIdList, uint8_t numberOfIds,
+ OCObservationId *obsIdList, uint16_t numberOfIds,
const OCRepPayload *payload,
uint32_t maxAge,
OCQualityOfService qos)
return OC_STACK_INVALID_PARAM;
}
- uint8_t numIds = numberOfIds;
+ uint16_t numIds = numberOfIds;
ResourceObserver *observer = NULL;
- uint8_t numSentNotification = 0;
+ uint16_t numSentNotification = 0;
OCServerRequest * request = NULL;
OCStackResult result = OC_STACK_ERROR;
bool observeErrorFlag = false;
OIC_LOG(INFO, TAG, "Entering GenerateObserverId");
VERIFY_NON_NULL (observationId);
- do
+ oc_mutex_lock(g_serverObsListMutex);
+
+ if (observer_count < MAX_OBSERVERS)
{
+ oc_mutex_unlock(g_serverObsListMutex);
do
{
- *observationId = OCGetRandomByte();
- } while (0 == *observationId); //Make sure *observationId is not 0
- // Check if observation Id already exists
- found = IsObserverAvailable (*observationId);
- } while (found);
-
+ do
+ {
+ *observationId = OCGetRandomTwoByte();
+ } while (0 == *observationId); //Make sure *observationId is not 0
+ // Check if observation Id already exists
+ found = IsObserverAvailable (*observationId);
+ } while (found);
OIC_LOG_V(INFO, TAG, "GeneratedObservation ID is %u", *observationId);
+ //oc_mutex_unlock(g_serverObsListMutex);
return OC_STACK_OK;
+ }
+ else
+ {
+ OIC_LOG_V(ERROR, TAG, "No more observers can be added");
+ oc_mutex_unlock(g_serverObsListMutex);
+
+ return OC_STACK_ERROR;
+ }
exit:
return OC_STACK_ERROR;
}
oc_mutex_lock(g_serverObsListMutex);
LL_APPEND (g_serverObsList, obsNode);
+ observer_count++;
oc_mutex_unlock(g_serverObsListMutex);
return OC_STACK_OK;
OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)obsNode->token, tokenLength);
LL_DELETE (g_serverObsList, obsNode);
+ observer_count--;
FreeObserver(obsNode);
}
oc_mutex_unlock(g_serverObsListMutex);