"""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 Message Receive Model """frompyjevsim.behavior_modelimportBehaviorModelfrompyjevsim.definitionimport*frompyjevsim.system_messageimportSysMessage
[docs]classMsgRecv(BehaviorModel):"""Message Receiver Model that handles simulation events."""def__init__(self,name):""" Args: name (str): The name of the message receiver """BehaviorModel.__init__(self,name)self.init_state("Wait")# Initialize initial stateself.insert_state("Wait",Infinite)# Add "Wait" stateself.insert_input_port("recv")# Add input port "recv"self.msg_recv=0# Initialize message received count
[docs]defext_trans(self,port,msg):""" Handles external transitions based on the input port. Args: port (str): The port that received the message msg (SysMessage): The received message """ifport=="recv":self._cur_state="Wait"# Remain in "Wait" statedata=msg.retrieve()# Retrieve message dataprint(f"[MsgRecv][IN]: {data[0]}")# Print received messageself.msg_recv+=1# Increment received message count
[docs]defoutput(self,msg_deliver):"""No output function for MsgRecv."""returnNone
[docs]defint_trans(self):"""Handles internal transitions based on the current state."""ifself._cur_state=="Wait":self._cur_state="Wait"# Remain in "Wait" state