comparison src/core/sat_main.py @ 2050:046449cc2bff

core, bridge, frontends: removed deprecated bridge method askConfirmation, confirmationAnswer, actionResult, actionResultExt and getWaitingConf
author Goffi <goffi@goffi.org>
date Sun, 28 Aug 2016 19:23:58 +0200
parents 19b9d3f8a6c7
children 4633cfcbcccb
comparison
equal deleted inserted replaced
2049:b67aece4a667 2050:046449cc2bff
51 class SAT(service.Service): 51 class SAT(service.Service):
52 52
53 def __init__(self): 53 def __init__(self):
54 self._cb_map = {} # map from callback_id to callbacks 54 self._cb_map = {} # map from callback_id to callbacks
55 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary) 55 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary)
56 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed
57 self.initialised = defer.Deferred() 56 self.initialised = defer.Deferred()
58 self.profiles = {} 57 self.profiles = {}
59 self.plugins = {} 58 self.plugins = {}
60 59
61 self.memory = Memory(self) 60 self.memory = Memory(self)
83 self.bridge.register("getContacts", self.getContacts) 82 self.bridge.register("getContacts", self.getContacts)
84 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup) 83 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup)
85 self.bridge.register("getMainResource", self.memory._getMainResource) 84 self.bridge.register("getMainResource", self.memory._getMainResource)
86 self.bridge.register("getPresenceStatuses", self.memory._getPresenceStatuses) 85 self.bridge.register("getPresenceStatuses", self.memory._getPresenceStatuses)
87 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) 86 self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
88 self.bridge.register("getWaitingConf", self.getWaitingConf)
89 self.bridge.register("messageSend", self._messageSend) 87 self.bridge.register("messageSend", self._messageSend)
90 self.bridge.register("getConfig", self._getConfig) 88 self.bridge.register("getConfig", self._getConfig)
91 self.bridge.register("setParam", self.setParam) 89 self.bridge.register("setParam", self.setParam)
92 self.bridge.register("getParamA", self.memory.getStringParamA) 90 self.bridge.register("getParamA", self.memory.getStringParamA)
93 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA) 91 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA)
102 self.bridge.register("updateContact", self._updateContact) 100 self.bridge.register("updateContact", self._updateContact)
103 self.bridge.register("delContact", self._delContact) 101 self.bridge.register("delContact", self._delContact)
104 self.bridge.register("isConnected", self.isConnected) 102 self.bridge.register("isConnected", self.isConnected)
105 self.bridge.register("launchAction", self.launchCallback) 103 self.bridge.register("launchAction", self.launchCallback)
106 self.bridge.register("actionsGet", self.actionsGet) 104 self.bridge.register("actionsGet", self.actionsGet)
107 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
108 self.bridge.register("progressGet", self._progressGet) 105 self.bridge.register("progressGet", self._progressGet)
109 self.bridge.register("progressGetAll", self._progressGetAll) 106 self.bridge.register("progressGetAll", self._progressGetAll)
110 self.bridge.register("getMenus", self.getMenus) 107 self.bridge.register("getMenus", self.getMenus)
111 self.bridge.register("getMenuHelp", self.getMenuHelp) 108 self.bridge.register("getMenuHelp", self.getMenuHelp)
112 self.bridge.register("discoInfos", self.memory.disco._discoInfos) 109 self.bridge.register("discoInfos", self.memory.disco._discoInfos)
517 return self.profiles[profile].isConnected() 514 return self.profiles[profile].isConnected()
518 515
519 516
520 ## XMPP methods ## 517 ## XMPP methods ##
521 518
522 def getWaitingConf(self, profile_key=None):
523 assert profile_key
524 client = self.getClient(profile_key)
525 ret = []
526 for conf_id in client._waiting_conf:
527 conf_type, data = client._waiting_conf[conf_id][:2]
528 ret.append((conf_id, conf_type, data))
529 return ret
530
531 def generateMessageXML(self, data): 519 def generateMessageXML(self, data):
532 """Generate <message/> stanza from message data 520 """Generate <message/> stanza from message data
533 521
534 @param data(dict): message data 522 @param data(dict): message data
535 domish element will be put in data['xml'] 523 domish element will be put in data['xml']
793 def findFeaturesSet(self, *args, **kwargs): 781 def findFeaturesSet(self, *args, **kwargs):
794 return self.memory.disco.findFeaturesSet(*args, **kwargs) 782 return self.memory.disco.findFeaturesSet(*args, **kwargs)
795 783
796 784
797 ## Generic HMI ## 785 ## Generic HMI ##
798
799 def actionResult(self, action_id, action_type, data, profile):
800 """Send the result of an action
801 @param action_id: same action_id used with action
802 @param action_type: result action_type ("PARAM", "SUCCESS", "ERROR", "XMLUI")
803 @param data: dictionary
804 """
805 self.bridge.actionResult(action_type, action_id, data, profile)
806
807 def actionResultExt(self, action_id, action_type, data, profile):
808 """Send the result of an action, extended version
809 @param action_id: same action_id used with action
810 @param action_type: result action_type /!\ only "DICT_DICT" for this method
811 @param data: dictionary of dictionaries
812 """
813 if action_type != "DICT_DICT":
814 log.error(_("action_type for actionResultExt must be DICT_DICT, fixing it"))
815 action_type = "DICT_DICT"
816 self.bridge.actionResultExt(action_type, action_id, data, profile)
817
818 def askConfirmation(self, conf_id, conf_type, data, cb, profile):
819 """Add a confirmation callback
820 @param conf_id: conf_id used to get answer
821 @param conf_type: confirmation conf_type ("YES/NO", "FILE_TRANSFER")
822 @param data: data (depend of confirmation conf_type)
823 @param cb: callback called with the answer
824 """
825 # FIXME: use XMLUI and *callback methods for dialog
826 client = self.getClient(profile)
827 if conf_id in client._waiting_conf:
828 log.error(_("Attempt to register two callbacks for the same confirmation"))
829 else:
830 client._waiting_conf[conf_id] = (conf_type, data, cb)
831 self.bridge.askConfirmation(conf_id, conf_type, data, profile)
832
833 def confirmationAnswer(self, conf_id, accepted, data, profile):
834 """Called by frontends to answer confirmation requests"""
835 client = self.getClient(profile)
836 log.debug(_(u"Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")})
837 if conf_id not in client._waiting_conf:
838 log.error(_(u"Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile})
839 else:
840 cb = client._waiting_conf[conf_id][-1]
841 del client._waiting_conf[conf_id]
842 cb(conf_id, accepted, data, profile)
843 786
844 def _killAction(self, keep_id, client): 787 def _killAction(self, keep_id, client):
845 log.debug(u"Killing action {} for timeout".format(keep_id)) 788 log.debug(u"Killing action {} for timeout".format(keep_id))
846 client.actions[keep_id] 789 client.actions[keep_id]
847 790