comparison src/cagou/core/cagou_main.py @ 73:674b1fa3c945

core: use memory map on a file to indicate pause/resume status, so backend can now it
author Goffi <goffi@goffi.org>
date Mon, 19 Dec 2016 23:50:19 +0100
parents 1a324c682d8a
children b84dadbab62b
comparison
equal deleted inserted replaced
72:1a324c682d8a 73:674b1fa3c945
67 # FIXME: move to separate android module 67 # FIXME: move to separate android module
68 kivy.support.install_android() 68 kivy.support.install_android()
69 # sys.platform is "linux" on android by default 69 # sys.platform is "linux" on android by default
70 # so we change it to allow backend to detect android 70 # so we change it to allow backend to detect android
71 sys.platform = "android" 71 sys.platform = "android"
72 import mmap
72 73
73 74
74 class NotifsIcon(IconButton): 75 class NotifsIcon(IconButton):
75 notifs = properties.ListProperty() 76 notifs = properties.ListProperty()
76 77
224 @param *args: additional arguments used in format 225 @param *args: additional arguments used in format
225 @param **kwargs: additional keyword arguments used in format 226 @param **kwargs: additional keyword arguments used in format
226 """ 227 """
227 return os.path.expanduser(path).format(*args, media=self.host.media_dir, **kwargs) 228 return os.path.expanduser(path).format(*args, media=self.host.media_dir, **kwargs)
228 229
230 def on_start(self):
231 # XXX: we use memory map instead of bridge because if we try to call a bridge method
232 # in on_pause method, the call data is not written before the actual pause
233 # we create a memory map on .cagou_status file with a 1 byte status
234 # status is:
235 # R => running
236 # P => paused
237 # S => stopped
238 self._first_pause = True
239 self.cagou_status_fd = open('.cagou_status', 'wb+')
240 self.cagou_status_fd.write('R')
241 self.cagou_status_fd.flush()
242 self.cagou_status = mmap.mmap(self.cagou_status_fd.fileno(), 1, prot=mmap.PROT_WRITE)
243
229 def on_pause(self): 244 def on_pause(self):
245 self.cagou_status[0] = 'P'
230 return True 246 return True
231 247
232 def on_resume(self): 248 def on_resume(self):
233 pass 249 self.cagou_status[0] = 'R'
250
251 def on_stop(self):
252 self.cagou_status[0] = 'S'
253 self.cagou_status.flush()
254 self.cagou_status_fd.close()
234 255
235 256
236 class Cagou(QuickApp): 257 class Cagou(QuickApp):
237 MB_HANDLE = False 258 MB_HANDLE = False
238 259