167 bool registrantFound =
false;
168 for (
unsigned int i = 0; i < msgRegistrantsPtr->size(); ++i)
170 if (msgRegistrantsPtr->at(i).first == &listeningEntity)
172 registrantFound =
true;
173 LOG_W(
"The Entity: " + listeningEntity.
GetName() +
" attempted to register for messages about an actor through invokable: " + invokableName +
". It is already registered through invokable: " + msgRegistrantsPtr->at(i).second)
179 if (!registrantFound)
183 LOG_D(
"Registering Entity: " + listeningEntity.
GetName() +
" for messages about an actor through invokable: " + invokableName)
195 std::vector<EntityInvokablePair>* msgRegistrantsPtr = &it->second;
196 for (
unsigned int i = 0; i < msgRegistrantsPtr->size(); ++i)
199 if (msgRegistrantsPtr->at(i).first == &listeningEntity)
201 msgRegistrantsPtr->erase(msgRegistrantsPtr->begin() + i);
202 LOG_D(
"Unregistered Entity: " + listeningEntity.
GetName() +
" from listening to messages about an actor.")
208 if (msgRegistrantsPtr->size() == 0)
215 LOG_W(
"Invalid attempt to unregister the Entity: " + listeningEntity.
GetName() +
" from listening to messages about an actor.")
225 std::string errorText =
"An actor/actor module with the same ID is already registered with the System Manager.";
246 LOG_D(
"Registered " + actor.
GetName() +
" of type: " + actor.
GetType() +
" with System Manager.")
255 ActorList::iterator found;
258 if (found->Get() == &actor)
278 LOG_D(
"Unregistered " + actor.
GetName() +
" of type: " + actor.
GetType() +
" from System Manager.")
284 LOG_W(
"Attempted to unregister a none registered Actor: " + actor.
GetName())
308 ActorIDMap::const_iterator it =
mActorIDMap.find(
id);
312 return it->second.Get();
323 std::vector<trManager::EntityBase*> actorList;
327 if (i->GetType() == actorType)
331 actorList.push_back(i);
342 std::vector<trManager::EntityBase*> actorList;
346 if (i->GetName() == actorName)
350 actorList.push_back(i);
365 EntityInvokableMap::iterator entityInvokableIt;
368 MessageRegistrationMap::iterator listenerIt;
384 entityInvokableMapPtr = &listenerIt->second;
387 entityInvokableIt = entityInvokableMapPtr->find(directorRef);
388 if (entityInvokableIt != entityInvokableMapPtr->end())
391 CallInvokable(message, entityInvokableIt->second, *directorRef);
419 std::vector<EntityInvokablePair>* listenerList = &listenerIt->second;
443 std::vector<EntityInvokablePair>* listenerList = &listenerIt->second;
459 MessageRegistrationVectorMap::iterator it;
469 std::vector<EntityInvokablePair>* msgRegistrantsPtr = &it->second;
471 for (
unsigned int i = 0; i < msgRegistrantsPtr->size(); ++i)
479 invokablePtr = actor->
GetInvokable(msgRegistrantsPtr->at(i).second);
481 if (invokablePtr !=
nullptr)
483 invokablePtr->
Invoke(message);
497 if (invokablePtr !=
nullptr)
500 invokablePtr->
Invoke(message);
504 LOG_E(
"Invokable: " + invokableName +
" was called, but the Entity: " + entity.
GetName() +
" does not have an invokable by that name.")
511 std::vector<EntityInvokablePair>* msgRegistrantsPtr =
nullptr;
518 msgRegistrantsPtr = &listenerIt->second;
519 for (
unsigned int i = 0; i<msgRegistrantsPtr->size(); ++i)
522 if (msgRegistrantsPtr->at(i).first == &actor)
524 msgRegistrantsPtr->erase(msgRegistrantsPtr->begin() + i);
530 if (msgRegistrantsPtr->empty())
552 for (
auto&& directorIt = listenerIt->second.begin(); directorIt != listenerIt->second.end();)
555 if (directorIt->first->GetUUID() == director.
GetUUID())
558 directorIt = listenerIt->second.erase(directorIt);
568 if (listenerIt->second.empty())
580 LOG_E(
"The Entity: " + director.
GetName() +
" is not a Director.")
587 std::vector<EntityInvokablePair>* msgRegistrantsPtr =
nullptr;
593 msgRegistrantsPtr = &listenerIt->second;
594 for (
unsigned int i = 0; i<msgRegistrantsPtr->size(); ++i)
597 if (msgRegistrantsPtr->at(i).first == &listeningEntity)
599 msgRegistrantsPtr->erase(msgRegistrantsPtr->begin() + i);
605 if (msgRegistrantsPtr->empty())
620 std::vector<EntityInvokablePair>* msgRegistrantsPtr = &messageMap[
const_cast<std::string*
>(&messageType)];
623 bool registrantFound =
false;
624 for (
unsigned int i = 0; i < msgRegistrantsPtr->size(); ++i)
626 if (msgRegistrantsPtr->at(i).first == &listeningEntity)
628 registrantFound =
true;
629 LOG_W(
"The Entity: " + listeningEntity.
GetName() +
" attempted to register for message: " + messageType +
" through invokable: " + invokableName +
". It is already registered through invokable: " + msgRegistrantsPtr->at(i).second)
635 if (!registrantFound)
639 LOG_D(
"Registering Entity: " + listeningEntity.
GetName() +
" for message: " + messageType +
" through invokable: " + invokableName)
647 MessageRegistrationVectorMap::iterator it = messageMap.find(const_cast<std::string*>(&messageType));
648 if (it != messageMap.end())
651 std::vector<EntityInvokablePair>* msgRegistrantsPtr = &it->second;
652 for (
unsigned int i = 0; i < msgRegistrantsPtr->size(); ++i)
655 if (msgRegistrantsPtr->at(i).first == &listeningEntity)
657 msgRegistrantsPtr->erase(msgRegistrantsPtr->begin() + i);
658 LOG_D(
"Unregistered Entity: " + listeningEntity.
GetName() +
" from message: " + messageType)
664 if (msgRegistrantsPtr->size() == 0)
666 messageMap.erase(it);
671 LOG_W(
"Invalid attempt to unregister the Entity: " + listeningEntity.
GetName() +
" from message: " + messageType)
679 EntityInvokableMap* entityInvokableMapPtr = &messageMap[
const_cast<std::string*
>(&messageType)];
683 EntityInvokableMap::iterator it = entityInvokableMapPtr->find(listeningEnt);
684 if (it == entityInvokableMapPtr->end())
687 entityInvokableMapPtr->insert(std::make_pair(listeningEnt, invokableName));
688 LOG_D(
"Registering Entity: " + listeningEnt->GetName() +
" for message: " + messageType +
" through invokable: " + invokableName)
692 LOG_W(
"The Entity: " + listeningEnt->GetName() +
" attempted to register for message: " + messageType +
" through invokable: " + invokableName +
". It is already registered through invokable: " + it->second)
700 MessageRegistrationMap::iterator it = messageMap.find(const_cast<std::string*>(&messageType));
701 if (it != messageMap.end())
705 for (EntityInvokableMap::iterator i = entityMap->begin(); i != entityMap->end(); ++i)
707 if (i->first == &listeningEntity)
711 LOG_D(
"Unregistered Entity: " + listeningEntity.
GetName() +
" from message: " + messageType)
714 if (entityMap->empty())
716 messageMap.erase(it);
722 LOG_W(
"Invalid attempt to unregister the Entity: " + listeningEntity.
GetName() +
" from message: " + messageType)
728 LOG_W(
"Invalid attempt to unregister the Entity: " + listeningEntity.
GetName() +
" from message: " + messageType)
740 std::string errorText =
"A director with the name: " + director.
GetName() +
" is already registered with the System Manager.";
767 LOG_D(
"Registered " + director.
GetName() +
" of type: " + director.
GetType() +
" with System Manager.")
773 LOG_E(
"The Entity: " + director.
GetName() +
" is not a Director.")
785 DirectorList::iterator found;
788 if (found->Get() == &director)
809 LOG_D(
"Unregistered " + director.
GetName() +
" of type: " + director.
GetType() +
" from System Manager.")
815 LOG_W(
"Attempted to unregister a none registered Director: " + director.
GetName())
821 LOG_E(
"The EntityBase: " + director.
GetName() +
" is not a Director.")
848 return it->second.Get();
863 return it->second.Get();
874 std::vector<trManager::EntityBase*> directorList;
878 if (i->GetType() == type)
880 directorList.push_back(i);
903 LOG_D(
"Shutting down System Manager")
905 LOG_D(
"Processing Last Messages")
908 LOG_D(
"Unregistering All Directors")
911 LOG_D(
"Unregistering All Actors and Actor Modules")
914 LOG_D(
"Removing all marked entities")
virtual void UnregisterActorFromGlobalMessages(trManager::EntityBase &actor)
Unregisters the actor/actor module from all messages that have registrations.
virtual const std::string & GetName()
Returns this instances name.
Sets the priority for a Director instance.
virtual const std::string & GetMessageType() const =0
Returns the Message type.
This class creates a GUID, or a Unique ID that is used through out TR to identify and distinguish one...
static trManager::SystemManager & GetInstance()
Holds the class type name for efficient comparisons.
virtual void CallInvokable(const trManager::MessageBase &message, const std::string &invokableName, trManager::EntityBase &entity)
Utility function.
virtual void SetSystemManager(trManager::SystemManager *sysMan)
This method is used by the System Manager to pass the Entity an instance if itself when it is registe...
const std::string & GetName() const
static const EntityType ACTOR_MODULE
A message that is sent out when an entity is unregistered from the System Manager.
An Invokable is a queriable method interface that can be added to a trManager::ActorBase Invoking the...
A string wrapper that will make sure that all of the strings with the same value will point to the sa...
static const trUtil::RefStr CLASS_TYPE
Adds an easy and swappable access to the base class.
void RegisterMsgWithMsgMap(const std::string &messageType, EntityBase &listeningEntity, const std::string &invokableName, MessageRegistrationMap &messageMap)
Registers the message with message map.
virtual void UnregisterEntityFromAboutMessages(trManager::EntityBase &listeningEntity)
Unregisters the entity from about messages about another actor.
DirectorIDMap mDirectorIDMap
System Manager class is a singleton that is responsible for all message routing and basic operations ...
virtual bool RegisterDirector(trManager::EntityBase &director, trManager::DirectorPriority &priority=trManager::DirectorPriority::NORMAL)
Adds a director to the list of components the system manager will communicate with.
virtual bool UnregisterActor(trManager::EntityBase &actor)
Disconnects the actor from the System Manager.
A message that is sent out when a new entity is registered with the System Manager.
virtual void UnregisterAllDirectors()
Unregisters all the directors from System Manager.
virtual trManager::EntityBase * FindDirector(const trBase::UniqueId &id) const
Finds and returns the director with the given ID.
virtual void ProcessMessages()
Sends out all the messages from the message queue.
DirectorNameMap mDirectorNameMap
virtual const std::string & GetType() const override
Returns the class type.
static bool CompareComponentPriority(const trBase::SmrtPtr< trManager::EntityBase > &first, const trBase::SmrtPtr< trManager::EntityBase > &second)
Local function used to compare priorities of Directors.
#define LOG_W(msg)
Log a WARNING message.
This class is part of the internal garbage collection system.
virtual bool RegisterActor(trManager::EntityBase &actor)
Registers an Actor or Actor Module with the System Manager.
static const EntityType ACTOR
virtual bool SendNetworkMessage(const trManager::MessageBase &message)
Send a Network message to an Actor, Actor Module, or a Director.
virtual void UnregisterFromMessage(const std::string &messageType, EntityBase &listeningActor)
Unregister an actor that is listening for a given message.
virtual bool UnregisterDirector(trManager::EntityBase &director)
Disconnects the director from System Manager.
virtual const trBase::UniqueId * GetAboutActorID() const
Returns the ID of the actor this message is about, or sent to.
virtual std::vector< trManager::EntityBase * > FindDirectors(const std::string &type) const
Finds and returns all the Directors of a given type.
virtual void RemoveMarkedEntities()
Removes all entities that were marked to be unregistered.
virtual void RegisterForMessagesAboutEntity(EntityBase &listeningEntity, const trBase::UniqueId &aboutEntityId, const std::string &invokableName)
Registers for messages about a specific actor.
static const trUtil::RefStr ON_MESSAGE_INVOKABLE
Holds the class type name for efficient comparisons.
virtual void ProcessMessage(const trManager::MessageBase &message)
Immediately processes the passed in message.
DirectorList mDirectorList
virtual void UnregisterDirectorFromGlobalMessages(trManager::EntityBase &director)
Unregisters the director from all messages that have registrations.
virtual const trBase::UniqueId * GetFromActorID() const
Returns the ID of the actor the message was sent from.
std::queue< trBase::SmrtPtr< const trManager::MessageBase > > mMessageQueue
virtual std::vector< trManager::EntityBase * > FindActorsByName(const std::string &actorName)
Searches for all actors by a given name.
UUIDRegistrationVectorMap mListenerRegistrationMap
MessageRegistrationMap mDirectorGlobalMsgRegistrationMap
void Invoke(const trManager::MessageBase &message)
Invoke this.
virtual void SendMessageToActors(const trManager::MessageBase &message)
Sends the passed in message to appropriate actors.
virtual bool SendMessage(const trManager::MessageBase &message)
Send a message to an Actor, Actor Module, or a Director.
#define LOG_E(msg)
Log an ERROR message.
trManager::Invokable * GetInvokable(const std::string &name)
Gets a registered invokable.
virtual void SendMessageToListeners(const trManager::MessageBase &message)
Sends a message to entities that are listening for messages about other actors.
MessageRegistrationVectorMap mEntityGlobalMsgRegistrationMap
void UnregisterMsgFromMsgVectorMap(const std::string &messageType, EntityBase &listeningEntity, MessageRegistrationVectorMap &messageMap)
Un register message from a given message map.
bool Valid() const
Returns True if the smart pointer has a valid internal pointer set.
virtual const trBase::UniqueId & GetUUID(void)
Returns the instances Universally Unique ID.
virtual void SendGlobalyRegisteredMessage(const trManager::MessageBase &message)
Sends out a message to all entities who had a global registration for it.
void RegisterMsgWithMsgVectorMap(const std::string &messageType, EntityBase &listeningEntity, const std::string &invokableName, MessageRegistrationVectorMap &messageMap)
Registers the message with a given message map.
virtual const bool & IsRegistered()
Returns True if the Instance is registered with a System Manager.
virtual trManager::EntityBase * FindActor(const trBase::UniqueId &id)
Searches for an actor or actor module with the given ID.
static const EntityType DIRECTOR
virtual void RegisterForMessage(const std::string &messageType, EntityBase &listeningActor, const std::string &invokableName)
Registers an actor for messages.
std::pair< trBase::SmrtPtr< trManager::EntityBase >, std::string > EntityInvokablePair
virtual void UnregisterFromMessagesAboutEntity(EntityBase &listeningEntity, const trBase::UniqueId &aboutEntityId)
Unregisters from messages about a specific actor.
const EntityType & GetEntityType()
Returns the Entity Type, which is usually a Director, Actor, or an Actor module.
virtual void SendMessageToDirectors(const trManager::MessageBase &message)
Send the passed in message to all registered Directors.
SystemManager(const std::string name=CLASS_TYPE)
Ctor.
virtual void ProcessNetworkMessages()
Sends out all the network messages from the message queue.
virtual const std::string & GetType() const override=0
Returns the class type.
This serves as the base class for the Entity class and removes a circular dependency between Entity a...
virtual void SetRegistration(bool isRegistered)
Is set to True by the System Manager when the class instance is registered with it.
virtual const bool & GetIsDirect() const
Returns True if this message is a direct message and skips all Directors.
Exception used for methods invalid parameters.
virtual std::vector< trManager::EntityBase * > FindActorsByType(const std::string &actorType)
Searches for all actors of a given type.
virtual void ShutDown()
Shuts down the System Manager and unregisters all entities.
virtual bool UnregisterAllActors()
Unregisters all actors from the System Manager.
This is the base class for all the messages in TR.
#define LOG_D(msg)
Log a DEBUG message.
std::vector< trBase::SmrtPtr< trManager::EntityBase > > mEntityDeleteList
static trBase::SmrtPtr< trManager::SystemManager > mInstance
virtual void OnAddedToSysMan()
Called by the System Manager when EntityBase Registration is complete.
void UnregisterMsgFromMsgMap(const std::string &messageType, EntityBase &listeningEntity, MessageRegistrationMap &messageMap)
Un register message from message map.
std::queue< trBase::SmrtPtr< const trManager::MessageBase > > mNetworkMessageQueue