#include <LoomKernel.h>
Public Types | |
typedef std::map< Agent *, std::queue< std::string > * > | QueueMap |
Public Methods | |
LoomKernel () | |
bool | hasAgent (const std::string &name) |
void | init (int port=-1) |
void | connectTo (std::string hostname, int port) |
void | sendMessageWith (Agent *agent, Effector *e) |
void | update () |
~LoomKernel () | |
void | add (const Sensor &newSensor) |
void | add (const Effector &newEffect) |
void | registerAgent (Agent *a) |
void | unregisterAgent (Agent *a) |
std::string | popPostQueue (Agent *a) |
std::list< Agent * > | getAgents () |
Public Attributes | |
boost::function< void() | bindedRun ) |
QueueMap | mPostQueueMap |
QueueMap | mPreQueueMap |
Private Methods | |
void | run (Agent *a) |
Private Attributes | |
std::list< Agent * > | mAgents |
std::list< Effector * > | effectorPool |
std::list< Sensor * > | sensorPool |
boost::thread_group | thrds |
boost::thread * | mThreadPtr |
|
here is a mapping from agent so in linear time given an agent we can find his queue. |
|
constructor |
|
destructor |
|
this method adds an effector to the global pool that all agents at this agentCollector have access to. |
|
this method adds a sensor to the global pool that all agents at this agentCollector have access to. |
|
connect to another plexus node at the given hostname and port |
|
|
|
hasAgent returns true if an agent with the given name exists on this agent Collector, otherwise returns false |
|
initialization method for the agentCollector. All the setup for the agents is done here, so it must be called before update gets called. NOTE: this method must be called before update get's called. |
|
this method returns the queue's front element and removes it from that agent's queue. |
|
registerAgent adds an agent to the agentCollector which spawns a thread for it and starts calling update on it. |
|
this method is needed for boost threads so that we have a function to run. The function sits and continually calls update on the agent until it recieves an unregisterAgent Command at which time we stop the thread of execution. |
|
pack up a message with an effector in it and send it over the network to the agent that it is supposed to go to |
|
unregisterAgent removes the agent from the agentCollector, which kills the thread for it and removes it from the list of agents on the collector. |
|
The update method should be called every frame to update all the agents of pending changes on them and to get any messages or effects from them. NOTE for non-distributed system: Actually if the system is not distributed then the update method doesn't need to be called it is just recommended. The reason is that if the agentCollector goes out of scope then the primordial thread for the whole system stops thus stopping all the agent. Making the update call every frame insures that the developer has kept this in mind. NOTE: init must be called before update. |
|
|
|
|
|
|
|
|
|
|
|
we also need a pointer to a thread so that we can pass a thread around |
|
|
|
this is the boost thread group so we can run each agent in it's own thread |