From 225ee8e5d1b8d8953e1825b9ceed74e2390051ab Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 2 Sep 2019 15:15:28 +0800 Subject: [PATCH] ble_mesh: introduce a helper for send callback function --- components/bt/esp_ble_mesh/mesh_core/net.c | 12 ++---------- components/bt/esp_ble_mesh/mesh_core/net.h | 16 ++++++++++++++++ components/bt/esp_ble_mesh/mesh_core/transport.c | 10 ++-------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index 667be152ff..59576349d5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -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; diff --git a/components/bt/esp_ble_mesh/mesh_core/net.h b/components/bt/esp_ble_mesh/mesh_core/net.h index 28cd91ce87..49907cef0b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.h +++ b/components/bt/esp_ble_mesh/mesh_core/net.h @@ -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_ */ diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index d358d9d446..359dffac4b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -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()) {