def answer_argue_item(self, message):
     """TODO.
     """
     sender = message.get_sender()
     received_argument = message.get_content()
     self.__used_arguments.append(received_argument)
     item = received_argument.get_item()
     is_positive = not received_argument.is_positive_argument()
     argument = self.argue_item(item, is_positive=is_positive)
     if argument is not None:
         self.__used_arguments.append(argument)
         answer = Message(self, sender, MessagePerformative.ARGUE, argument)
     else:
         non_proposed_items = self.get_non_proposed_items()
         if len(non_proposed_items) > 0:
             item = self.__preferences.most_preferred(non_proposed_items)
             self.__proposed_item.append(item)
             self.__was_proposed_to_me.append(False)
             answer = Message(self, sender, MessagePerformative.PROPOSE,
                              item)
         else:
             item = self.get_least_worst_proposed_item()
             answer = Message(self, sender, MessagePerformative.ACCEPT,
                              item)
     return answer
예제 #2
0
 def __init__(self, sender, receiver, message):
     '''
         sender: NodeFunction sender
         receiver: NodeVariable receiver
         message: list of the message's values
     '''
     Message.__init__(self, sender, receiver, message)
def getMessageFromJSON(aadl_namespace, aadl_type, json_source, associated_class):
    file_path = os.path.join(json_default_path, json_source)

    try:
        parsed = json.load(open(file_path))
    except json.JSONDecodeError:
        log.error("Unable to load JSON file {}".format(file_path))
        return None

    # new_msg_header = list(parsed.keys())[0]

    message = Message(aadl_namespace, aadl_type)

    # parameters_asn = parsed[new_msg_header]['values']

    for key, value in parsed["properties"].items():
        var = Variable()
        var.setName(key)
        # TODO string format + nested messages
        var.setType(getROSMsgtypeFromJSON(value["type"], associated_class))
        var.setIsParameter()

        message.addParameter(var)

    # Aggiungo il messaggio al suo relativo system
    message.system.addMessage(message)

    return message
예제 #4
0
 def receive(self, message, address):
     m = Message()
     m.bits = message
     if m.getType() == m.DATA:
         dm = DataMessage()
         dm.bits = message
         self.wrapperLayer.receive(dm.getSenderID(), dm.getMetaData(),
                                   dm.getData())
 def send_message(self, receiver, performative, content):
     """Sends a message given a receiver, a performative and a content.
     """
     message = Message(self, receiver, performative, content)
     message.send()
     answer = self.recv(receiver.get_channel())
     if message.needs_answer():
         self.treat_answer(answer)
예제 #6
0
    def enqueue(self, p, d):
        def validate(d):
            pass

        validate(d)
        msg = Message.decode(d)
        self.Inbound.Push(msg)
 def answer_query_ref(self, message):
     """Answers to QUERY_REF performative.
     """
     receiver = message.get_sender()
     performative = MessagePerformative.INFORM_REF
     content = self.__list_items
     return Message(self, receiver, performative, content)
 def answer_accepted_item(self, message):
     """TODO.
     """
     sender = message.get_sender()
     item = message.get_content()
     answer = Message(self, sender, MessagePerformative.COMMIT, item)
     return answer
 def answer_proposed_item(self, message):
     """Answers to a proposed Item.
     """
     sender = message.get_sender()
     proposed_item = message.get_content()
     self.__proposed_item.append(proposed_item)
     self.__was_proposed_to_me.append(True)
     is_accepted = self.__preferences.belongs_to_10percent_most_preferred(
         proposed_item, self.__list_items)
     if is_accepted:
         answer = Message(self, sender, MessagePerformative.ACCEPT,
                          proposed_item)
         return answer
     else:
         answer = Message(self, sender, MessagePerformative.ASK_WHY,
                          proposed_item)
         return answer
예제 #10
0
파일: Client.py 프로젝트: avlec/tdo
 def error():
     errMessage = Message('0000000000000000', '0000000000000000', 'server',
                          '0000000000000000',
                          'connection to server lost, shuting down',
                          'message').encode()
     # print(errMessage)
     C.print_message(errMessage)
     sys.exit(0)
예제 #11
0
파일: Client.py 프로젝트: avlec/tdo
 def get_input(self, p):
     while True:
         msg = None
         if self.gui:
             msg = self.gui.messageQueue.Pop()
         if msg:
             if self.command(msg):
                 return Message(CommonUtil.createID(), self.id, self.alias,
                                self.currentChannel, msg,
                                'command').encode()
             elif re.match(r'\/.+', msg):
                 print('commands info:'
                       )  # add a print out of all commands info
             else:
                 return Message(CommonUtil.createID(), self.id, self.alias,
                                self.currentChannel, msg,
                                'message').encode()
예제 #12
0
    async def run(self):
        msg = Message(Robot(), IsWithin(), Distance())

        while True:

            raise NotImplemented
            # get the data
            current_distance = self.__get_distance_reading()

            await self.queue.put(msg)
 def answer_ask_why_item(self, message):
     """TODO.
     """
     sender = message.get_sender()
     item = message.get_content()
     argument = self.argue_item(item, is_positive=True)
     if argument is not None:
         self.__used_arguments.append(argument)
         answer = Message(self, sender, MessagePerformative.ARGUE, argument)
     else:
         non_proposed_items = self.get_non_proposed_items()
         if len(non_proposed_items) > 0:
             item = self.__preferences.most_preferred(non_proposed_items)
             answer = Message(self, sender, MessagePerformative.PROPOSE,
                              item)
         else:
             item = self.get_least_worst_proposed_item()
             answer = Message(self, sender, MessagePerformative.ACCEPT,
                              item)
     return answer
    async def run(self):

        msg = Message(Robot(), HasHeading(), Bearing())

        while True:

            raise NotImplemented
            # get the data
            current_heading = self.__get_compass_reading()

            await self.queue.put(msg)
 def answer_commited_item(self, message):
     """Answer to a commit message.
     """
     sender = message.get_sender()
     item = message.get_content()
     if item not in self.__selected_items:
         self.add_selected_item(item)
         answer = Message(self, sender, MessagePerformative.COMMIT, item)
         return answer
     else:
         self.send_take_item(self.__manager, item)
         return
예제 #16
0
파일: Client.py 프로젝트: avlec/tdo
 def print_message(self, data):
     msg = Message.decode(data)
     # print(msg.senderAlias + ':' + msg.message)
     self.gui.updateChat(msg.senderAlias + ':' + msg.message + '\n',
                         'black', msg.messageId)
예제 #17
0
def welcome_message():
    msg = Message('0000000000000000', '0000000000000000', 'server',
                  '0000000000000000', 'welcome to TDO communication services',
                  'message')
    return msg
예제 #18
0
 def test_encode_then_decode(self):
     msg = Message("0000000000000000", "0000000000000000", "server",
                   "0000000000000000", "Hello world.", "message")
     enc = msg.encode()
     dec = Message.decode(enc)
     self.assertDictEqual(msg.__dict__, dec.__dict__)
예제 #19
0
 def getMessageFromTelegramMsg(telegram_msg):
     chat = Chat.from_telegram_msg(telegram_msg)
     from_ = From.from_telegram_msg(telegram_msg)
     message = Message(telegram_msg["message_id"], telegram_msg["date"],
                       telegram_msg["text"], chat, from_)
     return message