12 from datalayer.clib_client
import C_DLR_CLIENT, C_DLR_CLIENT_RESPONSE
16 ResponseCallback = typing.Callable[[
17 Result, typing.Optional[Variant], datalayer.clib.userData_c_void_p],
None]
30 self.
_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 datalayer.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: datalayer.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(datalayer.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 datalayer.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.encode(
'utf-8')
168 datalayer.clib.libcomm_datalayer.DLR_clientSetAuthToken(
173 returns persistent security access token for authentication
174 @returns <str> security access token for authentication
176 token = datalayer.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(datalayer.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(datalayer.clib.libcomm_datalayer.DLR_clientCreateSync(
199 self.__client, b_address, data.get_handle(), self.
__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(datalayer.clib.libcomm_datalayer.DLR_clientRemoveSync(
210 self.__client, b_address, self.
__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(datalayer.clib.libcomm_datalayer.DLR_clientBrowseSync(
223 self.__client, b_address, data.get_handle(), self.
__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(datalayer.clib.libcomm_datalayer.DLR_clientReadSync(
248 self.__client, b_address, args.get_handle(), self.
__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(datalayer.clib.libcomm_datalayer.DLR_clientWriteSync(
262 self.__client, b_address, data.get_handle(), self.
__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(datalayer.clib.libcomm_datalayer.DLR_clientMetadataSync(
276 self.__client, b_address, data.get_handle(), self.
__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(datalayer.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(datalayer.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(datalayer.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(datalayer.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
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(datalayer.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(datalayer.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(datalayer.clib.libcomm_datalayer.DLR_clientMetadataASync(self.__client,
405 """ _unregister_sync """
406 if sub
in self.__subs:
407 self.__subs.remove(sub)
410 cnb: datalayer.subscription.ResponseNotifyCallback,
411 userdata: userData_c_void_p =
None):
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: datalayer.subscription.ResponseNotifyCallback,
428 cb: ResponseCallback,
429 userdata: userData_c_void_p =
None):
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()
455 This function reads a values as a JSON string
456 @param[in] converter Reference to the converter (see System json_converter())
457 @param[in] address Address of the node to read
458 @param[in] indentStep Indentation length for json string
459 @returns tuple (Result, Variant)
460 @return <Result>, status of function call,
461 @return <Variant>, Generated JSON as Variant (string)
463 b_address = address.encode(
'utf-8')
465 result =
Result(datalayer.clib.libcomm_datalayer.DLR_clientReadJsonSync(
466 self.__client, conv.get_handle(), b_address, data.get_handle(), indet, self.
__token))
474 This function writes a JSON value
475 @param[in] converter Reference to the converter (see System json_converter())
476 @param[in] address Address of the node to write
477 @param[out] json JSON value to write
478 @param[in,out] error Error of conversion as variant string
479 @return result status of the function
480 @returns tuple (Result, Variant)
481 @return <Result>, status of function call,
482 @return <Variant>, Error of conversion as variant string
484 b_address = address.encode(
'utf-8')
485 b_json = json.encode(
'utf-8')
487 result =
Result(datalayer.clib.libcomm_datalayer.DLR_clientWriteJsonSync(
488 self.__client, conv.get_handle(), b_address, b_json, error.get_handle(), self.
__token))