Actorify backends

This commit is contained in:
Stein Magnus Jodal 2011-03-08 20:39:50 +01:00
parent 3a3777e93e
commit 65c64b4a8a
7 changed files with 19 additions and 15 deletions

View File

@ -10,6 +10,8 @@ class CurrentPlaylistController(object):
:type backend: :class:`mopidy.backends.base.Backend` :type backend: :class:`mopidy.backends.base.Backend`
""" """
pykka_traversable = True
def __init__(self, backend): def __init__(self, backend):
self.backend = backend self.backend = backend
self._cp_tracks = [] self._cp_tracks = []

View File

@ -10,6 +10,8 @@ class LibraryController(object):
:type provider: instance of :class:`BaseLibraryProvider` :type provider: instance of :class:`BaseLibraryProvider`
""" """
pykka_traversable = True
def __init__(self, backend, provider): def __init__(self, backend, provider):
self.backend = backend self.backend = backend
self.provider = provider self.provider = provider

View File

@ -15,6 +15,8 @@ class PlaybackController(object):
# pylint: disable = R0902 # pylint: disable = R0902
# Too many instance attributes # Too many instance attributes
pykka_traversable = True
#: Constant representing the paused state. #: Constant representing the paused state.
PAUSED = u'paused' PAUSED = u'paused'
@ -461,6 +463,7 @@ class PlaybackController(object):
For internal use only. Should be called by the backend directly after a For internal use only. Should be called by the backend directly after a
track has started playing. track has started playing.
""" """
return # TODO-PYKKA Send started_playing event to interested parties
if self.current_track is not None: if self.current_track is not None:
self.backend.core_queue.put({ self.backend.core_queue.put({
'to': 'frontend', 'to': 'frontend',
@ -476,6 +479,7 @@ class PlaybackController(object):
is stopped playing, e.g. at the next, previous, and stop actions and at is stopped playing, e.g. at the next, previous, and stop actions and at
end-of-track. end-of-track.
""" """
return # TODO-PYKKA Send stopped_playing event to interested parties
if self.current_track is not None: if self.current_track is not None:
self.backend.core_queue.put({ self.backend.core_queue.put({
'to': 'frontend', 'to': 'frontend',

View File

@ -1,3 +1,5 @@
from pykka.actor import ThreadingActor
from mopidy.backends.base import (Backend, CurrentPlaylistController, from mopidy.backends.base import (Backend, CurrentPlaylistController,
PlaybackController, BasePlaybackProvider, LibraryController, PlaybackController, BasePlaybackProvider, LibraryController,
BaseLibraryProvider, StoredPlaylistsController, BaseLibraryProvider, StoredPlaylistsController,
@ -5,15 +7,7 @@ from mopidy.backends.base import (Backend, CurrentPlaylistController,
from mopidy.models import Playlist from mopidy.models import Playlist
class DummyQueue(object): class DummyBackend(ThreadingActor, Backend):
def __init__(self):
self.received_messages = []
def put(self, message):
self.received_messages.append(message)
class DummyBackend(Backend):
""" """
A backend which implements the backend API in the simplest way possible. A backend which implements the backend API in the simplest way possible.
Used in tests of the frontends. Used in tests of the frontends.
@ -24,8 +18,6 @@ class DummyBackend(Backend):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(DummyBackend, self).__init__(*args, **kwargs) super(DummyBackend, self).__init__(*args, **kwargs)
self.core_queue = DummyQueue()
self.current_playlist = CurrentPlaylistController(backend=self) self.current_playlist = CurrentPlaylistController(backend=self)
library_provider = DummyLibraryProvider(backend=self) library_provider = DummyLibraryProvider(backend=self)

View File

@ -4,6 +4,8 @@ import multiprocessing
import os import os
import shutil import shutil
from pykka.actor import ThreadingActor
from mopidy import settings from mopidy import settings
from mopidy.backends.base import (Backend, CurrentPlaylistController, from mopidy.backends.base import (Backend, CurrentPlaylistController,
LibraryController, BaseLibraryProvider, PlaybackController, LibraryController, BaseLibraryProvider, PlaybackController,
@ -16,7 +18,7 @@ from .translator import parse_m3u, parse_mpd_tag_cache
logger = logging.getLogger(u'mopidy.backends.local') logger = logging.getLogger(u'mopidy.backends.local')
class LocalBackend(Backend): class LocalBackend(ThreadingActor, Backend):
""" """
A backend for playing music from a local music archive. A backend for playing music from a local music archive.

View File

@ -1,5 +1,7 @@
import logging import logging
from pykka.actor import ThreadingActor
from mopidy import settings from mopidy import settings
from mopidy.backends.base import (Backend, CurrentPlaylistController, from mopidy.backends.base import (Backend, CurrentPlaylistController,
LibraryController, PlaybackController, StoredPlaylistsController) LibraryController, PlaybackController, StoredPlaylistsController)
@ -8,7 +10,7 @@ logger = logging.getLogger('mopidy.backends.spotify')
ENCODING = 'utf-8' ENCODING = 'utf-8'
class SpotifyBackend(Backend): class SpotifyBackend(ThreadingActor, Backend):
""" """
A backend for playing music from the `Spotify <http://www.spotify.com/>`_ A backend for playing music from the `Spotify <http://www.spotify.com/>`_
music streaming service. The backend uses the official `libspotify music streaming service. The backend uses the official `libspotify
@ -59,6 +61,7 @@ class SpotifyBackend(Backend):
self.uri_handlers = [u'spotify:', u'http://open.spotify.com/'] self.uri_handlers = [u'spotify:', u'http://open.spotify.com/']
# TODO-PYKKA: Do setup after actor starts?
self.spotify = self._connect() self.spotify = self._connect()
def _connect(self): def _connect(self):

View File

@ -57,8 +57,7 @@ def setup_mixer():
return get_class(settings.MIXER).start_proxy() return get_class(settings.MIXER).start_proxy()
def setup_backend(): def setup_backend():
# TODO-PYKKA: Convert backend to one or more actors? return get_class(settings.BACKENDS[0]).start_proxy()
return get_class(settings.BACKENDS[0])()
def setup_frontends(): def setup_frontends():
frontends = [] frontends = []