mirror of https://github.com/labapart/gattlib
andded user data pointer gatt_connect_async signature. these data will be passed to gatt_connect_cb callback to get information about object requested connection
parent
0f8c02c6a6
commit
7a2fdbd062
|
@ -46,6 +46,7 @@ typedef struct {
|
|||
int connected;
|
||||
int timeout;
|
||||
GError* error;
|
||||
void* user_data;
|
||||
} io_connect_arg_t;
|
||||
|
||||
static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data) {
|
||||
|
@ -122,7 +123,7 @@ static void io_connect_cb(GIOChannel *io, GError *err, gpointer user_data) {
|
|||
|
||||
// Call callback if defined
|
||||
if (io_connect_arg->connect_cb) {
|
||||
io_connect_arg->connect_cb(NULL);
|
||||
io_connect_arg->connect_cb(NULL, io_connect_arg->user_data);
|
||||
}
|
||||
} else {
|
||||
gattlib_context_t* conn_context = io_connect_arg->conn->context;
|
||||
|
@ -155,7 +156,7 @@ static void io_connect_cb(GIOChannel *io, GError *err, gpointer user_data) {
|
|||
// Call callback if defined
|
||||
//
|
||||
if (io_connect_arg->connect_cb) {
|
||||
io_connect_arg->connect_cb(io_connect_arg->conn);
|
||||
io_connect_arg->connect_cb(io_connect_arg->conn, io_connect_arg->user_data);
|
||||
}
|
||||
|
||||
io_connect_arg->connected = TRUE;
|
||||
|
@ -310,9 +311,10 @@ static BtIOSecLevel get_bt_io_sec_level(gattlib_bt_sec_level_t sec_level) {
|
|||
|
||||
gatt_connection_t *gattlib_connect_async(const char *src, const char *dst,
|
||||
uint8_t dest_type, gattlib_bt_sec_level_t sec_level, int psm, int mtu,
|
||||
gatt_connect_cb_t connect_cb)
|
||||
gatt_connect_cb_t connect_cb, void* data)
|
||||
{
|
||||
io_connect_arg_t* io_connect_arg = malloc(sizeof(io_connect_arg_t));
|
||||
io_connect_arg->user_data = data;
|
||||
BtIOSecLevel bt_io_sec_level = get_bt_io_sec_level(sec_level);
|
||||
|
||||
return initialize_gattlib_connection(src, dst, dest_type, bt_io_sec_level,
|
||||
|
@ -341,7 +343,6 @@ gatt_connection_t *gattlib_connect(const char *src, const char *dst,
|
|||
BtIOSecLevel bt_io_sec_level = get_bt_io_sec_level(sec_level);
|
||||
io_connect_arg_t io_connect_arg;
|
||||
GSource* timeout;
|
||||
|
||||
gatt_connection_t *conn = initialize_gattlib_connection(src, dst, dest_type, bt_io_sec_level,
|
||||
psm, mtu, NULL, &io_connect_arg);
|
||||
if (conn == NULL) {
|
||||
|
@ -360,7 +361,6 @@ gatt_connection_t *gattlib_connect(const char *src, const char *dst,
|
|||
while ((io_connect_arg.connected == FALSE) && (io_connect_arg.timeout == FALSE)) {
|
||||
g_main_context_iteration(g_gattlib_thread.loop_context, FALSE);
|
||||
}
|
||||
|
||||
// Disconnect the timeout source
|
||||
g_source_destroy(timeout);
|
||||
|
||||
|
|
|
@ -152,7 +152,6 @@ int gattlib_discover_char_range(gatt_connection_t* connection, int start, int en
|
|||
while(user_data.discovered == FALSE) {
|
||||
g_main_context_iteration(g_gattlib_thread.loop_context, FALSE);
|
||||
}
|
||||
|
||||
*characteristics = user_data.characteristics;
|
||||
*characteristics_count = user_data.characteristics_count;
|
||||
|
||||
|
|
|
@ -180,7 +180,6 @@ int gattlib_write_char_by_handle(gatt_connection_t* connection, uint16_t handle,
|
|||
while(write_completed == FALSE) {
|
||||
g_main_context_iteration(g_gattlib_thread.loop_context, FALSE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ FREE_CONNECTION:
|
|||
|
||||
gatt_connection_t *gattlib_connect_async(const char *src, const char *dst,
|
||||
uint8_t dest_type, gattlib_bt_sec_level_t sec_level, int psm, int mtu,
|
||||
gatt_connect_cb_t connect_cb)
|
||||
gatt_connect_cb_t connect_cb, void* data)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ int main(int argc, char *argv[])
|
|||
dest_type = get_dest_type_from_str(opt_dst_type);
|
||||
sec_level = get_sec_level_from_str(opt_sec_level);
|
||||
connection = gattlib_connect_async(opt_src, opt_dst, dest_type, sec_level,
|
||||
opt_psm, opt_mtu, connect_cb);
|
||||
opt_psm, opt_mtu, connect_cb, NULL);
|
||||
if (connection == NULL) {
|
||||
got_error = TRUE;
|
||||
goto done;
|
||||
|
|
|
@ -110,7 +110,7 @@ static void set_state(enum state st)
|
|||
rl_redisplay();
|
||||
}
|
||||
|
||||
static void connect_cb(gatt_connection_t* connection)
|
||||
static void connect_cb(gatt_connection_t* connection, void* user_data)
|
||||
{
|
||||
if (connection == NULL) {
|
||||
set_state(STATE_DISCONNECTED);
|
||||
|
@ -304,7 +304,7 @@ static void cmd_connect(int argcp, char **argvp)
|
|||
dst_type = get_dest_type_from_str(opt_dst_type);
|
||||
sec_level = get_sec_level_from_str(opt_sec_level);
|
||||
connection = gattlib_connect_async(opt_src, opt_dst, dst_type, sec_level,
|
||||
opt_psm, opt_mtu, connect_cb);
|
||||
opt_psm, opt_mtu, connect_cb, NULL);
|
||||
if (connection == NULL) {
|
||||
set_state(STATE_DISCONNECTED);
|
||||
} else {
|
||||
|
|
|
@ -80,7 +80,7 @@ typedef struct _gatt_connection_t {
|
|||
} gatt_connection_t;
|
||||
|
||||
typedef void (*gattlib_discovered_device_t)(const char* addr, const char* name);
|
||||
typedef void (*gatt_connect_cb_t)(gatt_connection_t* connection);
|
||||
typedef void (*gatt_connect_cb_t)(gatt_connection_t* connection, void* user_data);
|
||||
typedef void* (*gatt_read_cb_t)(const void* buffer, size_t buffer_len);
|
||||
|
||||
|
||||
|
@ -107,7 +107,7 @@ gatt_connection_t *gattlib_connect(const char *src, const char *dst,
|
|||
|
||||
gatt_connection_t *gattlib_connect_async(const char *src, const char *dst,
|
||||
uint8_t dest_type, gattlib_bt_sec_level_t sec_level, int psm, int mtu,
|
||||
gatt_connect_cb_t connect_cb);
|
||||
gatt_connect_cb_t connect_cb, void* data);
|
||||
|
||||
int gattlib_disconnect(gatt_connection_t* connection);
|
||||
|
||||
|
|
Loading…
Reference in New Issue