@@ -19,13 +19,13 @@ struct connection_t {
1919 char * addr ;
2020 char name [32 ];
2121
22- gatt_connection_t * gconn ;
22+ gattlib_connection_t * gconn ;
2323 LIST_ENTRY (connection_t ) entries ;
2424};
2525
2626typedef struct gatt_info {
2727 SurviveContext * ctx ;
28- void * adapter ;
28+ gattlib_adapter_t * adapter ;
2929 LIST_HEAD (listhead , connection_t ) ble_connections ;
3030 og_thread_t thread ;
3131
@@ -53,7 +53,7 @@ static uuid_t *power_uuid() {
5353 return & uuid ;
5454}
5555
56- static uint32_t read_char_byte (gatt_connection_t * gatt_connection , uuid_t * uuid ) {
56+ static uint32_t read_char_byte (gattlib_connection_t * gatt_connection , uuid_t * uuid ) {
5757 void * buffer ;
5858 size_t buffer_length ;
5959
@@ -71,8 +71,9 @@ static uint32_t read_char_byte(gatt_connection_t *gatt_connection, uuid_t *uuid)
7171 return 0xFFFFFFFF ;
7272}
7373
74- static void ble_connect_device_done (gatt_connection_t * gatt_connection , void * arg ) {
75- struct connection_t * connection = arg ;
74+ static void ble_connect_device_done (gattlib_adapter_t * adapter , const char * dst ,
75+ gattlib_connection_t * gatt_connection , int error , void * user_data ) {
76+ struct connection_t * connection = user_data ;
7677 char * addr = connection -> addr ;
7778 SurviveContext * ctx = connection -> driver -> ctx ;
7879
@@ -130,26 +131,25 @@ static void ble_connect_device_done(gatt_connection_t *gatt_connection, void *ar
130131 return ;
131132
132133disconnect_exit :
133- gattlib_disconnect (gatt_connection );
134+ gattlib_disconnect (gatt_connection , false );
134135}
135136
136137static void * ble_connect_device (void * arg ) {
137138 struct connection_t * connection = arg ;
138139 char * addr = connection -> addr ;
139- gatt_connection_t * gatt_connection ;
140140 SurviveContext * ctx = connection -> driver -> ctx ;
141141
142- gatt_connection = gattlib_connect_async (connection -> driver -> adapter , addr , 0 , ble_connect_device_done , connection );
143-
144- if (gatt_connection == NULL ) {
145- SV_WARN ("Fail to connect to the bluetooth device %s." , addr );
142+ int ret = gattlib_connect (connection -> driver -> adapter , addr , 0 , ble_connect_device_done , connection );
143+ if (ret != GATTLIB_SUCCESS ) {
144+ SV_WARN ("Fail to connect to the bluetooth device %s: %d" , addr , ret );
146145 }
147146
148147 return 0 ;
149148}
150149
151- static void ble_discovered_device (void * adapter , const char * addr , const char * name , void * arg ) {
152- gatt_info * driver = (gatt_info * )arg ;
150+ static void ble_discovered_device (gattlib_adapter_t * adapter , const char * addr , const char * name ,
151+ void * user_data ) {
152+ gatt_info * driver = (gatt_info * )user_data ;
153153 SurviveContext * ctx = driver -> ctx ;
154154
155155 if (name == 0 || strncmp (name , "LHB" , strlen ("LHB" )) != 0 )
@@ -198,7 +198,7 @@ static int gatt_close(SurviveContext *ctx, void *arg) {
198198 SV_INFO ("GATT: Powering down base station %s" , driver -> lhs [i ]-> name );
199199 gattlib_write_char_by_uuid (driver -> lhs [i ]-> gconn , power_uuid (), & powerdown [0 ], 1 );
200200 gattlib_write_char_by_uuid (driver -> lhs [i ]-> gconn , power_uuid (), & powerdown [1 ], 1 );
201- gattlib_disconnect (driver -> lhs [i ]-> gconn );
201+ gattlib_disconnect (driver -> lhs [i ]-> gconn , true );
202202 }
203203 }
204204 }
0 commit comments