diff --git a/platypush/context/__init__.py b/platypush/context/__init__.py index bfe243b368..4a463947d2 100644 --- a/platypush/context/__init__.py +++ b/platypush/context/__init__.py @@ -9,6 +9,9 @@ backends = {} # Map: plugin_name -> plugin_instance plugins = {} +# Reference to the main application bus +main_bus = None + def register_backends(bus=None, global_scope=False, **kwargs): """ Initialize the backend objects based on the configuration and returns a name -> backend_instance map. @@ -19,6 +22,10 @@ def register_backends(bus=None, global_scope=False, **kwargs): kwargs -- Any additional key-value parameters required to initialize the backends """ + global main_bus + if bus: + main_bus = bus + if global_scope: global backends else: @@ -84,6 +91,10 @@ def get_plugin(plugin_name, reload=False): plugins[plugin_name] = plugin return plugin +def get_bus(): + global main_bus + return main_bus + def register_plugin(name, plugin, **kwargs): """ Registers a plugin instance by name """ global plugins diff --git a/platypush/plugins/video/omxplayer.py b/platypush/plugins/video/omxplayer.py index fbe5d44386..0f174376f6 100644 --- a/platypush/plugins/video/omxplayer.py +++ b/platypush/plugins/video/omxplayer.py @@ -10,6 +10,7 @@ from bs4 import BeautifulSoup from dbus.exceptions import DBusException from omxplayer import OMXPlayer +from platypush.context import get_bus from platypush.plugins.media import PlayerState from platypush.message.response import Response from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \ @@ -158,17 +159,17 @@ class VideoOmxplayerPlugin(Plugin): def on_play(self): def _f(player): - self.bus.post(VideoPlayEvent(video=self.player.get_source())) + get_bus().post(VideoPlayEvent(video=self.player.get_source())) return _f def on_pause(self): def _f(player): - self.bus.post(VideoPauseEvent(video=self.player.get_source())) + get_bus().post(VideoPauseEvent(video=self.player.get_source())) return _f def on_stop(self): def _f(player): - self.bus.post(VideoStopEvent()) + get_bus().post(VideoStopEvent()) return _f