Skip to content

Commit

Permalink
Add CoAP_Res_t to resource handler
Browse files Browse the repository at this point in the history
  • Loading branch information
NZSmartie committed Nov 28, 2017
1 parent 4a8087d commit 7c9e216
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/coap_interaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ CoAP_Result_t _rom CoAP_StartNotifyInteractions(CoAP_Res_t* pRes) {

//Call Notify Handler of resource and add to interaction list
if (newIA->pRespMsg != NULL && pRes->Notifier != NULL &&
pRes->Notifier(pObserver, newIA->pRespMsg) == HANDLER_OK) { //<------ call notify handler of resource
pRes->Notifier(pObserver, newIA->pRespMsg, pRes) == HANDLER_OK) { //<------ call notify handler of resource

newIA->Role = COAP_ROLE_NOTIFICATION;
newIA->State = COAP_STATE_READY_TO_NOTIFY;
Expand Down
6 changes: 3 additions & 3 deletions src/coap_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static void handleServerInteraction(CoAP_Interaction_t* pIA) {

// Call of external set resource handler
// could change type and code of message (ACK & EMPTY above only a guess!)
CoAP_HandlerResult_t Res = pIA->pRes->Handler(pIA->pReqMsg, pIA->pRespMsg);
CoAP_HandlerResult_t Res = pIA->pRes->Handler(pIA->pReqMsg, pIA->pRespMsg, pIA->pRes);

// Check return value of handler:
// a) everything fine - we got an response to send
Expand Down Expand Up @@ -535,7 +535,7 @@ static void handleNotifyInteraction(CoAP_Interaction_t* pIA) {
pIA->UpdatePendingNotification = false;
pIA->pRespMsg->MessageID = CoAP_GetNextMid();
//call notifier
if (pIA->pRes->Notifier(pIA->pObserver, pIA->pRespMsg) == HANDLER_ERROR) {
if (pIA->pRes->Notifier(pIA->pObserver, pIA->pRespMsg, pIA->pRes) == HANDLER_ERROR) {
RemoveObserveOptionFromMsg(pIA->pRespMsg);
CoAP_RemoveInteractionsObserver(pIA, pIA->pRespMsg->Token);
} else { //good response
Expand Down Expand Up @@ -571,7 +571,7 @@ static void handleNotifyInteraction(CoAP_Interaction_t* pIA) {
pIA->ResConfirmState = NOT_SET;

//call notifier
if (pIA->pRes->Notifier(pIA->pObserver, pIA->pRespMsg) == HANDLER_ERROR) {
if (pIA->pRes->Notifier(pIA->pObserver, pIA->pRespMsg, pIA->pRes) == HANDLER_ERROR) {
RemoveObserveOptionFromMsg(pIA->pRespMsg);
CoAP_RemoveInteractionsObserver(pIA, pIA->pRespMsg->Token);
} else { //good response
Expand Down
2 changes: 1 addition & 1 deletion src/coap_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ CoAP_Result_t _rom CoAP_NVloadObservers(uint8_t* pRawPage) {
}


CoAP_HandlerResult_t _rom WellKnown_GetHandler(CoAP_Message_t* pReq, CoAP_Message_t* pResp) {
CoAP_HandlerResult_t _rom WellKnown_GetHandler(CoAP_Message_t* pReq, CoAP_Message_t* pResp, CoAP_Res_t* res) {
// static uint8_t wellknownStr[500];
// uint8_t* pWr = wellknownStr;

Expand Down
6 changes: 4 additions & 2 deletions src/liblobaro_coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ typedef enum {
HANDLER_ERROR = 2
} CoAP_HandlerResult_t;

typedef CoAP_HandlerResult_t (*CoAP_ResourceHandler_fPtr_t)(CoAP_Message_t* pReq, CoAP_Message_t* pResp);
typedef struct CoAP_Res CoAP_Res_t;

typedef CoAP_HandlerResult_t (*CoAP_ResourceHandler_fPtr_t)(CoAP_Message_t* pReq, CoAP_Message_t* pResp, CoAP_Res_t* pResource);
// TODO: Can we use the CoAP_ResourceHandler_fPtr_t signature also for notifiers?
typedef CoAP_HandlerResult_t (*CoAP_ResourceNotifier_fPtr_t)(CoAP_Observer_t* pObserver, CoAP_Message_t* pResp);
typedef CoAP_HandlerResult_t (*CoAP_ResourceNotifier_fPtr_t)(CoAP_Observer_t* pObserver, CoAP_Message_t* pResp, CoAP_Res_t* pResource);

typedef struct {
uint16_t Cf; // Content-Format
Expand Down

0 comments on commit 7c9e216

Please sign in to comment.