ble_mesh: introduce a helper for send callback function

This commit is contained in:
lly 2019-09-02 15:15:28 +08:00
parent 05128c98ec
commit 9a672caa7e
3 changed files with 20 additions and 18 deletions

View 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;

View 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_ */

View 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()) {