00001 /*************************************************************************** 00002 * Copyright (C) 2003-2004 by Raphael Langerhorst * 00003 * raphael-langerhorst@gmx.at * 00004 * * 00005 * Permission is hereby granted, free of charge, to any person obtaining * 00006 * a copy of this software and associated documentation files (the * 00007 * "Software"), to deal in the Software without restriction, including * 00008 * without limitation the rights to use, copy, modify, merge, publish, * 00009 * distribute, sublicense, and/or sell copies of the Software, and to * 00010 * permit persons to whom the Software is furnished to do so, subject to * 00011 * the following conditions: * 00012 * * 00013 * The above copyright notice and this permission notice shall be * 00014 * included in all copies or substantial portions of the Software. * 00015 * * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* 00019 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * 00020 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * 00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * 00022 * OTHER DEALINGS IN THE SOFTWARE. * 00023 ***************************************************************************/ 00024 00025 #ifndef GAGENTH 00026 #define GAGENTH 00027 00028 #include <qobject.h> //inherited by GAgent 00029 #include <qthread.h> //inherited by GAgent 00030 #include <qptrlist.h> 00031 00032 namespace GCS 00033 { 00034 00035 class GElement; 00036 class GObject; 00037 class GEnergy; 00038 class GForm; 00039 class GElementID; 00040 class GElementInfluence; 00041 00081 class GAgent : public QObject, protected QThread 00082 { 00083 //make this class a Q_OBJECT, which means that signals 00084 //and slots can be used (see Qt documentation) 00085 Q_OBJECT 00086 00087 private: 00098 GObject* Object; 00099 00110 const QPtrList<GAgent>* Agents; 00111 00112 protected: 00113 00131 bool shutdown; 00132 00133 public: 00134 00140 GAgent(QObject* parent = 0, const char* name = 0); 00141 00149 virtual ~GAgent() {} 00150 00151 protected: 00152 00158 virtual void run(); 00159 00163 GObject* requestObject(); 00164 00168 GEnergy* requestEnergy(); 00169 00173 GForm* requestForm(); 00174 00178 const QPtrList<GAgent>& requestAgents() const; 00179 00183 const GElementID& getElementID() const; 00184 00188 const GElementID& getConnectionID() const; 00189 00190 protected slots: 00191 00200 virtual void beginPark(); 00201 00207 virtual void threadStart(double seconds_elapsed); 00208 00209 public slots: 00210 00222 virtual void receiveInfluence(GCS::GElementInfluence&); 00223 00224 signals: 00225 00230 void sendInfluence(const GCS::GElementID& target, 00231 GCS::GElementInfluence& influence); 00232 00244 void radiateInfluence(GCS::GElementInfluence& influence); 00245 00252 void parentChanged(const GCS::GElementID& oldParent, const GCS::GElementID& newParent); 00253 00258 void energyChanged(const GCS::GEnergy& changedEnergy); 00259 00264 void formChanged(const GCS::GForm& changedForm); 00265 00270 void agentChanged(const GCS::GAgent& changedAgent); 00271 00278 void childElementCreated(GCS::GElement* newElement); 00279 00286 void childElementRemoved(const GCS::GElementID& childID); 00287 00288 00289 public: 00290 00315 virtual bool isParked() const; 00316 00320 friend class GElement; 00321 00322 }; 00323 00324 } 00325 00326 #endif
1.3.6