import dbus.service
+import os
from brisa.core import log
+from brisa.upnp.device import Service, ServiceController
+
+pjoin = os.path.join
class PlayListOutBoundExcept(Exception):
def __rep__(self):
return "Play List Out of Bounds!"
-class PlayList(list, dbus.service.Object):
+
+class PlayList(Service):
"""Class PlayList
Introduction
============
Implements a playlist for ZukeBox server.
"""
- DBUS_SERVICE_NAME = "br.org.zagaia.PlayList"
- DBUS_OBJ_PATH = "br/org/zagaia/playlist"
- DBUS_IFACE = "br.org.zagaia.PlayList"
+ service_type = "urn:schemas-upnp-org:service:PlayList:1"
+ service_name = "PlayList"
+
+ def __init__(self, positions=10, xml_path):
+ scpd_path = pjoin(xml_path, "zukebox-playlist-scpd.xml")
+ Service.__init__(self, service_name, service_type, '', scpd_path,
+ PlayListControl(positions))
- def __init__(self, name="", positions=10):
- self.name = name
+class PlayListControl(ServiceController):
+
+ def __init__(self, positions):
self.positions = positions
- # when we create a playlist the current position is first
+ self.list = []
self.current = 0
- def is_locked(self):
- if not len(self) == self.positions:
+ def soap_IsLocked(self, *args, **kwargs):
+ if not len(self.list) == self.positions:
return False
return True
- def is_availble(self):
- if not len(self) == 0:
+ def soap_IsAvailble(self, *args, **kwargs):
+ if not len(self.list) == 0:
return True
return False
- @dbu.service.method(DBUS_IFACE)
- def append(self, obj):
- """Put a object in the playlist"""
+ def soap_Append(self, *args, **kwargs):
+ """Put a object in the playlist
+ """
if not self.is_locked():
log.info("object in playlist")
- self.append(obj)
+
+ self.list.append(obj)
else:
raise PlayListOutBoundExcept()
- @dbus.service.method(DBUS_IFACE)
def drop(self, index):
"""Pop the object at position passed by index
@param index
@type integer
"""
if self.is_availble():
- self.pop(index)
+ self.zplaylist.pop(index)
- @dbus.service.method(DBUS_IFACE)
def get_size(self):
"""Return the size of playlist"""
- return len(self)
+ return len(self.zplaylist)
- @dbus.service.method(DBUS_IFACE)
def clean_playlist(self):
if self.is_availble():
- while len(self) != 0:
- self.pop()
+ self.list = []