Browse Source

rever the queuing for SSDP, when using startService properly, it

isn't necessary...

make the mimetype function work..

do the notifies as part of startService which will get called once
the protocol is up...

[git-p4: depot-paths = "//depot/": change = 1277]
main
John-Mark Gurney 16 years ago
parent
commit
35961f5095
2 changed files with 38 additions and 43 deletions
  1. +2
    -11
      SSDP.py
  2. +36
    -32
      pymeds.py

+ 2
- 11
SSDP.py View File

@@ -42,16 +42,12 @@ class SSDPServer(DatagramProtocol):
def __init__(self):
# XXX - no init?
#DatagramProtocol.__init__(self)
self.__notifyqueue = []
pass

def startProtocol(self):
self.transport.joinGroup(SSDP_ADDR)
# so we don't get our own sends
self.transport.setLoopbackMode(0)
self.doNotify = self.realdoNotify
for i in self.__notifyqueue:
self.doNotify(i)
self.__notifyqueue = None

def doStop(self):
'''Make sure we send out the byebye notifications.'''
@@ -156,12 +152,7 @@ class SSDPServer(DatagramProtocol):
self.transport.write(resp, (SSDP_ADDR, SSDP_PORT))
self.transport.write(resp, (SSDP_ADDR, SSDP_PORT))

def queueDoNotify(self, st):
self.__notifyqueue.append(st)

doNotify = queueDoNotify

def realdoNotify(self, st):
def doNotify(self, st):
"""Do notification"""

log.msg('Sending alive notification for %s' % st)


+ 36
- 32
pymeds.py View File

@@ -83,14 +83,11 @@ class Options(usage.Options):
'port must be between 1024 and 65535')
self['port'] = port

class PyMedS(service.MultiService):
def startService(self):
service.MultiService.startService(self)

def fixupmimetypes()
def fixupmimetypes():
# Purely to ensure some sane mime-types. On MacOSX I need these.
# XXX - There isn't any easier way to get to the mime-type dict
# that I know of.
from twisted.web import static
medianode = static.File('pymediaserv')
medianode.contentTypes.update( {
# From: http://support.microsoft.com/kb/288102
@@ -123,17 +120,6 @@ def makeService(config):
listenAddr = config['addr']
listenPort = config['port']

serv = service.MultiService()

# Create SSDP server
from SSDP import SSDPServer, SSDP_PORT

s = SSDPServer()
debug.insertnamespace('s', s)

internet.MulticastServer(SSDP_PORT, s,
listenMultiple=True).setServiceParent(serv)

uuid = config.get('uuid', None)
if uuid is None:
uuid = generateuuid()
@@ -168,7 +154,7 @@ def makeService(config):
# This sets up the root to be the media dir so we don't have to
# enumerate the directory.
cds = ContentDirectoryServer(config['title'], klass=FSDirectory,
path=config['path'], urlbase=urlparse.urljoin(urlbase, 'content'),
path=config['path'], urlbase=urlparse.urljoin(urlbase, 'content/'),
webbase=content)
debug.insertnamespace('cds', cds)
root.putChild('ContentDirectory', cds)
@@ -177,28 +163,46 @@ def makeService(config):
root.putChild('root-device.xml', RootDevice())
root.putChild('content', content)


fixupmimetypes()

site = server.Site(root)
internet.TCPServer(listenPort, site).setServiceParent(serv)

# we need to do this after the children are there, since we send notifies
rdxml = urlparse.urljoin(urlbase, 'root-device.xml')
s.register('%s::upnp:rootdevice' % uuid,
'upnp:rootdevice', rdxml)
# Create SSDP server
from SSDP import SSDPServer, SSDP_PORT

s = SSDPServer()
debug.insertnamespace('s', s)

class PyMedS(service.MultiService):
def startService(self):
service.MultiService.startService(self)

rdxml = urlparse.urljoin(urlbase, 'root-device.xml')
s.register('%s::upnp:rootdevice' % uuid,
'upnp:rootdevice', rdxml)

s.register(uuid,
uuid,
rdxml)
s.register(uuid,
uuid,
rdxml)

s.register('%s::urn:schemas-upnp-org:device:MediaServer:1' % uuid,
'urn:schemas-upnp-org:device:MediaServer:1', rdxml)
s.register('%s::urn:schemas-upnp-org:device:MediaServer:1' % uuid,
'urn:schemas-upnp-org:device:MediaServer:1', rdxml)

s.register('%s::urn:schemas-upnp-org:service:ConnectionManager:1' % uuid,
'urn:schemas-upnp-org:device:ConnectionManager:1', rdxml)
s.register('%s::urn:schemas-upnp-org:service:ConnectionManager:1' % uuid,
'urn:schemas-upnp-org:device:ConnectionManager:1', rdxml)

s.register('%s::urn:schemas-upnp-org:service:ContentDirectory:1' % uuid,
'urn:schemas-upnp-org:device:ContentDirectory:1', rdxml)
s.register('%s::urn:schemas-upnp-org:service:ContentDirectory:1' % uuid,
'urn:schemas-upnp-org:device:ContentDirectory:1', rdxml)

def stopService(self):
# Some reason stopProtocol isn't called
s.doStop()
service.MultiService.stopService(self)

serv = PyMedS()

internet.TCPServer(listenPort, site).setServiceParent(serv)
internet.MulticastServer(SSDP_PORT, s,
listenMultiple=True).setServiceParent(serv)

return serv

Loading…
Cancel
Save