00001 // Copyright (C) 2009-2011 by Konrad Rosenbaum <konrad@silmor.de> 00002 // protected under the GNU LGPL version 3 or at your option any newer. 00003 // See COPYING.LGPL file that comes with this distribution. 00004 // 00005 00006 #ifndef WOLF_TRANSACTION_H 00007 #define WOLF_TRANSACTION_H 00008 00009 #include <QObject> 00010 #include <QList> 00011 #include <QString> 00012 00013 #include "nullable.h" 00014 #include "WHelper" 00015 #include <QPointer> 00016 00017 class WTransaction_Private; 00018 00020 class WTransaction:public WHelper 00021 { 00022 Q_OBJECT 00023 Q_ENUMS(Stage) 00024 Q_PROPERTY(Stage stage READ stage) 00025 Q_PROPERTY(bool isInProgress READ isInProgress) 00026 Q_PROPERTY(bool isFinished READ isFinished) 00027 Q_PROPERTY(bool isUnstarted READ isUnstarted) 00028 Q_PROPERTY(bool hasError READ hasError) 00029 Q_PROPERTY(QString errorType READ errorType) 00030 Q_PROPERTY(QString errorString READ errorString) 00031 Q_PROPERTY(QString interfaceName READ interface) 00032 public: 00034 enum Stage { 00035 Uninitialized=0, 00036 Request=1, 00037 Success=6, 00038 Error=10, 00039 }; 00040 00042 virtual Stage stage()const; 00044 virtual bool isInProgress()const{return stage()==Request;} 00046 virtual bool isFinished()const{return stage()&2;} 00048 virtual bool isUnstarted()const{return stage()==Uninitialized;} 00049 00051 virtual bool hasError()const; 00053 virtual QString errorType()const; 00055 virtual QString errorString()const; 00056 00058 virtual QString interface()const; 00059 00061 virtual ~WTransaction(); 00062 00064 class Log; 00065 class LogWrap; 00066 00068 class WaitFor_Private { 00069 public: 00070 virtual ~WaitFor_Private(){} 00071 WaitFor_Private& operator<<(WTransaction&); 00072 WaitFor_Private& operator<<(WTransaction*); 00073 protected: 00074 WaitFor_Private(int t){m_tmout=t;} 00075 virtual void loop()=0; 00076 QList<QPointer<WTransaction> > m_trn; 00077 int m_tmout; 00078 }; 00079 00081 class WaitForAny:public WaitFor_Private{ 00082 public: 00083 WaitForAny(int tmout=0):WaitFor_Private(tmout){} 00084 virtual ~WaitForAny(){loop();} 00085 protected: 00086 void loop(); 00087 }; 00089 class WaitForAll:public WaitFor_Private{ 00090 public: 00091 WaitForAll(int tmout=0):WaitFor_Private(tmout){} 00092 virtual ~WaitForAll(){loop();} 00093 protected: 00094 void loop(); 00095 }; 00096 00097 public slots: 00100 virtual bool waitForFinished(int tmout=30000); 00101 00102 protected: 00104 WTransaction(QString iface=QString()); 00106 WTransaction(const WTransaction&); 00107 00109 virtual WTransaction& operator=(const WTransaction&); 00110 00112 virtual QByteArray executeQuery(QString,QByteArray); 00113 00115 virtual void startQuery(QString,QByteArray); 00116 00118 virtual QByteArray encodeError()const; 00119 00120 protected slots: 00122 virtual void endQuery(); 00123 signals: 00125 void finished(); 00126 protected: 00127 friend class WTransaction::Log; 00128 friend class WTransaction::LogWrap; 00129 friend class WTransaction_Private; 00130 WTransaction_Private *d; 00131 }; 00132 00133 #endif