#endif
#define COAP_RESPONSE_200 COAP_RESPONSE_CODE(200) /* 2.00 OK */
#define COAP_RESPONSE_201 COAP_RESPONSE_CODE(201) /* 2.01 Created */
+#define COAP_RESPONSE_202 COAP_RESPONSE_CODE(202) /* 2.02 Created */
#define COAP_RESPONSE_304 COAP_RESPONSE_CODE(203) /* 2.03 Valid */
#define COAP_RESPONSE_400 COAP_RESPONSE_CODE(400) /* 4.00 Bad Request */
#define COAP_RESPONSE_404 COAP_RESPONSE_CODE(404) /* 4.04 Not Found */
*
* @return 0 - success, else - TBD error
*/
-OCStackResult OCSendCoAPNotification (unsigned char * uri, OCDevAddr *dstAddr, OCStackResult result,
+OCStackResult OCSendCoAPNotification (unsigned char * uri, OCDevAddr *dstAddr,
OCQualityOfService qos, OCCoAPToken * token,
- unsigned char *payload, uint32_t seqNum, uint32_t maxAge);
+ unsigned char *payload, OCResource *resPtr, uint32_t maxAge);
#endif /* OCCOAP_H_ */
return ret;
}
-OCStackResult OCSendCoAPNotification (unsigned char * uri, OCDevAddr *dstAddr, OCStackResult result,
+OCStackResult OCSendCoAPNotification (unsigned char * uri, OCDevAddr *dstAddr,
OCQualityOfService qos, OCCoAPToken * token,
- unsigned char *payload, uint32_t seqNum, uint32_t maxAge)
+ unsigned char *payload, OCResource *resPtr, uint32_t maxAge)
{
+ OCStackResult result = OC_STACK_ERROR;
coap_list_t *optList = NULL;
uint8_t coapMsgType = COAP_MESSAGE_NON;
uint8_t mediaType = COAP_MEDIATYPE_APPLICATION_JSON;
else
{
#endif
- result = FormOptionList(&optList, &mediaType, &maxAge, sizeof(seqNum),
- &seqNum, NULL, strlen((char *)uri), uri, 0, NULL, NULL, 0);
+ result = FormOptionList(&optList, &mediaType, &maxAge, sizeof(resPtr->sequenceNum),
+ &resPtr->sequenceNum, NULL, strlen((char *)uri), uri, 0, NULL, NULL, 0);
#ifdef WITH_PRESENCE
}
#endif
VERIFY_SUCCESS(result, OC_STACK_OK);
+ if(resPtr->resourceProperties == 0)
+ {
+ result = OC_STACK_RESOURCE_DELETED;
+ }
+
sendPdu = GenerateCoAPPdu(
coapMsgType == COAP_MESSAGE_CON ? COAP_MESSAGE_CON : COAP_MESSAGE_NON,
OCToCoAPResponseCode(result), coap_new_message_id(gCoAPCtx),
ret = COAP_RESPONSE_200;
break;
+ case OC_STACK_RESOURCE_DELETED:
+ ret = COAP_RESPONSE_202;
+ break;
+
case OC_STACK_INVALID_QUERY :
ret = COAP_RESPONSE_400;
break;
ret = OC_STACK_OK;
break;
+ case COAP_RESPONSE_202 :
+ ret = OC_STACK_RESOURCE_DELETED;
+ break;
+
case COAP_RESPONSE_400 :
ret = OC_STACK_INVALID_QUERY;
break;
/**
* Resource Properties
+ *
+ * OC_ACTIVE - When this bit is set, the resource is initialized, otherwise the resource
+ * is 'inactive'. 'inactive' signifies that the resource has been marked for
+ * deletion or is already deleted.
+ * OC_DISCOVERABLE - When this bit is set, the resource is allowed to be discovered by clients.
+ * OC_OBSERVABLE - When this bit is set, the resource is allowed to be observed by clients.
+ * OC_SLOW - When this bit is set, the resource has been marked as 'slow'. 'slow' signifies
+ * that responses from this resource can expect delays in processing its
+ * requests from clients.
*/
typedef enum {
- OC_ACTIVE = (1 << 0), // set == initialized; unset == deleted
- OC_DISCOVERABLE = (1 << 1), // Discovery of this resource allowed
- OC_OBSERVABLE = (1 << 2), // Observe allowed
- OC_SLOW = (1 << 3) // Expect delay in processing requests. Send ACK to request and send response later
+ OC_ACTIVE = (1 << 0),
+ OC_DISCOVERABLE = (1 << 1),
+ OC_OBSERVABLE = (1 << 2),
+ OC_SLOW = (1 << 3)
} OCResourceProperty;
/**
OC_STACK_OBSERVER_NOT_FOUND,
OC_STACK_OBSERVER_NOT_ADDED,
OC_STACK_OBSERVER_NOT_REMOVED,
+ OC_STACK_RESOURCE_DELETED,
#ifdef WITH_PRESENCE
OC_STACK_PRESENCE_STOPPED,
OC_STACK_PRESENCE_DO_NOT_HANDLE,
resourceObserver->NONCount++;
}
}
- OCSendCoAPNotification(resourceObserver->resUri, resourceObserver->addr,
- stackRet, qos,
- &(resourceObserver->token),
- jsonPayload, resPtr->sequenceNum, maxAge);
+ stackRet = OCSendCoAPNotification(resourceObserver->resUri, resourceObserver->addr,
+ qos, &(resourceObserver->token), jsonPayload, resPtr, maxAge);
}
else
{
result = response->cbNode->callBack(response->cbNode->context,
response->cbNode->handle, response->clientResponse);
if (result == OC_STACK_DELETE_TRANSACTION ||
- response->clientResponse->result == OC_STACK_COMM_ERROR)
+ response->clientResponse->result == OC_STACK_COMM_ERROR ||
+ response->clientResponse->result == OC_STACK_RESOURCE_DELETED)
{
FindAndDeleteClientCB(response->cbNode);
}
}
}
OCSendCoAPNotification (observation->resUri, observation->addr,
- OC_STACK_OK, qos,
- &(observation->token),
- bufNotify, resPtr->sequenceNum, maxAge);
+ qos, &(observation->token),
+ bufNotify, resPtr, maxAge);
numSentNotification++;
}
}
} else {
prev->next = temp->next;
}
+
+ resource->resourceProperties = (OCResourceProperty) 0; // Invalidate all Resource Properties.
+ OCNotifyAllObservers((OCResourceHandle)resource);
+
deleteResourceElements(temp);
OCFree(temp);
return 1;