comparison src/cagou/core/cagou_main.py @ 64:8e16abcadbb8

core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
author Goffi <goffi@goffi.org>
date Tue, 13 Dec 2016 23:10:43 +0100
parents af4f986d86f0
children 1c738621bc8d
comparison
equal deleted inserted replaced
63:af4f986d86f0 64:8e16abcadbb8
232 232
233 def __init__(self): 233 def __init__(self):
234 if bridge_name == 'embedded': 234 if bridge_name == 'embedded':
235 from sat.core import sat_main 235 from sat.core import sat_main
236 self.sat = sat_main.SAT() 236 self.sat = sat_main.SAT()
237 if sys.platform == 'android':
238 from android import AndroidService
239 service = AndroidService(u'Cagou (SàT)'.encode('utf-8'), u'Salut à Toi backend'.encode('utf-8'))
240 service.start(u'service started')
241 self.service = service
242
237 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge') 243 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge')
238 if bridge_module is None: 244 if bridge_module is None:
239 log.error(u"Can't import {} bridge".format(bridge_name)) 245 log.error(u"Can't import {} bridge".format(bridge_name))
240 sys.exit(1) 246 sys.exit(1)
241 else: 247 else:
258 264
259 def _bridgeCb(self): 265 def _bridgeCb(self):
260 super(Cagou, self)._bridgeCb() 266 super(Cagou, self)._bridgeCb()
261 self.bridge.getReady(self.onBackendReady) 267 self.bridge.getReady(self.onBackendReady)
262 268
269 def _bridgeEb(self, failure):
270 if bridge_name == "pb" and sys.platform == "android":
271 try:
272 self.retried += 1
273 except AttributeError:
274 self.retried = 1
275 from twisted.internet.error import ConnectionRefusedError
276 if failure.check(ConnectionRefusedError) and self.retried < 100:
277 if self.retried % 20 == 0:
278 log.debug("backend not ready, retrying ({})".format(self.retried))
279 Clock.schedule_once(lambda dummy: self.connectBridge(), 0.05)
280 return
281 super(Cagou, self)._bridgeEb(failure)
282
263 def run(self): 283 def run(self):
264 self.connectBridge() 284 self.connectBridge()
265 self.app.bind(on_stop=self.onStop) 285 self.app.bind(on_stop=self.onStop)
266 self.app.run() 286 self.app.run()
267 287