|
@@ -77,12 +77,12 @@ class callback_storage(dict):
|
77
|
77
|
pass # nothing to append
|
78
|
78
|
return None
|
79
|
79
|
|
80
|
|
- def add(self, service_id, data_id, callback):
|
|
80
|
+ def add(self, service_id, data_id, callback, *args, **kwargs):
|
81
|
81
|
if self.get(service_id, data_id) is not None:
|
82
|
82
|
raise RegistrationError("Callback for service_id (%s) and data_id (%s) already exists" % (repr(service_id), repr(data_id)))
|
83
|
83
|
if service_id not in self:
|
84
|
84
|
self[service_id] = {}
|
85
|
|
- self[service_id][data_id] = callback
|
|
85
|
+ self[service_id][data_id] = (callback, args, kwargs)
|
86
|
86
|
|
87
|
87
|
|
88
|
88
|
class data_storage(dict):
|
|
@@ -261,7 +261,7 @@ class struct_json_protocol(object):
|
261
|
261
|
repr(msg.get_data_id()),
|
262
|
262
|
repr(msg.get_data())
|
263
|
263
|
)
|
264
|
|
- callback = self.__callbacks__.get(msg.get_service_id(), msg.get_data_id())
|
|
264
|
+ callback, args, kwargs = self.__callbacks__.get(msg.get_service_id(), msg.get_data_id())
|
265
|
265
|
if msg.get_service_id() in self.SID_RESPONSE_DICT.keys():
|
266
|
266
|
#
|
267
|
267
|
# REQUEST RECEIVED
|
|
@@ -277,7 +277,7 @@ class struct_json_protocol(object):
|
277
|
277
|
else:
|
278
|
278
|
try:
|
279
|
279
|
logger.debug("%s Executing callback %s to process received data", self.LOG_PREFIX, callback.__name__)
|
280
|
|
- status, data = callback(msg)
|
|
280
|
+ status, data = callback(msg, *args, **kwargs)
|
281
|
281
|
except TypeError:
|
282
|
282
|
raise TypeError('Check return value of callback function {callback_name} for service_id {service_id} and data_id {data_id}'.format(callback_name=callback.__name__, service_id=repr(msg.get_service_id()), data_id=repr(msg.get_data_id())))
|
283
|
283
|
self.send(self.SID_RESPONSE_DICT[msg.get_service_id()], msg.get_data_id(), data, status=status)
|
|
@@ -294,7 +294,7 @@ class struct_json_protocol(object):
|
294
|
294
|
else:
|
295
|
295
|
try:
|
296
|
296
|
logger.debug("%s Executing callback %s to process received data", self.LOG_PREFIX, callback.__name__)
|
297
|
|
- status, data = callback(msg)
|
|
297
|
+ status, data = callback(msg, *args, **kwargs)
|
298
|
298
|
except TypeError:
|
299
|
299
|
raise TypeError('Check return value of callback function {callback_name} for service_id {service_id} and data_id {data_id}'.format(callback_name=callback.__name__, service_id=repr(msg.get_service_id()), data_id=repr(msg.get_data_id())))
|
300
|
300
|
|
|
@@ -349,7 +349,7 @@ class struct_json_protocol(object):
|
349
|
349
|
logger.log(log_lvl, '%s TX -> status: %d, service_id: %d, data_id: %d, data: "%s"', self.LOG_PREFIX, status, service_id, data_id, repr(data))
|
350
|
350
|
return self.__comm_inst__.send(self.__build_frame__(service_id, data_id, data, status), timeout=timeout, log_lvl=logging.DEBUG)
|
351
|
351
|
|
352
|
|
- def register_callback(self, service_id, data_id, callback):
|
|
352
|
+ def register_callback(self, service_id, data_id, callback, *args, **kwargs):
|
353
|
353
|
"""
|
354
|
354
|
:param service_id: The Service-ID for the message. See class definitions starting with ``SID_``.
|
355
|
355
|
:type service_id: int
|
|
@@ -373,7 +373,7 @@ class struct_json_protocol(object):
|
373
|
373
|
:param msg: A :class:`dict` containing all message information.
|
374
|
374
|
:returns: status (see class definition starting with ``STATUS_``), response_data (JSON compatible object)
|
375
|
375
|
"""
|
376
|
|
- self.__callbacks__.add(service_id, data_id, callback)
|
|
376
|
+ self.__callbacks__.add(service_id, data_id, callback, *args, **kwargs)
|
377
|
377
|
|
378
|
378
|
def authentificate(self, timeout=2):
|
379
|
379
|
"""
|