iqrfpy.itransport

Transport abstract class.

Serves as an abstract for communication channels.

  1"""Transport abstract class.
  2
  3Serves as an abstract for communication channels.
  4"""
  5from abc import ABC, abstractmethod
  6from typing import Callable, Optional
  7from iqrfpy.irequest import IRequest
  8from iqrfpy.iresponse import IResponse
  9from iqrfpy.confirmation import Confirmation
 10
 11
 12class ITransport(ABC):
 13    """Abstract class providing interface for communication channels."""
 14
 15    @abstractmethod
 16    def initialize(self) -> None:
 17        """Initialize transport and create a connection if applicable.
 18
 19        Raises:
 20            NotImplementedError: Abstract method not implemented.
 21        """
 22        raise NotImplementedError("Abstract method not implemented.")
 23
 24    @abstractmethod
 25    def terminate(self, force: bool = False) -> None:
 26        """Terminates transport.
 27
 28        Args:
 29            force (bool): Force terminate transport.
 30
 31        Raises:
 32            NotImplementedError: Abstract method not implemented.
 33        """
 34        raise NotImplementedError("Abstract method not implemented.")
 35
 36    @abstractmethod
 37    def send(self, request: IRequest) -> None:
 38        """Serialize passed request to format acceptable by the communication channel and send request.
 39
 40        Args:
 41            request (IRequest): Request message to send.
 42
 43        Raises:
 44            NotImplementedError: Abstract method not implemented.
 45        """
 46        raise NotImplementedError("Abstract method not implemented.")
 47
 48    @abstractmethod
 49    def send_and_receive(self, request: IRequest, timeout: Optional[float] = None) -> IResponse:
 50        """Serialize request to format acceptable by the communication channel, send request and receive response synchronously.
 51
 52        Args:
 53            request (IRequest): Request message to send.
 54            timeout (float, optional): Response timeout.
 55
 56        Returns:
 57            :obj:`IResponse`: Response message object.
 58
 59        Raises:
 60            NotImplementedError: Abstract method not implemented.
 61        """
 62        raise NotImplementedError("Abstract method not implemented.")
 63
 64    @abstractmethod
 65    def receive(self, timeout: Optional[float] = None) -> IResponse:
 66        """Receive and return response synchronously.
 67
 68        Args:
 69            timeout (float, optional): Response timeout.
 70
 71        Returns:
 72            :obj:`IResponse`: Response message object.
 73
 74        Raises:
 75            NotImplementedError: Abstract method not implemented.
 76        """
 77        raise NotImplementedError("Abstract method not implemented.")
 78
 79    @abstractmethod
 80    def confirmation(self) -> Confirmation:
 81        """Receive and return confirmation synchronously.
 82
 83        Returns:
 84            :obj:`Confirmation`: Confirmation message object.
 85
 86        Raises:
 87            NotImplementedError: Abstract method not implemented.
 88        """
 89        raise NotImplementedError("Abstract method not implemented.")
 90
 91    @abstractmethod
 92    def set_receive_callback(self, callback: Callable[[IResponse], None]) -> None:
 93        """Set callback to handle asynchronously received messages.
 94
 95        Args:
 96            callback (Callable[[IResponse], None]): Function to call once a message has been received and successfully
 97                                                    deserialized.
 98
 99        Raises:
100            NotImplementedError: Abstract method not implemented.
101        """
102        raise NotImplementedError("Abstract method not implemented.")
class ITransport(abc.ABC):
 13class ITransport(ABC):
 14    """Abstract class providing interface for communication channels."""
 15
 16    @abstractmethod
 17    def initialize(self) -> None:
 18        """Initialize transport and create a connection if applicable.
 19
 20        Raises:
 21            NotImplementedError: Abstract method not implemented.
 22        """
 23        raise NotImplementedError("Abstract method not implemented.")
 24
 25    @abstractmethod
 26    def terminate(self, force: bool = False) -> None:
 27        """Terminates transport.
 28
 29        Args:
 30            force (bool): Force terminate transport.
 31
 32        Raises:
 33            NotImplementedError: Abstract method not implemented.
 34        """
 35        raise NotImplementedError("Abstract method not implemented.")
 36
 37    @abstractmethod
 38    def send(self, request: IRequest) -> None:
 39        """Serialize passed request to format acceptable by the communication channel and send request.
 40
 41        Args:
 42            request (IRequest): Request message to send.
 43
 44        Raises:
 45            NotImplementedError: Abstract method not implemented.
 46        """
 47        raise NotImplementedError("Abstract method not implemented.")
 48
 49    @abstractmethod
 50    def send_and_receive(self, request: IRequest, timeout: Optional[float] = None) -> IResponse:
 51        """Serialize request to format acceptable by the communication channel, send request and receive response synchronously.
 52
 53        Args:
 54            request (IRequest): Request message to send.
 55            timeout (float, optional): Response timeout.
 56
 57        Returns:
 58            :obj:`IResponse`: Response message object.
 59
 60        Raises:
 61            NotImplementedError: Abstract method not implemented.
 62        """
 63        raise NotImplementedError("Abstract method not implemented.")
 64
 65    @abstractmethod
 66    def receive(self, timeout: Optional[float] = None) -> IResponse:
 67        """Receive and return response synchronously.
 68
 69        Args:
 70            timeout (float, optional): Response timeout.
 71
 72        Returns:
 73            :obj:`IResponse`: Response message object.
 74
 75        Raises:
 76            NotImplementedError: Abstract method not implemented.
 77        """
 78        raise NotImplementedError("Abstract method not implemented.")
 79
 80    @abstractmethod
 81    def confirmation(self) -> Confirmation:
 82        """Receive and return confirmation synchronously.
 83
 84        Returns:
 85            :obj:`Confirmation`: Confirmation message object.
 86
 87        Raises:
 88            NotImplementedError: Abstract method not implemented.
 89        """
 90        raise NotImplementedError("Abstract method not implemented.")
 91
 92    @abstractmethod
 93    def set_receive_callback(self, callback: Callable[[IResponse], None]) -> None:
 94        """Set callback to handle asynchronously received messages.
 95
 96        Args:
 97            callback (Callable[[IResponse], None]): Function to call once a message has been received and successfully
 98                                                    deserialized.
 99
100        Raises:
101            NotImplementedError: Abstract method not implemented.
102        """
103        raise NotImplementedError("Abstract method not implemented.")

Abstract class providing interface for communication channels.

@abstractmethod
def initialize(self) -> None:
16    @abstractmethod
17    def initialize(self) -> None:
18        """Initialize transport and create a connection if applicable.
19
20        Raises:
21            NotImplementedError: Abstract method not implemented.
22        """
23        raise NotImplementedError("Abstract method not implemented.")

Initialize transport and create a connection if applicable.

Raises:
  • NotImplementedError: Abstract method not implemented.
@abstractmethod
def terminate(self, force: bool = False) -> None:
25    @abstractmethod
26    def terminate(self, force: bool = False) -> None:
27        """Terminates transport.
28
29        Args:
30            force (bool): Force terminate transport.
31
32        Raises:
33            NotImplementedError: Abstract method not implemented.
34        """
35        raise NotImplementedError("Abstract method not implemented.")

Terminates transport.

Arguments:
  • force (bool): Force terminate transport.
Raises:
  • NotImplementedError: Abstract method not implemented.
@abstractmethod
def send(self, request: iqrfpy.irequest.IRequest) -> None:
37    @abstractmethod
38    def send(self, request: IRequest) -> None:
39        """Serialize passed request to format acceptable by the communication channel and send request.
40
41        Args:
42            request (IRequest): Request message to send.
43
44        Raises:
45            NotImplementedError: Abstract method not implemented.
46        """
47        raise NotImplementedError("Abstract method not implemented.")

Serialize passed request to format acceptable by the communication channel and send request.

Arguments:
  • request (IRequest): Request message to send.
Raises:
  • NotImplementedError: Abstract method not implemented.
@abstractmethod
def send_and_receive( self, request: iqrfpy.irequest.IRequest, timeout: Optional[float] = None) -> iqrfpy.iresponse.IResponse:
49    @abstractmethod
50    def send_and_receive(self, request: IRequest, timeout: Optional[float] = None) -> IResponse:
51        """Serialize request to format acceptable by the communication channel, send request and receive response synchronously.
52
53        Args:
54            request (IRequest): Request message to send.
55            timeout (float, optional): Response timeout.
56
57        Returns:
58            :obj:`IResponse`: Response message object.
59
60        Raises:
61            NotImplementedError: Abstract method not implemented.
62        """
63        raise NotImplementedError("Abstract method not implemented.")

Serialize request to format acceptable by the communication channel, send request and receive response synchronously.

Arguments:
  • request (IRequest): Request message to send.
  • timeout (float, optional): Response timeout.
Returns:

IResponse: Response message object.

Raises:
  • NotImplementedError: Abstract method not implemented.
@abstractmethod
def receive(self, timeout: Optional[float] = None) -> iqrfpy.iresponse.IResponse:
65    @abstractmethod
66    def receive(self, timeout: Optional[float] = None) -> IResponse:
67        """Receive and return response synchronously.
68
69        Args:
70            timeout (float, optional): Response timeout.
71
72        Returns:
73            :obj:`IResponse`: Response message object.
74
75        Raises:
76            NotImplementedError: Abstract method not implemented.
77        """
78        raise NotImplementedError("Abstract method not implemented.")

Receive and return response synchronously.

Arguments:
  • timeout (float, optional): Response timeout.
Returns:

IResponse: Response message object.

Raises:
  • NotImplementedError: Abstract method not implemented.
@abstractmethod
def confirmation(self) -> iqrfpy.confirmation.Confirmation:
80    @abstractmethod
81    def confirmation(self) -> Confirmation:
82        """Receive and return confirmation synchronously.
83
84        Returns:
85            :obj:`Confirmation`: Confirmation message object.
86
87        Raises:
88            NotImplementedError: Abstract method not implemented.
89        """
90        raise NotImplementedError("Abstract method not implemented.")

Receive and return confirmation synchronously.

Returns:

Confirmation: Confirmation message object.

Raises:
  • NotImplementedError: Abstract method not implemented.
@abstractmethod
def set_receive_callback(self, callback: Callable[[iqrfpy.iresponse.IResponse], NoneType]) -> None:
 92    @abstractmethod
 93    def set_receive_callback(self, callback: Callable[[IResponse], None]) -> None:
 94        """Set callback to handle asynchronously received messages.
 95
 96        Args:
 97            callback (Callable[[IResponse], None]): Function to call once a message has been received and successfully
 98                                                    deserialized.
 99
100        Raises:
101            NotImplementedError: Abstract method not implemented.
102        """
103        raise NotImplementedError("Abstract method not implemented.")

Set callback to handle asynchronously received messages.

Arguments:
  • callback (Callable[[IResponse], None]): Function to call once a message has been received and successfully deserialized.
Raises:
  • NotImplementedError: Abstract method not implemented.