core, bridge: actionsGet:
- added a new mechanism to keep actions until they are answered (or timeout-ed)
- keep_id must be explicitly used on actionNew
- actionsGet is used to retrive these actions
- the mechanism is used in deferXMLUI
This commit is contained in:
parent
c0b1f1a86e
commit
a42452ff57
2 changed files with 63 additions and 7 deletions
|
|
@ -102,6 +102,7 @@ class SAT(service.Service):
|
|||
self.bridge.register("delContact", self._delContact)
|
||||
self.bridge.register("isConnected", self.isConnected)
|
||||
self.bridge.register("launchAction", self.launchCallback)
|
||||
self.bridge.register("actionsGet", self.actionsGet)
|
||||
self.bridge.register("confirmationAnswer", self.confirmationAnswer)
|
||||
self.bridge.register("progressGet", self._progressGet)
|
||||
self.bridge.register("progressGetAll", self._progressGetAll)
|
||||
|
|
@ -785,16 +786,36 @@ class SAT(service.Service):
|
|||
del client._waiting_conf[conf_id]
|
||||
cb(conf_id, accepted, data, profile)
|
||||
|
||||
def actionNew(self, action_data, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
|
||||
"""Shortcut to bridge.actionNew which generate and id
|
||||
def _killAction(self, keep_id, client):
|
||||
log.debug(u"Killing action {} for timeout".format(keep_id))
|
||||
client.actions[keep_id]
|
||||
|
||||
def actionNew(self, action_data, security_limit=C.NO_SECURITY_LIMIT, keep_id=None, profile=C.PROF_KEY_NONE):
|
||||
"""Shortcut to bridge.actionNew which generate and id and keep for retrieval
|
||||
|
||||
@param action_data(dict): action data (see bridge documentation)
|
||||
@param security_limit: %(doc_security_limit)s
|
||||
@param keep_id(None, unicode): if not None, used to keep action for differed retrieval
|
||||
must be set to the callback_id
|
||||
action will be deleted after 30 min.
|
||||
@param profile: %(doc_profile)s
|
||||
"""
|
||||
id_ = unicode(uuid.uuid4())
|
||||
if keep_id is not None:
|
||||
client = self.getClient(profile)
|
||||
action_timer = reactor.callLater(60*30, self._killAction)
|
||||
client.actions[keep_id] = (action_data, id_, security_limit, action_timer)
|
||||
|
||||
self.bridge.actionNew(action_data, id_, security_limit, profile)
|
||||
|
||||
def actionsGet(self, profile):
|
||||
"""Return current non answered actions
|
||||
|
||||
@param profile: %(doc_profile)s
|
||||
"""
|
||||
client = self.getClient(profile)
|
||||
return [action_tuple[:-1] for action_tuple in client.actions.itervalues()]
|
||||
|
||||
def registerProgressCb(self, progress_id, callback, profile):
|
||||
"""Register a callback called when progress is requested for id"""
|
||||
client = self.getClient(profile)
|
||||
|
|
@ -904,9 +925,13 @@ class SAT(service.Service):
|
|||
- C.BOOL_TRUE
|
||||
- C.BOOL_FALSE
|
||||
"""
|
||||
profile = self.memory.getProfileName(profile_key)
|
||||
if not profile:
|
||||
raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile'))
|
||||
client = self.getClient(profile_key)
|
||||
try:
|
||||
action_tuple = client.actions[callback_id]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
action_tuple[-1].cancel() # the last item is the action timer
|
||||
|
||||
try:
|
||||
callback, args, kwargs = self._cb_map[callback_id]
|
||||
|
|
@ -918,7 +943,7 @@ class SAT(service.Service):
|
|||
raise exceptions.DataError("Required data for this callback is missing")
|
||||
args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args
|
||||
args.insert(0, data)
|
||||
kwargs["profile"] = profile
|
||||
kwargs["profile"] = client.profile
|
||||
del kwargs["with_data"]
|
||||
|
||||
if kwargs.pop('one_shot', False):
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class SatXMPPClient(client.XMPPClient):
|
|||
self.conn_deferred = defer.Deferred()
|
||||
self._waiting_conf = {} # callback called when a confirmation is received
|
||||
self._progress_cb = {} # callback called when a progress is requested (key = progress id)
|
||||
self.actions = {} # used to keep track of actions for retrieval (key = action_id)
|
||||
|
||||
def getConnectionDeferred(self):
|
||||
"""Return a deferred which fire when the client is connected"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue