2 @file corelink_client.py 3 Contains client to server commands. 7 import corelink_exception
8 import corelink_send_stream
9 import corelink_stream_data
10 import corelink_recv_stream
22 check whether it is active 24 corelink_const.LIB.getClientState.restype = ctypes.c_bool
25 ans = corelink_const.LIB.getClientState()
33 error_id_c = ctypes.c_int()
34 server_ip_c = ctypes.create_string_buffer(server_ip.encode(
'utf-8'))
35 port_c = ctypes.c_int(port)
36 corelink_const.LIB.corelinkConnect.argtypes = [ctypes.c_char_p,
38 ctypes.POINTER(ctypes.c_int)]
39 corelink_const.LIB.corelinkConnect(server_ip_c,port_c,ctypes.byref(error_id_c))
45 get_comm_response_data_helper 48 total_len = int.from_bytes(data[0],
"little")
49 int_size = ctypes.sizeof(ctypes.c_int)
51 cur_len = int.from_bytes(data[cur_p],
"little")
52 cur_msg_p = (total_len+1)*int_size
53 for _
in range(total_len):
54 data_parsed.append(data[cur_msg_p:cur_msg_p+cur_len])
55 cur_msg_p = cur_msg_p + cur_len
56 cur_p = cur_p + int_size
57 cur_len = int.from_bytes(data[cur_p],
"little")
65 if not corelink_const.LIB.getClientState():
71 corelink_const.LIB.corelinkCleanup()
76 get comm response data 78 response_len_c = ctypes.c_int()
79 corelink_const.LIB.getCommData.argtypes = [ctypes.POINTER(ctypes.c_int),
80 ctypes.POINTER(ctypes.c_int)]
81 corelink_const.LIB.getCommData.restype = ctypes.POINTER(ctypes.c_char)
82 response_msg = corelink_const.LIB.getCommData(ctypes.byref(comm_id_c),
83 ctypes.byref(response_len_c))
84 return Client.get_comm_response_data_helper(response_msg)
91 data_out = Client.get_comm_response_data(comm_id_c)
92 stream_id = int.from_bytes(data_out[0],
"little")
93 state = int.from_bytes(data_out[1],
"little")
94 mtu = int.from_bytes(data_out[2],
"little")
95 stream_id_c = ctypes.c_int(stream_id)
96 corelink_const.LIB.getStreamRef.argtypes = [ctypes.POINTER(ctypes.c_int)]
97 corelink_const.LIB.getStreamRef.restype = ctypes.c_int
98 stream_ref = corelink_const.LIB.getStreamRef(ctypes.byref(stream_id_c))
112 comm_id_c = ctypes.c_int()
113 error_id_c = ctypes.c_int()
114 workspace_c = ctypes.create_string_buffer(workspace.encode(
'utf-8'))
115 type_c = ctypes.create_string_buffer(types.encode(
'utf-8'))
116 meta_c = ctypes.create_string_buffer(meta.encode(
'utf-8'))
117 echo_c = ctypes.c_bool(
False)
118 alert_c = ctypes.c_bool(
False)
120 echo_c = ctypes.c_bool(
True)
122 alert_c = ctypes.c_bool(
True)
123 protocol_c = ctypes.c_int(protocol)
125 corelink_const.LIB.commAddSender.argtypes = [ctypes.c_char_p,
131 ctypes.POINTER(ctypes.c_int),
132 ctypes.POINTER(ctypes.c_int)]
133 corelink_const.LIB.commAddSender(workspace_c,
139 ctypes.byref(comm_id_c),
140 ctypes.byref(error_id_c))
149 receiver_id = ctypes.c_int(receiver_id)
150 sender_id = ctypes.c_int(sender_id)
151 corelink_const.LIB.commSubscribe.argtypes = [ctypes.POINTER(ctypes.c_int),
152 ctypes.POINTER(ctypes.c_int)]
153 corelink_const.LIB.commSubscribe.restype = ctypes.c_bool
154 output = corelink_const.LIB.commSubscribe(receiver_id,sender_id)
162 receiver_id = ctypes.c_int(receiver_id)
163 sender_id = ctypes.c_int(sender_id)
164 corelink_const.LIB.commUnSubscribe.argtypes = [ctypes.POINTER(ctypes.c_int),
165 ctypes.POINTER(ctypes.c_int)]
166 corelink_const.LIB.commUnSubscribe.restype = ctypes.c_bool
167 output = corelink_const.LIB.commUnSubscribe(receiver_id,sender_id)
175 sender_id = ctypes.c_int(sender_id)
176 corelink_const.LIB.commDisconnect.argtypes = [ctypes.POINTER(ctypes.c_int)]
177 corelink_const.LIB.commDisconnect.restype = ctypes.c_bool
178 output = corelink_const.LIB.commDisconnect(sender_id)
184 vec_string_to_char_array 186 lp_c_char = ctypes.POINTER(ctypes.c_char)
187 lp_lp_c_char = ctypes.POINTER(lp_c_char)
188 types_c = (ctypes.c_char_p * len(types))()
189 for (index,val)
in enumerate(types):
190 types_c[index] = val.encode(
"UTF-8")
191 ans = ctypes.cast(types_c, lp_lp_c_char)
199 comm_id_c = ctypes.c_int()
200 error_id_c = ctypes.c_int()
201 workspace_c = ctypes.create_string_buffer(workspace.encode(
'utf-8'))
202 types_c = Client.vec_string_to_char_array(types)
203 meta_c = ctypes.create_string_buffer(meta.encode(
'utf-8'))
204 echo_c = ctypes.c_bool(
False)
205 alert_c = ctypes.c_bool(
False)
207 echo_c = ctypes.c_bool(
True)
209 alert_c = ctypes.c_bool(
True)
210 protocol_c = ctypes.c_int(protocol)
211 types_size_c = ctypes.c_int(len(types))
212 corelink_const.LIB.commAddReceiver.argtypes = [ctypes.c_char_p,
213 ctypes.POINTER(ctypes.POINTER(ctypes.c_char)),
219 ctypes.POINTER(ctypes.c_int),
220 ctypes.POINTER(ctypes.c_int)]
221 corelink_const.LIB.commAddReceiver(workspace_c,
228 ctypes.byref(comm_id_c),
229 ctypes.byref(error_id_c))
238 error_id_c = ctypes.c_int()
239 corelink_const.LIB.corelinkConnectPlugin.argtypes = [ctypes.POINTER(ctypes.c_int)]
240 corelink_const.LIB.corelinkConnectPlugin(ctypes.byref(error_id_c))
248 corelink_const.LIB.getTokenStr.argtypes = [ctypes.POINTER(ctypes.c_char)]
249 token = ctypes.create_string_buffer(corelink_const.LIB.getTokenLen())
250 corelink_const.LIB.getTokenStr(token)
251 return token.value.decode(
"utf-8")
256 list server functions 258 comm_id_c = ctypes.c_int()
259 error_id_c = ctypes.c_int()
260 corelink_const.LIB.commListFunctions.argtypes = [ctypes.POINTER(ctypes.c_int),
261 ctypes.POINTER(ctypes.c_int)]
262 corelink_const.LIB.commListFunctions(ctypes.byref(comm_id_c), ctypes.byref(error_id_c))
264 temp = Client.get_comm_response_data(comm_id_c)
265 ans = [i.decode(
"utf-8")
for i
in temp]
271 describe server function 273 comm_id_c = ctypes.c_int()
274 error_id_c = ctypes.c_int()
275 function = str(function)
276 corelink_const.LIB.commGetFunctionInfo.argtypes = [ctypes.POINTER(ctypes.c_char),
277 ctypes.POINTER(ctypes.c_int),
278 ctypes.POINTER(ctypes.c_int)]
279 corelink_const.LIB.commGetFunctionInfo(function.encode(
"utf-8"),
280 ctypes.byref(comm_id_c),
281 ctypes.byref(error_id_c))
283 temp = Client.get_comm_response_data(comm_id_c)
284 ans = [i.decode(
"utf-8")
for i
in temp]
292 workspace = str(workspace)
293 corelink_const.LIB.commAddWorkspace.argtypes = [ctypes.POINTER(ctypes.c_char)]
294 corelink_const.LIB.commAddWorkspace(workspace.encode(
"utf-8"))
301 workspace = str(workspace)
302 corelink_const.LIB.commRmWorkspace.argtypes = [ctypes.POINTER(ctypes.c_char)]
303 corelink_const.LIB.commRmWorkspace(workspace.encode(
"utf-8"))
310 comm_id_c = ctypes.c_int()
311 error_id_c = ctypes.c_int()
312 corelink_const.LIB.commListWorkspaces.argtypes = [ctypes.POINTER(ctypes.c_int),
313 ctypes.POINTER(ctypes.c_int)]
314 corelink_const.LIB.commListWorkspaces(ctypes.byref(comm_id_c), ctypes.byref(error_id_c))
316 temp = Client.get_comm_response_data(comm_id_c)
317 ans = [i.decode(
"utf-8")
for i
in temp]
325 stream_id_c = ctypes.c_int(stream_id)
326 comm_id_c = ctypes.c_int()
327 error_id_c = ctypes.c_int()
328 corelink_const.LIB.commGetStreamInfo.argtypes = [ctypes.POINTER(ctypes.c_int),
329 ctypes.POINTER(ctypes.c_int),
330 ctypes.POINTER(ctypes.c_int)]
331 corelink_const.LIB.commGetStreamInfo(ctypes.byref(stream_id_c),
332 ctypes.byref(comm_id_c),
333 ctypes.byref(error_id_c))
335 temp = Client.get_data_stream_info(comm_id_c)
def stream_info(stream_id)
def get_data_stream_info(comm_id_c)
def is_receiver(stream_id)
def add_workspace(workspace)
def vec_string_to_char_array(types)
def create_receiver(workspace, types, meta, echo, alert, protocol)
def subscribe(receiver_id, sender_id)
def describe_server_function(function)
def get_receiver_handler(stream_id)
def create_sender(workspace, types, meta, echo, alert, protocol)
def get_dll_exception(error_id_ctypes)
def list_server_functions()
def get_comm_response_data_helper(data)
def un_subscribe(receiver_id, sender_id)
def connect(server_ip, port)
def list_client_streams()
def rm_workspace(workspace)
def get_comm_response_data(comm_id_c)