예제 #1
0
    def init_host(self, device, service_id, configid = None):
        """
Initializes a host service.

:param device: Host device this UPnP service is added to
:param service_id: Unique UPnP service ID
:param configid: UPnP configId for the host device

:return: (bool) Returns true if initialization was successful.
:since:  v0.2.00
        """

        self.configid = configid
        self.host_service = True
        self.service_id = service_id
        self.udn = device.get_udn()

        self.url_base = "{0}{1}/".format(device.get_url_base(), Link.encode_query_value(service_id))
        self.url_control = "{0}control".format(self.url_base)
        self.url_event_control = "{0}eventsub".format(self.url_base)
        self.url_scpd = "{0}xml".format(self.url_base)

        self._init_host_actions(device)
        self._init_host_variables(device)

        Hook.call("dNG.pas.upnp.Service.initHost", device = device, service = self)
        Hook.register_weakref("dNG.pas.upnp.Gena.onRegistered", self._on_gena_registration)

        return ((len(self.actions) + len(self.variables)) > 0)
예제 #2
0
    def _init(self):
        """
Initializes the dispatcher and stopping hook.

:since: v0.2.00
        """

        if (self.log_handler is not None): self.log_handler.debug("#echo(__FILEPATH__)# -{0!r}._init()- (#echo(__LINE__)#)", self, context = "pas_server")

        if (self.stopping_hook is not None):
            stopping_hook = ("dNG.pas.Status.onShutdown" if (self.stopping_hook == "") else self.stopping_hook)
            Hook.register_weakref(stopping_hook, self.thread_stop)
예제 #3
0
    def start(self, params = None, last_return = None):
        """
Start the timed tasks implementation.

:param params: Parameter specified
:param last_return: The return value from the last hook called.

:since: v0.2.00
        """

        if (not self.timer_active):
            with self.lock:
                # Thread safety
                if (not self.timer_active):
                    Hook.register_weakref("dNG.pas.Status.onShutdown", self.stop)

                    self.timer_active = True
                    self.timer_timestamp = -1
                    self.update_timestamp()
예제 #4
0
    def __init__(self):
        """
Constructor __init__(GlibThread)

:since: v0.2.00
        """

        Thread.__init__(self)

        self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
        """
The LogHandler is called whenever debug messages should be logged or errors
happened.
        """
        self.mainloop = None
        """
Active mainloop instance
        """

        Hook.register_weakref("dNG.pas.Status.onShutdown", self.stop)
예제 #5
0
    def init_host(self, device, service_id = None, configid = None):
        """
Initializes a host service.

:param device: Host device this UPnP service is added to
:param service_id: Unique UPnP service ID
:param configid: UPnP configId for the host device

:return: (bool) Returns true if initialization was successful.
:since:  v0.2.00
        """

        self.type = "ContentDirectory"
        self.upnp_domain = "schemas-upnp-org"
        self.version = "4"

        if (service_id is None): service_id = "ContentDirectory"

        Hook.register_weakref("dNG.pas.upnp.Resource.onUpdateIdChanged", self._on_updated_id)
        Hook.register_weakref("dNG.pas.upnp.services.ContentDirectory.onSystemUpdateIdChanged", self._on_updated_id)

        return AbstractService.init_host(self, device, service_id, configid)
예제 #6
0
    def __init__(self):
        """
Constructor __init__(AbstractServer)

:since: v1.0.0
        """

        Thread.__init__(self)

        self.host = None
        """
Configured server host
        """
        self._log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
        """
The LogHandler is called whenever debug messages should be logged or errors
happened.
        """
        self.port = None
        """
Configured server port
        """
        self.socket_hostname = None
        """
Socket server hostname
        """

        socket_hostname = getfqdn()

        try:
            getaddrinfo(socket_hostname, None)
            self.socket_hostname = socket_hostname
        except socket_error: self.socket_hostname = gethostname()

        self.socket_hostname = self.socket_hostname.lower()

        Hook.register_weakref("dNG.pas.http.Server.getHost", self.get_host)
        Hook.register_weakref("dNG.pas.http.Server.getPort", self.get_port)