Hook an MpdDispatcher directly onto each MpdSession

This commit is contained in:
Stein Magnus Jodal 2011-03-08 21:08:45 +01:00
parent 65c64b4a8a
commit a88cf1e2ca
2 changed files with 20 additions and 6 deletions

View File

@ -1,5 +1,8 @@
import re
from pykka.proxy import ActorProxy
from pykka.registry import ActorRegistry
from mopidy.frontends.mpd.exceptions import (MpdAckError, MpdArgError,
MpdUnknownCommand)
from mopidy.frontends.mpd.protocol import mpd_commands, request_handlers
@ -14,11 +17,20 @@ from mopidy.utils import flatten
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):
self.backend = backend
# XXX Consider merging MpdDispatcher into MpdSession
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_ok = False

View File

@ -3,6 +3,7 @@ import logging
import multiprocessing
from mopidy import settings
from mopidy.frontends.mpd.dispatcher import MpdDispatcher
from mopidy.frontends.mpd.protocol import ENCODING, LINE_TERMINATOR, VERSION
from mopidy.utils.log import indent
@ -10,8 +11,8 @@ logger = logging.getLogger('mopidy.frontends.mpd.session')
class MpdSession(asynchat.async_chat):
"""
The MPD client session. Keeps track of a single client and passes its
MPD requests to the dispatcher.
The MPD client session. Keeps track of a single client session. Any
requests from the client is passed on to the MPD request dispatcher.
"""
def __init__(self, server, client_socket, client_socket_address):
@ -22,6 +23,7 @@ class MpdSession(asynchat.async_chat):
self.input_buffer = []
self.authenticated = False
self.set_terminator(LINE_TERMINATOR.encode(ENCODING))
self.dispatcher = MpdDispatcher(self)
def start(self):
"""Start a new client session."""
@ -50,7 +52,7 @@ class MpdSession(asynchat.async_chat):
if response is not None:
self.send_response(response)
return
# TODO-PYKKA: Process request using MpdDispatcher/backend
response = self.dispatcher.handle_request(request)
if response is not None:
self.handle_response(response)