def signalControllerStart(self, signal, sender, **data):
        """
        Called to handle the EVT_DIRECTOR_CTRLSTART signal, which
        is used to return the result of a start command.

        :param data['data]: This will contain the name of the
        controller to be started. This name is the same name
        as that in the configuration section.

        :returns: a call result dict.

            rc['result'] = 'ok' | 'error'

            For ok result:

            rc['data'] = ''

            For error result:

            rc['data'] = 'Error / Exception message'

        Note: this will contain every controller except the
        director controller.

        Event Dispatched: EVT_DIRECTOR_CTRLSTART

        """
        msg = ''
        try:
            self.log.debug("signalControllerStart: received request (sig id %s)." % signal.uid)
            name = data['data']

            c = config.get_cfg()
            for ctrl in c.cfg:
                if ctrl.name == name:
                    if ctrl.disabled == "yes":
                        msg = "The controller '%s' is disabled and cannot be started" % name
                    else:
                        # indicate we're that the process should be start
                        # if it stops or exits.
                        #
                        ctrl.wasStopped = False
                        ctrl.mod.start()
                        msg = "Service '%s' start called." % ctrl.name

                    break

        except:
            self.log.exception("signalControllerStart: error handling signal (sig id %s) - " % signal.uid)
            msg = self.formatError()
            rc = self.resultDict(msg, 'error')

        else:
            rc = self.resultDict(msg)

        self.log.debug("signalControllerStart: replying to request (sig id %s) - " % signal.uid)
        messenger.reply(signal, rc)
    def reply(self, messenger_event, data):
        """Called to handle the reply for a VIEWPOINT_* command event.
        """
        # The uid of the signal is used as the 'address' that
        # a reply goes back to. We'll forward the replyto which
        # the xul browser will return to us later. The method
        # dataReceived then deal with the business of sending a
        # reply.
        reply_to = messenger_event.uid

        self.log.debug("replyTo: dispatching reply to <%s:%s>." %
                       (messenger_event, reply_to))

        messenger.reply(messenger_event, data)
    def reply(self, messenger_event, data):
        """Called to handle the reply for a VIEWPOINT_* command event.
        """
        # The uid of the signal is used as the 'address' that
        # a reply goes back to. We'll forward the replyto which
        # the xul browser will return to us later. The method
        # dataReceived then deal with the business of sending a
        # reply.
        reply_to = messenger_event.uid

        self.log.debug("replyTo: dispatching reply to <%s:%s>." % (
            messenger_event, reply_to
        ))

        messenger.reply(messenger_event, data)
    def signalExit(self, signal, sender, **data):
        """
        Called to handle the EVT_DIRECTOR_EXIT_ALL signal, which tells
        the director to shutdown normally.

        """
        self.log.warn("signalExit: EVT_DIRECTOR_EXIT_ALL received, exiting...")
        rc = self.resultDict('ok')
        messenger.reply(signal, rc)

        # allow time for message to reply of make its
        # way out of director process if needs be.
        time.sleep(2)
        self.log.warn("signalExit: calling manager exit.")
        self.manager.exit()
        self.log.warn("signalExit: bye, bye.")
    def signalPing(self, signal, sender, **data):
        """
        Called to handle the EVT_DIRECTOR_PING signal, which is
        used by other to see if the director is present and
        responding to signals.

        :param data['data]: should contain some string the callee
        wished to receive back. If the SignalsSender.ping() was
        called then this will be a uuid string. The ping function
        will warn if the same uuid is not returned.

        :returns: a call result dict.

            rc['result'] = 'ok'

            rc['data'] = the token we were given.

        """
        rtoken = data['data']
        self.log.debug("main: EVT_DIRECTOR_PING received token '%s' replying with same." % (rtoken))
        messenger.reply(signal, self.resultDict(rtoken))
    def signalConfiguration(self, signal, sender, **data):
        """
        Called to handle the EVT_DIRECTOR_CONFIGURATION signal, which
        is used to return the current director configuration.

        :param data['data]: None

        :returns: a call result dict.

            rc['result'] = 'ok' | 'error'

            For ok result:

            rc['data'] = [...]

            For error result:

            rc['data'] = 'Error / Exception message'

        Event Dispatched: EVT_DIRECTOR_CONFIGURATION

        """
        msg = ''
        cfg = None
        try:
            self.log.debug("signalConfiguration: received request (sig id %s)." % signal.uid)
            cfg = config.export_configuration()

        except:
            self.log.exception("signalConfiguration: error handling signal (sig id %s) - " % signal.uid)
            msg = self.formatError()
            rc = self.resultDict(msg, 'error')

        else:
            rc = self.resultDict(cfg)

        self.log.debug("signalConfiguration: replying to request (sig id %s) - " % signal.uid)
        messenger.reply(signal, rc)
    def signalControllerState(self, signal, sender, **data):
        """
        Called to handle the EVT_DIRECTOR_CTRLSTATE signal, which
        is used to return the state of all controllers listed in
        the configuration.

        :param: None

        :returns: a call result dict.

            rc['result'] = 'ok' | 'error'

            For ok result:

            rc['data'] = [
                dict(name='..name..', disabled='no'|'yes', started=False | True, config={...}),
                :
                etc
            ]

            For error result:

            rc['data'] = 'Error / Exception message'

        Note: this will contain every controller except the
        director controller.

        Event Dispatched: EVT_DIRECTOR_CTRLSTATE

        """
        controller_state = []
        try:
            self.log.debug("controllerState: received request (sig id %s)." % signal.uid)

            c = config.get_cfg()

            for ctrl in c.cfg:
                if ctrl.name == 'director':
                    # skip the director as its not a normal controller.
                    continue

                # Recover the config for just this controller:
                ctrl_config = {}
                if ctrl.config:
                    ctrl_config = ctrl.config

                # Check if the controller module is present and actually running.
                started = False
                if ctrl.mod:
                    started = ctrl.mod.isStarted()

                controller_state.append(dict(
                    name=ctrl.name,
                    disabled=ctrl.disabled,
                    started=started,
                    config=ctrl_config,
                ))

        except:
            self.log.exception("controllerState: error handling signal (sig id %s) - " % signal.uid)
            msg = self.formatError()
            rc = self.resultDict(msg, 'error')

        else:
            rc = self.resultDict(controller_state)

        self.log.debug("controllerState: replying to request (sig id %s) - " % signal.uid)
        messenger.reply(signal, rc)
            else:
                msg = True

        except:
            self.log.exception("signalControllerReload: error handling signal (sig id %s) - " % signal.uid)
            msg = self.formatError()
            rc = self.resultDict(msg, 'error')

        else:
            rc = self.resultDict(msg)
            if error:
                rc = self.resultDict(msg, 'error')

        self.log.debug("signalControllerReload: replying to request (sig id %s) - " % signal.uid)
        messenger.reply(signal, rc)

    def signalConfiguration(self, signal, sender, **data):
        """
        Called to handle the EVT_DIRECTOR_CONFIGURATION signal, which
        is used to return the current director configuration.

        :param data['data]: None

        :returns: a call result dict.

            rc['result'] = 'ok' | 'error'

            For ok result:

            rc['data'] = [...]