MPD: Use core actor passed to frontend
This commit is contained in:
parent
9fd3e93cb6
commit
c115cf123f
@ -32,7 +32,8 @@ class MpdFrontend(actor.ThreadingActor, core.CoreListener):
|
||||
port = settings.MPD_SERVER_PORT
|
||||
|
||||
try:
|
||||
network.Server(hostname, port, protocol=MpdSession,
|
||||
network.Server(hostname, port,
|
||||
protocol=MpdSession, protocol_kwargs={'core': core},
|
||||
max_connections=settings.MPD_SERVER_MAX_CONNECTIONS)
|
||||
except IOError as error:
|
||||
logger.error(u'MPD server startup failed: %s', locale_decode(error))
|
||||
@ -76,9 +77,9 @@ class MpdSession(network.LineProtocol):
|
||||
encoding = protocol.ENCODING
|
||||
delimiter = r'\r?\n'
|
||||
|
||||
def __init__(self, connection):
|
||||
def __init__(self, connection, core=None):
|
||||
super(MpdSession, self).__init__(connection)
|
||||
self.dispatcher = dispatcher.MpdDispatcher(self)
|
||||
self.dispatcher = dispatcher.MpdDispatcher(session=self, core=core)
|
||||
|
||||
def on_start(self):
|
||||
logger.info(u'New MPD connection from [%s]:%s', self.host, self.port)
|
||||
|
||||
@ -27,12 +27,12 @@ class MpdDispatcher(object):
|
||||
|
||||
_noidle = re.compile(r'^noidle$')
|
||||
|
||||
def __init__(self, session=None):
|
||||
def __init__(self, session=None, core=None):
|
||||
self.authenticated = False
|
||||
self.command_list = False
|
||||
self.command_list_ok = False
|
||||
self.command_list_index = None
|
||||
self.context = MpdContext(self, session=session)
|
||||
self.context = MpdContext(self, session=session, core=core)
|
||||
|
||||
def handle_request(self, request, current_command_list_index=None):
|
||||
"""Dispatch incoming requests to the correct handler."""
|
||||
@ -221,27 +221,18 @@ class MpdContext(object):
|
||||
#: The current :class:`mopidy.frontends.mpd.MpdSession`.
|
||||
session = None
|
||||
|
||||
#: The Mopidy core API. An instance of :class:`mopidy.core.Core`.
|
||||
core = None
|
||||
|
||||
#: The active subsystems that have pending events.
|
||||
events = None
|
||||
|
||||
#: The subsytems that we want to be notified about in idle mode.
|
||||
subscriptions = None
|
||||
|
||||
def __init__(self, dispatcher, session=None):
|
||||
def __init__(self, dispatcher, session=None, core=None):
|
||||
self.dispatcher = dispatcher
|
||||
self.session = session
|
||||
self.core = core
|
||||
self.events = set()
|
||||
self.subscriptions = set()
|
||||
self._core = None
|
||||
|
||||
@property
|
||||
def core(self):
|
||||
"""
|
||||
The Mopidy core. An instance of :class:`mopidy.core.Core`.
|
||||
"""
|
||||
if self._core is None:
|
||||
core_refs = ActorRegistry.get_by_class(core.Core)
|
||||
assert len(core_refs) == 1, \
|
||||
'Expected exactly one running core instance.'
|
||||
self._core = core_refs[0].proxy()
|
||||
return self._core
|
||||
|
||||
@ -27,7 +27,7 @@ class BaseTestCase(unittest.TestCase):
|
||||
self.core = core.Core.start(backend=self.backend).proxy()
|
||||
|
||||
self.connection = MockConnection()
|
||||
self.session = mpd.MpdSession(self.connection)
|
||||
self.session = mpd.MpdSession(self.connection, core=self.core)
|
||||
self.dispatcher = self.session.dispatcher
|
||||
self.context = self.dispatcher.context
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ class StatusHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.backend = dummy.DummyBackend.start(audio=None).proxy()
|
||||
self.core = core.Core.start(backend=self.backend).proxy()
|
||||
self.dispatcher = dispatcher.MpdDispatcher()
|
||||
self.dispatcher = dispatcher.MpdDispatcher(core=self.core)
|
||||
self.context = self.dispatcher.context
|
||||
|
||||
def tearDown(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user