Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

LoomKernel.h

Go to the documentation of this file.
00001 /***************************************************************** lm-cpr beg
00002  *
00003  * AI Loom - A cross platform artificial intelligence framework
00004  * AI Loom is (c) Copyright 2003 Josh Brown
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  *
00021  * -----------------------------------------------------------------
00022  * File:          $RCSfile: LoomKernel.h,v $
00023  * Date modified: $Date: 2003/10/21 18:55:19 $
00024  * Version:       $Revision: 1.3 $
00025  * -----------------------------------------------------------------
00026  *
00027  ************************************************************** lm-cpr-end */
00028 #ifndef LM_LOOM_KERNEL_H
00029 #define LM_LOOM_KERNEL_H
00030 
00031 
00032 #include <boost/bind.hpp>
00033 #include <boost/function.hpp>
00034 #include <boost/thread/mutex.hpp>
00035 #include <boost/thread/thread.hpp>
00036 
00037 #include <list>
00038 #include <map>
00039 #include <queue>
00040 #include <string>
00041 
00042 #ifdef PLEXUS
00043 #include <plx/Router/NodePtr.h>
00044 #endif
00045 
00046 namespace lm
00047 {
00048    // forward declarations
00049    class Agent;
00050    class Effector;
00051    class Sensor;
00052    class NetworkConnection;
00053    
00054 
00062    class LoomKernel
00063    {
00064    public:
00068       LoomKernel();
00069 
00074       bool hasAgent(const std::string& name);
00075 
00081       void init(int port = -1);
00082 
00086       void connectTo(std::string hostname, int port);
00087 
00092       void sendMessageWith(Agent* agent, Effector* e);
00093       
00106       void update();
00107       
00111       ~LoomKernel();
00112 
00117       void add(const Sensor& newSensor);
00118 
00123       void add(const Effector& newEffect);
00124 
00129       void registerAgent(Agent* a);
00130 
00136       void unregisterAgent(Agent* a);
00137       
00142       std::string popPostQueue(Agent* a);
00143  
00144       std::list<Agent*> getAgents();
00145       
00146    public:
00147       // public functor that bind returns on run
00148       boost::function<void ()> bindedRun;
00149       
00150    private:
00151 
00158       void run(Agent* a);
00159       
00160       //  a list of the agents in this agentCollector
00161       std::list<Agent*> mAgents;
00162 
00163       // the effector pool that all agents in this agentCollector can use
00164       std::list<Effector*> effectorPool;
00165 
00166       // the sensor pool that all agents in this agentCollector can use
00167       std::list<Sensor*> sensorPool;
00168 
00169 #ifdef PLEXUS
00170       // the plexus node for this agent collector
00171       plx::NodePtr mLocalNode;
00172 #endif
00173 
00177       boost::thread_group thrds;
00178 
00183       boost::thread* mThreadPtr;
00184 
00189    public:
00190       typedef std::map<Agent*, std::queue<std::string>* > QueueMap;
00191       QueueMap mPostQueueMap;
00192       QueueMap mPreQueueMap;
00193 
00194 #ifdef PLEXUS
00195       NetworkConnection* mNetworkConnection;
00196 #endif
00197    };
00198 
00199    
00200 } // end namespace
00201 
00202 #endif // LM_AGENT_COLLECTOR_H

Generated on Wed Oct 22 21:33:21 2003 for AI Loom by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002