Ejemplo n.º 1
0
class UPnPServer:

    """This class implements an extensible UPnP Server."""

    def __init__(self, task_runner, product_name,
                 root_device_config=None, logger=None):
        
        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)
        
        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr, self._ssdp_server,
                                  self._http_server, self._ed, device,
                                  product_name, logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids
        
        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)

    def get_presentation_url(self):
        root = self.get_root_device()
        return root.base_url + root.get_presentation_url()

    def announce(self):
        """Causes underlying SSDPServer to re-announce itself."""
        self._tr.add_task(self._ssdp_server.announce)

    def close(self):
        """Close the UPnP server."""
        self._sm.close()
        self._ssdp_server.close()
        self._http_server.close()
        self._ed.close()
Ejemplo n.º 2
0
    def __init__(self,
                 task_runner,
                 product_name,
                 root_device_config=None,
                 logger=None):

        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)

        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr,
                                  self._ssdp_server,
                                  self._http_server,
                                  self._ed,
                                  device,
                                  product_name,
                                  logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids

        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)
Ejemplo n.º 3
0
    def __init__(self, task_runner, product_name,
                 root_device_config=None, logger=None):
        
        # TaskRunner
        self._tr = task_runner

        # Logger
        self._logger = _Logger(logger)

        # Initalise Root Device
        if not root_device_config:
            self._root_device_config = DEFAULT_ROOT_DEVICE_CONFIG
        else:
            self._root_device_config = root_device_config
        device = upnpdevice.UPnPDevice(self._root_device_config)
        device.set_is_root(True)
        
        # Event Dispatcher (HTTP Client)
        self._ed = EventDispatcher(self._tr, logger=self._logger)

        # HTTP Server
        self._http_server = HTTPServer(self._tr, logger=self._logger)

        # SSDP Server
        self._ssdp_server = SSDPServer(self._tr, logger=self._logger)

        # ServiceManager (The Core)
        self._sm = ServiceManager(self._tr, self._ssdp_server,
                                  self._http_server, self._ed, device,
                                  product_name, logger=self._logger)

        # Export Service Manager API
        self.add_service = self._sm.add_service
        self.get_service = self._sm.get_service
        self.get_service_ids = self._sm.get_service_ids
        
        # Export Internals
        self.get_root_device = self._sm.get_root_device

        # Startup done by TaskRunner
        self._tr.add_task(self._sm.startup)