

Definition at line 14 of file AgentPack.h.
Public Member Functions | |
| AgentPack () | |
| ~AgentPack () | |
| void | addAgent (BaseAgent *agent) |
| Insert agent to pack and insert his to listeners too. | |
| void | removeAgent (const std::string &name) |
| Remove agent from pack and remove his from listeners too. | |
| void | init (const std::string &stopAgent="") |
| Init all agents bellow stopAgent. | |
| void | update () |
| void | shutdown () |
| Shutdown initialized agents in reverse order. | |
Static Public Member Functions | |
| static BaseAgent * | getAgent (const std::string &name) |
| Return agent according his name. | |
|
|
Definition at line 18 of file AgentPack.cpp. 00019 {
00020 //NOTE: this is not thread safe
00021 if (ms_singleton) {
00022 throw LogicException(ExInfo("AgentPack is singleton"));
00023 }
00024
00025 ms_singleton = this;
00026 //NOTE: MessagerAgent must be the first
00027 MessagerAgent *messager = new MessagerAgent();
00028 messager->init();
00029 addAgent(messager);
00030 }
|
|
|
Definition at line 32 of file AgentPack.cpp. 00033 {
00034 t_agents::iterator end = m_agents.end();
00035 for (t_agents::iterator i = m_agents.begin(); i != end; ++i) {
00036 delete i->second;
00037 }
00038 ms_singleton = NULL;
00039 }
|
|
|
Insert agent to pack and insert his to listeners too. NOTE: agent->init() is not called yet
Definition at line 50 of file AgentPack.cpp. 00051 {
00052 std::pair<t_agents::iterator,bool> status =
00053 m_agents.insert(
00054 std::pair<std::string,BaseAgent*>(agent->getName(), agent));
00055 if (!status.second) {
00056 throw NameException(ExInfo("agent already exists")
00057 .addInfo("name", agent->getName()));
00058 }
00059
00060 MessagerAgent::agent()->addListener(agent);
00061 }
|
|
|
Return agent according his name.
Definition at line 87 of file AgentPack.cpp. 00088 {
00089 if (NULL == ms_singleton) {
00090 throw LogicException(ExInfo("AgentPack is not ready"));
00091 }
00092
00093 t_agents::iterator it = ms_singleton->m_agents.find(name);
00094 if (ms_singleton->m_agents.end() == it) {
00095 throw NameException(ExInfo("cannot find agent")
00096 .addInfo("name", name));
00097 }
00098
00099 if (!it->second->isInitialized()) {
00100 throw LogicException(ExInfo("agent is not initialized")
00101 .addInfo("name", name));
00102 }
00103 return it->second;
00104 }
|
|
|
Init all agents bellow stopAgent. Init all agents when stopAgent is not found. Definition at line 111 of file AgentPack.cpp. 00112 {
00113 t_agents::iterator stop = m_agents.find(stopAgent);
00114
00115 for (t_agents::iterator i = m_agents.begin(); i != stop; ++i) {
00116 if (!i->second->isInitialized()) {
00117 i->second->init();
00118 }
00119 }
00120 }
|
|
|
Remove agent from pack and remove his from listeners too.
Definition at line 69 of file AgentPack.cpp. 00070 {
00071 t_agents::iterator it = m_agents.find(name);
00072 if (m_agents.end() != it) {
00073 MessagerAgent::agent()->removeListener(name);
00074 delete it->second;
00075 m_agents.erase(it);
00076 }
00077 }
|
|
|
Shutdown initialized agents in reverse order.
Definition at line 135 of file AgentPack.cpp. 00136 {
00137 t_agents::reverse_iterator rend = m_agents.rend();
00138 for (t_agents::reverse_iterator i = m_agents.rbegin();
00139 i != rend; ++i)
00140 {
00141 if (i->second->isInitialized()) {
00142 i->second->shutdown();
00143 }
00144 }
00145 }
|
|
|
Definition at line 123 of file AgentPack.cpp. 00124 {
00125 t_agents::iterator end = m_agents.end();
00126 for (t_agents::iterator i = m_agents.begin(); i != end; ++i) {
00127 i->second->update();
00128 }
00129 }
|
1.4.2