<br><br><div class="gmail_quote">On Wed, May 9, 2012 at 12:42 PM, Paul Fox <span dir="ltr"><<a href="mailto:pgf@laptop.org" target="_blank">pgf@laptop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
i would much prefer that we could prevent suspend during any<br>
audio playback, rather than have to have anyone that wants<br>
to make noise do it individually.<br>
<br></blockquote><div><br></div><div>But this should be done at a lower level, right?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
that being said, you can eliminate any of the code below that deals<br>
with the ohm keystore. if we move away from powerd, it likely won't<br>
be back to ohmd.<br>
<br></blockquote><div><br></div><div>Thanks. I was not sure if needed.</div><div><br></div><div>Gonzalo</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
paul<br>
<div><div class="h5"><br>
<a href="mailto:godiard@sugarlabs.org">godiard@sugarlabs.org</a> wrote:<br>
> From: Gonzalo Odiard <<a href="mailto:godiard@gmail.com">godiard@gmail.com</a>><br>
><br>
> To avoid stoping playing the text when the xo go to sleep.<br>
> This patch creates a file in /var/run/powerd-inhibit-suspend/<br>
> and remove it when finish. Is the same technique used in activities<br>
> (the code is copied from Distance activity) but we need decide<br>
> if is the right thing to do in sugar.<br>
><br>
> Signed-off-by: Gonzalo Odiard <<a href="mailto:gonzalo@laptop.org">gonzalo@laptop.org</a>><br>
> ---<br>
> src/jarabe/model/speech.py | 69 ++++++++++++++++++++++++++++++++++++++++----<br>
> 1 file changed, 63 insertions(+), 6 deletions(-)<br>
><br>
> diff --git a/src/jarabe/model/speech.py b/src/jarabe/model/speech.py<br>
> index 1cb0ad4..24f4152 100644<br>
> --- a/src/jarabe/model/speech.py<br>
> +++ b/src/jarabe/model/speech.py<br>
> @@ -21,6 +21,7 @@ import gconf<br>
> import gst<br>
> import gtk<br>
> import gobject<br>
> +import dbus<br>
><br>
><br>
> DEFAULT_PITCH = 0<br>
> @@ -30,6 +31,10 @@ DEFAULT_RATE = 0<br>
><br>
> _speech_manager = None<br>
><br>
> +# directory exists if powerd is running. create a file here,<br>
> +# named after our pid, to inhibit suspend.<br>
> +POWERD_INHIBIT_DIR = '/var/run/powerd-inhibit-suspend'<br>
> +<br>
><br>
> class SpeechManager(gobject.GObject):<br>
><br>
> @@ -138,7 +143,20 @@ class _GstSpeechPlayer(gobject.GObject):<br>
> gobject.GObject.__init__(self)<br>
> self._pipeline = None<br>
><br>
> + self.using_powerd = False<br>
> + if not self.powerd_running():<br>
> + try:<br>
> + bus = dbus.SystemBus()<br>
> + proxy = bus.get_object('org.freedesktop.ohm',<br>
> + '/org/freedesktop/ohm/Keystore')<br>
> + self.ohm_keystore = dbus.Interface(<br>
> + proxy, 'org.freedesktop.ohm.Keystore')<br>
> + except dbus.DBusException, e:<br>
> + logging.warning("Error setting OHM inhibit: %s", e)<br>
> + self.ohm_keystore = None<br>
> +<br>
> def restart_sound_device(self):<br>
> + self._inhibit_suspend()<br>
> if self._pipeline is None:<br>
> logging.debug('Trying to restart not initialized sound device')<br>
> return<br>
> @@ -147,6 +165,7 @@ class _GstSpeechPlayer(gobject.GObject):<br>
> self.emit('play')<br>
><br>
> def pause_sound_device(self):<br>
> + self._allow_suspend()<br>
> if self._pipeline is None:<br>
> return<br>
><br>
> @@ -154,6 +173,7 @@ class _GstSpeechPlayer(gobject.GObject):<br>
> self.emit('pause')<br>
><br>
> def stop_sound_device(self):<br>
> + self._allow_suspend()<br>
> if self._pipeline is None:<br>
> return<br>
><br>
> @@ -172,12 +192,9 @@ class _GstSpeechPlayer(gobject.GObject):<br>
> bus.connect('message', self.__pipe_message_cb)<br>
><br>
> def __pipe_message_cb(self, bus, message):<br>
> - if message.type == gst.MESSAGE_EOS:<br>
> - self._pipeline.set_state(gst.STATE_NULL)<br>
> - self.emit('stop')<br>
> - elif message.type == gst.MESSAGE_ERROR:<br>
> - self._pipeline.set_state(gst.STATE_NULL)<br>
> - self.emit('stop')<br>
> + if message.type == gst.MESSAGE_EOS or \<br>
> + message.type == gst.MESSAGE_ERROR:<br>
> + self.stop_sound_device()<br>
><br>
> def speak(self, pitch, rate, voice_name, text):<br>
> # TODO workaround for <a href="http://bugs.sugarlabs.org/ticket/1801" target="_blank">http://bugs.sugarlabs.org/ticket/1801</a><br>
> @@ -223,6 +240,46 @@ class _GstSpeechPlayer(gobject.GObject):<br>
> locale, best)<br>
> return best<br>
><br>
> + def powerd_running(self):<br>
> + self.using_powerd = os.access(POWERD_INHIBIT_DIR, os.W_OK)<br>
> + logging.debug("using_powerd: %d", self.using_powerd)<br>
> + return self.using_powerd<br>
> +<br>
> + def _inhibit_suspend(self):<br>
> + if self.using_powerd:<br>
> + fd = open(POWERD_INHIBIT_DIR + "/%u" % os.getpid(), 'w')<br>
> + logging.debug("inhibit_suspend file is %s" % \<br>
> + POWERD_INHIBIT_DIR + "/%u" % os.getpid())<br>
> + fd.close()<br>
> + return True<br>
> +<br>
> + if self.ohm_keystore is not None:<br>
> + try:<br>
> + self.ohm_keystore.SetKey('suspend.inhibit', 1)<br>
> + return self.ohm_keystore.GetKey('suspend.inhibit')<br>
> + except dbus.exceptions.DBusException:<br>
> + logging.warning("failed to inhibit suspend")<br>
> + return False<br>
> + else:<br>
> + return False<br>
> +<br>
> + def _allow_suspend(self):<br>
> + if self.using_powerd:<br>
> + os.unlink(POWERD_INHIBIT_DIR + "/%u" % os.getpid())<br>
> + logging.debug("allow_suspend unlinking %s" % \<br>
> + POWERD_INHIBIT_DIR + "/%u" % os.getpid())<br>
> + return True<br>
> +<br>
> + if self.ohm_keystore is not None:<br>
> + try:<br>
> + self.ohm_keystore.SetKey('suspend.inhibit', 0)<br>
> + return self.ohm_keystore.GetKey('suspend.inhibit')<br>
> + except dbus.exceptions.DBusException:<br>
> + logging.error("failed to allow suspend")<br>
> + return False<br>
> + else:<br>
> + return False<br>
> +<br>
><br>
> def get_speech_manager():<br>
> global _speech_manager<br>
> --<br>
> 1.7.10.1<br>
><br>
</div></div> > _______________________________________________<br>
> Sugar-devel mailing list<br>
> <a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
> <a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
<br>
=---------------------<br>
paul fox, <a href="mailto:pgf@laptop.org">pgf@laptop.org</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Gonzalo Odiard<br>SugarLabs Argentina<br><br>