gattlib/gattlib-py/gattlib/exception.py

63 lines
1.1 KiB
Python
Raw Normal View History

2021-09-01 00:00:36 +02:00
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2016-2021, Olivier Martin <olivier@labapart.org>
#
GATTLIB_SUCCESS = 0
GATTLIB_INVALID_PARAMETER = 1
GATTLIB_NOT_FOUND = 2
GATTLIB_OUT_OF_MEMORY = 3
GATTLIB_NOT_SUPPORTED = 4
GATTLIB_DEVICE_ERROR = 5
GATTLIB_ERROR_DBUS = 6
2019-05-19 12:47:21 +02:00
class GattlibException(Exception):
pass
class AdapterNotOpened(GattlibException):
pass
2019-05-19 12:47:21 +02:00
class InvalidParameter(GattlibException):
pass
2019-05-19 12:47:21 +02:00
class NotFound(GattlibException):
pass
2019-05-19 12:47:21 +02:00
class OutOfMemory(GattlibException):
pass
2019-05-19 12:47:21 +02:00
class NotSupported(GattlibException):
pass
2019-05-19 12:47:21 +02:00
class DeviceError(GattlibException):
pass
2019-05-19 12:47:21 +02:00
class DBusError(GattlibException):
pass
2019-05-19 12:47:21 +02:00
def handle_return(ret):
if ret == GATTLIB_INVALID_PARAMETER:
raise InvalidParameter()
elif ret == GATTLIB_NOT_FOUND:
raise NotFound()
elif ret == GATTLIB_OUT_OF_MEMORY:
raise OutOfMemory()
elif ret == GATTLIB_NOT_SUPPORTED:
raise NotSupported()
elif ret == GATTLIB_DEVICE_ERROR:
raise DeviceError()
elif ret == GATTLIB_ERROR_DBUS:
raise DBusError()
elif ret != 0:
raise RuntimeError("Gattlib exception %d" % ret)