Messaging - JayhawkZombie/EECS581Project GitHub Wiki
Messaging
Internal Messaging
You can use the internal messaging system by interfacing with the Engine::Messager
singleton.
There are several ways to post a message:
-
If you know the InternalID for the object you want to communicate with, use this method:
static bool PostMessageForInstance(std::uint32_t Source, std::uint32_t Destination, const SystemMessage &Message)
- Whenever that instanced object polls for messages, yours will be there
-
If you know the name of the class you want to communicate with, use this method:
static bool PostMessageForClass(std::uint32_t Source, const std::string ReceivingClass, const SystemMessage &Message)
- Whenever that class polls for messages, yours will be there
-
If you wish to post to the log, use this method:
static bool PostLogMessage(std::uint32_t Source, const SystemMessage &Message, MessageLogLevel Level)
-
If you wish to post to the activity log, use this method:
static bool PostToActivityLog(const SystemMessage &Message)
You can construct a SystemMessage
object using its constructor as follows:
SystemMessage(SystemMessageType MessageType, std::uint32_t Source, std::uint32_t Destination, const std::string &Post)
SystemMessageType
is an enum designed to clarify the reason for the post, and its possible values are:
enum class SystemMessageType : std::uint32_t
{
// An incoming notification
Notification = 0 ,
// Some type of incoming engine request
Request ,
// Some type of critical message
Critical ,
//Activity log
ActivityLog
};
MessageLogLevel
is designed to signal the intent of the log and note if it is a routine log or documentation of some error. It's possible values are:
enum class MessageLogLevel : std::uint32_t
{
//Just a message - for testing / monitoring - assume a valid state
Normal = 0 ,
// Elevated - for debugging - assume a valid state, but be prepared for unexpected behavior
Elevated ,
// High - For reporting errors - do not assume a valid state
High ,
//Critical - for failures - be prepared for a potential crash
Critical ,
//Unrecoverable - we're going down
Unrecoverable
};
You do not need to retrieve the singleton's instance. It will be created by calling Engine::Messager::Init()
inside Startup.cpp
and will be destroyed by calling Engine::Messager::Shutdown()
inside 'Shutdown.cpp`. There is not public method available to retrieve the singleton instance. All intended functionality can be implemented using the public interface methods described above.
Example of posting a log message:
Messager::PostLogMessage(0, SystemMessage(SystemMessageType::ActivityLog, 0, 0, "EngineStartup"), MessageLogLevel::Normal);
Example of posting to the activity log:
PostToActivityLog(SystemMessage(SystemMessageType::ActivityLog, Source, 0, ALogMsg));