KENSv3
KAIST Educational Network System
Classes | Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
E::Module Class Reference

Module is an interface for classes which can send/receive Message to/from the System. More...

#include <E_Module.hpp>

Inheritance diagram for E::Module:
E::NetworkModule E::Wire E::Host E::Link E::Hub E::Switch

Classes

class  EmptyMessage
 
class  MessageBase
 Interface of Message. Every message implementation must inherit this class. More...
 

Public Types

using Message = std::unique_ptr< MessageBase >
 

Public Member Functions

 Module (System &system)
 Module must belong to a System. Module is registered to a System when it is created. More...
 
std::string getModuleName ()
 
std::string getModuleName (const ModuleID moduleID)
 
Time getCurrentTime ()
 

Protected Member Functions

virtual Module::Message messageReceived (const ModuleID from, Module::MessageBase &message)
 This is a callback function called by the System. This function is automatically called when you received a Message. If you want to handle Message, override this function with your own handler. More...
 
virtual void messageFinished (const ModuleID to, Message message, Module::MessageBase &response)
 This is a callback function called by the System. This function is automatically called after your message is processed by the destination module. If you want to handle Message, override this function with your own handler. YOU MUST DEALLOCATE EVERY SUCCESSFUL MESSAGE YOU ALLOCATED JUST HERE. INSTANT RESPONSE messages(return value of messageReceived) are also deallocated here. SELF messages are also deallocated here. More...
 
virtual void messageCancelled (const ModuleID to, Message message)
 This is a callback function called by the System. This function is automatically called when the message is cancelled before it is processed. This function is called AT THE TIME WHEN THE MESSAGE WAS SUPPOSED TO BE SENT. If you want to handle Message, override this function with your own handler. YOU MUST DEALLOCATE EVERY CANCELLED MESSAGE YOU ALLOCATED JUST HERE. More...
 
virtual UUID sendMessage (const ModuleID to, Module::Message message, Time timeAfter) final
 Send a Message to other Module. Every message has its own delay before it is actually sent. The System guarantees the total ordering of all delayed messages in the System. More...
 
virtual UUID sendMessageSelf (Module::Message message, Time timeAfter) final
 Send a Message to self Every message has its own delay before it is actually sent. The System guarantees the total ordering of all delayed messages in the System. More...
 
virtual bool cancelMessage (UUID messageID) final
 Cancel the raised Message. If a message is not actually sent yet, you can cancel the message. If the message is already sent, this function has no effect. More...
 

Friends

class System
 

Detailed Description

Module is an interface for classes which can send/receive Message to/from the System.

See also
System

Constructor & Destructor Documentation

◆ Module()

E::Module::Module ( System system)

Module must belong to a System. Module is registered to a System when it is created.

Parameters
systemSystem to be registered.

Member Function Documentation

◆ cancelMessage()

bool E::Module::cancelMessage ( UUID  messageID)
finalprotectedvirtual

Cancel the raised Message. If a message is not actually sent yet, you can cancel the message. If the message is already sent, this function has no effect.

Parameters
messageIDUnique ID that represents the target Message to be cancelled.
Returns
Whether the cancellation is successful.
Note
You cannot override this function.
See also
sendMessage

◆ messageCancelled()

virtual void E::Module::messageCancelled ( const ModuleID  to,
Message  message 
)
inlineprotectedvirtual

This is a callback function called by the System. This function is automatically called when the message is cancelled before it is processed. This function is called AT THE TIME WHEN THE MESSAGE WAS SUPPOSED TO BE SENT. If you want to handle Message, override this function with your own handler. YOU MUST DEALLOCATE EVERY CANCELLED MESSAGE YOU ALLOCATED JUST HERE.

Parameters
toDestination of the Message(including [this]). If you sent a message to yourself, this parameter would be [this].
messageMessage to be deallocated. This is the message you allocated.
Note
Using default implementation is forbidden. If you use send any message, you must override this function with your own implementation. This function is similar to messageFinished except its response message is always null.
See also
messageFinished

◆ messageFinished()

virtual void E::Module::messageFinished ( const ModuleID  to,
Message  message,
Module::MessageBase response 
)
inlineprotectedvirtual

This is a callback function called by the System. This function is automatically called after your message is processed by the destination module. If you want to handle Message, override this function with your own handler. YOU MUST DEALLOCATE EVERY SUCCESSFUL MESSAGE YOU ALLOCATED JUST HERE. INSTANT RESPONSE messages(return value of messageReceived) are also deallocated here. SELF messages are also deallocated here.

Parameters
toDestination of the Message(including [this]). If you sent a message to yourself, this parameter would be [this].
messageMessage to be deallocated. This is the message you allocated.
responseIf the message is successfully processed, the receiver may give an instance response by return value. Response message is deallocated by the responder's messageFinished, so DO NOT DEALLOCATE THE RESPONSE MESSAGE.
Note
Using default implementation is forbidden. If you use send any message, you must override this function with your own implementation.

◆ messageReceived()

virtual Module::Message E::Module::messageReceived ( const ModuleID  from,
Module::MessageBase message 
)
inlineprotectedvirtual

This is a callback function called by the System. This function is automatically called when you received a Message. If you want to handle Message, override this function with your own handler.

Parameters
fromSource module which created and sent the message. This cannot be null (someone must create the message). If you sent a message to yourself, this parameter would be [this].
messageMessage you received. This message is allocated by other module, so DO NOT DEALLOCATE THE GIVEN MESSAGE (even it is your self message).
Returns
If you want to give a feedback to the sender of this message, ALLOCATE ANOTHER MESSAGE and return it.
Note
Using default implementation is forbidden. If you use the default implementation, no module can send messages to you.

◆ sendMessage()

UUID E::Module::sendMessage ( const ModuleID  to,
Module::Message  message,
Time  timeAfter 
)
finalprotectedvirtual

Send a Message to other Module. Every message has its own delay before it is actually sent. The System guarantees the total ordering of all delayed messages in the System.

Parameters
toDestination Module. You can send a Message to yourself (this).
messageMessage to be sent. YOU MUST ALLOCATE THE MESSAGE TO BE SENT.
timeAfterDelay of this message. The receiver will receive the Message at [current time] + [delay].
Returns
UUID of generated message. This UUID is used for cancellation of the message.
Note
You cannot override this function.
See also
messageFinished and messageReceived for allocate/deallocate convention.

◆ sendMessageSelf()

UUID E::Module::sendMessageSelf ( Module::Message  message,
Time  timeAfter 
)
finalprotectedvirtual

Send a Message to self Every message has its own delay before it is actually sent. The System guarantees the total ordering of all delayed messages in the System.

Parameters
messageMessage to be sent. YOU MUST ALLOCATE THE MESSAGE TO BE SENT.
timeAfterDelay of this message. The receiver will receive the Message at [current time] + [delay].
Returns
UUID of generated message. This UUID is used for cancellation of the message.
Note
You cannot override this function.
See also
messageFinished and messageReceived for allocate/deallocate convention.

The documentation for this class was generated from the following files: