backends: Add BackendListener interface with playlists_loaded() event

This commit is contained in:
Stein Magnus Jodal 2012-11-17 00:53:45 +01:00
parent 9fbb797607
commit 0f6c9a1673
3 changed files with 52 additions and 0 deletions

View File

@ -33,6 +33,13 @@ Library provider
:members:
Backend listener
================
.. autoclass:: mopidy.backends.listener.BackendListener
:members:
.. _backend-implementations:
Backend implementations

View File

@ -0,0 +1,32 @@
from __future__ import unicode_literals
import pykka
class BackendListener(object):
"""
Marker interface for recipients of events sent by the backend actors.
Any Pykka actor that mixes in this class will receive calls to the methods
defined here when the corresponding events happen in the core actor. This
interface is used both for looking up what actors to notify of the events,
and for providing default implementations for those listeners that are not
interested in all events.
Normally, only the Core actor should mix in this class.
"""
@staticmethod
def send(event, **kwargs):
"""Helper to allow calling of backend listener events"""
listeners = pykka.ActorRegistry.get_by_class(BackendListener)
for listener in listeners:
getattr(listener.proxy(), event)(**kwargs)
def playlists_loaded(self):
"""
Called when playlists are loaded or refreshed.
*MAY* be implemented by actor.
"""
pass

View File

@ -0,0 +1,13 @@
from __future__ import unicode_literals
from mopidy.backends.listener import BackendListener
from tests import unittest
class CoreListenerTest(unittest.TestCase):
def setUp(self):
self.listener = BackendListener()
def test_listener_has_default_impl_for_playlists_loaded(self):
self.listener.playlists_loaded()