GAgent.h

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2006 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 <QThread>
00029 #include <QStringList>
00030 #include <qdom.h>
00031 
00032 
00033 namespace GCS
00034 {
00035 
00036 class GElement;
00037 class GObject;
00038 class GEnergy;
00039 class GForm;
00040 class GVector3;
00041 class GMatrix44;
00042 class GElementID;
00043 class GElementInfluence;
00044 class GElementData;
00045 
00087 class GAgent : protected QThread
00088 {
00089   //make this class a Q_OBJECT, which means that signals
00090   //and slots can be used (see Qt documentation)
00091   Q_OBJECT
00092 
00093   private:
00104     GObject* Object;
00105     
00116     QList<GAgent*>* Agents;
00117     
00118   protected:
00119     
00137     bool shutdown;
00138      
00139   public:
00140 
00145     GAgent();
00146 
00154     virtual ~GAgent() {}
00155     
00161     const GElementID& getElementID() const;
00162     
00183     virtual QString getAgentName() const;
00184 
00192     virtual QStringList getAvailableActions() const;
00193     
00199     virtual QString getActionDescription(const QString& action) const;
00200 
00201   protected:
00202   
00209     virtual void run();
00210     
00257     bool msleepCheckShutdown(unsigned long msecs, unsigned long checkinterval = 5000);
00258   
00262     GObject* requestObject();
00263     
00267     const GObject* requestObject() const;
00268     
00272     GEnergy* requestEnergy();
00273     
00277     const GEnergy* requestEnergy() const;
00278     
00282     GForm* requestForm();
00283     
00287     const GForm* requestForm() const;
00288     
00292     GElementData* requestElementData();
00293     
00297     const GElementData* requestElementData() const;
00298     
00302     QList<const GAgent*> requestAgents() const;
00303     
00307     const GElementID& getConnectionID() const;
00308     
00309   protected slots:
00310   
00319     virtual void beginPark();
00320       
00326     virtual void threadStart(double seconds_elapsed);
00327 
00328   public slots:
00329 
00341     virtual void receiveInfluence(const GCS::GElementInfluence&);
00342 
00352     virtual void performAction(const QString& action, QStringList params);
00353     
00358     virtual void reparented(const GCS::GElementID& old_parent, const GCS::GElementID& new_parent, const GCS::GMatrix44& transformation);
00359 
00360   signals:
00361 
00366     void sendInfluence(const GCS::GElementInfluence& influence, const GCS::GElementID& destination);
00367 
00383     void radiateInfluence(const GCS::GElementInfluence& influence, double radius_factor);
00384     
00391     void parentChanged(const GCS::GElementID& newParent, const GCS::GElementID& oldParent, const GCS::GMatrix44& transformation);
00392     
00397     void energyChanged(const GCS::GEnergy& changedEnergy);
00398 
00403     void formChanged(const GCS::GForm& changedForm);
00404 
00414     void elementDataChanged(const QString& xmlpath);
00415     
00422     void childElementCreated(GCS::GElement* newElement);
00423     
00430     void childElementRemoved(const GCS::GElementID& childID);
00431     
00432     
00433   public:
00434   
00459     virtual bool isParked() const;
00460       
00464     friend class GElement;
00465     
00466 };
00467 
00468 }
00469 
00470 #endif

Generated on Thu Nov 16 07:49:12 2006 for G System by  doxygen 1.4.7