ctrlX Data Layer API for Python  3.3.0
The ctrlX Data Layer API allows access to the ctrlX Data Layer with Python
provider.py
1 """
2 Class Provider
3 """
4 import ctrlxdatalayer
5 from ctrlxdatalayer.clib_provider import C_DLR_PROVIDER
6 from ctrlxdatalayer.provider_node import ProviderNode
7 from ctrlxdatalayer.variant import Result, Variant
8 
9 
10 class Provider:
11  """
12  Provider interface to manage provider nodes
13  Hint: see python context manager for instance handling
14  """
15 
16  __slots__ = ['__provider', '__closed']
17 
18  def __init__(self, c_provider: C_DLR_PROVIDER):
19  """
20  generate Provider
21  """
22  self.__provider: C_DLR_PROVIDER = c_provider
23  self.__closed__closed = False
24 
25  def __enter__(self):
26  """
27  use the python context manager
28  """
29  return self
30 
31  def __exit__(self, exc_type, exc_val, exc_tb):
32  """
33  use the python context manager
34  """
35  self.closeclose()
36 
37  def close(self):
38  """
39  closes the provider instance
40  """
41  if self.__closed__closed:
42  return
43  self.__closed__closed = True
44  ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerStop(self.__provider)
45  ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerDelete(
46  self.__provider)
47 
48  def register_type(self, address: str, pathname: str) -> Result:
49  """
50  Register a type to the datalayer
51  @param[in] address Address of the node to register (no wildcards allowed)
52  @param[in] pathname Path to flatbuffer bfbs
53  @returns <Result>, status of function call
54  """
55  b_address = address.encode('utf-8')
56  b_pathname = pathname.encode('utf-8')
57  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerRegisterType(self.__provider, b_address, b_pathname))
58 
59  def unregister_type(self, address: str) -> Result:
60  """
61  Unregister a type from the datalayer
62  @param[in] address Address of the node to register (wildcards allowed)
63  @returns <Result>, status of function call
64  """
65  b_address = address.encode('utf-8')
66  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerUnregisterType(self.__provider, b_address))
67 
68  def register_node(self, address: str, node: ProviderNode) -> Result:
69  """
70  Register a node to the datalayer
71  @param[in] address Address of the node to register (wildcards allowed)
72  @param[in] node Node to register
73  @returns <Result>, status of function call
74  """
75  b_address = address.encode('utf-8')
76  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerRegisterNode(self.__provider, b_address, node.get_handle()))
77 
78  def unregister_node(self, address: str) -> Result:
79  """
80  Unregister a node from the datalayer
81  @param[in] address Address of the node to register (wildcards allowed)
82  @returns <Result>, status of function call
83  """
84  b_address = address.encode('utf-8')
85  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerUnregisterNode(self.__provider, b_address))
86 
87  def set_timeout_node(self, node: ProviderNode, timeout_ms: int) -> Result:
88  """
89  Set timeout for a node for asynchron requests (default value is 1000ms)
90  @param[in] node Node to set timeout for
91  @param[in] timeoutMS Timeout in milliseconds for this node
92  @returns <Result>, status of function call
93  """
94  if node is None:
95  return Result.FAILED
96  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerSetTimeoutNode(self.__provider, node.get_handle(), timeout_ms))
97 
98  def start(self) -> Result:
99  """
100  Start the provider
101  @returns <Result>, status of function call
102  """
103  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerStart(self.__provider))
104 
105  def stop(self) -> Result:
106  """
107  Stop the provider
108  @returns <Result>, status of function call
109  """
110  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerStop(self.__provider))
111 
112  def is_connected(self) -> bool:
113  """
114  returns whether provider is connected
115  @returns status of connection
116  """
117  return ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerIsConnected(self.__provider)
118 
119  def get_token(self) -> Variant:
120  """
121  return the current token of the current request.You can call this function during your onRead, onWrite, ... methods of your ProviderNodes. If there is no current request the method return an empty token
122  @returns <Variant> current token
123  """
124  return Variant(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerGetToken(self.__provider))
125 
126  def register_type_variant(self, address: str, data: Variant) -> Result:
127  """
128  Register a type to the datalayer
129  @param[in] address Address of the node to register (no wildcards allowed)
130  @param[in] data Variant with flatbuffer type
131  @returns <Result>, status of function call
132  """
133  b_address = address.encode('utf-8')
134  return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerRegisterTypeVariant(self.__provider, b_address, data.get_handle()))
Variant get_token(self)
return the current token of the current request.You can call this function during your onRead,...
Definition: provider.py:123
Result stop(self)
Stop the provider.
Definition: provider.py:109
Result register_type_variant(self, str address, Variant data)
Register a type to the datalayer.
Definition: provider.py:132
def __exit__(self, exc_type, exc_val, exc_tb)
use the python context manager
Definition: provider.py:34
Result register_type(self, str address, str pathname)
Register a type to the datalayer.
Definition: provider.py:54
def __enter__(self)
use the python context manager
Definition: provider.py:28
Result unregister_node(self, str address)
Unregister a node from the datalayer.
Definition: provider.py:83
Result start(self)
Start the provider.
Definition: provider.py:102
def close(self)
closes the provider instance
Definition: provider.py:40
def __init__(self, C_DLR_PROVIDER c_provider)
generate Provider
Definition: provider.py:21
bool is_connected(self)
returns whether provider is connected
Definition: provider.py:116
Result unregister_type(self, str address)
Unregister a type from the datalayer.
Definition: provider.py:64
Result register_node(self, str address, ProviderNode node)
Register a node to the datalayer.
Definition: provider.py:74
Result set_timeout_node(self, ProviderNode node, int timeout_ms)
Set timeout for a node for asynchron requests (default value is 1000ms)
Definition: provider.py:93
Variant is a container for a many types of data.
Definition: variant.py:150