Skip to content

Commit ca3ebce

Browse files
eivindj-nordiclemrey
authored andcommitted
lib: Align event handlers
* Add error events to the ble_adv library event handler. The error handler is removed. * Add error events to the nrf_ble_qwr library event handler. The error handler is removed. * Rename nrf_ble_qwr to ble_qwr to align with other libraries. * Align lbs event handler with other services and libraries. * Align nus event handler with other services and libraries. * Align lite_buttons with other libraries and services. * event_handler -> evt_handler Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent 22d5e64 commit ca3ebce

File tree

25 files changed

+416
-345
lines changed

25 files changed

+416
-345
lines changed

include/ble_adv.h

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ enum ble_adv_mode {
8282
};
8383

8484
/**
85-
* @brief Advertising events.
85+
* @brief Advertising event types.
8686
*/
87-
enum ble_adv_evt {
87+
enum ble_adv_evt_type {
88+
/**
89+
* @brief Error.
90+
*/
91+
BLE_ADV_EVT_ERROR,
8892
/**
8993
* @brief Idle; no connectable advertising is ongoing.
9094
*/
@@ -131,15 +135,25 @@ enum ble_adv_evt {
131135
BLE_ADV_EVT_PEER_ADDR_REQUEST
132136
};
133137

134-
/**
135-
* @brief BLE advertising event handler.
136-
*/
137-
typedef void (*ble_adv_evt_handler_t)(enum ble_adv_evt adv_evt);
138+
/** @brief Advertising event. */
139+
struct ble_adv_evt {
140+
/** @brief Advertising event type. */
141+
enum ble_adv_evt_type evt_type;
142+
union {
143+
/** @ref BLE_ADV_EVT_ERROR event data. */
144+
struct {
145+
int reason;
146+
} error;
147+
};
148+
};
149+
150+
/** Forward definition of ble_adv struct */
151+
struct ble_adv;
138152

139153
/**
140-
* @brief BLE advertising error handler type.
154+
* @brief BLE advertising event handler.
141155
*/
142-
typedef void (*ble_adv_error_handler_t)(int error);
156+
typedef void (*ble_adv_evt_handler_t)(struct ble_adv *adv, const struct ble_adv_evt *adv_evt);
143157

144158
/**
145159
* @brief BLE advertising instance.
@@ -169,10 +183,6 @@ struct ble_adv {
169183
* @brief Instance event handler.
170184
*/
171185
ble_adv_evt_handler_t evt_handler;
172-
/**
173-
* @brief Instance error handler.
174-
*/
175-
ble_adv_error_handler_t error_handler;
176186
/**
177187
* @brief GAP advertising parameters.
178188
*/
@@ -233,10 +243,6 @@ struct ble_adv_config {
233243
* @brief Event handler.
234244
*/
235245
ble_adv_evt_handler_t evt_handler;
236-
/**
237-
* @brief Error handler.
238-
*/
239-
ble_adv_error_handler_t error_handler;
240246
/**
241247
* @brief Connection configuration tag.
242248
*/

include/ble_conn_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef void (*ble_conn_params_evt_handler_t)(const struct ble_conn_params_evt *
8383
* @returns 0 On success.
8484
* @returns -EFAULT If @p handler is @c NULL.
8585
*/
86-
int ble_conn_params_event_handler_set(ble_conn_params_evt_handler_t handler);
86+
int ble_conn_params_evt_handler_set(ble_conn_params_evt_handler_t handler);
8787

8888
/**
8989
* @brief Override GAP connection parameters for given peer.

include/nrf_ble_qwr.h renamed to include/ble_qwr.h

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/** @file
88
*
9-
* @defgroup nrf_ble_qwr Queued Writes module
9+
* @defgroup ble_qwr Queued Writes module
1010
* @{
1111
* @ingroup ble_sdk_lib
1212
* @brief Module for handling Queued Write operations.
@@ -15,7 +15,7 @@
1515
* commands. It also manages memory requests related to these operations.
1616
*
1717
* @note The application must propagate BLE stack events to this module by calling
18-
* @ref nrf_ble_qwr_on_ble_evt().
18+
* @ref ble_qwr_on_ble_evt().
1919
*/
2020

2121
#ifndef NRF_BLE_QUEUED_WRITES_H__
@@ -31,94 +31,103 @@ extern "C" {
3131
#include <ble_gatts.h>
3232

3333
/**
34-
* @brief Macro for defining a nrf_ble_qwr instance.
34+
* @brief Macro for defining a ble_qwr instance.
3535
*
3636
* @param _name Name of the instance.
3737
* @hideinitializer
3838
*/
39-
#define NRF_BLE_QWR_DEF(_name) \
40-
static struct nrf_ble_qwr _name; \
39+
#define BLE_QWR_DEF(_name) \
40+
static struct ble_qwr _name; \
4141
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
42-
nrf_ble_qwr_on_ble_evt, \
42+
ble_qwr_on_ble_evt, \
4343
&_name, \
44-
CONFIG_NRF_BLE_QWR_BLE_OBSERVER_PRIO)
44+
CONFIG_BLE_QWR_BLE_OBSERVER_PRIO)
4545

4646
/* Error code used by the module to reject prepare write requests on non-registered attributes. */
47-
#define NRF_BLE_QWR_REJ_REQUEST_ERR_CODE BLE_GATT_STATUS_ATTERR_APP_BEGIN + 0
47+
#define BLE_QWR_REJ_REQUEST_ERR_CODE BLE_GATT_STATUS_ATTERR_APP_BEGIN + 0
4848

4949
/** @brief Queued Writes module event types. */
50-
enum nrf_ble_qwr_evt_type {
50+
enum ble_qwr_evt_type {
51+
/** Error event */
52+
BLE_QWR_EVT_ERROR,
5153
/** Event that indicates that an execute write command was received for a registered handle
5254
* and that the received data was actually written and is now ready.
5355
*/
54-
NRF_BLE_QWR_EVT_EXECUTE_WRITE,
56+
BLE_QWR_EVT_EXECUTE_WRITE,
5557
/** Event that indicates that an execute write command was received for a registered handle
5658
* and that the write request must now be accepted or rejected.
5759
*/
58-
NRF_BLE_QWR_EVT_AUTH_REQUEST,
60+
BLE_QWR_EVT_AUTH_REQUEST,
5961
};
6062

6163
/** @brief Queued Writes module events. */
62-
struct nrf_ble_qwr_evt {
64+
struct ble_qwr_evt {
6365
/** Type of the event. */
64-
enum nrf_ble_qwr_evt_type evt_type;
65-
/** Handle of the attribute to which the event relates. */
66-
uint16_t attr_handle;
66+
enum ble_qwr_evt_type evt_type;
67+
union {
68+
/** @ref BLE_QWR_EVT_ERROR event data. */
69+
struct {
70+
int reason;
71+
} error;
72+
/** @ref BLE_QWR_EVT_EXECUTE_WRITE event data. */
73+
struct {
74+
/** Handle of the attribute to which the event relates. */
75+
uint16_t attr_handle;
76+
} exec_write;
77+
/** @ref BLE_QWR_EVT_AUTH_REQUEST event data. */
78+
struct {
79+
/** Handle of the attribute to which the event relates. */
80+
uint16_t attr_handle;
81+
} auth_req;
82+
};
6783
};
6884

69-
/* Forward declaration of the struct nrf_ble_qwr. */
70-
struct nrf_ble_qwr;
85+
/* Forward declaration of the struct ble_qwr. */
86+
struct ble_qwr;
7187

7288
/**
7389
* @brief Queued Writes module event handler type.
7490
*
75-
* If the provided event is of type @ref NRF_BLE_QWR_EVT_AUTH_REQUEST,
91+
* If the provided event is of type @ref BLE_QWR_EVT_AUTH_REQUEST,
7692
* this function must accept or reject the execute write request by returning
7793
* one of the @ref BLE_GATT_STATUS_CODES.
7894
*/
79-
typedef uint16_t (*nrf_ble_qwr_evt_handler_t)(struct nrf_ble_qwr *qwr, struct nrf_ble_qwr_evt *evt);
80-
81-
/**
82-
* @brief Type definition for error handler function that will be called in case of an error.
83-
*/
84-
typedef void (*nrf_ble_qwr_error_handler_t)(int err);
95+
typedef uint16_t (*ble_qwr_evt_handler_t)(struct ble_qwr *qwr, const struct ble_qwr_evt *evt);
8596

8697
/**
8798
* @brief Queued Writes structure.
8899
* @details This structure contains status information for the Queued Writes module.
89100
*/
90-
struct nrf_ble_qwr {
101+
struct ble_qwr {
91102
/** Flag that indicates whether the module has been initialized. */
92103
uint32_t initialized;
104+
/** Event handler function that is called for events concerning the handles of all
105+
* registered attributes.
106+
*/
107+
ble_qwr_evt_handler_t evt_handler;
93108
/** Connection handle. */
94109
uint16_t conn_handle;
95-
/** Error handler. */
96-
nrf_ble_qwr_error_handler_t error_handler;
97110
/** Flag that indicates whether a mem_reply is pending
98111
* (because a previous attempt returned busy).
99112
*/
100113
bool is_user_mem_reply_pending;
101-
#if (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0)
114+
#if (CONFIG_BLE_QWR_MAX_ATTR > 0)
102115
/** List of handles for registered attributes, for which the module accepts and handles
103116
* prepare write operations.
104117
*/
105-
uint16_t attr_handles[CONFIG_NRF_BLE_QWR_MAX_ATTR];
118+
uint16_t attr_handles[CONFIG_BLE_QWR_MAX_ATTR];
106119
/** Number of registered attributes. */
107120
uint8_t nb_registered_attr;
108121
/** List of attribute handles that have been written to during the current prepare write or
109122
* execute write operation.
110123
*/
111-
uint16_t written_attr_handles[CONFIG_NRF_BLE_QWR_MAX_ATTR];
124+
uint16_t written_attr_handles[CONFIG_BLE_QWR_MAX_ATTR];
112125
/** Number of attributes that have been written to during the current prepare write or
113126
* execute write operation.
114127
*/
115128
uint8_t nb_written_handles;
116129
/** Memory buffer that is provided to the SoftDevice on an ON_USER_MEM_REQUEST event. */
117130
ble_user_mem_block_t mem_buffer;
118-
/** Event handler function that is called for events concerning the handles of all
119-
* registered attributes.
120-
*/
121-
nrf_ble_qwr_evt_handler_t callback;
122131
#endif
123132
};
124133

@@ -127,16 +136,14 @@ struct nrf_ble_qwr {
127136
*
128137
* @details This structure contains all information needed to initialize the Queued Writes module.
129138
*/
130-
struct nrf_ble_qwr_init {
131-
/** Error handler. */
132-
nrf_ble_qwr_error_handler_t error_handler;
133-
#if (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0)
134-
/** Memory buffer that is provided to the SoftDevice on an ON_USER_MEM_REQUEST event. */
135-
ble_user_mem_block_t mem_buffer;
139+
struct ble_qwr_config {
136140
/** Event handler function that is called for events concerning the handles of all
137141
* registered attributes.
138142
*/
139-
nrf_ble_qwr_evt_handler_t callback;
143+
ble_qwr_evt_handler_t evt_handler;
144+
#if (CONFIG_BLE_QWR_MAX_ATTR > 0)
145+
/** Memory buffer that is provided to the SoftDevice on an ON_USER_MEM_REQUEST event. */
146+
ble_user_mem_block_t mem_buffer;
140147
#endif
141148
};
142149

@@ -156,7 +163,7 @@ struct nrf_ble_qwr_init {
156163
* @retval -EFAULT If @p qwr or @p qwr_init is @c NULL.
157164
* @retval -EPERM If the given @p qwr instance has already been initialized.
158165
*/
159-
int nrf_ble_qwr_init(struct nrf_ble_qwr *qwr, struct nrf_ble_qwr_init const *qwr_init);
166+
int ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config);
160167

161168

162169
/**
@@ -173,7 +180,7 @@ int nrf_ble_qwr_init(struct nrf_ble_qwr *qwr, struct nrf_ble_qwr_init const *qwr
173180
* @retval -EFAULT If @p qwr is @c NULL.
174181
* @retval -EPERM If the given @p qwr instance has not been initialized.
175182
*/
176-
int nrf_ble_qwr_conn_handle_assign(struct nrf_ble_qwr *qwr, uint16_t conn_handle);
183+
int ble_qwr_conn_handle_assign(struct ble_qwr *qwr, uint16_t conn_handle);
177184

178185
/**
179186
* @brief Function for handling BLE stack events.
@@ -183,9 +190,9 @@ int nrf_ble_qwr_conn_handle_assign(struct nrf_ble_qwr *qwr, uint16_t conn_handle
183190
* @param[in] ble_evt Event received from the BLE stack.
184191
* @param[in] context Queued Writes structure.
185192
*/
186-
void nrf_ble_qwr_on_ble_evt(ble_evt_t const *ble_evt, void *context);
193+
void ble_qwr_on_ble_evt(ble_evt_t const *ble_evt, void *context);
187194

188-
#if (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0)
195+
#if (CONFIG_BLE_QWR_MAX_ATTR > 0)
189196
/**
190197
* @brief Function for registering an attribute with the Queued Writes module.
191198
*
@@ -200,13 +207,13 @@ void nrf_ble_qwr_on_ble_evt(ble_evt_t const *ble_evt, void *context);
200207
* @retval -EFAULT If @p qwr is @c NULL.
201208
* @retval -EPERM If the given @p qwr instance has not been initialized.
202209
*/
203-
int nrf_ble_qwr_attr_register(struct nrf_ble_qwr *qwr, uint16_t attr_handle);
210+
int ble_qwr_attr_register(struct ble_qwr *qwr, uint16_t attr_handle);
204211

205212

206213
/**
207214
* @brief Function for retrieving the received data for a given attribute.
208215
*
209-
* @details Call this function after receiving an @ref NRF_BLE_QWR_EVT_AUTH_REQUEST
216+
* @details Call this function after receiving an @ref BLE_QWR_EVT_AUTH_REQUEST
210217
* event to retrieve a linear copy of the data that was received for the given attribute.
211218
*
212219
* @param[in] qwr Queued Writes structure.
@@ -219,9 +226,9 @@ int nrf_ble_qwr_attr_register(struct nrf_ble_qwr *qwr, uint16_t attr_handle);
219226
* @retval -EFAULT If @p qwr, @p mem or @p len is @c NULL.
220227
* @retval -EPERM If the given @p qwr instance has not been initialized.
221228
*/
222-
int nrf_ble_qwr_value_get(
223-
struct nrf_ble_qwr *qwr, uint16_t attr_handle, uint8_t *mem, uint16_t *len);
224-
#endif /* (CONFIG_NRF_BLE_QWR_MAX_ATTR > 0) */
229+
int ble_qwr_value_get(
230+
struct ble_qwr *qwr, uint16_t attr_handle, uint8_t *mem, uint16_t *len);
231+
#endif /* (CONFIG_BLE_QWR_MAX_ATTR > 0) */
225232

226233
#ifdef __cplusplus
227234
}

include/bluetooth/services/ble_lbs.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,33 @@ struct ble_lbs;
4141
extern void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance); \
4242
NRF_SDH_BLE_OBSERVER(_name ## _obs, ble_lbs_on_ble_evt, &_name, BLE_LBS_BLE_OBSERVER_PRIO)
4343

44-
typedef void (*ble_lbs_led_write_handler_t)(uint16_t conn_handle, struct ble_lbs *lbs,
45-
uint8_t value);
44+
enum ble_lbs_evt_type {
45+
BLE_LBS_EVT_LED_WRITE,
46+
};
47+
48+
struct ble_lbs_evt {
49+
enum ble_lbs_evt_type evt_type;
50+
union {
51+
/** @ref BLE_LBS_EVT_LED_WRITE event data. */
52+
struct {
53+
/** Connection handle */
54+
uint16_t conn_handle;
55+
/** Value to write */
56+
uint8_t value;
57+
} led_write;
58+
};
59+
};
60+
61+
/** @brief LED button Service event handler */
62+
typedef void (*lbs_evt_handler_t)(struct ble_lbs *lbs, const struct ble_lbs_evt *lbs_evt);
4663

4764
/**
4865
* @brief LED Button Service init structure. This structure contains all options and data needed
4966
* for initialization of the service.
5067
*/
5168
struct ble_lbs_config {
5269
/** @brief Event handler to be called when the LED Characteristic is written. */
53-
ble_lbs_led_write_handler_t led_write_handler;
70+
lbs_evt_handler_t evt_handler;
5471
};
5572

5673
/**
@@ -66,7 +83,7 @@ struct ble_lbs {
6683
/** @brief UUID type for the LED Button Service. */
6784
uint8_t uuid_type;
6885
/** @brief Event handler to be called when the LED Characteristic is written. */
69-
ble_lbs_led_write_handler_t led_write_handler;
86+
lbs_evt_handler_t evt_handler;
7087
};
7188

7289
/**

include/bluetooth/services/ble_nus.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct ble_nus_evt {
112112
};
113113

114114
/** @brief Nordic UART Service event handler type. */
115-
typedef void (*ble_nus_data_handler_t) (struct ble_nus_evt *evt);
115+
typedef void (*ble_nus_evt_handler_t) (const struct ble_nus_evt *evt);
116116

117117
/*
118118
* @brief Nordic UART Service initialization structure.
@@ -123,7 +123,7 @@ typedef void (*ble_nus_data_handler_t) (struct ble_nus_evt *evt);
123123
*/
124124
struct ble_nus_config {
125125
/** Event handler to be called for handling received data. */
126-
ble_nus_data_handler_t data_handler;
126+
ble_nus_evt_handler_t evt_handler;
127127
};
128128

129129
/**
@@ -143,7 +143,7 @@ struct ble_nus {
143143
/** Link context with handles of all current connections and its context. */
144144
struct ble_nus_ctx *const ctx;
145145
/** Event handler to be called for handling received data. */
146-
ble_nus_data_handler_t data_handler;
146+
ble_nus_evt_handler_t evt_handler;
147147
};
148148

149149
/**

0 commit comments

Comments
 (0)