Hook an MpdDispatcher directly onto each MpdSession
This commit is contained in:
parent
65c64b4a8a
commit
a88cf1e2ca
@ -1,5 +1,8 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
from pykka.proxy import ActorProxy
|
||||||
|
from pykka.registry import ActorRegistry
|
||||||
|
|
||||||
from mopidy.frontends.mpd.exceptions import (MpdAckError, MpdArgError,
|
from mopidy.frontends.mpd.exceptions import (MpdAckError, MpdArgError,
|
||||||
MpdUnknownCommand)
|
MpdUnknownCommand)
|
||||||
from mopidy.frontends.mpd.protocol import mpd_commands, request_handlers
|
from mopidy.frontends.mpd.protocol import mpd_commands, request_handlers
|
||||||
@ -14,11 +17,20 @@ from mopidy.utils import flatten
|
|||||||
|
|
||||||
class MpdDispatcher(object):
|
class MpdDispatcher(object):
|
||||||
"""
|
"""
|
||||||
Dispatches MPD requests to the correct handler.
|
The MPD session feeds the MPD dispatcher with requests. The dispatcher
|
||||||
|
finds the correct handler, processes the request and sends the response
|
||||||
|
back to the MPD session.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, backend=None):
|
# XXX Consider merging MpdDispatcher into MpdSession
|
||||||
self.backend = backend
|
|
||||||
|
def __init__(self, session):
|
||||||
|
self.session = session
|
||||||
|
|
||||||
|
# TODO-PYKKA: Get reference to backend in a more generic way
|
||||||
|
backend_refs = ActorRegistry.get_by_class_name('SpotifyBackend')
|
||||||
|
self.backend = ActorProxy(backend_refs[0])
|
||||||
|
|
||||||
self.command_list = False
|
self.command_list = False
|
||||||
self.command_list_ok = False
|
self.command_list_ok = False
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import logging
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
from mopidy import settings
|
from mopidy import settings
|
||||||
|
from mopidy.frontends.mpd.dispatcher import MpdDispatcher
|
||||||
from mopidy.frontends.mpd.protocol import ENCODING, LINE_TERMINATOR, VERSION
|
from mopidy.frontends.mpd.protocol import ENCODING, LINE_TERMINATOR, VERSION
|
||||||
from mopidy.utils.log import indent
|
from mopidy.utils.log import indent
|
||||||
|
|
||||||
@ -10,8 +11,8 @@ logger = logging.getLogger('mopidy.frontends.mpd.session')
|
|||||||
|
|
||||||
class MpdSession(asynchat.async_chat):
|
class MpdSession(asynchat.async_chat):
|
||||||
"""
|
"""
|
||||||
The MPD client session. Keeps track of a single client and passes its
|
The MPD client session. Keeps track of a single client session. Any
|
||||||
MPD requests to the dispatcher.
|
requests from the client is passed on to the MPD request dispatcher.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, server, client_socket, client_socket_address):
|
def __init__(self, server, client_socket, client_socket_address):
|
||||||
@ -22,6 +23,7 @@ class MpdSession(asynchat.async_chat):
|
|||||||
self.input_buffer = []
|
self.input_buffer = []
|
||||||
self.authenticated = False
|
self.authenticated = False
|
||||||
self.set_terminator(LINE_TERMINATOR.encode(ENCODING))
|
self.set_terminator(LINE_TERMINATOR.encode(ENCODING))
|
||||||
|
self.dispatcher = MpdDispatcher(self)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start a new client session."""
|
"""Start a new client session."""
|
||||||
@ -50,7 +52,7 @@ class MpdSession(asynchat.async_chat):
|
|||||||
if response is not None:
|
if response is not None:
|
||||||
self.send_response(response)
|
self.send_response(response)
|
||||||
return
|
return
|
||||||
# TODO-PYKKA: Process request using MpdDispatcher/backend
|
response = self.dispatcher.handle_request(request)
|
||||||
if response is not None:
|
if response is not None:
|
||||||
self.handle_response(response)
|
self.handle_response(response)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user