12 from ctrlxdatalayer.clib_client
import C_DLR_CLIENT, C_DLR_CLIENT_RESPONSE
16 ResponseCallback = typing.Callable[[
17 Result, typing.Optional[Variant], ctrlxdatalayer.clib.userData_c_void_p],
None]
30 self.
_ptr_ptr: typing.Optional[ctypes._CFuncPtr] =
None
47 Settings of different timeout values
56 Client interface for accessing data from the system
58 Hint: see python context manager for instance handling
63 def __init__(self, c_client: C_DLR_CLIENT):
65 @param[in] client Reference to the client
68 self.__client: C_DLR_CLIENT = c_client
70 self.__ptrs: typing.List[_CallbackPtr] = []
76 use the python context manager
80 def __exit__(self, exc_type, exc_val, exc_tb):
82 use the python context manager
88 closes the client instance
96 ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientDelete(self.__client)
104 handle value of Client
114 def __create_callback(self, cb: ResponseCallback):
119 self.__ptrs.append(cb_ptr)
121 def _cb(c_result: ctrlxdatalayer.clib.C_DLR_RESULT,
122 c_data: ctypes.c_void_p, c_userdata: ctypes.c_void_p):
124 datalayer calls this function
127 cb(
Result(c_result),
None, c_userdata)
130 cb(
Result(c_result), data, c_userdata)
132 self.__ptrs.remove(cb_ptr)
134 cb_ptr.set_ptr(C_DLR_CLIENT_RESPONSE(_cb))
135 return cb_ptr.get_ptr()
137 def _test_callback(self, cb: ResponseCallback):
143 def set_timeout(self, timeout: TimeoutSetting, value: int) -> Result:
145 Set client timeout value
146 @param[in] timeout Timeout to set (see DLR_TIMEOUT_SETTING)
147 @param[in] value Value to set
148 @returns <Result>, status of function call
150 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientSetTimeout(
151 self.__client, timeout.value, value))
155 returns whether provider is connected
156 @returns <bool> status of connection
158 return ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientIsConnected(self.__client)
162 Set persistent security access token for authentication as JWT payload
163 @param[in] token Security access &token for authentication
166 raise TypeError(
'token is invalid')
167 self.
__token__token = token.encode(
'utf-8')
168 ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientSetAuthToken(
169 self.__client, self.
__token__token)
173 returns persistent security access token for authentication
174 @returns <str> security access token for authentication
176 token = ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientGetAuthToken(
179 return token.decode(
'utf-8')
183 Ping the next hop. This function is synchronous: It will wait for the answer.
184 @returns <Result> status of function call
186 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientPingSync(self.__client))
188 def create_sync(self, address: str, data: Variant):
190 Create an object. This function is synchronous: It will wait for the answer.
191 @param[in] address Address of the node to create object in
192 @param[in] variant Data of the object
193 @returns tuple (Result, Variant)
194 @return <Result>, status of function call
195 @return <Variant>, variant result of write
197 b_address = address.encode(
'utf-8')
198 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientCreateSync(
199 self.__client, b_address, data.get_handle(), self.
__token__token))
204 Remove an object. This function is synchronous: It will wait for the answer.
205 @param[in] address Address of the node to remove
206 @returns <Result> status of function call
208 b_address = address.encode(
'utf-8')
209 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientRemoveSync(
210 self.__client, b_address, self.
__token__token))
214 Browse an object. This function is synchronous: It will wait for the answer.
215 @param[in] address Address of the node to browse
216 @returns tuple (Result, Variant)
217 @return <Result>, status of function call,
218 @return <Variant>, Children of the node. Data will be provided as Variant array of strings.
220 b_address = address.encode(
'utf-8')
222 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientBrowseSync(
223 self.__client, b_address, data.get_handle(), self.
__token__token))
228 Read an object. This function is synchronous: It will wait for the answer.
229 @param[in] address Address of the node to read
230 @returns tuple (Result, Variant)
231 @return <Result>, status of function call,
232 @return <Variant>, Data of the node
239 Read an object. This function is synchronous: It will wait for the answer.
240 @param[in] address Address of the node to read
241 @param[in,out] args Read arguments data of the node
242 @returns tuple (Result, Variant)
243 @return <Result>, status of function call,
244 @return <Variant>, Data of the node
246 b_address = address.encode(
'utf-8')
247 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientReadSync(
248 self.__client, b_address, args.get_handle(), self.
__token__token))
251 def write_sync(self, address: str, data: Variant):
253 Write an object. This function is synchronous: It will wait for the answer.
254 @param[in] address Address of the node to write
255 @param[in] variant New data of the node
256 @returns tuple (Result, Variant)
257 @return <Result>, status of function call,
258 @return <Variant>, result of write
260 b_address = address.encode(
'utf-8')
261 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientWriteSync(
262 self.__client, b_address, data.get_handle(), self.
__token__token))
267 Read metadata of an object. This function is synchronous: It will wait for the answer.
268 @param[in] address Address of the node to read metadata of
269 @returns tuple (Result, Variant)
270 @return <Result>, status of function call,
271 @return <Variant>, Metadata of the node. Data will be provided as Variant flatbuffers with metadata.fbs data type.
273 b_address = address.encode(
'utf-8')
275 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientMetadataSync(
276 self.__client, b_address, data.get_handle(), self.
__token__token))
279 def ping_async(self, cb: ResponseCallback, userdata: userData_c_void_p =
None) -> Result:
281 Ping the next hop. This function is asynchronous. It will return immediately. Callback will be called if function call is finished.
282 @param[in] callback Callback to call when function is finished
283 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
284 @returns <Result> status of function call
286 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientPingASync(
290 cb: ResponseCallback, userdata: userData_c_void_p =
None) -> Result:
292 Create an object. This function is asynchronous. It will return immediately. Callback will be called if function call is finished. Result data may be provided in callback function.
293 @param[in] address Address of the node to create object in
294 @param[in] data Data of the object
295 @param[in] callback Callback to call when function is finished
296 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
297 @returns <Result> status of function call
299 b_address = address.encode(
'utf-8')
300 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientCreateASync(
301 self.__client, b_address, data.get_handle(),
305 cb: ResponseCallback,
306 userdata: userData_c_void_p =
None) -> Result:
308 Remove an object. This function is asynchronous. It will return immediately. Callback will be called if function call is finished. Result data may be provided in callback function.
309 @param[in] address Address of the node to remove
310 @param[in] callback Callback to call when function is finished
311 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
312 @returns <Result> status of function call
314 b_address = address.encode(
'utf-8')
315 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientRemoveASync(self.__client,
323 cb: ResponseCallback,
324 userdata: userData_c_void_p =
None) -> Result:
326 Browse an object. This function is asynchronous. It will return immediately. Callback will be called if function call is finished. Result data may be provided in callback function.
327 @param[in] address Address of the node to browse
328 @param[in] callback Callback to call when function is finished
329 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
330 @returns <Result> status of function call
332 b_address = address.encode(
'utf-8')
333 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientBrowseASync(
337 cb: ResponseCallback, userdata: userData_c_void_p =
None) -> Result:
339 Read an object. This function is asynchronous. It will return immediately. Callback will be called if function call is finished. Result data may be provided in callback function.
340 @param[in] address Address of the node to read
341 @param[in] callback Callback to call when function is finished
342 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
343 @returns <Result>, status of function call
346 return self.
read_async_argsread_async_args(address, args, cb, userdata)
349 cb: ResponseCallback, userdata: userData_c_void_p =
None) -> Result:
351 Read an object. This function is asynchronous. It will return immediately. Callback will be called if function call is finished. Result data may be provided in callback function.
352 @param[in] address Address of the node to read
353 @param[in] args Read arguments data of the node
354 @param[in] callback Callback to call when function is finished
355 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
356 @returns <Result>, status of function call
358 b_address = address.encode(
'utf-8')
359 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientReadASync(self.__client,
368 data: Variant, cb: ResponseCallback,
369 userdata: userData_c_void_p =
None) -> Result:
371 Write an object. This function is synchronous: It will wait for the answer.
372 @param[in] address Address of the node to read metadata
373 @param[in] data Data of the object
374 @param[in] callback Callback to call when function is finished
375 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
376 @returns <Result>, status of function call
378 b_address = address.encode(
'utf-8')
379 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientWriteASync(self.__client,
388 cb: ResponseCallback, userdata: userData_c_void_p =
None) -> Result:
390 Read metadata of an object. This function is asynchronous. It will return immediately. Callback will be called if function call is finished. Result data may be provided in callback function.
391 @param[in] address Address of the node to read metadata
392 @param[in] callback Callback to call when function is finished
393 @param[in] userdata User data - will be returned in callback as userdata. You can use this userdata to identify your request
394 @returns <Result>, status of function call
396 b_address = address.encode(
'utf-8')
397 return Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientMetadataASync(self.__client,
405 """ _unregister_sync """
406 if sub
in self.__subs:
407 self.__subs.remove(sub)
410 cnb: ctrlxdatalayer.subscription.ResponseNotifyCallback,
411 userdata: userData_c_void_p =
None):
413 Set up a subscription
414 @param[in] ruleset Variant that describe ruleset of subscription as subscription.fbs
415 @param[in] publishCallback Callback to call when new data is available
416 @param[in] userdata User data - will be returned in publishCallback as userdata. You can use this userdata to identify your subscription
417 @result <Result>, status of function cal
420 r = sub._create(prop, cnb, userdata)
422 self.__subs.append(sub)
427 cnb: ctrlxdatalayer.subscription.ResponseNotifyCallback,
428 cb: ResponseCallback,
429 userdata: userData_c_void_p =
None):
431 Set up a subscription
432 @param[in] ruleset Variant that describe ruleset of subscription as subscription.fbs
433 @param[in] publishCallback Callback to call when new data is available
434 @param[in] userdata User data - will be returned in publishCallback as userdata. You can use this userdata to identify your subscription
435 @result <Result>, status of function cal
438 r = sub._create(prop, cnb, cb, userdata)
440 self.__subs.append(sub)
443 def __close_all_subs(self):
444 """ __close_all_subs """
445 subs = self.__subs.copy()
454 data: Variant =
None):
456 This function reads a values as a JSON string
457 @param[in] converter Reference to the converter (see System json_converter())
458 @param[in] address Address of the node to read
459 @param[in] indentStep Indentation length for json string
460 @param[in] json Generated JSON as Variant (string)
461 @returns tuple (Result, Variant)
462 @return <Result>, status of function call,
463 @return <Variant>, Generated JSON as Variant (string)
465 b_address = address.encode(
'utf-8')
469 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientReadJsonSync(
470 self.__client, conv.get_handle(), b_address, data.get_handle(), indent, self.
__token__token))
478 This function writes a JSON value
479 @param[in] converter Reference to the converter (see System json_converter())
480 @param[in] address Address of the node to write
481 @param[in] json JSON value to write
482 @param[in,out] error Error of conversion as variant string
483 @return result status of the function
484 @returns tuple (Result, Variant)
485 @return <Result>, status of function call,
486 @return <Variant>, Error of conversion as variant string
488 b_address = address.encode(
'utf-8')
489 b_json = json.encode(
'utf-8')
491 result =
Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_clientWriteJsonSync(
492 self.__client, conv.get_handle(), b_address, b_json, error.get_handle(), self.
__token__token))
Client interface for accessing data from the system.
Result read_async_args(self, str address, Variant args, ResponseCallback cb, userData_c_void_p userdata=None)
Read an object.
def read_sync_args(self, str address, Variant args)
Read an object.
def __exit__(self, exc_type, exc_val, exc_tb)
use the python context manager
Result create_async(self, str address, Variant data, ResponseCallback cb, userData_c_void_p userdata=None)
Create an object.
Result browse_async(self, str address, ResponseCallback cb, userData_c_void_p userdata=None)
Browse an object.
def __close_all_subs(self)
def __enter__(self)
use the python context manager
Result remove_async(self, str address, ResponseCallback cb, userData_c_void_p userdata=None)
Remove an object.
Result set_timeout(self, TimeoutSetting timeout, int value)
Set client timeout value.
def get_token(self)
internal token
def __init__(self, C_DLR_CLIENT c_client)
def create_sync(self, str address, Variant data)
Create an object.
def create_subscription_async(self, Variant prop, ctrlxdatalayer.subscription.ResponseNotifyCallback cnb, ResponseCallback cb, userData_c_void_p userdata=None)
Set up a subscription.
Result ping_async(self, ResponseCallback cb, userData_c_void_p userdata=None)
Ping the next hop.
def read_sync(self, str address)
Read an object.
def close(self)
closes the client instance
def write_sync(self, str address, Variant data)
Write an object.
Result ping_sync(self)
Ping the next hop.
def get_handle(self)
handle value of Client
def read_json_sync(self, Converter conv, str address, int indent, Variant data=None)
This function reads a values as a JSON string.
def create_bulk(self)
Setup a bulk object.
str get_auth_token(self)
returns persistent security access token for authentication
def set_auth_token(self, str token)
Set persistent security access token for authentication as JWT payload.
bool is_connected(self)
returns whether provider is connected
def write_json_sync(self, Converter conv, str address, str json)
This function writes a JSON value.
Result metadata_async(self, str address, ResponseCallback cb, userData_c_void_p userdata=None)
Read metadata of an object.
def metadata_sync(self, str address)
Read metadata of an object.
Result write_async(self, str address, Variant data, ResponseCallback cb, userData_c_void_p userdata=None)
Write an object.
def create_subscription_sync(self, Variant prop, ctrlxdatalayer.subscription.ResponseNotifyCallback cnb, userData_c_void_p userdata=None)
Set up a subscription.
def __create_callback(self, ResponseCallback cb)
Result read_async(self, str address, ResponseCallback cb, userData_c_void_p userdata=None)
Read an object.
Result remove_sync(self, str address)
Remove an object.
def browse_sync(self, str address)
Browse an object.
Settings of different timeout values.
def set_ptr(self, ptr)
setter CallbackPtr
def get_ptr(self)
getter CallbackPtr
def __init__(self)
init _CallbackPtr
Variant is a container for a many types of data.