From 104d30c9894484735e15642450924061d1d0d391 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 15 Aug 2019 08:54:08 +0300 Subject: [PATCH] Bluetooth: Mesh: Introduce a helper for send callback finalization There are several places that require the send callbacks to be called immediately. Reduce the code a bit by introducing a helper for this. Signed-off-by: Johan Hedberg --- subsys/bluetooth/mesh/net.c | 10 +--------- subsys/bluetooth/mesh/net.h | 16 ++++++++++++++++ subsys/bluetooth/mesh/transport.c | 10 +--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 2c7e9321122..b0851de3b60 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -897,15 +897,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/subsys/bluetooth/mesh/net.h b/subsys/bluetooth/mesh/net.h index 8e675858495..a4ff4477fdb 100644 --- a/subsys/bluetooth/mesh/net.h +++ b/subsys/bluetooth/mesh/net.h @@ -362,3 +362,19 @@ struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr, u16_t lpn_counter, u16_t frnd_counter); 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); + } +} diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index b3c14dbd572..a59612ad395 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -426,15 +426,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_BT_MESH_LOW_POWER) &&