Exemple #1
0
    def _set_ref_count(self, new_value):
        """Set a new value to ref_count."""
        logger.debug("ref_count is %r, changing value to %r.", self._ref_count, new_value)
        if new_value < 0:
            self._ref_count = 0
            msg = "Attempting to decrease ref_count to a negative value (%r)."
            logger.warning(msg, new_value)
        else:
            self._ref_count = new_value

        if self._ref_count == 0:
            logger.debug("Setting up timer with %r (%r, %r).", self.timeout_func, TIMEOUT_INTERVAL, self.shutdown)
            self.timeout_func(TIMEOUT_INTERVAL, self.shutdown)
Exemple #2
0
    def __call__(self, *args, **kwargs):
        """Call this instance."""
        app_name = args[0] if len(args) > 0 else None
        logger.debug('Handling signal_name: %r, app_name: %r.',
                     self.signal_name, app_name)

        if app_name != APP_NAME:
            # This fixed bug #818190: filter signals not related to APP_NAME
            logger.info('Received %r but app_name %r does not match %r, ' \
                        'exiting.', self.signal_name, app_name, APP_NAME)
            return

        if self.callback is not None:
            # drop the app name, callers do not care about it
            args = args[1:]
            logger.debug('Calling %r with %d args and %d kwargs.',
                         self.callback, len(args), len(kwargs))
            return self.callback(*args, **kwargs)
Exemple #3
0
    def _signal_handler(self, *args, **kwargs):
        """Generic signal handler."""
        member = kwargs.get("member", None)
        app_name = args[0] if len(args) > 0 else None
        logger.debug("Handling DBus signal for member: %r, app_name: %r.", member, app_name)

        if app_name != APP_NAME:
            logger.info("Received %r but app_name %r does not match %r, " "exiting.", member, app_name, APP_NAME)
            return

        sig = getattr(self, member)

        if member in ("CredentialsFound", "CredentialsError"):
            # this are the only signals that will forward the parameter
            logger.info("%r", member)
            arg = args[1]
            sig(arg)
        else:
            sig()
Exemple #4
0
 def shutdown(self):
     """If no ongoing requests, call self.shutdown_func."""
     logger.debug("shutdown!, ref_count is %r.", self._ref_count)
     if self._ref_count == 0:
         logger.info("Shutting down, calling %r.", self.shutdown_func)
         self.shutdown_func()