Mercurial > libervia-desktop-kivy
diff 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 |
line wrap: on
line diff
--- a/src/cagou/core/cagou_main.py Sun Dec 18 21:01:04 2016 +0100 +++ b/src/cagou/core/cagou_main.py Mon Dec 19 23:50:19 2016 +0100 @@ -69,6 +69,7 @@ # sys.platform is "linux" on android by default # so we change it to allow backend to detect android sys.platform = "android" + import mmap class NotifsIcon(IconButton): @@ -226,11 +227,31 @@ """ return os.path.expanduser(path).format(*args, media=self.host.media_dir, **kwargs) + def on_start(self): + # XXX: we use memory map instead of bridge because if we try to call a bridge method + # in on_pause method, the call data is not written before the actual pause + # we create a memory map on .cagou_status file with a 1 byte status + # status is: + # R => running + # P => paused + # S => stopped + self._first_pause = True + self.cagou_status_fd = open('.cagou_status', 'wb+') + self.cagou_status_fd.write('R') + self.cagou_status_fd.flush() + self.cagou_status = mmap.mmap(self.cagou_status_fd.fileno(), 1, prot=mmap.PROT_WRITE) + def on_pause(self): + self.cagou_status[0] = 'P' return True def on_resume(self): - pass + self.cagou_status[0] = 'R' + + def on_stop(self): + self.cagou_status[0] = 'S' + self.cagou_status.flush() + self.cagou_status_fd.close() class Cagou(QuickApp):