mirror of https://github.com/labapart/gattlib
gattlib: Move 'struct _gatt_connection_t' out of 'gattlib.h'
parent
8438cd5c0d
commit
046f077085
|
@ -76,7 +76,7 @@ set(gattlib_SRCS gattlib_adapter.c
|
|||
gattlib_connect.c
|
||||
gattlib_discover.c
|
||||
gattlib_read_write.c
|
||||
../gattlib_common.c)
|
||||
${CMAKE_SOURCE_DIR}/common/gattlib_common.c)
|
||||
|
||||
# Added Glib support
|
||||
pkg_search_module(GLIB REQUIRED glib-2.0)
|
||||
|
@ -87,7 +87,7 @@ list(APPEND gattlib_LIBS ${GLIB_LDFLAGS})
|
|||
include_directories(${BLUEZ_INCLUDE_DIRS})
|
||||
list(APPEND gattlib_LIBS ${BLUEZ_LDFLAGS})
|
||||
|
||||
include_directories(.)
|
||||
include_directories(. ${CMAKE_SOURCE_DIR}/common)
|
||||
if(BLUEZ_VERSION_MAJOR STREQUAL "4")
|
||||
list(APPEND gattlib_SRCS ${bluez4_SRCS})
|
||||
include_directories(${bluez4_DIR}/attrib ${bluez4_DIR}/btio ${bluez4_DIR}/src ${bluez4_DIR}/lib)
|
||||
|
|
|
@ -68,13 +68,13 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
|
|||
|
||||
switch (pdu[0]) {
|
||||
case ATT_OP_HANDLE_NOTIFY:
|
||||
if (conn->notification_handler) {
|
||||
conn->notification_handler(&uuid, &pdu[3], len - 3, conn->notification_user_data);
|
||||
if (gattlib_has_valid_handler(&conn->notification)) {
|
||||
gattlib_call_notification_handler(&conn->notification, &uuid, &pdu[3], len - 3);
|
||||
}
|
||||
break;
|
||||
case ATT_OP_HANDLE_IND:
|
||||
if (conn->indication_handler) {
|
||||
conn->indication_handler(&uuid, &pdu[3], len - 3, conn->indication_user_data);
|
||||
if (gattlib_has_valid_handler(&conn->indication)) {
|
||||
gattlib_call_notification_handler(&conn->notification, &uuid, &pdu[3], len - 3);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* GattLib - GATT Library
|
||||
*
|
||||
* Copyright (C) 2016-2017 Olivier Martin <olivier@labapart.org>
|
||||
* Copyright (C) 2016-2019 Olivier Martin <olivier@labapart.org>
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -29,6 +29,7 @@
|
|||
#define BLUEZ_VERSIONS(major, minor) (((major) << 8) | (minor))
|
||||
#define BLUEZ_VERSION BLUEZ_VERSIONS(BLUEZ_VERSION_MAJOR, BLUEZ_VERSION_MINOR)
|
||||
|
||||
#include "gattlib_internal_defs.h"
|
||||
#include "gattlib.h"
|
||||
|
||||
#include "uuid.h"
|
||||
|
@ -38,6 +39,8 @@
|
|||
#include "src/shared/util.h"
|
||||
#endif
|
||||
|
||||
typedef struct _GAttrib GAttrib;
|
||||
|
||||
struct gattlib_thread_t {
|
||||
int ref;
|
||||
pthread_t thread;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef __GATTLIB_INTERNAL_DEFS_H__
|
||||
#define __GATTLIB_INTERNAL_DEFS_H__
|
||||
|
||||
#include "gattlib.h"
|
||||
|
||||
struct _gatt_connection_t {
|
||||
void* context;
|
||||
|
||||
gattlib_event_handler_t notification_handler;
|
||||
void* notification_user_data;
|
||||
|
||||
gattlib_event_handler_t indication_handler;
|
||||
void* indication_user_data;
|
||||
|
||||
gattlib_disconnection_handler_t disconnection_handler;
|
||||
void* disconnection_user_data;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -76,11 +76,11 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org-bluez-battery1.c
|
|||
COMMENT "Generate D-Bus 'org.bluez.Battery1.xml'"
|
||||
)
|
||||
|
||||
include_directories(. ${CMAKE_CURRENT_BINARY_DIR} ${GIO_UNIX_INCLUDE_DIRS} ${BLUEZ_INCLUDE_DIRS})
|
||||
include_directories(. ${CMAKE_SOURCE_DIR}/common ${CMAKE_CURRENT_BINARY_DIR} ${GIO_UNIX_INCLUDE_DIRS} ${BLUEZ_INCLUDE_DIRS})
|
||||
|
||||
set(gattlib_SRCS gattlib.c
|
||||
bluez5/lib/uuid.c
|
||||
../gattlib_common.c
|
||||
${CMAKE_SOURCE_DIR}/common/gattlib_common.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/org-bluez-adaptater1.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/org-bluez-device1.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/org-bluez-gattcharacteristic1.c
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#ifndef __GATTLIB_INTERNAL_H__
|
||||
#define __GATTLIB_INTERNAL_H__
|
||||
|
||||
#include "gattlib_internal_defs.h"
|
||||
#include "gattlib.h"
|
||||
|
||||
#include "org-bluez-adaptater1.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# GattLib - GATT Library
|
||||
#
|
||||
# Copyright (C) 2016-2017 Olivier Martin <olivier@labapart.org>
|
||||
# Copyright (C) 2016-2019 Olivier Martin <olivier@labapart.org>
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
|
@ -27,7 +27,7 @@ pkg_search_module(GATTLIB REQUIRED gattlib)
|
|||
pkg_search_module(GLIB REQUIRED glib-2.0)
|
||||
pkg_search_module(PCRE REQUIRED libpcre)
|
||||
|
||||
include_directories(${GLIB_INCLUDE_DIRS})
|
||||
include_directories(${CMAKE_SOURCE_DIR}/common ${GLIB_INCLUDE_DIRS})
|
||||
|
||||
#
|
||||
# Add Bluetooth support: Workaround as the current 'gatttool' example
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
#include "gattlib.h"
|
||||
#include "gatttool.h"
|
||||
|
||||
#include "gattlib_internal_defs.h"
|
||||
|
||||
static gchar *opt_src = NULL;
|
||||
static gchar *opt_dst = NULL;
|
||||
static gchar *opt_dst_type = NULL;
|
||||
|
@ -146,7 +148,7 @@ done:
|
|||
|
||||
static gboolean primary(gpointer user_data)
|
||||
{
|
||||
gatt_connection_t* connection = (gatt_connection_t*)user_data;
|
||||
struct _gatt_connection_t *connection = (struct _gatt_connection_t *)user_data;
|
||||
gattlib_context_t* conn_context = connection->context;
|
||||
GAttrib *attrib = conn_context->attrib;
|
||||
char uuid_str[MAX_LEN_UUID_STR + 1];
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#include "gattlib.h"
|
||||
#include "gatttool.h"
|
||||
|
||||
#include "gattlib_internal_defs.h"
|
||||
|
||||
static gatt_connection_t* g_connection = NULL;
|
||||
static GMainLoop *event_loop;
|
||||
static GString *prompt;
|
||||
|
@ -325,7 +327,8 @@ static void cmd_connect(int argcp, char **argvp)
|
|||
if (connection == NULL) {
|
||||
set_state(STATE_DISCONNECTED);
|
||||
} else {
|
||||
gattlib_context_t* conn_context = g_connection->context;
|
||||
struct _gatt_connection_t *gatt_connection = (struct _gatt_connection_t *)g_connection;
|
||||
gattlib_context_t* conn_context = gatt_connection->context;
|
||||
g_io_add_watch(conn_context->io, G_IO_HUP, channel_watcher, NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ extern "C" {
|
|||
GATTLIB_CONNECTION_OPTIONS_LEGACY_BDADDR_LE_RANDOM | \
|
||||
GATTLIB_CONNECTION_OPTIONS_LEGACY_BT_SEC_LOW
|
||||
|
||||
typedef struct _GAttrib GAttrib;
|
||||
typedef struct _gatt_connection_t gatt_connection_t;
|
||||
|
||||
typedef void (*gattlib_event_handler_t)(const uuid_t* uuid, const uint8_t* data, size_t data_length, void* user_data);
|
||||
|
||||
|
@ -101,19 +101,6 @@ typedef void (*gattlib_event_handler_t)(const uuid_t* uuid, const uint8_t* data,
|
|||
*/
|
||||
typedef void (*gattlib_disconnection_handler_t)(void* user_data);
|
||||
|
||||
typedef struct _gatt_connection_t {
|
||||
void* context;
|
||||
|
||||
gattlib_event_handler_t notification_handler;
|
||||
void* notification_user_data;
|
||||
|
||||
gattlib_event_handler_t indication_handler;
|
||||
void* indication_user_data;
|
||||
|
||||
gattlib_disconnection_handler_t disconnection_handler;
|
||||
void* disconnection_user_data;
|
||||
} 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, void* user_data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue