2 Class Sync Subscription
12 from ctrlxdatalayer.clib_client
import (C_DLR_CLIENT_NOTIFY_RESPONSE,
21 __slots__ = [
'__ptr_notify',
'__closed',
'__client',
'__id',
'__mock']
25 @param [in] client Reference to the client
29 self.
__client__client = weakref.ref(client)
35 use the python context manager
39 def __exit__(self, exc_type, exc_val, exc_tb):
41 use the python context manager
59 def __create_sub_callback(self, cb: ctrlxdatalayer.subscription.ResponseNotifyCallback):
66 def _cb(status: ctrlxdatalayer.clib.C_DLR_RESULT, items: ctypes.POINTER(C_NotifyItem),
67 count: ctypes.c_uint32, userdata: ctypes.c_void_p):
69 datalayer calls this function
74 for x
in range(0, count):
76 items[x].data, items[x].info)
77 if not self.
__mock__mock
and len(n.get_address()) == 0:
79 notify_items.append(n)
80 cb(r, notify_items, userdata)
85 cb_ptr.set_ptr(C_DLR_CLIENT_NOTIFY_RESPONSE(_cb))
86 return cb_ptr.get_ptr()
88 def _test_notify_callback(self, cb: ctrlxdatalayer.subscription.ResponseNotifyCallback):
97 closes the client instance
106 def _create(self, prop: Variant, cnb: ctrlxdatalayer.subscription.ResponseNotifyCallback,
107 userdata: userData_c_void_p =
None) -> Result:
109 Set up a subscription
110 @param[in] ruleset Variant that describe ruleset of subscription as subscription.fbs
111 @param[in] publishCallback Callback to call when new data is available
112 @param[in] userdata User data - will be returned in publishCallback as userdata. You can use this userdata to identify your subscription
113 @result <Result> status of function cal
115 r =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientCreateSubscriptionSync(
116 self.
__client__client().get_handle(), prop.get_handle(),
122 def subscribe(self, address: str) -> Result:
124 Adds a node to a subscription id
125 @param[in] address Address of a node, that should be added to the given subscription.
126 @result <Result> status of function call
128 b_id = self.
ididid().encode(
'utf-8')
129 b_address = address.encode(
'utf-8')
130 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientSubscribeSync(
131 self.
__client__client().get_handle(), b_id, b_address))
135 Removes a node from a subscription id
136 @param[in] address Address of a node, that should be removed to the given subscription.
137 @result <Result> status of function call
139 b_id = self.
ididid().encode(
'utf-8')
140 b_address = address.encode(
'utf-8')
141 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientUnsubscribeSync(
142 self.
__client__client().get_handle(), b_id, b_address))
146 Adds a list of nodes to a subscription id
147 @param[in] address List of Addresses of a node, that should be added to the given subscription.
148 @param[in] count Count of addresses.
149 @result <Result> status of function call
151 b_id = self.
ididid().encode(
'utf-8')
152 b_address = (ctypes.c_char_p * len(address))(*
153 [d.encode(
'utf-8')
for d
in address])
154 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientSubscribeMultiSync(
155 self.
__client__client().get_handle(), b_id, b_address, len(address)))
159 Removes a set of nodes from a subscription id
160 @param[in] address Set of addresses of nodes, that should be removed to the given subscription.
161 @result <Result> status of function call
163 b_id = self.
ididid().encode(
'utf-8')
164 b_address = (ctypes.c_char_p * len(address))(*
165 [d.encode(
'utf-8')
for d
in address])
166 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientUnsubscribeMultiSync(
167 self.
__client__client().get_handle(), b_id, b_address, len(address)))
171 Removes subscription id completely
172 @result <Result> status of function call
176 self.
__client__client()._unregister_sync(self)
177 b_id = self.
ididid().encode(
'utf-8')
178 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientUnsubscribeAllSync(
179 self.
__client__client().get_handle(), b_id))
Client interface for accessing data from the system.
str id(self)
Subscription ID.
Result unsubscribe(self, str address)
Removes a node from a subscription id.
def __exit__(self, exc_type, exc_val, exc_tb)
use the python context manager
Result unsubscribe_all(self)
Removes subscription id completely.
str id(self)
Subscription ID.
def __enter__(self)
use the python context manager
Result unsubscribe_multi(self, typing.List[str] address)
Removes a set of nodes from a subscription id.
def on_close(self)
on_close
Result subscribe_multi(self, typing.List[str] address)
Adds a list of nodes to a subscription id.
def __init__(self, ctrlxdatalayer.client.Client client)
def close(self)
closes the client instance
def __create_sub_callback(self, ctrlxdatalayer.subscription.ResponseNotifyCallback cb)
Result subscribe(self, str address)
Adds a node to a subscription id.