00001 /* 00002 * Copyright (c) 2011-2012 MLBA-Team. 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 00023 #ifndef QDISPATCH_GROUP_H_ 00024 #define QDISPATCH_GROUP_H_ 00025 00026 #include <QtCore/qobject.h> 00027 #include <QtCore/qscopedpointer.h> 00028 00029 #include "qdispatchglobal.h" 00030 #include "qblockrunnable.h" 00031 00037 QT_BEGIN_HEADER 00038 QT_BEGIN_NAMESPACE 00039 00040 class QRunnable; 00041 class QDispatchQueue; 00042 class QTime; 00043 00044 QT_MODULE(Dispatch) 00045 00046 00056 class Q_DISPATCH_EXPORT QDispatchGroup : public QObject, public xdispatch::group { 00057 00058 Q_OBJECT 00059 00060 public: 00064 QDispatchGroup(); 00065 QDispatchGroup(dispatch_group_t); 00066 QDispatchGroup(const QDispatchGroup&); 00067 QDispatchGroup(const xdispatch::group&); 00068 ~QDispatchGroup(); 00069 00075 void async(QRunnable* r, const xdispatch::queue& q = xdispatch::global_queue()); 00076 using xdispatch::group::async; 00083 bool wait(const QTime& t); 00084 using xdispatch::group::wait; 00097 void notify(QRunnable* r, const xdispatch::queue& = xdispatch::global_queue()); 00101 void notify(xdispatch::operation*, const xdispatch::queue& = xdispatch::global_queue()); 00102 #ifdef XDISPATCH_HAS_BLOCKS 00103 00106 inline void notify(dispatch_block_t b, const xdispatch::queue& q = xdispatch::global_queue()) { 00107 notify( new QBlockRunnable(b), q ); 00108 } 00109 #endif 00110 00124 void enableAllFinishedSignal(); 00125 00126 public slots: 00127 void resume(); 00128 void suspend(); 00129 00130 signals: 00140 void allFinished(); 00141 00142 private: 00143 00144 class Emitter; 00145 friend class Emitter; 00146 friend Q_DECL_EXPORT QDebug operator<<(QDebug, const QDispatchGroup&); 00147 00148 class Private; 00149 QScopedPointer<Private> d; 00150 }; 00151 00152 Q_DECL_EXPORT QDebug operator<<(QDebug, const QDispatchGroup&); 00153 00154 QT_END_NAMESPACE 00155 QT_END_HEADER 00156 00159 #endif /* QDISPATCH_GROUP_H_ */