2 Class Sync Subscription
12 from datalayer.clib_client
import C_DLR_CLIENT_NOTIFY_RESPONSE, C_NotifyItem
20 __slots__ = [
'__ptr_notify',
'__closed',
'__client',
'__id']
24 @param [in] client Reference to the client
33 use the python context manager
37 def __exit__(self, exc_type, exc_val, exc_tb):
39 use the python context manager
57 def __create_sub_callback(self, cb: datalayer.subscription.ResponseNotifyCallback):
64 def _cb(status: datalayer.clib.C_DLR_RESULT, items: ctypes.POINTER(C_NotifyItem),
65 count: ctypes.c_uint32, userdata: ctypes.c_void_p):
67 datalayer calls this function
72 for x
in range(0, count):
74 items[x].data, items[x].info)
75 notify_items.append(n)
76 cb(r, notify_items, userdata)
81 cb_ptr.set_ptr(C_DLR_CLIENT_NOTIFY_RESPONSE(_cb))
82 return cb_ptr.get_ptr()
84 def _test_notify_callback(self, cb: datalayer.subscription.ResponseNotifyCallback):
92 closes the client instance
101 def _create(self, prop: Variant, cnb: datalayer.subscription.ResponseNotifyCallback,
102 userdata: userData_c_void_p =
None) -> Result:
105 @param[in] ruleset Variant that describe ruleset of subscription as subscription.fbs
106 @param[in] publishCallback Callback to call when new data is available
107 @param[in] userdata User data - will be returned in publishCallback as userdata. You can use this userdata to identify your subscription
108 @result <Result> status of function cal
110 r =
Result(datalayer.clib.libcomm_datalayer.DLR_clientCreateSubscriptionSync(
111 self.
__client().get_handle(), prop.get_handle(),
117 def subscribe(self, address: str) -> Result:
119 Adds a node to a subscription id
120 @param[in] address Address of a node, that should be added to the given subscription.
121 @result <Result> status of function call
123 b_id = self.
id().encode(
'utf-8')
124 b_address = address.encode(
'utf-8')
125 return Result(datalayer.clib.libcomm_datalayer.DLR_clientSubscribeSync(
126 self.
__client().get_handle(), b_id, b_address))
130 Removes a node from a subscription id
131 @param[in] address Address of a node, that should be removed to the given subscription.
132 @result <Result> status of function call
134 b_id = self.
id().encode(
'utf-8')
135 b_address = address.encode(
'utf-8')
136 return Result(datalayer.clib.libcomm_datalayer.DLR_clientUnsubscribeSync(
137 self.
__client().get_handle(), b_id, b_address))
141 Adds a list of nodes to a subscription id
142 @param[in] address List of Addresses of a node, that should be added to the given subscription.
143 @param[in] count Count of addresses.
144 @result <Result> status of function call
146 b_id = self.
id().encode(
'utf-8')
147 b_address = (ctypes.c_char_p * len(address))(*
148 [d.encode(
'utf-8')
for d
in address])
149 return Result(datalayer.clib.libcomm_datalayer.DLR_clientSubscribeMultiSync(
150 self.
__client().get_handle(), b_id, b_address, len(address)))
154 Removes a set of nodes from a subscription id
155 @param[in] address Set of addresses of nodes, that should be removed to the given subscription.
156 @result <Result> status of function call
158 b_id = self.
id().encode(
'utf-8')
159 b_address = (ctypes.c_char_p * len(address))(*
160 [d.encode(
'utf-8')
for d
in address])
161 return Result(datalayer.clib.libcomm_datalayer.DLR_clientUnsubscribeMultiSync(
162 self.
__client().get_handle(), b_id, b_address, len(address)))
166 Removes subscription id completely
167 @result <Result> status of function call
171 self.
__client()._unregister_sync(self)
172 b_id = self.
id().encode(
'utf-8')
173 return Result(datalayer.clib.libcomm_datalayer.DLR_clientUnsubscribeAllSync(
174 self.
__client().get_handle(), b_id))