comparison frontends/src/bridge/DBus.py @ 1072:d123d61976c8

bridge (D-Bus): frontend side now use a 120 s timeout for async calls
author Goffi <goffi@goffi.org>
date Sun, 15 Jun 2014 00:18:28 +0200
parents 95758ef3faa8
children f094583732de
comparison
equal deleted inserted replaced
1071:eef1f200d733 1072:d123d61976c8
30 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix 30 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix
31 const_ERROR_PREFIX = const_INT_PREFIX + ".error" 31 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
32 const_OBJ_PATH = '/org/goffi/SAT/bridge' 32 const_OBJ_PATH = '/org/goffi/SAT/bridge'
33 const_CORE_SUFFIX = ".core" 33 const_CORE_SUFFIX = ".core"
34 const_PLUGIN_SUFFIX = ".plugin" 34 const_PLUGIN_SUFFIX = ".plugin"
35 const_TIMEOUT = 120
35 36
36 37
37 def dbus_to_bridge_exception(dbus_e): 38 def dbus_to_bridge_exception(dbus_e):
38 """Convert a DBusException to a BridgeException. 39 """Convert a DBusException to a BridgeException.
39 40
98 _callback = args.pop() 99 _callback = args.pop()
99 100
100 method = getattr(self.db_plugin_iface, name) 101 method = getattr(self.db_plugin_iface, name)
101 102
102 if async: 103 if async:
104 kwargs['timeout'] = const_TIMEOUT
103 kwargs['reply_handler'] = _callback 105 kwargs['reply_handler'] = _callback
104 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err)) 106 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
105 107
106 return method(*args, **kwargs) 108 return method(*args, **kwargs)
107 109
108 return getPluginMethod 110 return getPluginMethod
109 def addContact(self, entity_jid, profile_key="@DEFAULT@"): 111 def addContact(self, entity_jid, profile_key="@DEFAULT@"):
110 return self.db_core_iface.addContact(entity_jid, profile_key) 112 return self.db_core_iface.addContact(entity_jid, profile_key)
111 113
112 def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None): 114 def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None):
113 return self.db_core_iface.asyncConnect(profile_key, password, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 115 return self.db_core_iface.asyncConnect(profile_key, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
114 116
115 def asyncCreateProfile(self, profile, password='', callback=None, errback=None): 117 def asyncCreateProfile(self, profile, password='', callback=None, errback=None):
116 return self.db_core_iface.asyncCreateProfile(profile, password, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 118 return self.db_core_iface.asyncCreateProfile(profile, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
117 119
118 def asyncDeleteProfile(self, profile, callback=None, errback=None): 120 def asyncDeleteProfile(self, profile, callback=None, errback=None):
119 return self.db_core_iface.asyncDeleteProfile(profile, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 121 return self.db_core_iface.asyncDeleteProfile(profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
120 122
121 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): 123 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
122 return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))) 124 return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
123 125
124 def confirmationAnswer(self, id, accepted, data, profile): 126 def confirmationAnswer(self, id, accepted, data, profile):
125 return self.db_core_iface.confirmationAnswer(id, accepted, data, profile) 127 return self.db_core_iface.confirmationAnswer(id, accepted, data, profile)
126 128
127 def delContact(self, entity_jid, profile_key="@DEFAULT@"): 129 def delContact(self, entity_jid, profile_key="@DEFAULT@"):
128 return self.db_core_iface.delContact(entity_jid, profile_key) 130 return self.db_core_iface.delContact(entity_jid, profile_key)
129 131
130 def discoInfos(self, entity_jid, profile_key, callback=None, errback=None): 132 def discoInfos(self, entity_jid, profile_key, callback=None, errback=None):
131 return self.db_core_iface.discoInfos(entity_jid, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 133 return self.db_core_iface.discoInfos(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
132 134
133 def discoItems(self, entity_jid, profile_key, callback=None, errback=None): 135 def discoItems(self, entity_jid, profile_key, callback=None, errback=None):
134 return self.db_core_iface.discoItems(entity_jid, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 136 return self.db_core_iface.discoItems(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
135 137
136 def disconnect(self, profile_key="@DEFAULT@"): 138 def disconnect(self, profile_key="@DEFAULT@"):
137 return self.db_core_iface.disconnect(profile_key) 139 return self.db_core_iface.disconnect(profile_key)
138 140
139 def getConfig(self, section, name): 141 def getConfig(self, section, name):
147 149
148 def getEntityData(self, jid, keys, profile): 150 def getEntityData(self, jid, keys, profile):
149 return self.db_core_iface.getEntityData(jid, keys, profile) 151 return self.db_core_iface.getEntityData(jid, keys, profile)
150 152
151 def getHistory(self, from_jid, to_jid, limit, between=True, profile="@NONE@", callback=None, errback=None): 153 def getHistory(self, from_jid, to_jid, limit, between=True, profile="@NONE@", callback=None, errback=None):
152 return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, profile, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 154 return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
153 155
154 def getLastResource(self, contact_jid, profile_key="@DEFAULT@"): 156 def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
155 return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key)) 157 return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))
156 158
157 def getMenuHelp(self, menu_id, language): 159 def getMenuHelp(self, menu_id, language):
162 164
163 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): 165 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
164 return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key)) 166 return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key))
165 167
166 def getParams(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): 168 def getParams(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
167 return unicode(self.db_core_iface.getParams(security_limit, app, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))) 169 return unicode(self.db_core_iface.getParams(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
168 170
169 def getParamsCategories(self, ): 171 def getParamsCategories(self, ):
170 return self.db_core_iface.getParamsCategories() 172 return self.db_core_iface.getParamsCategories()
171 173
172 def getParamsForCategory(self, category, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): 174 def getParamsForCategory(self, category, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
173 return unicode(self.db_core_iface.getParamsForCategory(category, security_limit, app, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))) 175 return unicode(self.db_core_iface.getParamsForCategory(category, security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
174 176
175 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): 177 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
176 return unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))) 178 return unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
177 179
178 def getPresenceStatuses(self, profile_key="@DEFAULT@"): 180 def getPresenceStatuses(self, profile_key="@DEFAULT@"):
179 return self.db_core_iface.getPresenceStatuses(profile_key) 181 return self.db_core_iface.getPresenceStatuses(profile_key)
180 182
181 def getProfileName(self, profile_key="@DEFAULT@"): 183 def getProfileName(self, profile_key="@DEFAULT@"):
186 188
187 def getProgress(self, id, profile): 189 def getProgress(self, id, profile):
188 return self.db_core_iface.getProgress(id, profile) 190 return self.db_core_iface.getProgress(id, profile)
189 191
190 def getReady(self, callback=None, errback=None): 192 def getReady(self, callback=None, errback=None):
191 return self.db_core_iface.getReady(reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 193 return self.db_core_iface.getReady(timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
192 194
193 def getVersion(self, ): 195 def getVersion(self, ):
194 return unicode(self.db_core_iface.getVersion()) 196 return unicode(self.db_core_iface.getVersion())
195 197
196 def getWaitingConf(self, profile_key): 198 def getWaitingConf(self, profile_key):
201 203
202 def isConnected(self, profile_key="@DEFAULT@"): 204 def isConnected(self, profile_key="@DEFAULT@"):
203 return self.db_core_iface.isConnected(profile_key) 205 return self.db_core_iface.isConnected(profile_key)
204 206
205 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None): 207 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None):
206 return self.db_core_iface.launchAction(callback_id, data, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 208 return self.db_core_iface.launchAction(callback_id, data, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
207 209
208 def loadParamsTemplate(self, filename): 210 def loadParamsTemplate(self, filename):
209 return self.db_core_iface.loadParamsTemplate(filename) 211 return self.db_core_iface.loadParamsTemplate(filename)
210 212
211 def paramsRegisterApp(self, xml, security_limit=-1, app=''): 213 def paramsRegisterApp(self, xml, security_limit=-1, app=''):
213 215
214 def saveParamsTemplate(self, filename): 216 def saveParamsTemplate(self, filename):
215 return self.db_core_iface.saveParamsTemplate(filename) 217 return self.db_core_iface.saveParamsTemplate(filename)
216 218
217 def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None): 219 def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
218 return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))) 220 return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
219 221
220 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"): 222 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
221 return self.db_core_iface.setParam(name, value, category, security_limit, profile_key) 223 return self.db_core_iface.setParam(name, value, category, security_limit, profile_key)
222 224
223 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"): 225 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"):