libXDispatch 0.5
include/QtDispatch/qdispatchsource.h
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2011 MLBA. All rights reserved.
00003 *
00004 * @MLBA_OPEN_LICENSE_HEADER_START@
00005 *
00006 * Licensed under the Apache License, Version 2.0 (the "License");
00007 * you may not use this file except in compliance with the License.
00008 * You may obtain a copy of the License at
00009 * 
00010 *     http://www.apache.org/licenses/LICENSE-2.0
00011 * 
00012 * Unless required by applicable law or agreed to in writing, software
00013 * distributed under the License is distributed on an "AS IS" BASIS,
00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 * See the License for the specific language governing permissions and
00016 * limitations under the License.
00017 *
00018 * @MLBA_OPEN_LICENSE_HEADER_END@
00019 */
00020 
00021 
00022 #ifndef QDISPATCH_SOURCE_H_
00023 #define QDISPATCH_SOURCE_H_
00024 
00025 #include <qobject.h>
00026 #include <qrunnable.h>
00027 
00028 #include "qdispatchglobal.h"
00029 #include "../xdispatch/dispatch.h"
00030 
00031 QT_BEGIN_HEADER
00032 QT_BEGIN_NAMESPACE
00033 
00034 class QRunnable;
00035 class QIODevice;
00036 class QNetworkAccessManager;
00037 class QDispatchQueue;
00038 class QNetworkReply;
00039 
00040 QT_MODULE(Dispatch)
00041 
00042 class QDispatchSource;
00043 
00052 class Q_DISPATCH_EXPORT QDispatchSourceType : public QObject {
00053 
00054        Q_OBJECT
00055 
00056 protected:
00060        virtual void init(QThread*) = 0;
00061 
00062 signals:
00072        void ready(QObject* = NULL);
00073 
00074        friend class QDispatchSource;
00075 };
00076 
00084 class Q_DISPATCH_EXPORT QDispatchSourceTypeSignal : public QDispatchSourceType {
00085 
00086 public:
00087        QDispatchSourceTypeSignal(QObject* sender, const char* signal);
00088        ~QDispatchSourceTypeSignal();
00089 
00090 protected:
00091        virtual void init(QThread*);
00092 
00093 private:
00094        Q_DISABLE_COPY(QDispatchSourceTypeSignal);
00095 
00096 };
00097 
00106 class Q_DISPATCH_EXPORT QDispatchSourceTypeIODevice : public QDispatchSourceType {
00107 
00108        Q_OBJECT
00109 
00110 public:
00111        QDispatchSourceTypeIODevice(QIODevice*);
00112        ~QDispatchSourceTypeIODevice();
00113 
00114 protected:
00115        virtual void init(QThread*);
00116 
00117 private slots:
00118        void avail();
00119 
00120 private:
00121        Q_DISABLE_COPY(QDispatchSourceTypeIODevice);
00122        QIODevice* dev;
00123 };
00124 
00133 class Q_DISPATCH_EXPORT QDispatchSourceTypeIODeviceRead : public QDispatchSourceTypeIODevice {
00134 
00135        Q_OBJECT
00136 
00137 public:
00138        QDispatchSourceTypeIODeviceRead(QIODevice*);
00139 
00140 private:
00141        Q_DISABLE_COPY(QDispatchSourceTypeIODeviceRead);
00142 };
00143 
00152 class Q_DISPATCH_EXPORT QDispatchSourceTypeIODeviceWrite : public QDispatchSourceType {
00153 
00154        Q_OBJECT
00155 
00156 public:
00157        QDispatchSourceTypeIODeviceWrite(QIODevice*);
00158        ~QDispatchSourceTypeIODeviceWrite();
00159 
00160 protected:
00161        virtual void init(QThread*);
00162 
00163 private slots:
00164        void finished(qint64);
00165 
00166 private:
00167        Q_DISABLE_COPY(QDispatchSourceTypeIODeviceWrite);
00168        QIODevice* dev;
00169 };
00170 
00179 class Q_DISPATCH_EXPORT QDispatchSourceTypeNetworkManager : public QDispatchSourceType {
00180 
00181        Q_OBJECT
00182 
00183 public:
00184        QDispatchSourceTypeNetworkManager(QNetworkAccessManager*);
00185        ~QDispatchSourceTypeNetworkManager();
00186 
00187 private slots:
00188        void finished(QNetworkReply*);
00189 
00190 protected:
00191        void init(QThread*);
00192 
00193 private:
00194        Q_DISABLE_COPY(QDispatchSourceTypeNetworkManager);
00195        QNetworkAccessManager* manager;
00196 };
00197 
00212 class Q_DISPATCH_EXPORT QDispatchSource : public QObject {
00213 
00214        Q_OBJECT
00215 
00216 public:
00221        QDispatchSource(QDispatchSourceType*);
00222        ~QDispatchSource();
00230        void setHandler(QRunnable*);
00231 #ifdef XDISPATCH_HAS_BLOCKS
00232 
00239        void setHandler(dispatch_block_t);
00240 #endif
00241 
00245        void setTarget(const QDispatchQueue&);
00258        template <typename T> static T* data(){
00259         return qobject_cast<T*>(_data());
00260     }
00261 
00262 public slots:
00263        void resume();
00264        void suspend();
00265 
00266 private slots:
00267        void signal(QObject* = NULL);
00268 
00269 private:
00270        Q_DISABLE_COPY(QDispatchSource);
00271        class Private;
00272        Private* d;
00273 
00274     static QObject* _data();
00275 
00276 };
00277 
00278 
00279 QT_END_NAMESPACE
00280 QT_END_HEADER
00281 
00282 #endif /* QDISPATCH_SOURCE_H_ */

Generated on Wed Feb 22 2012 19:54:05 for libXDispatch by Doxygen 1.7.4
Content © 2011-2012 MLBA (about | privacy) – Design © 2010-2012 Emzeat. All Rights reserved.