From: konrad Date: Sun, 22 Feb 2009 15:33:09 +0000 (+0000) Subject: woc creates WObjects for qt side X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0e46af7230512c0347d7f81b420a16a52a26c561;p=konrad%2Fsmoke.git woc creates WObjects for qt side git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@274 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/phpscan.pri b/src/phpscan.pri index 4f163c5..c5f4b00 100644 --- a/src/phpscan.pri +++ b/src/phpscan.pri @@ -3,40 +3,77 @@ #use genphpscan.sh to regenerate it! HEADERS += \ -../www/inc/global_functions.php \ -../www/inc/tr.php \ -../www/inc/global_variables.php \ +../www/inc/db/db_mysql.php \ ../www/inc/db/db_scheme.php \ ../www/inc/db/db.php \ -../www/inc/db/db_mysql.php \ -../www/inc/machine/template.php \ +../www/inc/wob/wt_cart_ticket.php \ +../www/inc/wob/wt_users.php \ +../www/inc/wob/wt_cart.php \ +../www/inc/wob/wo_Voucher.php \ +../www/inc/wob/wt_host.php \ +../www/inc/wob/wt_room.php \ +../www/inc/wob/wt_moneylog.php \ +../www/inc/wob/wt_customer.php \ +../www/inc/wob/wo_CartVoucher.php \ +../www/inc/wob/wt_webuser.php \ +../www/inc/wob/wt_shipping.php \ +../www/inc/wob/wt_websession.php \ +../www/inc/wob/wt_voucher.php \ +../www/inc/wob/wt_event.php \ +../www/inc/wob/wo_CartOrder.php \ +../www/inc/wob/wt_order.php \ +../www/inc/wob/autoload.php \ +../www/inc/wob/wt_session.php \ +../www/inc/wob/wo_Order.php \ +../www/inc/wob/wt_template.php \ +../www/inc/wob/wt_userhosts.php \ +../www/inc/wob/wo_User.php \ +../www/inc/wob/wt_userrole.php \ +../www/inc/wob/wo_Ticket.php \ +../www/inc/wob/wo_CartTicket.php \ +../www/inc/wob/wt_cart_voucher.php \ +../www/inc/wob/wt_config.php \ +../www/inc/wob/schema.php \ +../www/inc/wob/wt_ticket.php \ +../www/inc/wbase/exception.php \ +../www/inc/wbase/object.php \ +../www/inc/wbase/autoload.php \ +../www/inc/wbase/table.php \ +../www/inc/wbase/schema.php \ +../www/inc/loader_nonadmin.php \ +../www/inc/listing.php \ +../www/inc/machine/cauth_hash.php \ ../www/inc/machine/version.php \ -../www/inc/machine/cauth_string.php \ ../www/inc/machine/host.php \ ../www/inc/machine/cauth_mhash.php \ -../www/inc/machine/cauth_hash.php \ ../www/inc/machine/session.php \ -../www/inc/rendering/cart_listing.php \ +../www/inc/machine/template.php \ +../www/inc/machine/cauth_string.php \ +../www/inc/global_variables.php \ +../www/inc/loader.php \ +../www/inc/global_functions.php \ +../www/inc/tr.php \ ../www/inc/rendering/event_listing.php \ -../www/inc/rendering/order_listing.php \ +../www/inc/rendering/cart_listing.php \ ../www/inc/rendering/submit.php \ -../www/inc/loader.php \ -../www/inc/listing.php \ -../www/inc/classes/websession.php \ +../www/inc/rendering/order_listing.php \ ../www/inc/classes/random.php \ -../www/inc/classes/room.php \ -../www/inc/classes/ticket.php \ -../www/inc/classes/cart.php \ ../www/inc/classes/parser.php \ -../www/inc/classes/language_manager.php \ ../www/inc/classes/customer.php \ -../www/inc/classes/error.php \ +../www/inc/classes/language_manager.php \ +../www/inc/classes/ticket.php \ ../www/inc/classes/event.php \ -../www/inc/classes/config_manager.php \ ../www/inc/classes/order.php \ +../www/inc/classes/config_manager.php \ +../www/inc/classes/cart.php \ +../www/inc/classes/room.php \ ../www/inc/classes/voucher.php \ -../www/inc/loader_nonadmin.php \ +../www/inc/classes/websession.php \ +../www/inc/classes/error.php \ +../www/test.php \ ../www/admin.php \ -../www/index.php \ +../www/config.php \ ../www/machine.php \ +../www/index.php \ +../www/info.php \ diff --git a/src/smoke.pro b/src/smoke.pro index 83deff3..5fb39bd 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -82,7 +82,7 @@ HEADERS = \ moneylog.h \ autoupdate.h \ domquery.h - + #some PHP files are listed in this file to scan them for translatable items #use genphpscan.sh to regenerate it. include( phpscan.pri ) @@ -97,5 +97,6 @@ TRANSLATIONS = \ include(../zip/zip.pri) include(wbase/wbase.pri) +include(wob/wob.pri) LIBS += -lgmp diff --git a/src/wbase/WObject.cpp b/src/wbase/WObject.cpp new file mode 100644 index 0000000..85ad4d2 --- /dev/null +++ b/src/wbase/WObject.cpp @@ -0,0 +1,13 @@ +// +// C++ Implementation: wobject +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "WObject.h" \ No newline at end of file diff --git a/src/wbase/WObject.h b/src/wbase/WObject.h new file mode 100644 index 0000000..6e57f15 --- /dev/null +++ b/src/wbase/WObject.h @@ -0,0 +1,36 @@ +// +// C++ Interface: wobject +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOLF_WOBJECT_H +#define WOLF_WOBJECT_H + +#include +#include + +#include "nullable.h" +#include "exception.h" + +class QDomElement; + +class WObject:public QObject +{ + protected: + WObject(){} +}; + +class WDeserializerException:public WException +{ + public: + WDeserializerException(QString e):WException(e,"Deserializer"){} +}; + +#endif diff --git a/src/wbase/WTransaction.cpp b/src/wbase/WTransaction.cpp new file mode 100644 index 0000000..926ba37 --- /dev/null +++ b/src/wbase/WTransaction.cpp @@ -0,0 +1,11 @@ +// +// C++ Implementation: wtransaction +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// diff --git a/src/wbase/WTransaction.h b/src/wbase/WTransaction.h new file mode 100644 index 0000000..2f0b656 --- /dev/null +++ b/src/wbase/WTransaction.h @@ -0,0 +1,25 @@ +// +// C++ Interface: wtransaction +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOLF_TRANSACTION_H +#define WOLF_TRANSACTION_H + +#include +#include + +#include "nullable.h" + +class WTransaction:public QObject +{ +}; + +#endif diff --git a/src/wbase/exception.h b/src/wbase/exception.h new file mode 100644 index 0000000..59e4c6e --- /dev/null +++ b/src/wbase/exception.h @@ -0,0 +1,29 @@ +// +// C++ Interface: exception +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOLF_EXCEPTION_H +#define WOLF_EXCEPTION_H + +#include + +class WException +{ + protected: + WException(QString e,QString c){err=e;comp=c;} + + QString error()const{return err;} + QString component()const{return comp;} + private: + QString err,comp; +}; + +#endif diff --git a/src/wbase/nullable.h b/src/wbase/nullable.h index 7a802eb..3b90ed3 100644 --- a/src/wbase/nullable.h +++ b/src/wbase/nullable.h @@ -21,8 +21,8 @@ templateclass Nullable Nullable(const T&t){isnull=false;elem=t;} Nullable(const Nullable&t){isnull=t.isnull;elem=t.elem;} - Nullable& operator=(const T&t){isnull=false;elem=t;} - Nullable& operator=(const Nullable&t){isnull=t.isnull;elem=t.elem;} + Nullable& operator=(const T&t){isnull=false;elem=t;return *this;} + Nullable& operator=(const Nullable&t){isnull=t.isnull;elem=t.elem;return *this;} bool isNull()const{return isnull;} diff --git a/src/wbase/wbase.pri b/src/wbase/wbase.pri index cb96ee1..90988ba 100644 --- a/src/wbase/wbase.pri +++ b/src/wbase/wbase.pri @@ -1 +1,10 @@ -HEADERS += wbase/nullable.h +HEADERS += \ + wbase/nullable.h \ + wbase/WObject.h \ + wbase/WTransaction.h + +SOURCES += \ + wbase/WObject.cpp \ + wbase/WTransaction.cpp + +INCLUDEPATH += ./wbase ./wob \ No newline at end of file diff --git a/wob/order.wolf b/wob/order.wolf index aaa244b..8b2c486 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -92,6 +92,7 @@ ticketid eventid price status + ticketid eventid price status orderid @@ -103,11 +104,14 @@ - - + + + + + + - @@ -135,6 +139,6 @@ orderid customerid seller amountpaid state amountdue - orderid customerid seller amountpaid state amountdue tickets/Full vouchers/Full + orderid customerid seller amountpaid state amountdue tickets/inOrder vouchers/inOrder \ No newline at end of file diff --git a/wob/user.wolf b/wob/user.wolf index 119742a..348ffe2 100644 --- a/wob/user.wolf +++ b/wob/user.wolf @@ -45,9 +45,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + \ No newline at end of file diff --git a/woc/phpout.cpp b/woc/phpout.cpp index c505e26..716ebf6 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -39,6 +39,7 @@ WocPHPServerOut::WocPHPServerOut(QString srcDir,QString subDir,QString ext,bool m_loader.setFileName(m_basedir+"/"+m_subdir+"/autoload"+m_fileext); if(!m_loader.open(QIODevice::ReadWrite|QIODevice::Truncate)){ qDebug("Error: PHP Server Generator - cannot create loader file, deactivating output."); + emit errorFound(); return; } m_loader.write(PHPSTART); @@ -46,6 +47,7 @@ WocPHPServerOut::WocPHPServerOut(QString srcDir,QString subDir,QString ext,bool m_schema.setFileName(m_basedir+"/"+m_subdir+"/schema"+m_fileext); if(!m_schema.open(QIODevice::ReadWrite|QIODevice::Truncate)){ qDebug("Error: PHP Server Generator - cannot create DB schema file."); + emit errorFound(); return; } m_schema.write(PHPSTART); @@ -76,6 +78,7 @@ void WocPHPServerOut::newTable(const WocTable&tbl) QFile tf(m_basedir+"/"+fn); if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){ qDebug("Error: cannot create PHP table file %s.",fn.toAscii().data()); + emit errorFound(); return; } tf.write(PHPSTART); @@ -224,13 +227,14 @@ void WocPHPServerOut::newClass(const WocClass&cls) QFile tf(m_basedir+"/"+fn); if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){ qDebug("Error: cannot create PHP object file %s.",fn.toAscii().data()); + emit errorFound(); return; } tf.write(PHPSTART); //// //generate code - QString code="class "+cna+" extends "+cls.baseClass()+"{\n\n"; + QString code="class "+cna+" extends "+cls.serverBaseClass()+"{\n\n"; tf.write(code.toAscii()); //enums diff --git a/woc/processor.cpp b/woc/processor.cpp index a1e8dec..ee29475 100644 --- a/woc/processor.cpp +++ b/woc/processor.cpp @@ -47,6 +47,7 @@ WocProcessor::WocProcessor() m_svnExe="svn"; m_dbInst="dbInst"; m_dbSchema="dbSchema"; + m_error=false; inst=this; } @@ -75,6 +76,7 @@ bool WocProcessor::processFile(QString fn) } //go on, process file qDebug("Info: processing file %s...",fn.toLocal8Bit().data()); + m_error=false; QDomNodeList nl=root.childNodes(); for(int i=0;i(nm,tp)); + } + //calls + nl2=el.elementsByTagName("Call"); + for(int j=0;j(nm,tp)); + } + } +} + +bool WocTransaction::hasInput(QString v)const +{ + for(int i=0;i > columnEnums(QString)const; + /**returns all enum definitions of the table; see also columnEnums */ QList > getEnums()const; + /**returns a list of all foreign definitions - methods that return data from other tables*/ QStringList foreigns()const; + /**returns the definition of a specific foreign table query method*/ QString foreignQuery(QString)const; + /**returns whether a foreign table query method exists*/ bool haveForeign(QString)const; + /**returns a list of all preset values (to be generated when the DB is created); + each entry in the list is a dictionary with the column name as key and the intended preset value as value - each entry of the list is one DB row, each key-value-pair in the map is one preset value in that row*/ QList > presets()const{return m_presets;} private: bool m_valid,m_backup; @@ -157,61 +185,132 @@ class WocTable QList >m_presets; }; +/**internal representation of a transaction*/ class WocTransaction { public: - WocTransaction(const QDomElement&){} - bool isValid(){return true;} + /**initializes a transaction from XML*/ + WocTransaction(const QDomElement&); + /**returns whether parsing it was successful*/ + bool isValid()const{return m_valid;} + + /**returns the name of the transaction*/ + QString name()const{return m_name;} + + /**returns whether an input variable exists*/ + bool hasInput(QString v)const; + /**returns the names of all inputs in the order of definition*/ + QStringList inputNames()const; + /**returns the type of an input variable*/ + QString inputType(QString)const; + + /**returns whether an output variable exists*/ + bool hasOutput(QString v)const; + /**returns the names of all outputs in the order of definition*/ + QStringList outputNames()const; + /**returns the type of an output variable*/ + QString outputType(QString)const; + + /**returns whether a specific language binding exists for a call*/ + bool hasCall(QString c)const{return m_call.contains(c);} + /**returns the called function*/ + QString callFunction(QString c)const{return m_call[c];} + + /**authentication mode*/ + enum AuthMode { + /**default: need a valid session and the privilege*/ + Checked, + /**only need to be authenticated, every valid user can do it*/ + Auth, + /**available even to anonymous/unauthenticated users*/ + Open + }; + AuthMode authMode()const{return m_mode;} + + private: + QString m_name; + bool m_valid; + AuthMode m_mode; + QMap m_call; + QList >m_input,m_output; }; +/**base class of all output generators*/ class WocOutput:public QObject { Q_OBJECT public: + /**the constructor should set up and initialize the environment of the generator*/ WocOutput(); + /**currently there is no guarantee that the destructor is ever called.*/ virtual ~WocOutput(); protected slots: - virtual void finalize()=0; + /**called whenever the parser finds a new class in the XML input; some references might not exist yet*/ virtual void newClass(const WocClass&)=0; + /**called whenever the parser finds a new table in the XML input; the parser guarantees that tables it depends on already exist (it will throw an error otherwise)*/ virtual void newTable(const WocTable&)=0; + /**called whenever the parser finds a new transaction; the parser guarantees that all referenced types exist (it will throw an error otherwise)*/ virtual void newTransaction(const WocTransaction&)=0; + /**called when the parsing is complete: it should clean up the generators environment; it may not be called if woc stops with an error*/ + virtual void finalize()=0; + signals: + void errorFound(); }; +/**central processing singleton*/ class WocProcessor:public QObject { Q_OBJECT public: WocProcessor(); + /**called from main loop to parse a file*/ bool processFile(QString); + /**called from main loop to finalize its work*/ void finalize(); + /**returns the instance of the processor (if it exists yet)*/ static WocProcessor* instance(){return inst;} + + /**returns the base directory of the project (all other pathes are relative to it)*/ QString baseDir()const{return m_baseDir;} + /**returns the directory where WOLFs are found, should normally not be used outside this class*/ QString wobDir()const{return m_wobDir;} + /**returns the current communication protocol version*/ QString verComm()const{return m_verComm;} + /**returns the communication protocol version that is at least needed to be compatible*/ QString verNeedComm()const{return m_verNeedComm;} + /**returns a human readable version string*/ QString verHR()const{return m_verHR;} + /**returns the SVN revision of the project: it contains two tokens, the first one is the current revision or min-max if the working copy contains mixed revisions; the second token contains the word "vanilla" if there are no local modifications, or "modified" if there are local modifications*/ QString svnRevision()const{return m_svnRev;} + /**returns the variable name that will contain the database driver instance*/ QString dbInst()const{return m_dbInst;} + /**returns the variable name that will contain the database schema object*/ QString dbSchema()const{return m_dbSchema;} + /**returns the database schema version*/ QString dbVersion()const{return m_dbVer;} + /**returns whether a table exists*/ bool hasTable(QString)const; + /**returns the requested table*/ WocTable table(QString)const; + /**returns whether a class exists*/ bool hasClass(QString)const; signals: void sfinalize(); void newClass(const WocClass&); void newTable(const WocTable&); void newTransaction(const WocTransaction&); - + private slots: + void errorFound(); private: QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR; QString m_svnTarget,m_svnRev,m_svnExe,m_dbInst,m_dbSchema,m_dbVer; + bool m_error; QList m_tables; QList m_classes; @@ -219,6 +318,7 @@ class WocProcessor:public QObject static WocProcessor*inst; + /**helper: calls SVN and parses its output*/ void callSvn(); }; diff --git a/woc/qtout.cpp b/woc/qtout.cpp index 9c2c412..21390de 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -12,8 +12,326 @@ #include "qtout.h" -WocQtClientOut::WocQtClientOut(QString srcDir,QString subDir,QString prifile){} -void WocQtClientOut::finalize(){} -void WocQtClientOut::newClass(const WocClass&){} -void WocQtClientOut::newTable(const WocTable&){} -void WocQtClientOut::newTransaction(const WocTransaction&){} +#include + +WocQtClientOut::WocQtClientOut(QString srcDir,QString subDir,QString prifile,bool clean) +{ + qDebug("Info: creating Qt Client Output Generator."); + m_basedir=WocProcessor::instance()->baseDir()+"/"+srcDir; + m_subdir=subDir; + //cleanup directory (remove normal files, assume remainder is harmless) + QDir d(m_basedir+"/"+m_subdir); + if(d.exists() && clean){ + QStringList ent=d.entryList(QDir::Files); + for(int i=0;i\n" + "#include \n"; +//end section of all source files +static const QByteArray SRCEND="\n//END OF FILE\n"; + +void WocQtClientOut::newClass(const WocClass&cls) +{ + QString cn="WO"+cls.name(); + QString cna=cn; + if(cls.isAbstract())cna+="Abstract"; + addFile(cna); + QFile hdr(m_basedir+"/"+m_subdir+"/"+cna+".h"); + QFile src(m_basedir+"/"+m_subdir+"/"+cna+".cpp"); + if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) || + !src.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create class files for class %s.",cn.toAscii().data()); + emit errorFound(); + return; + } + //lead in + hdr.write(QByteArray(HDRSTART).replace("%",cna.toAscii())); + src.write(QByteArray(SRCSTART).replace("%",cna.toAscii())); + + QString hcd; + QString scd; + //includes + hcd="#include \""+cls.clientBaseClass()+".h\"\n\n"; + QStringList k=cls.propertyNames(); + for(int i=0;i >ev=cls.enumValues(k[i]); + if(ev.size()<1){ + qDebug("Error: enums must have at least one member - class %s enum %s",cls.name().toAscii().data(),k[i].toAscii().data()); + emit errorFound(); + return; + } + for(int j=0;j + class WocQtClientOut:public WocOutput { public: - WocQtClientOut(QString srcDir,QString subDir,QString prifile); + WocQtClientOut(QString srcDir,QString subDir,QString prifile,bool clean); + ~WocQtClientOut(); protected: virtual void finalize(); virtual void newClass(const WocClass&); virtual void newTable(const WocTable&); virtual void newTransaction(const WocTransaction&); + private: + QString m_basedir,m_subdir; + QFile m_pri; + + /**helper: adds a file to the project file*/ + void addFile(QString basename); + /**helper: generate enums for classes*/ + void classEnums(const WocClass&,QFile&,QFile&,QString); + /**helper: generate properties*/ + void classProperties(const WocClass&,QFile&,QFile&); + /**helper: generate constructors/deserializer/copiers*/ + void classDeserializer(const WocClass&,QFile&,QFile&,QString); + /**helper: generate serializers*/ + void classSerializers(const WocClass&,QFile&,QFile&); + /**helper: generate a proper Qt type for a property*/ + QString qttype(const WocClass&,QString,bool dolist=true); }; #endif