"""Author: Changbeom Choi (@cbchoi)Copyright (c) 2014-2020 Handong Global UniversityCopyright (c) 2021-2024 Hanbat National UniversityLicense: MIT. The full license text is available at:https://github.com/eventsim/pyjevsim/blob/main/LICENSEThis module contains an object SysMessage for handling messages (port and data) between Models. """from.system_objectimportSystemObject
[docs]classSysMessage(SystemObject):"""SysMessage for handling messages(port and data) between Models."""def__init__(self,src_name="",dst_name=""):""" Args: src_name (str): The source name(Model name) dst_name (str): The destination name(port) """super().__init__()self._src=src_name# Source name(Model)self._dst=dst_name# Destination name(port)self._msg_time=-1# Message timeself._msg_list=[]# List of messagesdef__str__(self):""" Returns the string representation of the message. Returns: str: The string representation """returnsuper().__str__()+f"\tSRC:{self._src}\t DST:{self._dst}"
[docs]definsert(self,msg):""" Inserts a message into the message list(data). Args: msg (any): The message to insert """self._msg_list.append(msg)
[docs]defextend(self,_list):""" Extends the message list with multiple messages. Args: _list (list): The list of messages to add """self._msg_list.extend(_list)
[docs]defretrieve(self):""" Retrieves the list of messages. Returns: list: The list of messages """returnself._msg_list
[docs]defget_src(self):""" Returns the source(model) name of the message. Returns: str: The source name """returnself._src
[docs]defget_dst(self):""" Returns the destination(port) name of the message. Returns: str: The destination(port) name """returnself._dst
[docs]defset_msg_time(self,_time):""" Sets the message time. Args: _time (float): The time to set """self._msg_time=_time
[docs]defget_msg_time(self):""" Returns the message time. Returns: float: The message time """returnself._msg_time