GStorage.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 - 2006 by the G System Team                        *
00003  *   http://www.g-system.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 GWEGSTORAGE_H
00026 #define GWEGSTORAGE_H
00027 
00028 #include <QObject>
00029 #include <QList>
00030 #include <QSqlDatabase>
00031 #include <QMutex>
00032 
00033 #include <exception>
00034 
00035 class QDomDocument;
00036 class QStringList;
00037 
00038 namespace GCS
00039 {
00040   class GElement;
00041   class GElementID;
00042   class GAgent;
00043   class GEnergy;
00044   class GForm;
00045   class GVector3;
00046   class GElementData;
00047   class GWorldData;
00048 }
00049 
00050 namespace GWE
00051 {
00052 
00059 class GStorageException : public std::exception
00060 {
00061   private:
00062     
00066     QString Text;
00067   public:
00068     
00072     GStorageException(QString error) : Text(error) {}
00073     
00077     virtual ~GStorageException() throw() {}
00078     
00082     QString toString() {return Text;}
00083 };
00084 
00115 class GStorage : public QObject, public QMutex
00116 {
00117   Q_OBJECT
00118     
00119   protected:
00120     
00125     QSqlDatabase Database;
00126     
00131     QString DbDriver;
00132     
00137     QString DbName;
00138     
00144     QString DbHost;
00145     
00152     int DbPort;
00153     
00158     QString DbUser;
00159     
00164     QString DbPassword;
00165     
00166   public:
00167     
00171     GStorage(QObject *parent = 0);
00172     
00176     virtual ~GStorage();
00177     
00184     void setDatabaseDriver(QString driver);
00185     
00191     void setDatabaseName(QString connection);
00192     
00198     void setDatabaseHost(QString host);
00199     
00205     void setDatabasePort(int port);
00206     
00211     void setDatabaseUser(QString user);
00212     
00217     void setDatabasePassword(QString password);
00218     
00224     void setDatabase(QString driver, QString name, QString user, QString password, QString host="", int port=0);
00225     
00232     bool connectDatabase();
00233     
00237     bool isDatabaseConnected();
00238     
00245     bool initializeDatabase();
00246     
00251     bool disconnectDatabase();
00252     
00256     QString getLastDatabaseError();
00257     
00258     //BEGIN Data management
00259     
00260   protected:
00261     
00262     GCS::GVector3 getVector3(unsigned long id) throw(GStorageException);
00263     
00264   public:
00265     
00266     //BEGIN GWE stuff
00267     
00268     // get
00269     
00273     QStringList getAllElementOwners() throw(GStorageException);
00274     
00275     QStringList getAllServers() throw(GStorageException);
00276     
00277     bool getServerExists(const QString& server) throw(GStorageException);
00278     
00279     QStringList getServersForElementChildren(const GCS::GElementID& parent) throw(GStorageException);
00280 
00281     QList<GCS::GElementID> getElementsForServer(const QString& server) throw(GStorageException);
00282     
00283     QString getManagingServerForElement(const GCS::GElementID& id) throw(GStorageException);
00284     
00285     QString getServerPresence(const QString& server) throw(GStorageException);
00286     
00287     QStringList getServersSubscribedToElementUpdates(const GCS::GElementID& id) throw(GStorageException);
00288     
00289     QStringList getServersSubscribedToDataUpdates(const GCS::GElementID& id) throw(GStorageException);
00290     
00291     QStringList getServersSubscribedToEnergyUpdates(const GCS::GElementID& id) throw(GStorageException);
00292     
00293     QStringList getServersSubscribedToFormUpdates(const GCS::GElementID& id) throw(GStorageException);
00294     
00295     // modifications:
00296     
00300     void addServer(const QString& server, const QString& presence) throw(GStorageException);
00301     
00302     void updateServerPresence(const QString& server, const QString& presence) throw(GStorageException);
00303     
00308     void removeServer(const QString& server) throw(GStorageException);
00309     
00313     void setSubscription(const GCS::GElementID& element, const QString& server, const QString& type) throw(GStorageException);
00314     
00318     void clearSubscription(const GCS::GElementID& element, const QString& server, const QString& type) throw(GStorageException);
00319     
00320     void updateManagingServer(const GCS::GElementID& element, const QString& new_server) throw(GStorageException);
00321     
00322     
00323     //END GWE stuff
00324     
00325     //BEGIN Element stuff
00326     
00327     // NOTE the agent list has only one column, it might be extended in the future
00328     
00329     // get
00330     
00331     bool getElementExists(const GCS::GElementID& id) throw(GStorageException);
00332     
00333     QList<GCS::GElementID> getAllElementIDs() throw(GStorageException);
00334     
00335     QList<GCS::GElementID> getAllElementIDsByServer(const QString& managing_server) throw(GStorageException);
00336     
00341     GCS::GElement* getElement(const GCS::GElementID& id, const GCS::GWorldData* data) throw(GStorageException);
00342     
00343     QList<GCS::GElement*> getElements(QList<GCS::GElementID> id_list, const GCS::GWorldData* worlddata) throw(GStorageException);
00344     
00345     GCS::GElementData* getElementData(const GCS::GElementID& id) throw(GStorageException);
00346     
00347     GCS::GEnergy* getElementEnergy(const GCS::GElementID& id) throw(GStorageException);
00348     
00349     GCS::GForm* getElementForm(const GCS::GElementID& id) throw(GStorageException);
00350     
00351     QList<GCS::GElementID> getChildren(const GCS::GElementID& id) throw(GStorageException);
00352     
00353     GCS::GElementID getParent(const GCS::GElementID& id) throw(GStorageException);
00354     
00355     QStringList getElementAgents(const GCS::GElementID& id) throw(GStorageException);
00356     
00357     GCS::GElementID getConnection(const GCS::GElementID& id) throw(GStorageException);
00358     
00359     
00360     QStringList getAllAgents() throw(GStorageException);
00361     
00365     QString getAgent(const QString& agent) throw(GStorageException);
00366     
00367     // modifications
00368     
00369     void addElement(const GCS::GElement* element, const QString& managing_server) throw(GStorageException);
00370     
00371     void updateElement(const GCS::GElement* element) throw(GStorageException);
00372     
00373     void removeElement(const GCS::GElementID& id) throw(GStorageException);
00374     
00375     void removeElements(QList<GCS::GElementID> id_list) throw(GStorageException);
00376     
00377     void reparentElement(const GCS::GElementID& element, const GCS::GElementID& old_parent, const GCS::GElementID& new_parent) throw(GStorageException);
00378     
00379     void changeConnection(const GCS::GElementID& element, const GCS::GElementID& connection) throw(GStorageException);
00380     
00381     void addElementAgent(const GCS::GElementID& element, const QString& agent) throw(GStorageException);
00382     
00383     void removeElementAgent(const GCS::GElementID& element, const QString& agent) throw(GStorageException);
00384     
00388     QStringList removeAllElementAgents(const GCS::GElementID& element) throw(GStorageException);
00389     
00393     QList<GCS::GElementID> removeAgentFromAllElements(const QString& agent) throw(GStorageException);
00394     
00395     void updateElementData(const GCS::GElementID& element, const GCS::GElementData* data) throw(GStorageException);
00396     
00397     void updateEnergy(const GCS::GElementID& element, const GCS::GEnergy* energy) throw(GStorageException);
00398     
00399     void updateForm(const GCS::GElementID& element, const GCS::GForm* form) throw(GStorageException);
00400     
00401     
00402     void removeAllAgents() throw(GStorageException);
00403     
00404     void addAgent(const QString& agent) throw(GStorageException);
00405     
00410     void removeAgent(const QString& agent) throw(GStorageException);
00411     
00412     //END Element stuff
00413     
00414     //END Data management
00415 };
00416 
00417 }
00418 
00419 #endif

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