backends: Add BackendListener interface with playlists_loaded() event
This commit is contained in:
parent
9fbb797607
commit
0f6c9a1673
@ -33,6 +33,13 @@ Library provider
|
||||
:members:
|
||||
|
||||
|
||||
Backend listener
|
||||
================
|
||||
|
||||
.. autoclass:: mopidy.backends.listener.BackendListener
|
||||
:members:
|
||||
|
||||
|
||||
.. _backend-implementations:
|
||||
|
||||
Backend implementations
|
||||
|
||||
32
mopidy/backends/listener.py
Normal file
32
mopidy/backends/listener.py
Normal 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
|
||||
13
tests/backends/listener_test.py
Normal file
13
tests/backends/listener_test.py
Normal 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()
|
||||
Loading…
Reference in New Issue
Block a user