mirror of https://github.com/labapart/gattlib
Return specific error code when the adapter or device has been removed
parent
0e34df58e5
commit
cdd62f6d35
|
@ -21,7 +21,7 @@ int gattlib_register_notification(gattlib_connection_t* connection, gattlib_even
|
|||
}
|
||||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_DEVICE_DISCONNECTED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ int gattlib_register_indication(gattlib_connection_t* connection, gattlib_event_
|
|||
}
|
||||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_DEVICE_DISCONNECTED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ int gattlib_register_on_disconnect(gattlib_connection_t *connection, gattlib_dis
|
|||
}
|
||||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_DEVICE_DISCONNECTED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ int gattlib_device_set_state(gattlib_adapter_t* adapter, const char* device_id,
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ int gattlib_connect(gattlib_adapter_t* adapter, const char *dst,
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ int gattlib_discover_primary(gattlib_connection_t* connection, gattlib_primary_s
|
|||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
g_rec_mutex_unlock(&m_gattlib_mutex);
|
||||
return GATTLIB_INVALID_PARAMETER;
|
||||
return GATTLIB_DEVICE_DISCONNECTED;
|
||||
}
|
||||
|
||||
// Increase 'bluez_device' reference counter to avoid to keep the lock longer
|
||||
|
@ -507,7 +507,7 @@ int gattlib_discover_primary(gattlib_connection_t* connection, gattlib_primary_s
|
|||
}
|
||||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_DEVICE_DISCONNECTED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -669,7 +669,7 @@ int gattlib_discover_char_range(gattlib_connection_t* connection, uint16_t start
|
|||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
g_rec_mutex_unlock(&m_gattlib_mutex);
|
||||
return GATTLIB_INVALID_PARAMETER;
|
||||
return GATTLIB_DEVICE_DISCONNECTED;
|
||||
}
|
||||
|
||||
OrgBluezDevice1* bluez_device = connection->backend.bluez_device;
|
||||
|
@ -927,7 +927,7 @@ int gattlib_discover_char_range(gattlib_connection_t* connection, uint16_t start
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_DEVICE_DISCONNECTED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -1058,7 +1058,7 @@ int get_bluez_device_from_mac(struct _gattlib_adapter *adapter, const char *mac_
|
|||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
g_rec_mutex_unlock(&m_gattlib_mutex);
|
||||
return GATTLIB_INVALID_PARAMETER;
|
||||
return GATTLIB_ADAPTER_CLOSE;
|
||||
}
|
||||
|
||||
if (adapter->backend.adapter_proxy == NULL) {
|
||||
|
@ -1106,7 +1106,7 @@ int gattlib_get_rssi(gattlib_connection_t *connection, int16_t *rssi)
|
|||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
g_rec_mutex_unlock(&m_gattlib_mutex);
|
||||
return GATTLIB_INVALID_PARAMETER;
|
||||
return GATTLIB_DEVICE_DISCONNECTED;
|
||||
}
|
||||
|
||||
// device is actually a GObject. Increasing its reference counter prevents to
|
||||
|
|
|
@ -490,7 +490,7 @@ int gattlib_adapter_scan_enable_with_filter(gattlib_adapter_t* adapter, uuid_t *
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ int gattlib_adapter_scan_enable_with_filter(gattlib_adapter_t* adapter, uuid_t *
|
|||
|
||||
// Ensure the adapter is still valid when we get the mutex again
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -546,7 +546,7 @@ int gattlib_adapter_scan_enable_with_filter_non_blocking(gattlib_adapter_t* adap
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -584,7 +584,7 @@ int gattlib_adapter_scan_disable(gattlib_adapter_t* adapter) {
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ int gattlib_adapter_close(gattlib_adapter_t* adapter) {
|
|||
g_rec_mutex_lock(&m_gattlib_mutex);
|
||||
|
||||
if (!gattlib_adapter_is_valid(adapter)) {
|
||||
ret = GATTLIB_INVALID_PARAMETER;
|
||||
ret = GATTLIB_ADAPTER_CLOSE;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ int gattlib_get_advertisement_data(gattlib_connection_t *connection,
|
|||
|
||||
if (!gattlib_device_is_valid(connection->device)) {
|
||||
g_rec_mutex_unlock(&m_gattlib_mutex);
|
||||
return GATTLIB_INVALID_PARAMETER;
|
||||
return GATTLIB_DEVICE_DISCONNECTED;
|
||||
}
|
||||
|
||||
// device is actually a GObject. Increasing its reference counter prevents to
|
||||
|
|
|
@ -15,6 +15,8 @@ GATTLIB_DEVICE_NOT_CONNECTED = 7
|
|||
GATTLIB_NO_ADAPTER = 8
|
||||
GATTLIB_BUSY = 9
|
||||
GATTLIB_UNEXPECTED = 10
|
||||
GATTLIB_ADAPTER_CLOSE = 11
|
||||
GATTLIB_DEVICE_DISCONNECTED = 12
|
||||
|
||||
GATTLIB_ERROR_MODULE_MASK = 0xF0000000
|
||||
GATTLIB_ERROR_DBUS = 0x10000000
|
||||
|
@ -52,6 +54,12 @@ class NotSupported(GattlibException):
|
|||
class NotConnected(GattlibException):
|
||||
pass
|
||||
|
||||
class AdapterClose(GattlibException):
|
||||
pass
|
||||
|
||||
class Disconnected(GattlibException):
|
||||
pass
|
||||
|
||||
class DeviceError(GattlibException):
|
||||
def __init__(self, adapter: str = None, mac_address: str = None) -> None:
|
||||
self.adapter = adapter
|
||||
|
@ -96,6 +104,10 @@ def handle_return(ret):
|
|||
raise Busy()
|
||||
elif ret == GATTLIB_UNEXPECTED:
|
||||
raise Unexpected()
|
||||
elif ret == GATTLIB_ADAPTER_CLOSE:
|
||||
raise AdapterClose()
|
||||
elif ret == GATTLIB_DEVICE_DISCONNECTED:
|
||||
raise Disconnected()
|
||||
elif (ret & GATTLIB_ERROR_MODULE_MASK) == GATTLIB_ERROR_DBUS:
|
||||
raise DBusError((ret >> 8) & 0xFFF, ret & 0xFFFF)
|
||||
elif ret == -22: # From '-EINVAL'
|
||||
|
|
|
@ -52,6 +52,8 @@ extern "C" {
|
|||
#define GATTLIB_NO_ADAPTER 8
|
||||
#define GATTLIB_BUSY 9
|
||||
#define GATTLIB_UNEXPECTED 10
|
||||
#define GATTLIB_ADAPTER_CLOSE 11
|
||||
#define GATTLIB_DEVICE_DISCONNECTED 12
|
||||
#define GATTLIB_ERROR_MODULE_MASK 0xF0000000
|
||||
#define GATTLIB_ERROR_DBUS 0x10000000
|
||||
#define GATTLIB_ERROR_BLUEZ 0x20000000
|
||||
|
|
Loading…
Reference in New Issue