9 from ctrlxdatalayer.clib_provider_node
import (
10 C_DLR_PROVIDER_NODE_CALLBACK, C_DLR_PROVIDER_NODE_CALLBACKDATA,
11 C_DLR_PROVIDER_NODE_CALLBACKS, C_DLR_PROVIDER_NODE_FUNCTION,
12 C_DLR_PROVIDER_NODE_FUNCTION_DATA, C_DLR_PROVIDER_SUBSCRIPTION_FUNCTION,
13 C_DLR_SUBSCRIPTION, C_DLR_VARIANT, address_c_char_p, userData_c_void_p)
17 NodeCallback = typing.Callable[[Result, typing.Optional[Variant]],
None]
18 NodeFunction = typing.Callable[[userData_c_void_p, str, NodeCallback],
None]
19 NodeFunctionData = typing.Callable[[
20 userData_c_void_p, str, Variant, NodeCallback],
None]
21 NodeFunctionSubscription = typing.Callable[[
22 userData_c_void_p, ProviderSubscription, str],
None]
35 self.
_ptr_ptr: typing.Optional[ctypes._CFuncPtr] =
None
52 Provider Node callbacks interface
54 __slots__ = [
'on_create',
'on_remove',
'on_browse',
55 'on_read',
'on_write',
'on_metadata',
56 'on_subscribe',
'on_unsubscribe']
59 on_create: NodeFunctionData,
60 on_remove: NodeFunction,
61 on_browse: NodeFunction,
62 on_read: NodeFunctionData,
63 on_write: NodeFunctionData,
64 on_metadata: NodeFunction,
65 on_subscribe: NodeFunctionSubscription =
None,
66 on_unsubscribe: NodeFunctionSubscription =
None):
68 init ProviderNodeCallbacks
82 Provider node interface for providing data to the system
84 Hint: see python context manager for instance handling
86 __slots__ = [
'__ptrs',
'__c_cbs',
'__closed',
'__provider_node']
88 def __init__(self, cbs: ProviderNodeCallbacks, userdata: userData_c_void_p =
None):
92 self.__ptrs: typing.List[_CallbackPtr] = []
93 if cbs.on_subscribe
is None:
94 self.
__c_cbs__c_cbs = C_DLR_PROVIDER_NODE_CALLBACKS(
104 self.
__c_cbs__c_cbs = C_DLR_PROVIDER_NODE_CALLBACKS(
117 self.
__provider_node__provider_node = ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerNodeCreate(
122 use the python context manager
126 def __exit__(self, exc_type, exc_val, exc_tb):
128 use the python context manager
140 closes the node instance
145 ctrlxdatalayer.clib.libcomm_datalayer.DLR_providerNodeDelete(
152 handle value of ProviderNode
156 def __create_callback(self,
157 c_cb: C_DLR_PROVIDER_NODE_CALLBACK,
158 c_cbdata: C_DLR_PROVIDER_NODE_CALLBACKDATA) -> NodeCallback:
162 def cb(result: Result, data: typing.Optional[Variant]):
165 c_cb(c_cbdata, result.value,
None)
167 c_cb(c_cbdata, result.value, data.get_handle())
170 def __create_function(self, func: NodeFunction):
172 create callback management
175 self.__ptrs.append(cb_ptr)
177 def _func(c_userdata: userData_c_void_p,
178 c_address: address_c_char_p,
179 c_cb: C_DLR_PROVIDER_NODE_CALLBACK,
180 c_cbdata: C_DLR_PROVIDER_NODE_CALLBACKDATA) -> C_DLR_RESULT:
182 datalayer calls this function
184 address = c_address.decode(
'utf-8')
186 func(c_userdata, address, cb)
187 return Result.OK.value
188 cb_ptr.set_ptr(C_DLR_PROVIDER_NODE_FUNCTION(_func))
189 return cb_ptr.get_ptr()
191 def __create_function_data(self, func: NodeFunctionData):
193 create callback management
196 self.__ptrs.append(cb_ptr)
198 def _func(c_userdata: userData_c_void_p,
199 c_address: address_c_char_p,
200 c_data: C_DLR_VARIANT,
201 c_cb: C_DLR_PROVIDER_NODE_CALLBACK,
202 c_cbdata: C_DLR_PROVIDER_NODE_CALLBACKDATA) -> C_DLR_RESULT:
204 datalayer calls this function
206 address = c_address.decode(
'utf-8')
209 func(c_userdata, address, data, cb)
210 return Result.OK.value
211 cb_ptr.set_ptr(C_DLR_PROVIDER_NODE_FUNCTION_DATA(_func))
212 return cb_ptr.get_ptr()
214 def __create_function_subscribe(self, func: NodeFunctionSubscription):
216 create callback managment
219 self.__ptrs.append(cb_ptr)
221 def _func(c_userdata: userData_c_void_p,
222 c_subscribe: C_DLR_SUBSCRIPTION,
223 c_address: address_c_char_p) -> C_DLR_RESULT:
225 datalayer calls this function
227 if c_address
is None:
228 return Result.OK.value
230 return Result.OK.value
231 address = c_address.decode(
'utf-8')
233 func(c_userdata, sub, address)
234 return Result.OK.value
235 cb_ptr.set_ptr(C_DLR_PROVIDER_SUBSCRIPTION_FUNCTION(_func))
236 return cb_ptr.get_ptr()
238 def _test_function(self, func: NodeFunction):
244 def _test_function_data(self, func: NodeFunctionData):
Provider Node callbacks interface.
def __init__(self, NodeFunctionData on_create, NodeFunction on_remove, NodeFunction on_browse, NodeFunctionData on_read, NodeFunctionData on_write, NodeFunction on_metadata, NodeFunctionSubscription on_subscribe=None, NodeFunctionSubscription on_unsubscribe=None)
init ProviderNodeCallbacks
Provider node interface for providing data to the system.
def __exit__(self, exc_type, exc_val, exc_tb)
use the python context manager
def __create_function_subscribe(self, NodeFunctionSubscription func)
def __enter__(self)
use the python context manager
def __create_function_data(self, NodeFunctionData func)
def close(self)
closes the node instance
def get_handle(self)
handle value of ProviderNode
def __create_function(self, NodeFunction func)
NodeCallback __create_callback(self, C_DLR_PROVIDER_NODE_CALLBACK c_cb, C_DLR_PROVIDER_NODE_CALLBACKDATA c_cbdata)
def __init__(self, ProviderNodeCallbacks cbs, userData_c_void_p userdata=None)
init ProviderNode
def set_ptr(self, ptr)
setter _CallbackPtr
def get_ptr(self)
getter _CallbackPtr
def __init__(self)
init _CallbackPtr
ProviderSubscription helper class.