Python Client  0.0.0.0
Python wrapper for Corelink DLL
corelink_init.py
Go to the documentation of this file.
1 """
2  @file corelink_init.py
3  Copies the initialization from the DLL to wrapper
4 """
5 import ctypes
6 import corelink_const
7 import corelink_exception
8 
9 # pylint: disable=global-statement
10 # global declaration is essential
11 CALLBACK_UPDATE = None
12 CALLBACK_UPDATE_M = None
13 CALLBACK_SETONSTALE = None
14 CALLBACK_SETONSTALE_M = None
15 
16 class DLLInit:
17  """
18  DLLInit
19  """
20  @staticmethod
21  def init():
22  """
23  Initilaize
24  """
25  corelink_const.LIB.DLLInit()
26  corelink_const.LIB.setDroppedCallbackHandler(None)
27  corelink_const.LIB.setStaleCallbackHandler(None)
28  corelink_const.LIB.setSubscribeCallbackHandler(None)
29  corelink_const.LIB.setUpdateCallbackHandler(None)
30 
31  @staticmethod
32  def set_init_state(state):
33  """"
34  Set Initial State
35  """
36  state_c = ctypes.c_int(state)
37  error_id = ctypes.c_int()
38  corelink_const.LIB.setInitState(state_c,ctypes.byref(error_id))
40 
41  @staticmethod
42  def set_server_credentials(username,password):
43  """
44  Set Server Credentials
45  """
46  username_c = username.encode('utf-8')
47  password_c = password.encode('utf-8')
48  corelink_const.LIB.setServerCredentials.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
49  corelink_const.LIB.setServerCredentials(username_c,password_c)
50 
51  @staticmethod
52  def set_on_stale(func):
53  """
54  Set on stale
55  """
56  global CALLBACK_SETONSTALE,CALLBACK_SETONSTALE_M
57  CALLBACK_SETONSTALE_M = func
58  CALLBACK_SETONSTALE = ctypes.CFUNCTYPE(None,
59  ctypes.POINTER(ctypes.c_int))(DLLInit.set_on_stale_temp)
60  corelink_const.LIB.setStaleCallbackHandler(CALLBACK_SETONSTALE)
61 
62  @staticmethod
63  def set_on_stale_temp(send_id):
64  """
65  Helper function for setOn stale
66  """
67  global CALLBACK_SETONSTALE_M
68  CALLBACK_SETONSTALE_M((send_id.contents).value)
69  @staticmethod
70  def set_on_update(func):
71  """
72  Set on Update
73  """
74  global CALLBACK_UPDATE,CALLBACK_UPDATE_M
75  CALLBACK_UPDATE_M = func
76  CALLBACK_UPDATE = ctypes.CFUNCTYPE(None,
77  ctypes.POINTER(ctypes.c_int),
78  ctypes.POINTER(ctypes.c_int))(DLLInit.set_on_update_temp)
79  corelink_const.LIB.setUpdateCallbackHandler(CALLBACK_UPDATE)
80 
81  @staticmethod
82  def set_on_update_temp(recv_id,send_id):
83  """"
84  Set on Update helper function
85  """
86  global CALLBACK_UPDATE_M
87  CALLBACK_UPDATE_M((recv_id.contents).value,(send_id.contents).value)