Exemple #1
0
    def _get_message(self):
        """
        Return the first message in the queue.
        """

        if len(self.queue) == 0:
            return

        message = self.queue.pop(0)  # .get()

        # If this is a raw message string, convert it to a RobotMessage
        # instance
        if type(message) == str:

            try:
                m = RobotMessage()
                m.from_string(message)
                message = m
            except exceptions.BotMessageError as err:
                message = "Mangled message ({})".format(err.args[0])
                self._queue_message(message, destination_device="warn")
                return None

        if self.verbosity > 0:
            message.pretty_print()

        return message
Exemple #2
0
    def _queue_message(self,
                       message="",
                       destination_device="controller",
                       destination="",
                       delay_time=0.0,
                       msg_string=None):
        """
        Append to a RobotMessage instance to self._messages in a thread-safe
        manner.  Automatically set the source and source device.  Take args
        to set other attributes.
        """


        if type(message) != RobotMessage:

            m = RobotMessage(destination=destination,
                             destination_device=destination_device,
                             source="robot",
                             source_device=self.name,
                             delay_time=delay_time,
                             message=message)

            # If msg_string is set to something besides None, parse that string
            # and load into the RobotMessage instance.
            if msg_string != None:
                m.from_string(msg_string)
            message = m
                
        with self._lock:
            self._messages.append(message)             
Exemple #3
0
    def _queue_message(self, message="", destination="robot", destination_device="", delay_time=0.0, msg_string=None):
        """
        Append to a RobotMessage instance to to the message queue.  If message
        is already a RobotMessage, pass it through without modification.  If it
        is a string, construct the RobotMessage, setting source to "manager".
        """

        if type(message) != RobotMessage:

            m = RobotMessage(
                destination=destination,
                destination_device=destination_device,
                source="manager",
                source_device="",
                delay_time=delay_time,
                message=message,
            )

            # If msg_string is set to something besides None, parse that string
            # and load into the RobotMessage instance.
            if msg_string != None:
                m.from_string(msg_string)

            message = m

        if self.verbosity > 0:
            message.pretty_print()

        self.queue.append(message)  # .put(message)