{
OCEntityHandlerResponse ehResponse = {};
char presenceResBuf[MAX_RESPONSE_LENGTH] = {};
+
//This is effectively the implementation for the presence entity handler.
OC_LOG(DEBUG, TAG, PCF("This notification is for Presence"));
+
result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
0, resPtr->sequenceNum, qos, resourceObserver->query,
NULL, NULL,
}
uint8_t numIds = numberOfIds;
- ResourceObserver *observation = NULL;
+ ResourceObserver *observer = NULL;
uint8_t numSentNotification = 0;
OCServerRequest * request = NULL;
OCStackResult result = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Entering SendListObserverNotification"));
while(numIds)
{
- OC_LOG_V(INFO, TAG, "Need to notify observation id %d", *obsIdList);
- observation = GetObserverUsingId (*obsIdList);
- if(observation)
+ observer = GetObserverUsingId (*obsIdList);
+ if(observer)
{
- // Found observation - verify if it matches the resource handle
- if (observation->resource == resource)
+ // Found observer - verify if it matches the resource handle
+ if (observer->resource == resource)
{
- qos = DetermineObserverQoS(OC_REST_GET, observation, qos);
+ qos = DetermineObserverQoS(OC_REST_GET, observer, qos);
result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
- 0, resource->sequenceNum, qos, observation->query,
- NULL, NULL, observation->token, observation->tokenLength,
- observation->resUri, 0,
- &(observation->addressInfo), observation->connectivityType);
+ 0, resource->sequenceNum, qos, observer->query,
+ NULL, NULL, observer->token, observer->tokenLength,
+ observer->resUri, 0,
+ &(observer->addressInfo), observer->connectivityType);
if(request)
{
result = OCDoResponse(&ehResponse);
if(result == OC_STACK_OK)
{
- // Increment sent notifications only if OCDoResponse is successful
+ OC_LOG_V(INFO, TAG, "Observer id %d notified.", *obsIdList);
+
+ // Increment only if OCDoResponse is successful
numSentNotification++;
OCFree(ehResponse.payload);
FindAndDeleteServerRequest(request);
}
+ else
+ {
+ OC_LOG_V(INFO, TAG, "Error notifying observer id %d.", *obsIdList);
+ }
}
else
{
resObs = GetObserverUsingId (*observationId);
} while (NULL != resObs);
- OC_LOG_V(INFO, TAG, "Observation ID is %u", *observationId);
+ OC_LOG_V(INFO, TAG, "Generated bservation ID is %u", *observationId);
return OC_STACK_OK;
exit:
CARequestInfo_t requestInfo ={};
CAGroupEndpoint_t grpEnd = {};
- // To track if memory is allocated for additional header options
-
OC_LOG(INFO, TAG, PCF("Entering OCDoResource"));
// Validate input parameters
switch (method)
{
case OC_REST_GET:
- case OC_REST_PUT:
- case OC_REST_POST:
- case OC_REST_DELETE:
case OC_REST_OBSERVE:
case OC_REST_OBSERVE_ALL:
case OC_REST_CANCEL_OBSERVE:
+ requestInfo.method = CA_GET;
break;
+
+ case OC_REST_PUT:
+ requestInfo.method = CA_PUT;
+ break;
+
+ case OC_REST_POST:
+ requestInfo.method = CA_POST;
+ break;
+
+ case OC_REST_DELETE:
+ requestInfo.method = CA_DELETE;
+ break;
+
#ifdef WITH_PRESENCE
case OC_REST_PRESENCE:
+ // Replacing method type with GET because "presence"
+ // is a stack layer only implementation.
+ requestInfo.method = CA_GET;
break;
#endif
+
default:
result = OC_STACK_INVALID_METHOD;
goto exit;
goto exit;
}
- switch (method)
- {
- case OC_REST_GET:
- case OC_REST_OBSERVE:
- case OC_REST_OBSERVE_ALL:
- case OC_REST_CANCEL_OBSERVE:
- {
- requestInfo.method = CA_GET;
- break;
- }
- case OC_REST_PUT:
- {
- requestInfo.method = CA_PUT;
- break;
- }
- case OC_REST_POST:
- {
- requestInfo.method = CA_POST;
- break;
- }
- case OC_REST_DELETE:
- {
- requestInfo.method = CA_DELETE;
- break;
- }
- #ifdef WITH_PRESENCE
- case OC_REST_PRESENCE:
- {
- // Replacing method type with GET because "presence"
- // is a stack layer only implementation.
- requestInfo.method = CA_GET;
- break;
- }
- #endif
- default:
- result = OC_STACK_INVALID_METHOD;
- goto exit;
- }
-
// create token
caResult = CAGenerateToken(&token, tokenLength);
if (caResult != CA_STATUS_OK)
}
requestData.type = qualityOfServiceToMessageType(qos);
+
requestData.token = token;
requestData.tokenLength = tokenLength;
+
if ((method == OC_REST_OBSERVE) || (method == OC_REST_OBSERVE_ALL))
{
result = CreateObserveHeaderOption (&(requestData.options), options,
requestData.options = (CAHeaderOption_t*)options;
requestData.numOptions = numOptions;
}
+
requestData.payload = (char *)request;
requestInfo.info = requestData;
+
CATransportType_t caConType;
result = OCToCATransportType((OCConnectivityType) conType, &caConType);
}
if (result != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, PCF("OCDoResource error"));
+ OC_LOG_V(ERROR, TAG, PCF("OCDoResource error no %d"), result);
FindAndDeleteClientCB(clientCB);
OCFree(resHandle);
OCFree(requestUri);
{
case OC_REST_OBSERVE:
case OC_REST_OBSERVE_ALL:
- OC_LOG(INFO, TAG, PCF("Canceling observation"));
if(qos == OC_HIGH_QOS)
{
requestData.type = qualityOfServiceToMessageType(qos);
requestData.token = clientCB->token;
requestData.tokenLength = clientCB->tokenLength;
- if (CreateObserveHeaderOption (&(requestData.options),
+
+ if (CreateObserveHeaderOption (&(requestData.options),
options, numOptions, OC_OBSERVE_DEREGISTER) != OC_STACK_OK)
{
return OC_STACK_ERROR;
OC_LOG(ERROR, TAG, PCF("CASendRequest error"));
ret = OC_STACK_ERROR;
}
- ret = CAResultToOCResult (caResult);
+ ret = CAResultToOCResult (caResult);
}
else
{
FindAndDeleteClientCB(clientCB);
}
break;
+
#ifdef WITH_PRESENCE
case OC_REST_PRESENCE:
FindAndDeleteClientCB(clientCB);
break;
}
}
+ else
+ {
+ OC_LOG(ERROR, TAG, PCF("Client callback not found. Called OCCancel twice?"));
+ }
+
Error:
CADestroyRemoteEndpoint(endpoint);
if (requestData.numOptions > 0)
exit:
if (result != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, PCF("OCProcessPresence error"));
+ OC_LOG_V(ERROR, TAG, PCF("OCProcessPresence error no %d"), result);
}
return result;
}