Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Commit

Permalink
Quick fix: correctly handle collection resource in observe handler
Browse files Browse the repository at this point in the history
Change-Id: Ie2540cfa7b6cef69fbc1c71f3c1cbc44c87c9121
Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17161
  • Loading branch information
kmaloor committed Feb 9, 2017
1 parent 57cb129 commit d7f9cd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions api/oc_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ oc_get_collection_by_uri(const char *uri_path, int uri_path_len)
return collection;
}

bool
oc_check_if_collection(oc_resource_t *resource)
{
oc_collection_t *collection = oc_list_head(oc_collections);
while (collection != NULL) {
if ((oc_collection_t *)resource == collection)
return true;
collection = collection->next;
}
return false;
}

bool
oc_collection_add(oc_collection_t *collection)
{
Expand Down
1 change: 1 addition & 0 deletions include/oc_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ oc_collection_t *oc_collection_alloc(void);
oc_collection_t *oc_get_collection_by_uri(const char *uri_path,
int uri_path_len);
oc_collection_t *oc_collection_get_all(void);
bool oc_check_if_collection(oc_resource_t *resource);
bool oc_collection_add(oc_collection_t *collection);

#endif /* OC_COLLECTION_H */
14 changes: 12 additions & 2 deletions messaging/coap/observe.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
#include "oc_blockwise.h"
#endif /* OC_BLOCK_WISE_SET_MTU */

#ifdef OC_COLLECTIONS
#include "oc_collection.h"
#endif /* OC_COLLECTIONS */

#include "oc_coap.h"
#include "oc_rep.h"
#include "oc_ri.h"
Expand Down Expand Up @@ -264,8 +268,14 @@ coap_notify_observers(oc_resource_t *resource,
request.response = &response;
request.request_payload = NULL;
oc_rep_new(response_buffer.buffer, response_buffer.buffer_size);
resource->get_handler.cb(&request, resource->default_interface,
resource->get_handler.user_data);
#ifdef OC_COLLECTIONS
if (oc_check_if_collection(resource))
oc_handle_collection_request(OC_GET, &request,
resource->default_interface);
else
#endif /* OC_COLLECTIONS */
resource->get_handler.cb(&request, resource->default_interface,
resource->get_handler.user_data);
response_buf = &response_buffer;
if (response_buf->code == OC_IGNORE) {
LOG("coap_notify_observers: Resource ignored request\n");
Expand Down

0 comments on commit d7f9cd7

Please sign in to comment.