]> granicus.if.org Git - esp-idf/commitdiff
ble_mesh: introduce a helper for send callback function
authorlly <lly@espressif.com>
Mon, 2 Sep 2019 07:15:28 +0000 (15:15 +0800)
committerlly <lly@espressif.com>
Mon, 9 Sep 2019 09:15:16 +0000 (17:15 +0800)
components/bt/esp_ble_mesh/mesh_core/net.c
components/bt/esp_ble_mesh/mesh_core/net.h
components/bt/esp_ble_mesh/mesh_core/transport.c

index 667be152ff26c772fa0cf2a33bcf2808e55aed5c..59576349d5b6fa09733e016f514f0f6b3f78bcf3 100644 (file)
@@ -785,7 +785,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
 
     if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
         bt_mesh_proxy_relay(&buf->b, dst)) {
-        net_buf_unref(buf);
+        send_cb_finalize(cb, cb_data);
     } else {
         bt_mesh_adv_send(buf, cb, cb_data);
     }
@@ -901,15 +901,7 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
             /* Notify completion if this only went
              * through the Mesh Proxy.
              */
-            if (cb) {
-                if (cb->start) {
-                    cb->start(0, 0, cb_data);
-                }
-
-                if (cb->end) {
-                    cb->end(0, cb_data);
-                }
-            }
+            send_cb_finalize(cb, cb_data);
 
             err = 0;
             goto done;
index 28cd91ce872bcf1934cb333deb33539529f653f9..49907cef0b7f1aec91f9231de0fedb3700c93902 100644 (file)
@@ -385,4 +385,20 @@ struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr,
 void friend_cred_clear(struct friend_cred *cred);
 int friend_cred_del(u16_t net_idx, u16_t addr);
 
+static inline void send_cb_finalize(const struct bt_mesh_send_cb *cb,
+                    void *cb_data)
+{
+    if (!cb) {
+        return;
+    }
+
+    if (cb->start) {
+        cb->start(0, 0, cb_data);
+    }
+
+    if (cb->end) {
+        cb->end(0, cb_data);
+    }
+}
+
 #endif /* _NET_H_ */
index d358d9d4466bf2fbce2bf253ca7d4ba10a4c0d0c..359dffac4b858b33008d02d234f3f393aeb53e17 100644 (file)
@@ -148,6 +148,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
              * out through the Friend Queue.
              */
             net_buf_unref(buf);
+            send_cb_finalize(cb, cb_data);
             return 0;
         }
     }
@@ -435,14 +436,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
          * there's no other way to track this (at least currently)
          * with the Friend Queue.
          */
-        if (cb) {
-            if (cb->start) {
-                cb->start(0, 0, cb_data);
-            }
-            if (cb->end) {
-                cb->end(0, cb_data);
-            }
-        }
+        send_cb_finalize(cb, cb_data);
     }
 
     if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {