# Copyright (c) 2020 Jeff Irion and contributors
#
# This file is part of the aio-adb-shell package.
"""A base class for handles used to communicate with a device.
* :class:`BaseHandle`
* :meth:`BaseHandle.bulk_read`
* :meth:`BaseHandle.bulk_write`
* :meth:`BaseHandle.close`
* :meth:`BaseHandle.connect`
"""
try:
from abc import ABC, abstractmethod
except ImportError: # pragma: no cover
from abc import ABCMeta, abstractmethod
class ABC(object): # pylint: disable=too-few-public-methods
"""A Python2-compatible `ABC` class.
"""
__metaclass__ = ABCMeta
[docs]class BaseHandle(ABC):
"""A base handle class.
"""
[docs] @abstractmethod
async def close(self):
"""Close the connection.
"""
[docs] @abstractmethod
async def connect(self, timeout_s=None):
"""Create a connection to the device.
Parameters
----------
timeout_s : float, None
A connection timeout
"""
[docs] @abstractmethod
async def bulk_read(self, numbytes, timeout_s=None):
"""Read data from the device.
Parameters
----------
numbytes : int
The maximum amount of data to be received
timeout_s : float, None
A timeout for the read operation
Returns
-------
bytes
The received data
"""
[docs] @abstractmethod
async def bulk_write(self, data, timeout_s=None):
"""Send data to the device.
Parameters
----------
data : bytes
The data to be sent
timeout_s : float, None
A timeout for the write operation
Returns
-------
int
The number of bytes sent
"""