fix wrong replies for change and do
now correctly reply with 'changed' and 'done' Change-Id: Ic2b8e6d6d7d4c8301dc8b273115a10e1f8e40a2e
This commit is contained in:
parent
b6af55c358
commit
002c843d74
@ -158,8 +158,6 @@ class Dispatcher(object):
|
|||||||
|
|
||||||
def get_module(self, modulename):
|
def get_module(self, modulename):
|
||||||
module = self._dispatcher_modules.get(modulename, modulename)
|
module = self._dispatcher_modules.get(modulename, modulename)
|
||||||
if module != modulename:
|
|
||||||
self.log.debug('get_module(%r) -> %r' % (modulename, module))
|
|
||||||
return module
|
return module
|
||||||
|
|
||||||
def remove_module(self, modulename_or_obj):
|
def remove_module(self, modulename_or_obj):
|
||||||
@ -220,8 +218,10 @@ class Dispatcher(object):
|
|||||||
|
|
||||||
# now call func and wrap result as value
|
# now call func and wrap result as value
|
||||||
# note: exceptions are handled in handle_request, not here!
|
# note: exceptions are handled in handle_request, not here!
|
||||||
func = getattr(moduleobj, 'do'+command)
|
func = getattr(moduleobj, 'do'+command)
|
||||||
res = Value(modulename, command=command, value=func(*arguments), t=time.time())
|
res = func(*arguments)
|
||||||
|
res = CommandReply(module=modulename, command=command, result=[res, dict(t=time.time())])
|
||||||
|
# res = Value(modulename, command=command, value=func(*arguments), t=time.time())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _setParamValue(self, modulename, pname, value):
|
def _setParamValue(self, modulename, pname, value):
|
||||||
@ -242,8 +242,8 @@ class Dispatcher(object):
|
|||||||
else:
|
else:
|
||||||
setattr(moduleobj, pname, value)
|
setattr(moduleobj, pname, value)
|
||||||
if pobj.timestamp:
|
if pobj.timestamp:
|
||||||
return Value(modulename, pname, value=pobj.value, t=pobj.timestamp)
|
return WriteReply(module=modulename, parameter=pname, value=[pobj.value, dict(t=pobj.timestamp)])
|
||||||
return Value(modulename, pname, value=pobj.value)
|
return WriteReply(module=modulename, parameter=pname, value=[pobj.value, {}])
|
||||||
|
|
||||||
def _getParamValue(self, modulename, pname):
|
def _getParamValue(self, modulename, pname):
|
||||||
moduleobj = self.get_module(modulename)
|
moduleobj = self.get_module(modulename)
|
||||||
|
@ -50,19 +50,17 @@ ENABLEEVENTSREPLY = 'active' # literal, is end-of-initial-data-transfer
|
|||||||
DISABLEEVENTSREQUEST = 'deactivate' # literal
|
DISABLEEVENTSREQUEST = 'deactivate' # literal
|
||||||
DISABLEEVENTSREPLY = 'inactive' # literal
|
DISABLEEVENTSREPLY = 'inactive' # literal
|
||||||
COMMANDREQUEST = 'do' # +module:command +json args (if needed)
|
COMMANDREQUEST = 'do' # +module:command +json args (if needed)
|
||||||
COMMANDREPLY = 'doing' # +module:command +json args (if needed)
|
COMMANDREPLY = 'done' # +module:command +json args (if needed) # send after the command finished !
|
||||||
WRITEREQUEST = 'change' # +module[:parameter] +json_value -> NO direct reply, calls TRIGGER internally!
|
WRITEREQUEST = 'change' # +module[:parameter] +json_value -> NO direct reply, calls TRIGGER internally!
|
||||||
WRITEREPLY = 'changing' # +module[:parameter] +json_value -> NO direct reply, calls TRIGGER internally!
|
WRITEREPLY = 'changed' # +module[:parameter] +json_value # send with the read back value
|
||||||
TRIGGERREQUEST = 'read' # +module[:parameter] -> NO direct reply, calls TRIGGER internally!
|
TRIGGERREQUEST = 'poll' # +module[:parameter] -> NO direct reply, calls TRIGGER internally!
|
||||||
|
EVENT = 'event' # +module[:parameter] +json_value (value, qualifiers_as_dict)
|
||||||
HEARTBEATREQUEST = 'ping' # +nonce_without_space
|
HEARTBEATREQUEST = 'ping' # +nonce_without_space
|
||||||
HEARTBEATREPLY = 'pong' # +nonce_without_space
|
HEARTBEATREPLY = 'pong' # +nonce_without_space
|
||||||
EVENTTRIGGERREPLY = 'update' # +module[:parameter] +json_result_value_with_qualifiers NO REQUEST (use WRITE/TRIGGER)
|
|
||||||
EVENTCOMMANDREPLY = 'done' # +module:command +json result (if needed)
|
|
||||||
#EVENTWRITEREPLY = 'changed' # +module[:parameter] +json_result_value_with_qualifiers NO REQUEST (use WRITE/TRIGGER)
|
|
||||||
ERRORREPLY = 'ERROR' # +errorclass +json_extended_info
|
ERRORREPLY = 'ERROR' # +errorclass +json_extended_info
|
||||||
HELPREQUEST = 'help' # literal
|
HELPREQUEST = 'help' # literal
|
||||||
HELPREPLY = 'helping' # +line number +json_text
|
HELPREPLY = 'helping' # +line number +json_text
|
||||||
ERRORCLASSES = ['NoSuchDevice', 'NoSuchParameter', 'NoSuchCommand',
|
ERRORCLASSES = ['NoSuchDevice', 'NoSuchParameter', 'NoSuchCommand',
|
||||||
'CommandFailed', 'ReadOnly', 'BadValue', 'CommunicationFailed',
|
'CommandFailed', 'ReadOnly', 'BadValue', 'CommunicationFailed',
|
||||||
'IsBusy', 'IsError', 'SyntaxError', 'InternalError',
|
'IsBusy', 'IsError', 'SyntaxError', 'InternalError',
|
||||||
'CommandRunning', 'Disabled',]
|
'CommandRunning', 'Disabled',]
|
||||||
@ -80,17 +78,15 @@ class DemoEncoder(MessageEncoder):
|
|||||||
DeactivateRequest: (DISABLEEVENTSREQUEST,),
|
DeactivateRequest: (DISABLEEVENTSREQUEST,),
|
||||||
DeactivateReply : (DISABLEEVENTSREPLY,),
|
DeactivateReply : (DISABLEEVENTSREPLY,),
|
||||||
CommandRequest : (COMMANDREQUEST, lambda msg: "%s:%s" % (msg.module, msg.command), 'arguments',),
|
CommandRequest : (COMMANDREQUEST, lambda msg: "%s:%s" % (msg.module, msg.command), 'arguments',),
|
||||||
CommandReply : (COMMANDREPLY, lambda msg: "%s:%s" % (msg.module, msg.command), 'arguments',),
|
CommandReply : (COMMANDREPLY, lambda msg: "%s:%s" % (msg.module, msg.command), 'result',),
|
||||||
WriteRequest : (WRITEREQUEST, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, 'value',),
|
WriteRequest : (WRITEREQUEST, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, 'value',),
|
||||||
WriteReply : (WRITEREPLY, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, 'value',),
|
WriteReply : (WRITEREPLY, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, 'value',),
|
||||||
PollRequest : (TRIGGERREQUEST, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, ),
|
PollRequest : (TRIGGERREQUEST, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, ),
|
||||||
HeartbeatRequest : (HEARTBEATREQUEST, 'nonce',),
|
HeartbeatRequest : (HEARTBEATREQUEST, 'nonce',),
|
||||||
HeartbeatReply : (HEARTBEATREPLY, 'nonce',),
|
HeartbeatReply : (HEARTBEATREPLY, 'nonce',),
|
||||||
HelpMessage: (HELPREQUEST, ),
|
HelpMessage: (HELPREQUEST, ),
|
||||||
# EventMessage : (EVENTREPLY, lambda msg: "%s:%s" % (msg.module, msg.parameter or (msg.command+'()'))
|
|
||||||
# if msg.parameter or msg.command else msg.module, 'value',),
|
|
||||||
ErrorMessage : (ERRORREPLY, 'errorclass', 'errorinfo',),
|
ErrorMessage : (ERRORREPLY, 'errorclass', 'errorinfo',),
|
||||||
Value: (EVENTTRIGGERREPLY, lambda msg: "%s:%s" % (msg.module, msg.parameter or (msg.command+'()'))
|
Value: (EVENT, lambda msg: "%s:%s" % (msg.module, msg.parameter or (msg.command+'()'))
|
||||||
if msg.parameter or msg.command else msg.module,
|
if msg.parameter or msg.command else msg.module,
|
||||||
lambda msg: [msg.value, msg.qualifiers] if msg.qualifiers else [msg.value]),
|
lambda msg: [msg.value, msg.qualifiers] if msg.qualifiers else [msg.value]),
|
||||||
}
|
}
|
||||||
@ -104,7 +100,7 @@ class DemoEncoder(MessageEncoder):
|
|||||||
DISABLEEVENTSREQUEST: lambda spec, data:DeactivateRequest(),
|
DISABLEEVENTSREQUEST: lambda spec, data:DeactivateRequest(),
|
||||||
DISABLEEVENTSREPLY: lambda spec, data:DeactivateReply(),
|
DISABLEEVENTSREPLY: lambda spec, data:DeactivateReply(),
|
||||||
COMMANDREQUEST: lambda spec, data:CommandRequest(module=spec[0], command=spec[1], arguments=data),
|
COMMANDREQUEST: lambda spec, data:CommandRequest(module=spec[0], command=spec[1], arguments=data),
|
||||||
COMMANDREPLY: lambda spec, data: CommandReply(module=spec[0], command=spec[1], arguments=data),
|
COMMANDREPLY: lambda spec, data: CommandReply(module=spec[0], command=spec[1], result=data),
|
||||||
WRITEREQUEST: lambda spec, data: WriteRequest(module=spec[0], parameter=spec[1], value=data),
|
WRITEREQUEST: lambda spec, data: WriteRequest(module=spec[0], parameter=spec[1], value=data),
|
||||||
WRITEREPLY:lambda spec, data:WriteReply(module=spec[0], parameter=spec[1], value=data),
|
WRITEREPLY:lambda spec, data:WriteReply(module=spec[0], parameter=spec[1], value=data),
|
||||||
TRIGGERREQUEST:lambda spec, data:PollRequest(module=spec[0], parameter=spec[1]),
|
TRIGGERREQUEST:lambda spec, data:PollRequest(module=spec[0], parameter=spec[1]),
|
||||||
@ -113,14 +109,12 @@ class DemoEncoder(MessageEncoder):
|
|||||||
HELPREQUEST: lambda spec, data:HelpMessage(),
|
HELPREQUEST: lambda spec, data:HelpMessage(),
|
||||||
# HELPREPLY: lambda spec, data:None, # ignore this
|
# HELPREPLY: lambda spec, data:None, # ignore this
|
||||||
ERRORREPLY:lambda spec, data:ErrorMessage(errorclass=spec[0], errorinfo=data),
|
ERRORREPLY:lambda spec, data:ErrorMessage(errorclass=spec[0], errorinfo=data),
|
||||||
EVENTTRIGGERREPLY:lambda spec, data:Value(module=spec[0], parameter=spec[1], value=data[0], qualifiers=data[1] if len(data)>1 else {}),
|
EVENT:lambda spec, data:Value(module=spec[0], parameter=spec[1], value=data[0], qualifiers=data[1] if len(data)>1 else {}),
|
||||||
EVENTCOMMANDREPLY: lambda spec, data:None, # ignore this
|
|
||||||
# EVENTWRITEREPLY:lambda spec, data:Value(module=spec[0], parameter=spec[1], value=data[0], qualifiers=data[1] if len(data)>1 else {}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwds):
|
def __init__(self, *args, **kwds):
|
||||||
MessageEncoder.__init__(self, *args, **kwds)
|
MessageEncoder.__init__(self, *args, **kwds)
|
||||||
self.tests()
|
#self.tests()
|
||||||
|
|
||||||
def encode(self, msg):
|
def encode(self, msg):
|
||||||
"""msg object -> transport layer message"""
|
"""msg object -> transport layer message"""
|
||||||
@ -196,7 +190,7 @@ class DemoEncoder(MessageEncoder):
|
|||||||
print "---- Testing decoding -----"
|
print "---- Testing decoding -----"
|
||||||
for msgtype, _ in sorted(self.DECODEMAP.items()):
|
for msgtype, _ in sorted(self.DECODEMAP.items()):
|
||||||
msg = '%s a:b 3' % msgtype
|
msg = '%s a:b 3' % msgtype
|
||||||
if msgtype in [EVENTTRIGGERREPLY]:#, EVENTWRITEREPLY]:
|
if msgtype == EVENT:
|
||||||
msg = '%s a:b [3,{"t":193868}]' % msgtype
|
msg = '%s a:b [3,{"t":193868}]' % msgtype
|
||||||
print msg
|
print msg
|
||||||
d=self.decode(msg)
|
d=self.decode(msg)
|
||||||
@ -204,6 +198,4 @@ class DemoEncoder(MessageEncoder):
|
|||||||
print self.encode(d)
|
print self.encode(d)
|
||||||
print
|
print
|
||||||
print "---- Testing done -----"
|
print "---- Testing done -----"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class CommandRequest(Message):
|
|||||||
class CommandReply(Message):
|
class CommandReply(Message):
|
||||||
is_reply = True
|
is_reply = True
|
||||||
command = ''
|
command = ''
|
||||||
arguments = None
|
result = None
|
||||||
|
|
||||||
class WriteRequest(Message):
|
class WriteRequest(Message):
|
||||||
is_request = True
|
is_request = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user