Commit 7835dbac authored by Mandeep Shetty's avatar Mandeep Shetty Committed by Erich Keane

Removed duplicate switch case in OCDoResource.

There were two separate switch statements for validation and converting
to CA method. Moved it to one.
Also improved logging, variable names and vertical spacing in some
sections.

Change-Id: Ic68253dd23e5da15d469951293fc4173a13f7afd
Signed-off-by: default avatarMandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1045Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarDoug Hudson <douglas.hudson@intel.com>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent 1704c7bd
......@@ -161,8 +161,10 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
{
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,
......@@ -228,7 +230,7 @@ OCStackResult SendListObserverNotification (OCResource * resource,
}
uint8_t numIds = numberOfIds;
ResourceObserver *observation = NULL;
ResourceObserver *observer = NULL;
uint8_t numSentNotification = 0;
OCServerRequest * request = NULL;
OCStackResult result = OC_STACK_ERROR;
......@@ -237,21 +239,20 @@ OCStackResult SendListObserverNotification (OCResource * resource,
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)
{
......@@ -275,12 +276,18 @@ OCStackResult SendListObserverNotification (OCResource * resource,
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
{
......@@ -328,7 +335,7 @@ OCStackResult GenerateObserverId (OCObservationId *observationId)
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:
......
......@@ -1881,8 +1881,6 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
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
......@@ -1899,17 +1897,32 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
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;
......@@ -1980,45 +1993,6 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
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)
......@@ -2030,8 +2004,10 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
}
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,
......@@ -2048,9 +2024,11 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
requestData.options = (CAHeaderOption_t*)options;
requestData.numOptions = numOptions;
}
requestData.payload = (char *)request;
requestInfo.info = requestData;
CATransportType_t caConType;
result = OCToCATransportType((OCConnectivityType) conType, &caConType);
......@@ -2120,7 +2098,7 @@ exit:
}
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);
......@@ -2180,12 +2158,12 @@ OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption
{
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),
options, numOptions, OC_OBSERVE_DEREGISTER) != OC_STACK_OK)
{
......@@ -2225,6 +2203,7 @@ OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption
FindAndDeleteClientCB(clientCB);
}
break;
#ifdef WITH_PRESENCE
case OC_REST_PRESENCE:
FindAndDeleteClientCB(clientCB);
......@@ -2235,6 +2214,11 @@ OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption
break;
}
}
else
{
OC_LOG(ERROR, TAG, PCF("Client callback not found. Called OCCancel twice?"));
}
Error:
CADestroyRemoteEndpoint(endpoint);
if (requestData.numOptions > 0)
......@@ -2358,7 +2342,7 @@ OCStackResult OCProcessPresence()
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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment