Pass core actor to frontends
This commit is contained in:
parent
63cd153b1b
commit
706b6c6d3f
@ -6,22 +6,36 @@ The following requirements applies to any frontend implementation:
|
||||
|
||||
- A frontend MAY do mostly whatever it wants to, including creating threads,
|
||||
opening TCP ports and exposing Mopidy for a group of clients.
|
||||
|
||||
- A frontend MUST implement at least one `Pykka
|
||||
<http://pykka.readthedocs.org/>`_ actor, called the "main actor" from here
|
||||
on.
|
||||
|
||||
- The main actor MUST accept a constructor argument ``core``, which will be an
|
||||
:class:`ActorProxy <pykka.proxy.ActorProxy>` for the core actor. This object
|
||||
gives access to the full :ref:`core-api`.
|
||||
|
||||
- It MAY use additional actors to implement whatever it does, and using actors
|
||||
in frontend implementations is encouraged.
|
||||
|
||||
- The frontend is activated by including its main actor in the
|
||||
:attr:`mopidy.settings.FRONTENDS` setting.
|
||||
|
||||
- The main actor MUST be able to start and stop the frontend when the main
|
||||
actor is started and stopped.
|
||||
|
||||
- The frontend MAY require additional settings to be set for it to
|
||||
work.
|
||||
|
||||
- Such settings MUST be documented.
|
||||
|
||||
- The main actor MUST stop itself if the defined settings are not adequate for
|
||||
the frontend to work properly.
|
||||
- Any actor which is part of the frontend MAY implement any listener interface
|
||||
from :mod:`mopidy.listeners` to receive notification of the specified events.
|
||||
|
||||
- Any actor which is part of the frontend MAY implement the
|
||||
:class:`mopidy.core.CoreListener` interface to receive notification of the
|
||||
specified events.
|
||||
|
||||
|
||||
Frontend implementations
|
||||
========================
|
||||
|
||||
@ -54,8 +54,8 @@ def main():
|
||||
setup_settings(options.interactive)
|
||||
audio = setup_audio()
|
||||
backend = setup_backend(audio)
|
||||
setup_core(audio, backend)
|
||||
setup_frontends()
|
||||
core = setup_core(audio, backend)
|
||||
setup_frontends(core)
|
||||
loop.run()
|
||||
except SettingsError as e:
|
||||
logger.error(e.message)
|
||||
@ -137,17 +137,17 @@ def stop_backend():
|
||||
|
||||
|
||||
def setup_core(audio, backend):
|
||||
return Core.start(audio, backend).proxy()
|
||||
return Core.start(audio=audio, backend=backend).proxy()
|
||||
|
||||
|
||||
def stop_core():
|
||||
stop_actors_by_class(Core)
|
||||
|
||||
|
||||
def setup_frontends():
|
||||
def setup_frontends(core):
|
||||
for frontend_class_name in settings.FRONTENDS:
|
||||
try:
|
||||
get_class(frontend_class_name).start()
|
||||
get_class(frontend_class_name).start(core=core)
|
||||
except OptionalDependencyError as e:
|
||||
logger.info(u'Disabled: %s (%s)', frontend_class_name, e)
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ class LastfmFrontend(ThreadingActor, core.CoreListener):
|
||||
- :attr:`mopidy.settings.LASTFM_PASSWORD`
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, core):
|
||||
super(LastfmFrontend, self).__init__()
|
||||
self.lastfm = None
|
||||
self.last_start_time = None
|
||||
|
||||
@ -26,7 +26,7 @@ class MpdFrontend(actor.ThreadingActor, core.CoreListener):
|
||||
- :attr:`mopidy.settings.MPD_SERVER_PASSWORD`
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, core):
|
||||
super(MpdFrontend, self).__init__()
|
||||
hostname = network.format_hostname(settings.MPD_SERVER_HOSTNAME)
|
||||
port = settings.MPD_SERVER_PORT
|
||||
|
||||
@ -55,7 +55,7 @@ class MprisFrontend(ThreadingActor, core.CoreListener):
|
||||
player.Quit(dbus_interface='org.mpris.MediaPlayer2')
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, core):
|
||||
super(MprisFrontend, self).__init__()
|
||||
self.indicate_server = None
|
||||
self.mpris_object = None
|
||||
|
||||
@ -16,7 +16,7 @@ from tests import unittest
|
||||
@unittest.skipUnless(sys.platform.startswith('linux'), 'requires Linux')
|
||||
class BackendEventsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mpris_frontend = MprisFrontend() # As a plain class, not an actor
|
||||
self.mpris_frontend = MprisFrontend(core=None) # As a plain class, not an actor
|
||||
self.mpris_object = mock.Mock(spec=objects.MprisObject)
|
||||
self.mpris_frontend.mpris_object = self.mpris_object
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user