2 @file corelink_recv_stream.py 3 Handler class for the receiver streams. 4 A container for the stream id and necessary data to call associated functions. 8 import corelink_stream_data
13 RECV_CALLBACK_TYPE = ctypes.CFUNCTYPE(
None,(ctypes.c_int),
14 (ctypes.c_int),ctypes.
15 POINTER(ctypes.c_char),
19 CALLBACK_TYPE = ctypes.CFUNCTYPE(
None,(ctypes.c_int),(ctypes.c_int),ctypes.c_wchar_p)
21 RECV_CALLBACK_JSON_TYPE = ctypes.CFUNCTYPE(
None,(ctypes.c_int),
23 ctypes.POINTER(ctypes.c_char),
27 CALLBACK_JSON_TYPE = ctypes.CFUNCTYPE(
None,(ctypes.c_int),
35 Recv callback for Json 39 global CALLBACK_JSON_TYPE
40 callback = ctypes.cast(callback, CALLBACK_JSON_TYPE)
41 json_data = msg[:json_len].decode(
"utf-8")
42 msg_data= msg[json_len:json_len+msg_len].decode(
"utf-8")
43 callback(recv_id, send_id, msg_data,json_data)
52 msg_data= msg[json_len:json_len+msg_len].decode(
"utf-8")
53 callback = ctypes.cast(callback, CALLBACK_TYPE)
54 callback(recv_id, send_id, msg_data)
62 self.
update(arg[0],arg[1],arg[2])
66 if(stream_data.state & corelink_const.STATE_CODES[
'STREAM_STATE_RECV']) >0:
67 self.
update(stream_data.stream_id,stream_data.state,stream_data.stream_ref)
69 self.
update(-1,corelink_const.STATE_CODES[
'STREAM_STATE_NONE'],-1)
70 if isinstance(arg[0],RecvStream):
72 self.
update(rhs.stream_id,rhs.state,rhs.stream_ref)
76 def update(self,stream_id,state,stream_ref):
90 corelink_const.LIB.setOnRecv.restype = ctypes.c_void_p
91 _ = corelink_const.LIB.setOnRecv((ctypes.c_int(self.
state)),
93 ctypes.byref(ctypes.c_int(self.
stream_id)),
None,
None)
97 set on receive message 99 global RECV_CALLBACK_TYPE,CALLBACK_TYPE
102 self.
callback = ctypes.cast(callback,ctypes.c_void_p)
103 corelink_const.LIB.setOnRecv.restype = ctypes.c_void_p
104 _ = corelink_const.LIB.setOnRecv((ctypes.c_int(self.
state)),
106 ctypes.byref(ctypes.c_int(self.
stream_id)),
111 set on receive msg json 113 global RECV_CALLBACK_JSON_TYPE,CALLBACK_JSON_TYPE
116 self.
callback = ctypes.cast(callback,ctypes.c_void_p)
117 corelink_const.LIB.setOnRecv.restype = ctypes.c_void_p
118 _ = corelink_const.LIB.setOnRecv((ctypes.c_int(self.
state)),
120 ctypes.byref(ctypes.c_int(self.
stream_id)),
128 corelink_const.LIB.getStreamState.argtypes = [ctypes.POINTER(ctypes.c_int)]
129 corelink_const.LIB.getStreamState.restype = ctypes.c_int
130 state = corelink_const.LIB.getStreamState(ctypes.byref(ctypes.c_int(stream_id)))
132 corelink_const.LIB.getStreamRef.argtypes = [ctypes.POINTER(ctypes.c_int)]
133 corelink_const.LIB.getStreamRef.restype = ctypes.c_int
134 ref = corelink_const.LIB.getStreamRef(ctypes.byref(ctypes.c_int(stream_id)))
135 if(ref <0
or (state & corelink_const.STATE_CODES[
'STREAM_STATE_RECV'])==0 ):
def recv_callback_json(recv_id, send_id, msg, json_len, msg_len, callback)
def recv_callback(recv_id, send_id, msg, json_len, msg_len, callback)
def get_receiver_handler(stream_id)
def update(self, stream_id, state, stream_ref)
def set_on_receive_msg_json(self, func)
def set_on_receive_msg(self, func)