mkiiskila closed pull request #1488: oic; observer bug fixes
URL: https://github.com/apache/mynewt-core/pull/1488
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index b2564ff399..6bbd1bd141 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -410,6 +410,9 @@ oc_ri_invoke_coap_entity_handler(struct coap_packet_rx 
*request,
   oc_response_buffer_t response_buffer;
   oc_response_t response_obj;
   struct os_mbuf *m = NULL;
+#ifdef OC_SERVER
+  int rc;
+#endif
 
   response_buffer.buffer = NULL;
   response_buffer.block_offset = offset;
@@ -598,35 +601,33 @@ oc_ri_invoke_coap_entity_handler(struct coap_packet_rx 
*request,
        * requesting client as an observer.
        */
       if (observe == 0) {
-        if (coap_observe_handler(request, response, cur_resource, endpoint) ==
-            0) {
+        rc = coap_observe_handler(request, response, cur_resource, endpoint);
+        if (rc >= 0) {
+          coap_set_header_observe(response, 0);
+        }
+        if (rc == 0) {
           /* If the resource is marked as periodic observable it means
            * it must be polled internally for updates (which would lead to
            * notifications being sent). If so, add the resource to a list of
            * periodic GET callbacks to utilize the framework's internal
            * polling mechanism.
            */
-          bool set_observe_option = true;
           if (cur_resource->properties & OC_PERIODIC) {
-              os_callout_reset(&cur_resource->callout,
+            os_callout_reset(&cur_resource->callout,
                 (cur_resource->observe_period_mseconds * 
OS_TICKS_PER_SEC)/1000);
           }
-
-          if (set_observe_option) {
-            coap_set_header_observe(response, 0);
-          }
         }
-      }
-      /* If the observe option is set to 1, make an attempt to remove
-       * the requesting client from the list of observers. In addition,
-       * remove the resource from the list periodic GET callbacks if it
-       * is periodic observable.
-       */
-      else if (observe == 1) {
-        if (coap_observe_handler(request, response, cur_resource, endpoint) >
-            0) {
-          if (cur_resource->properties & OC_PERIODIC) {
-              os_callout_stop(&cur_resource->callout);
+      } else if (observe == 1) {
+        /* If the observe option is set to 1, make an attempt to remove
+         * the requesting client from the list of observers. In addition,
+         * remove the resource from the list periodic GET callbacks if it
+         * is periodic observable, and this was the only observer.
+         */
+        rc = coap_observe_handler(request, response, cur_resource, endpoint);
+        if (rc > 0) {
+          if (!cur_resource->num_observers &&
+              cur_resource->properties & OC_PERIODIC) {
+            os_callout_stop(&cur_resource->callout);
           }
         }
       }
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c 
b/net/oic/src/port/mynewt/ble_adaptor.c
index ac6f188001..9802ce61bb 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -32,6 +32,7 @@
 #include "oic/messaging/coap/coap.h"
 #include "oic/port/oc_connectivity.h"
 #include "oic/port/mynewt/ble.h"
+#include "messaging/coap/observe.h"
 #include "host/ble_hs.h"
 #include "services/gap/ble_svc_gap.h"
 #include "services/gatt/ble_svc_gatt.h"
@@ -345,6 +346,8 @@ oc_ble_coap_conn_del(uint16_t conn_handle)
     struct os_mbuf_pkthdr *pkt;
     struct os_mbuf *m;
     struct oc_endpoint_ble *oe_ble;
+    struct oc_endpoint oe;
+    int i;
 
     OC_LOG(DEBUG, "oc_gatt endconn %x\n", conn_handle);
     STAILQ_FOREACH(pkt, &oc_ble_reass_q, omp_next) {
@@ -356,6 +359,19 @@ oc_ble_coap_conn_del(uint16_t conn_handle)
             break;
         }
     }
+
+    /*
+     * Remove CoAP observers (if any) registered for this connection.
+     */
+    memset(&oe, 0, sizeof(oe));
+    oe_ble = (struct oc_endpoint_ble *)&oe;
+    oe_ble->ep.oe_type = oc_gatt_transport_id;
+    oe_ble->ep.oe_flags = 0;
+    oe_ble->conn_handle = conn_handle;
+    for (i = 0; i < OC_BLE_SRV_CNT; i++) {
+        oe_ble->srv_idx = i;
+        coap_remove_observer_by_client(&oe);
+    }
 }
 
 int


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to