├── tests └── CMakeLists.txt ├── KF5AsynQtConfig.cmake.in ├── .gitignore ├── metainfo.yaml ├── src ├── libAsynQt.pc.cmake ├── basic │ ├── all.h │ ├── readyfuture.cpp │ ├── readyfuture.h │ ├── delayedfuture.cpp │ ├── canceledfuture.h │ └── delayedfuture.h ├── version.cpp ├── wrappers │ ├── process.cpp │ ├── dbus.h │ └── process.h ├── private │ ├── basic │ │ ├── readyfuture_p.h │ │ ├── delayedfuture_p.h │ │ └── canceledfuture_p.h │ ├── operations │ │ ├── cast_p.h │ │ ├── filter_p.h │ │ ├── flatten_p.h │ │ └── transform_p.h │ ├── utils_p.h │ └── wrappers │ │ ├── dbus_p.h │ │ └── process_p.h ├── operations │ ├── cast.h │ ├── flatten.h │ ├── filter.h │ ├── continuewith.h │ └── transform.h ├── version.h └── CMakeLists.txt ├── vim-extrarc ├── LICENSING ├── autotests ├── CMakeLists.txt ├── base │ ├── cast_test.h │ ├── continuewith_test.h │ ├── flatten_test.h │ ├── filter_test.h │ ├── transform_test.h │ ├── cast_test.cpp │ ├── continuewith_test.cpp │ ├── filter_test.cpp │ ├── flatten_test.cpp │ └── transform_test.cpp ├── wrappers │ ├── basic_test.h │ ├── qdbus_test.h │ ├── qprocess_test.h │ ├── qprocess_test.cpp │ ├── qdbus_test.cpp │ └── basic_test.cpp ├── common.cpp ├── main.cpp └── common.h ├── CMakeLists.txt ├── COPYING.LGPL-3 ├── COPYING.LGPL-2 └── COPYING.LGPL-2.1 /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /KF5AsynQtConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | find_dependency(Qt5Core @REQUIRED_QT_VERSION@) 4 | 5 | include("${CMAKE_CURRENT_LIST_DIR}/KF5AsynQtLibraryTargets.cmake") 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .debug 2 | tags 3 | _tests 4 | .videproject/ctags 5 | *swp 6 | *~ 7 | .kdev4 8 | .cmake-params 9 | .ycm_extra_conf.py 10 | .ycm_extra_conf.pyc 11 | .clang_complete 12 | kactivities.kdev4 13 | compile_commands.json 14 | /apidocs 15 | GPATH 16 | GRTAGS 17 | GSYMS 18 | GTAGS 19 | -------------------------------------------------------------------------------- /metainfo.yaml: -------------------------------------------------------------------------------- 1 | maintainer: ivan 2 | description: Making QFuture useful 3 | tier: 1 4 | type: functional 5 | platforms: 6 | - name: All 7 | portingAid: false 8 | deprecated: false 9 | release: false 10 | libraries: 11 | - qmake: AsynQt 12 | cmake: "KF5::AsynQt" 13 | cmakename: KF5AsynQt 14 | -------------------------------------------------------------------------------- /src/libAsynQt.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=${CMAKE_INSTALL_PREFIX} 2 | exec_prefix=${BIN_INSTALL_DIR} 3 | libdir=${LIB_INSTALL_DIR} 4 | includedir=${INCLUDE_INSTALL_DIR} 5 | 6 | Name: libAsynQt 7 | Description: libAsynQt provides useful features for QFuture 8 | URL: http://www.kde.org 9 | Requires: 10 | Version: ${ASYNQT_LIB_VERSION_STRING} 11 | Libs: -L${LIB_INSTALL_DIR} -lKF5AsynQt 12 | Cflags: -I${INCLUDE_INSTALL_DIR} 13 | -------------------------------------------------------------------------------- /vim-extrarc: -------------------------------------------------------------------------------- 1 | 2 | set makeprg=OBJ_REPLACEMENT='s=src=build-clang='\ makeobj 3 | 4 | imap :SlimuxShellRun make && ./autotests/stats/KActivitiesStatsTest ResultWatcher 5 | map :SlimuxShellRun make && ./autotests/stats/KActivitiesStatsTest ResultWatcher 6 | 7 | let g:ctrlpswitcher_project_sources = expand(':p:h')."/src" 8 | let g:ctrlpswitcher_mode = 1 9 | 10 | set foldmethod=marker 11 | set foldmarker=//_,//^ 12 | 13 | -------------------------------------------------------------------------------- /LICENSING: -------------------------------------------------------------------------------- 1 | 2 | AsynQt is licensed under LGPL 2 or later. 3 | 4 | It is most likely that LGPL 3 is the one that will suit everyone the most, 5 | except projects that use GPL 2. 6 | 7 | Since AsynQt is a header-only library, LGPL 2 might be problematic 8 | due to its viral effect. This problem is fixed in LGPL 3 which 9 | allows using LGPL3 header-only libraries in closed-source projects. 10 | 11 | 12 | For more information about LGPL3, check out the great Eigen Licensing FAQ 13 | http://eigen.tuxfamily.org/index.php?title=Licensing_FAQ&oldid=1116 14 | 15 | -------------------------------------------------------------------------------- /src/basic/all.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "readyfuture.h" 23 | #include "canceledfuture.h" 24 | #include "delayedfuture.h" 25 | 26 | -------------------------------------------------------------------------------- /autotests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim:set softtabstop=3 shiftwidth=3 tabstop=3 expandtab: 2 | project (AsynQtTest) 3 | 4 | find_package (Qt5 REQUIRED NO_MODULE COMPONENTS Test Core DBus) 5 | 6 | include_directories ( 7 | ${CMAKE_SOURCE_DIR}/src/ 8 | ${CMAKE_BINARY_DIR}/src/lib/core/ 9 | ${CMAKE_BINARY_DIR}/src/ 10 | ) 11 | 12 | string (REPLACE "-fno-exceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 13 | add_definitions (-fexceptions) 14 | add_definitions (-DENABLE_EVIL_QFUTURE_HACKS_THAT_SHOULD_BE_IN_QT) 15 | 16 | set ( 17 | AsynQtTest_SRCS 18 | 19 | main.cpp 20 | 21 | wrappers/basic_test.cpp 22 | wrappers/qdbus_test.cpp 23 | wrappers/qprocess_test.cpp 24 | 25 | base/cast_test.cpp 26 | base/continuewith_test.cpp 27 | base/filter_test.cpp 28 | base/flatten_test.cpp 29 | base/transform_test.cpp 30 | 31 | common.cpp 32 | ) 33 | 34 | if (NOT WIN32) 35 | 36 | add_executable ( 37 | AsynQtTest 38 | ${AsynQtTest_SRCS} 39 | ) 40 | 41 | target_link_libraries ( 42 | AsynQtTest 43 | Qt5::Core 44 | Qt5::Test 45 | Qt5::DBus 46 | KF5::AsynQt 47 | ) 48 | 49 | endif () 50 | -------------------------------------------------------------------------------- /src/basic/readyfuture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "readyfuture.h" 23 | 24 | namespace AsynQt { 25 | 26 | QFuture makeReadyFuture() 27 | { 28 | QFutureInterface interface; 29 | auto future = interface.future(); 30 | 31 | interface.reportStarted(); 32 | interface.reportFinished(); 33 | 34 | return future; 35 | } 36 | 37 | } // namespace AsynQt 38 | 39 | -------------------------------------------------------------------------------- /autotests/base/cast_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_CAST_H 23 | #define TEST_CAST_H 24 | 25 | #include 26 | 27 | class QProcess; 28 | 29 | namespace base { 30 | 31 | class CastTest : public QObject { 32 | Q_OBJECT 33 | 34 | public: 35 | CastTest(); 36 | 37 | private Q_SLOTS: 38 | void initTestCase(); 39 | void cleanupTestCase(); 40 | 41 | void testCastBytesToString(); 42 | void testCastBytesToStringWithPipeSyntax(); 43 | 44 | }; 45 | 46 | } // namespace base 47 | 48 | #endif // TEST_CAST_H 49 | 50 | -------------------------------------------------------------------------------- /src/version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "version.h" 23 | 24 | namespace AsynQt { 25 | 26 | unsigned int version() 27 | { 28 | return ASYNQT_VERSION; 29 | } 30 | 31 | unsigned int versionMajor() 32 | { 33 | return ASYNQT_VERSION_MAJOR; 34 | } 35 | 36 | unsigned int versionMinor() 37 | { 38 | return ASYNQT_VERSION_MINOR; 39 | } 40 | 41 | unsigned int versionRelease() 42 | { 43 | return ASYNQT_VERSION_RELEASE; 44 | } 45 | 46 | const char *versionString() 47 | { 48 | return ASYNQT_VERSION_STRING; 49 | } 50 | 51 | } // AsynQt namespace 52 | -------------------------------------------------------------------------------- /autotests/base/continuewith_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_CONTINUEWITH_H 23 | #define TEST_CONTINUEWITH_H 24 | 25 | #include 26 | 27 | class QProcess; 28 | 29 | namespace base { 30 | 31 | class ContinueWithTest : public QObject { 32 | Q_OBJECT 33 | 34 | public: 35 | ContinueWithTest(); 36 | 37 | private Q_SLOTS: 38 | void initTestCase(); 39 | void cleanupTestCase(); 40 | 41 | void testContinueWith(); 42 | void testContinueWithOperator(); 43 | void testContinueWithFailures(); 44 | 45 | }; 46 | 47 | } // namespace base 48 | 49 | #endif // TEST_CONTINUEWITH_H 50 | 51 | -------------------------------------------------------------------------------- /autotests/wrappers/basic_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_BASIC_FUTURES_H 23 | #define TEST_BASIC_FUTURES_H 24 | 25 | #include 26 | 27 | namespace wrappers { 28 | 29 | class BasicFuturesTest : public QObject { 30 | Q_OBJECT 31 | 32 | public: 33 | BasicFuturesTest(); 34 | 35 | private Q_SLOTS: 36 | void initTestCase(); 37 | void cleanupTestCase(); 38 | 39 | void testReadyFutures(); 40 | void testCanceledFutures(); 41 | void testDelayedFutures(); 42 | void testDelayedFuturesStdChrono(); 43 | 44 | }; 45 | 46 | } // namespace wrappers 47 | 48 | #endif // TEST_BASIC_FUTURES_H 49 | 50 | -------------------------------------------------------------------------------- /src/wrappers/process.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "process.h" 23 | 24 | namespace AsynQt { 25 | namespace Process { 26 | 27 | QFuture exec(const QString &command, const QStringList &arguments) 28 | { 29 | return exec(command, arguments, [](QProcess *process) { return process; }); 30 | } 31 | 32 | QFuture getOutput(const QString &command, 33 | const QStringList &arguments) 34 | { 35 | return exec(command, arguments, [](QProcess *process) { 36 | return process->readAllStandardOutput(); 37 | }); 38 | } 39 | 40 | } // namespace Process 41 | } // namespace AsynQt 42 | -------------------------------------------------------------------------------- /autotests/base/flatten_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_FLATTEN_H 23 | #define TEST_FLATTEN_H 24 | 25 | #include 26 | 27 | class QProcess; 28 | 29 | namespace base { 30 | 31 | class FlattenTest : public QObject { 32 | Q_OBJECT 33 | 34 | public: 35 | FlattenTest(); 36 | 37 | private Q_SLOTS: 38 | void initTestCase(); 39 | void cleanupTestCase(); 40 | 41 | void testFlatten(); 42 | void testFlattenWithFailures(); 43 | void testFlattenVoid(); 44 | void testFlattenVoidWithFailures(); 45 | void testFlattenWithPipeSyntax(); 46 | 47 | }; 48 | 49 | } // namespace base 50 | 51 | #endif // TEST_FLATTEN_H 52 | 53 | -------------------------------------------------------------------------------- /autotests/wrappers/qdbus_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_DBUS_H 23 | #define TEST_DBUS_H 24 | 25 | #include 26 | #include 27 | 28 | namespace wrappers { 29 | 30 | class DBusExecutionTest : public QObject { 31 | Q_OBJECT 32 | 33 | public: 34 | DBusExecutionTest(); 35 | 36 | private Q_SLOTS: 37 | void initTestCase(); 38 | void cleanupTestCase(); 39 | 40 | void testDBusExecution(); 41 | void testDBusExecutionWithArgument(); 42 | void testDBusExecutionError(); 43 | 44 | private: 45 | QDBusInterface *m_dbus; 46 | 47 | }; 48 | 49 | } // namespace wrappers 50 | 51 | #endif // TEST_DBUS_H 52 | 53 | -------------------------------------------------------------------------------- /autotests/wrappers/qprocess_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_PROCESS_H 23 | #define TEST_PROCESS_H 24 | 25 | #include 26 | 27 | class QProcess; 28 | 29 | namespace wrappers { 30 | 31 | class ProcessExecutionTest : public QObject { 32 | Q_OBJECT 33 | 34 | public: 35 | ProcessExecutionTest(); 36 | 37 | private Q_SLOTS: 38 | void initTestCase(); 39 | void cleanupTestCase(); 40 | 41 | void testProcessExecution(); 42 | void testProcessExecutionWithMap(); 43 | void testProcessOutput(); 44 | 45 | private: 46 | QProcess *m_process; 47 | 48 | }; 49 | 50 | } // namespace wrappers 51 | 52 | #endif // TEST_PROCESS_H 53 | 54 | -------------------------------------------------------------------------------- /autotests/common.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "common.h" 23 | 24 | namespace common { 25 | 26 | QByteArray _helloKdeMessage = "Hello KDE!\n"; 27 | 28 | QByteArray helloKdeMessage() 29 | { 30 | return _helloKdeMessage; 31 | } 32 | 33 | QFuture execHelloKde() 34 | { 35 | return Process::getOutput("echo", { _helloKdeMessage.trimmed() }); 36 | } 37 | 38 | QFuture execEcho(const QString &message) 39 | { 40 | return Process::getOutput("echo", { message.trimmed() }); 41 | } 42 | 43 | QFuture fail(const QString &message) 44 | { 45 | Q_UNUSED(message) 46 | return makeCanceledFuture(); 47 | } 48 | 49 | } // namespace common 50 | 51 | -------------------------------------------------------------------------------- /autotests/base/filter_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_FILTER_H 23 | #define TEST_FILTER_H 24 | 25 | #include 26 | 27 | class QProcess; 28 | 29 | namespace base { 30 | 31 | class FilterTest : public QObject { 32 | Q_OBJECT 33 | 34 | public: 35 | FilterTest(); 36 | 37 | private Q_SLOTS: 38 | void initTestCase(); 39 | void cleanupTestCase(); 40 | 41 | void testFilterWithFunctions(); 42 | void testFilterWithFunctionObjects(); 43 | void testFilterWithLambdas(); 44 | void testFilterWithPipeSyntax(); 45 | 46 | void testFilterWithCanceledFutures(); 47 | void testFilterWithReadyFutures(); 48 | 49 | }; 50 | 51 | } // namespace base 52 | 53 | #endif // TEST_FILTER_H 54 | 55 | -------------------------------------------------------------------------------- /src/private/basic/readyfuture_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | namespace AsynQt { 34 | namespace detail { 35 | 36 | template 37 | QFuture::type> 38 | makeReadyFuture(_Result &&value) 39 | { 40 | QFutureInterface<_Result> interface; 41 | auto future = interface.future(); 42 | 43 | interface.reportStarted(); 44 | interface.reportResult(std::forward<_Result>(value)); 45 | interface.reportFinished(); 46 | 47 | return future; 48 | } 49 | 50 | } // namespace detail 51 | } // namespace AsynQt 52 | 53 | -------------------------------------------------------------------------------- /src/basic/readyfuture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_CONS_READY_FUTURE_H 23 | #define ASYNQT_CONS_READY_FUTURE_H 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "../private/basic/readyfuture_p.h" 33 | 34 | namespace AsynQt { 35 | 36 | /** 37 | * Creates a future that has already been completed, 38 | * and that contains the specified value 39 | */ 40 | template 41 | QFuture::type> makeReadyFuture(_Result &&value) 42 | { 43 | return detail::makeReadyFuture(std::forward<_Result>(value)); 44 | } 45 | 46 | /** 47 | * Creates a void future that has already been completed. 48 | */ 49 | ASYNQT_EXPORT 50 | QFuture makeReadyFuture(); 51 | 52 | } // namespace AsynQt 53 | 54 | #endif // ASYNQT_CONS_READY_FUTURE_H 55 | 56 | -------------------------------------------------------------------------------- /autotests/base/transform_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TEST_TRANSFORM_H 23 | #define TEST_TRANSFORM_H 24 | 25 | #include 26 | 27 | class QProcess; 28 | 29 | namespace base { 30 | 31 | class TransformTest : public QObject { 32 | Q_OBJECT 33 | 34 | public: 35 | TransformTest(); 36 | 37 | private Q_SLOTS: 38 | void initTestCase(); 39 | void cleanupTestCase(); 40 | 41 | void testTransformWithFunctions(); 42 | void testTransformWithFunctionObjects(); 43 | void testTransformWithLambdas(); 44 | void testTransformWithPipeSyntax(); 45 | 46 | void testTransformVoidToValueFuture(); 47 | void testTransformValueToVoidFuture(); 48 | void testTransformVoidToVoidFuture(); 49 | 50 | void testTransformWithCanceledFutures(); 51 | void testTransformWithReadyFutures(); 52 | 53 | }; 54 | 55 | } // namespace base 56 | 57 | #endif // TEST_TRANSFORM_H 58 | 59 | -------------------------------------------------------------------------------- /autotests/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "common.h" 27 | 28 | #include "wrappers/basic_test.h" 29 | #include "wrappers/qdbus_test.h" 30 | #include "wrappers/qprocess_test.h" 31 | 32 | #include "base/cast_test.h" 33 | #include "base/continuewith_test.h" 34 | #include "base/filter_test.h" 35 | #include "base/flatten_test.h" 36 | #include "base/transform_test.h" 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | QCoreApplication app(argc, argv); 41 | 42 | RUN_TEST(wrappers::ProcessExecutionTest); 43 | RUN_TEST(wrappers::DBusExecutionTest); 44 | RUN_TEST(wrappers::BasicFuturesTest); 45 | 46 | RUN_TEST(base::CastTest); 47 | RUN_TEST(base::TransformTest); 48 | RUN_TEST(base::FlattenTest); 49 | RUN_TEST(base::FilterTest); 50 | RUN_TEST(base::ContinueWithTest); 51 | 52 | return 1; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/operations/cast.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_BASE_CAST_H 23 | #define ASYNQT_BASE_CAST_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "transform.h" 32 | #include "../private/operations/cast_p.h" 33 | 34 | namespace AsynQt { 35 | 36 | /** 37 | * Casts the future result into the specified type. 38 | * 39 | * 40 | * auto future = AsynQt::Process::getOutput("echo", { "Hello KDE" }); 41 | * auto castFuture = AsynQt::qfuture_cast(future); 42 | * 43 | */ 44 | template 45 | QFuture<_Out> qfuture_cast(const QFuture<_In> &future) 46 | { 47 | return detail::qfuture_cast_impl<_Out>(future); 48 | } 49 | 50 | namespace operators { 51 | 52 | template 53 | detail::operators::CastModifier<_Out> cast() 54 | { 55 | return detail::operators::CastModifier<_Out>(); 56 | } 57 | 58 | } // namespace operator 59 | 60 | } // namespace AsynQt 61 | 62 | #endif // ASYNQT_BASE_CAST_H 63 | 64 | -------------------------------------------------------------------------------- /src/operations/flatten.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_BASE_FLATTEN_H 23 | #define ASYNQT_BASE_FLATTEN_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "../private/operations/flatten_p.h" 32 | 33 | namespace AsynQt { 34 | 35 | /** 36 | * Takes a future of a future, and flattens it out. 37 | * 38 | * If any of the futures is canceled, the resulting future 39 | * will be canceled as well. 40 | * 41 | * @arg future future that contains another future of type T 42 | * @returns a single-level future of type T 43 | */ 44 | template 45 | QFuture<_Result> flatten(const QFuture> &future) 46 | { 47 | return detail::flatten_impl(future); 48 | } 49 | 50 | namespace operators { 51 | 52 | inline 53 | detail::operators::FlattenModifier flatten() 54 | { 55 | return detail::operators::FlattenModifier(); 56 | } 57 | 58 | } // namespace operators 59 | 60 | } // namespace AsynQt 61 | 62 | #endif // ASYNQT_BASE_FLATTEN_H 63 | 64 | -------------------------------------------------------------------------------- /src/private/operations/cast_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | 23 | // 24 | // W A R N I N G 25 | // ------------- 26 | // 27 | // This file is not part of the AsynQt API. It exists purely as an 28 | // implementation detail. This header file may change from version to 29 | // version without notice, or even be removed. 30 | // 31 | // We mean it. 32 | // 33 | 34 | namespace AsynQt { 35 | namespace detail { 36 | 37 | template 38 | QFuture<_Out> qfuture_cast_impl(const QFuture<_In> &future) 39 | { 40 | return transform(future, [] (const _In &value) -> _Out { 41 | return static_cast<_Out>(value); 42 | }); 43 | } 44 | 45 | namespace operators { 46 | 47 | template 48 | struct CastModifier { 49 | }; 50 | 51 | template 52 | auto operator | (const QFuture<_In> &future, 53 | CastModifier<_Out> &&) 54 | -> decltype(qfuture_cast_impl<_Out>(future)) 55 | { 56 | return qfuture_cast_impl<_Out>(future); 57 | } 58 | 59 | } // namespace operators 60 | 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/basic/delayedfuture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "delayedfuture.h" 23 | 24 | namespace AsynQt { 25 | 26 | namespace detail { 27 | 28 | class DelayedVoidFutureInterface 29 | : public QObject 30 | , QFutureInterface { 31 | 32 | public: 33 | DelayedVoidFutureInterface(int milliseconds) 34 | : m_milliseconds(milliseconds) 35 | { 36 | } 37 | 38 | QFuture start() 39 | { 40 | auto future = this->future(); 41 | 42 | this->reportStarted(); 43 | 44 | QTimer::singleShot(m_milliseconds, [this] { 45 | this->reportFinished(); 46 | deleteLater(); 47 | }); 48 | 49 | deleteLater(); 50 | 51 | return future; 52 | } 53 | 54 | private: 55 | int m_milliseconds; 56 | }; 57 | 58 | } // namespace detail 59 | 60 | QFuture makeDelayedFuture(int milliseconds) 61 | { 62 | using namespace detail; 63 | return (new DelayedVoidFutureInterface(milliseconds))->start(); 64 | } 65 | 66 | } // namespace AsynQt 67 | 68 | -------------------------------------------------------------------------------- /src/operations/filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_BASE_FILTER_H 23 | #define ASYNQT_BASE_FILTER_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "../private/operations/filter_p.h" 32 | 33 | namespace AsynQt { 34 | 35 | /** 36 | * Takes a future of a future, and flattens it out. 37 | * 38 | * If any of the futures is canceled, the resulting future 39 | * will be canceled as well. 40 | * 41 | * @arg future future that contains another future of type T 42 | * @returns a single-level future of type T 43 | */ 44 | template 45 | QFuture<_Result> filter(const QFuture<_Result> &future, 46 | _Predicate &&predicate) 47 | { 48 | return detail::filter_impl(future, std::forward<_Predicate>(predicate)); 49 | } 50 | 51 | namespace operators { 52 | 53 | template 54 | inline 55 | detail::operators::FilterModifier<_Predicate> filter(_Predicate &&predicate) 56 | { 57 | return detail::operators::FilterModifier<_Predicate>(std::forward<_Predicate>(predicate)); 58 | } 59 | 60 | } // namespace operators 61 | 62 | } // namespace AsynQt 63 | 64 | #endif // ASYNQT_BASE_FILTER_H 65 | 66 | -------------------------------------------------------------------------------- /src/private/utils_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_PRIVATE_UTILS_P_H 23 | #define ASYNQT_PRIVATE_UTILS_P_H 24 | 25 | namespace AsynQt { 26 | namespace detail { 27 | 28 | #define IMPLEMENT_FUTURE_WATCHER_HANDLER(SignalName, EventName) \ 29 | template \ 30 | inline void EventName(const std::unique_ptr> &watcher, \ 31 | Function function) \ 32 | { \ 33 | QObject::connect(watcher.get(), &QFutureWatcherBase::SignalName, \ 34 | function); \ 35 | } 36 | 37 | IMPLEMENT_FUTURE_WATCHER_HANDLER(finished, onFinished) 38 | IMPLEMENT_FUTURE_WATCHER_HANDLER(canceled, onCanceled) 39 | IMPLEMENT_FUTURE_WATCHER_HANDLER(resultReadyAt, onResultReadyAt) 40 | 41 | template 42 | inline void 43 | onResultReadyAt(const std::unique_ptr> &watcher, 44 | Function function) 45 | { 46 | Q_UNUSED(watcher) 47 | Q_UNUSED(function) 48 | } 49 | 50 | #undef IMPLEMENT_FUTURE_WATCHER_HANDLER 51 | 52 | } // namespace detail 53 | } // namespace AsynQt 54 | 55 | #endif // ASYNQT_PRIVATE_UTILS_P_H 56 | 57 | -------------------------------------------------------------------------------- /src/private/basic/delayedfuture_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | namespace AsynQt { 34 | namespace detail { 35 | 36 | template 37 | class DelayedFutureInterface 38 | : public QObject 39 | , public QFutureInterface<_Result> { 40 | 41 | public: 42 | DelayedFutureInterface(_Result value, int milliseconds) 43 | : m_value(value) 44 | , m_milliseconds(milliseconds) 45 | { 46 | } 47 | 48 | QFuture<_Result> start() 49 | { 50 | auto future = this->future(); 51 | 52 | this->reportStarted(); 53 | 54 | QTimer::singleShot(m_milliseconds, [this] { 55 | this->reportResult(m_value); 56 | this->reportFinished(); 57 | deleteLater(); 58 | }); 59 | 60 | return future; 61 | } 62 | 63 | private: 64 | _Result m_value; 65 | int m_milliseconds; 66 | 67 | }; 68 | 69 | template 70 | DelayedFutureInterface::type> * 71 | newDelayedFutureInterface(_Result &&result, int milliseconds) 72 | { 73 | return new DelayedFutureInterface::type>( 74 | std::forward<_Result>(result), milliseconds); 75 | } 76 | 77 | } // namespace detail 78 | } // namespace AsynQt 79 | 80 | -------------------------------------------------------------------------------- /autotests/wrappers/qprocess_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "qprocess_test.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "common.h" 31 | 32 | namespace wrappers { 33 | 34 | ProcessExecutionTest::ProcessExecutionTest() 35 | { 36 | } 37 | 38 | void ProcessExecutionTest::testProcessExecution() 39 | { 40 | auto future = AsynQt::Process::exec("sleep", { "2" }); 41 | 42 | QVERIFY(waitForFuture(future, 3 _seconds)); 43 | 44 | auto process = future.result(); 45 | 46 | QCOMPARE(process->program(), QString("sleep")); 47 | } 48 | 49 | void ProcessExecutionTest::testProcessExecutionWithMap() 50 | { 51 | bool mapFunctionCalled = false; 52 | 53 | auto future = AsynQt::Process::exec( 54 | "sleep", { "2" }, 55 | [&mapFunctionCalled] (QProcess *process) { 56 | mapFunctionCalled = true; 57 | 58 | return process->exitCode(); 59 | }); 60 | 61 | QVERIFY(waitForFuture(future, 3 _seconds)); 62 | 63 | QVERIFY(mapFunctionCalled); 64 | 65 | QCOMPARE(future.result(), 0); 66 | } 67 | 68 | void ProcessExecutionTest::testProcessOutput() 69 | { 70 | auto future = AsynQt::Process::getOutput("echo", { "Hello KDE" }); 71 | 72 | QVERIFY(waitForFuture(future, 1 _seconds)); 73 | 74 | QCOMPARE(future.result(), QByteArray("Hello KDE\n")); 75 | 76 | } 77 | 78 | void ProcessExecutionTest::initTestCase() 79 | { 80 | m_process = new QProcess(); 81 | } 82 | 83 | void ProcessExecutionTest::cleanupTestCase() 84 | { 85 | delete m_process; 86 | } 87 | 88 | } // namespace wrappers 89 | -------------------------------------------------------------------------------- /autotests/wrappers/qdbus_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "qdbus_test.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | namespace wrappers { 36 | 37 | DBusExecutionTest::DBusExecutionTest() 38 | { 39 | } 40 | 41 | void DBusExecutionTest::testDBusExecution() 42 | { 43 | auto future = AsynQt::DBus::asyncCall(m_dbus, "GetId"); 44 | 45 | QVERIFY(waitForFuture(future, 1 _seconds)); 46 | 47 | auto result = future.result(); 48 | 49 | QCOMPARE(result.size(), 50 | QString("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").size()); 51 | 52 | VERIFY_TYPE(future, QFuture); 53 | } 54 | 55 | void DBusExecutionTest::testDBusExecutionWithArgument() 56 | { 57 | auto future = AsynQt::DBus::asyncCall( 58 | m_dbus, "GetNameOwner", "org.freedesktop.DBus"); 59 | 60 | COMPARE_FINISHED_BEFORE(future, QStringLiteral("org.freedesktop.DBus"), 1 _seconds); 61 | VERIFY_TYPE(future, QFuture); 62 | } 63 | 64 | void DBusExecutionTest::testDBusExecutionError() 65 | { 66 | auto future = AsynQt::DBus::asyncCall( 67 | m_dbus, "ThisMethodDoesNotExist_Really_Really"); 68 | 69 | VERIFY_CANCELED_BEFORE(future, 1 _seconds); 70 | VERIFY_TYPE(future, QFuture); 71 | } 72 | 73 | 74 | void DBusExecutionTest::initTestCase() 75 | { 76 | m_dbus = new QDBusInterface("org.freedesktop.DBus", "/"); 77 | } 78 | 79 | void DBusExecutionTest::cleanupTestCase() 80 | { 81 | delete m_dbus; 82 | } 83 | 84 | } // namespace wrappers 85 | 86 | -------------------------------------------------------------------------------- /autotests/base/cast_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "cast_test.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "common.h" 32 | 33 | namespace base { 34 | 35 | CastTest::CastTest() 36 | { 37 | } 38 | 39 | void CastTest::testCastBytesToString() 40 | { 41 | auto future = AsynQt::Process::getOutput("echo", { "Hello KDE" }); 42 | 43 | auto castFuture = AsynQt::qfuture_cast(future); 44 | 45 | COMPARE_FINISHED_BEFORE(castFuture, QString("Hello KDE\n"), 1 _seconds); 46 | VERIFY_TYPE(future, QFuture); 47 | VERIFY_TYPE(castFuture, QFuture); 48 | } 49 | 50 | void CastTest::testCastBytesToStringWithPipeSyntax() 51 | { 52 | using namespace operators; 53 | 54 | TEST_CHUNK("With temporary future") { 55 | auto future = AsynQt::Process::getOutput("echo", { "Hello KDE" }); 56 | 57 | auto castFuture = future | cast(); 58 | 59 | COMPARE_FINISHED_BEFORE(castFuture, QString("Hello KDE\n"), 1 _seconds); 60 | VERIFY_TYPE(future, QFuture); 61 | VERIFY_TYPE(castFuture, QFuture); 62 | } 63 | 64 | TEST_CHUNK("Without temporary future") { 65 | auto castFuture = AsynQt::Process::getOutput("echo", { "Hello KDE" }) 66 | | cast(); 67 | 68 | COMPARE_FINISHED_BEFORE(castFuture, QString("Hello KDE\n"), 1 _seconds); 69 | VERIFY_TYPE(castFuture, QFuture); 70 | } 71 | } 72 | 73 | 74 | 75 | void CastTest::initTestCase() 76 | { 77 | } 78 | 79 | void CastTest::cleanupTestCase() 80 | { 81 | } 82 | 83 | } // namespace base 84 | 85 | -------------------------------------------------------------------------------- /src/private/basic/canceledfuture_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | namespace AsynQt { 34 | 35 | namespace detail { 36 | 37 | template 38 | QFuture<_Result> makeCanceledFuture() 39 | { 40 | QFutureInterface<_Result> interface; 41 | auto future = interface.future(); 42 | 43 | interface.reportStarted(); 44 | interface.reportCanceled(); 45 | interface.reportFinished(); 46 | 47 | return future; 48 | } 49 | 50 | #ifndef QT_NO_EXCEPTIONS 51 | template 52 | QFuture<_Result> makeCanceledFuture(const QException &exception) 53 | { 54 | QFutureInterface<_Result> interface; 55 | auto future = interface.future(); 56 | 57 | interface.reportStarted(); 58 | interface.reportException(exception); 59 | interface.reportFinished(); 60 | 61 | return future; 62 | } 63 | #endif 64 | 65 | 66 | } // namespace detail 67 | } // namespace AsynQt 68 | 69 | #ifdef ENABLE_EVIL_QFUTURE_HACKS_THAT_SHOULD_BE_IN_QT 70 | 71 | class AsynQt_QFuturePrivacyHack_hasException; 72 | template <> 73 | inline bool QFuture::isCanceled() const 74 | { 75 | return d.exceptionStore().hasException(); 76 | } 77 | 78 | class AsynQt_QFuturePrivacyHack_throwPossibleException; 79 | template <> 80 | inline void QFuture::cancel() 81 | { 82 | return d.exceptionStore().throwPossibleException(); 83 | } 84 | 85 | #endif 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/wrappers/dbus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_CONS_DBUSFUTURE_H 23 | #define ASYNQT_CONS_DBUSFUTURE_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include "../private/wrappers/dbus_p.h" 36 | 37 | namespace AsynQt { 38 | 39 | /** 40 | * Creates a future from the specified dbus reply 41 | */ 42 | template 43 | QFuture<_Result> makeFuture(QDBusPendingReply<_Result> dbusReply) 44 | { 45 | using namespace detail; 46 | 47 | return (new DBusCallFutureInterface<_Result>(dbusReply))->start(); 48 | } 49 | 50 | namespace DBus { 51 | 52 | /** 53 | * Makes an asynchronous call to the specified DBus interface, 54 | * and wraps the result in a future. 55 | */ 56 | template 57 | QFuture<_Result> 58 | asyncCall(QDBusAbstractInterface *interface, const QString &method, 59 | const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), 60 | const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), 61 | const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), 62 | const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant()) 63 | { 64 | using namespace detail; 65 | 66 | auto callFutureInterface = new DBusCallFutureInterface 67 | <_Result>(interface->asyncCall(method, arg1, arg2, arg3, arg4, arg5, 68 | arg6, arg7, arg8)); 69 | 70 | return callFutureInterface->start(); 71 | } 72 | 73 | } // namespace DBus 74 | 75 | } // namespace AsynQt 76 | 77 | #endif // ASYNQT_CONS_DBUSFUTURE_H 78 | 79 | -------------------------------------------------------------------------------- /src/private/wrappers/dbus_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | namespace AsynQt { 34 | namespace detail { 35 | 36 | template 37 | class DBusCallFutureInterface : public QObject, 38 | public QFutureInterface<_Result> { 39 | public: 40 | DBusCallFutureInterface(QDBusPendingReply<_Result> reply) 41 | : reply(reply) 42 | { 43 | } 44 | 45 | ~DBusCallFutureInterface() 46 | { 47 | } 48 | 49 | void callFinished(); 50 | 51 | QFuture<_Result> start() 52 | { 53 | replyWatcher.reset(new QDBusPendingCallWatcher(reply)); 54 | 55 | QObject::connect(replyWatcher.get(), 56 | &QDBusPendingCallWatcher::finished, 57 | [this] () { callFinished(); }); 58 | 59 | this->reportStarted(); 60 | 61 | if (reply.isFinished()) { 62 | this->callFinished(); 63 | } 64 | 65 | return this->future(); 66 | } 67 | 68 | private: 69 | QDBusPendingReply<_Result> reply; 70 | std::unique_ptr replyWatcher; 71 | }; 72 | 73 | template 74 | void DBusCallFutureInterface<_Result>::callFinished() 75 | { 76 | if (!reply.isError()) { 77 | this->reportResult(reply.value()); 78 | this->reportFinished(); 79 | 80 | } else { 81 | this->reportCanceled(); 82 | 83 | } 84 | 85 | deleteLater(); 86 | } 87 | 88 | template <> 89 | void DBusCallFutureInterface::callFinished(); 90 | 91 | } // namespace detail 92 | } // namespace AsynQt 93 | 94 | -------------------------------------------------------------------------------- /src/operations/continuewith.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_BASE_CONTINUEWITH_H 23 | #define ASYNQT_BASE_CONTINUEWITH_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "flatten.h" 32 | #include "transform.h" 33 | 34 | namespace AsynQt { 35 | 36 | /** 37 | * This method is similar to `transform`, 38 | * but it takes a transformation function (in this 39 | * case, called a continuation) that does not 40 | * return a normal value, but also a new future. 41 | * It returns the future that will be returned 42 | * by the continuation. 43 | * 44 | * It is equivalent to calling `flatten` on the result 45 | * of the `transform` function when a continuation 46 | * is passed to it. 47 | * 48 | * Example: 49 | * 50 | * 51 | * QFuture input = getUserInput(); 52 | * QFuture continueWith(input, [] (QString message) { 53 | * return server.send(message); 54 | * }); 55 | * 56 | * 57 | * @arg future the future to connect the continuation to 58 | * @arg continuation the continuation function 59 | * @returns the future that the continuation will return 60 | */ 61 | template 62 | auto continueWith(const QFuture<_In> &future, _Continuation &&continuation) 63 | -> decltype(flatten(transform(future, std::forward<_Continuation>(continuation)))) 64 | { 65 | return flatten(transform(future, std::forward<_Continuation>(continuation))); 66 | } 67 | 68 | namespace operators { 69 | 70 | template 71 | auto operator | (const QFuture<_In> &future, _Continuation &&continuation) 72 | -> decltype(continueWith(future, continuation)) 73 | { 74 | return continueWith(future, continuation); 75 | } 76 | 77 | } // namespace operators 78 | 79 | } // namespace AsynQt 80 | 81 | #endif // ASYNQT_BASE_CONTINUEWITH_H 82 | 83 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_VERSION_H 23 | #define ASYNQT_VERSION_H 24 | 25 | /** @file version.h */ 26 | 27 | #include 28 | // #include "asynqt_export.h" 29 | 30 | /** 31 | * String version of libAsynQt version, suitable for use in 32 | * file formats or network protocols 33 | */ 34 | #define ASYNQT_VERSION_STRING \ 35 | "6.2.0" 36 | 37 | /// @brief Major version of libAsynQt, at compile time 38 | #define ASYNQT_VERSION_MAJOR \ 39 | 6 40 | /// @brief Minor version of libAsynQt, at compile time 41 | #define ASYNQT_VERSION_MINOR \ 42 | 2 43 | /// @brief Release version of libAsynQt, at compile time 44 | #define ASYNQT_VERSION_RELEASE \ 45 | 0 46 | 47 | #define ASYNQT_MAKE_VERSION(a, b, c) \ 48 | (((a) << 16) | ((b) << 8) | (c)) 49 | 50 | /** 51 | * Compile time macro for the version number of libAsynQt 52 | */ 53 | #define ASYNQT_VERSION \ 54 | ASYNQT_MAKE_VERSION(ASYNQT_VERSION_MAJOR, ASYNQT_VERSION_MINOR, ASYNQT_VERSION_RELEASE) 55 | 56 | /** 57 | * Compile-time macro for checking the AsynQt version. Not useful for 58 | * detecting the version of libAsynQt at runtime. 59 | */ 60 | #define ASYNQT_IS_VERSION(a, b, c) \ 61 | (ASYNQT_VERSION >= ASYNQT_MAKE_VERSION(a, b, c)) 62 | 63 | /** 64 | * Namespace for everything in libAsynQt 65 | */ 66 | namespace AsynQt { 67 | 68 | /** 69 | * The runtime version of libAsynQt 70 | */ 71 | ASYNQT_EXPORT unsigned int version(); 72 | 73 | /** 74 | * The runtime major version of libAsynQt 75 | */ 76 | ASYNQT_EXPORT unsigned int versionMajor(); 77 | 78 | /** 79 | * The runtime major version of libAsynQt 80 | */ 81 | ASYNQT_EXPORT unsigned int versionMinor(); 82 | 83 | /** 84 | * The runtime major version of libAsynQt 85 | */ 86 | ASYNQT_EXPORT unsigned int versionRelease(); 87 | 88 | /** 89 | * The runtime version string of libAsynQt 90 | */ 91 | ASYNQT_EXPORT const char *versionString(); 92 | 93 | } // AsynQt namespace 94 | 95 | #endif // multiple inclusion guard 96 | -------------------------------------------------------------------------------- /src/basic/canceledfuture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_CONS_CANCELED_FUTURE_H 23 | #define ASYNQT_CONS_CANCELED_FUTURE_H 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifndef QT_NO_EXCEPTIONS 33 | #include 34 | #endif 35 | 36 | #include "../private/basic/canceledfuture_p.h" 37 | 38 | namespace AsynQt { 39 | 40 | /** 41 | * Creates a canceled future. 42 | */ 43 | template 44 | QFuture<_Result> makeCanceledFuture() 45 | { 46 | // No need to decay the type, expecting the user not to try 47 | // and make a future of ref-to-type or anything that funny 48 | return detail::makeCanceledFuture<_Result>(); 49 | } 50 | 51 | #ifndef QT_NO_EXCEPTIONS 52 | /** 53 | * Creates a canceled future. 54 | */ 55 | template 56 | QFuture<_Result> makeCanceledFuture(const QException &exception) 57 | { 58 | // No need to decay the type, expecting the user not to try 59 | // and make a future of ref-to-type or anything that funny 60 | return detail::makeCanceledFuture<_Result>(exception); 61 | } 62 | 63 | #ifdef ENABLE_EVIL_QFUTURE_HACKS_THAT_SHOULD_BE_IN_QT 64 | 65 | namespace evil { 66 | 67 | // TODO: Remove these 68 | 69 | template 70 | bool hasException(const QFuture &future) 71 | { 72 | return 73 | reinterpret_cast*>( 74 | &future) 75 | ->isCanceled(); 76 | } 77 | 78 | template 79 | void throwPossibleException(QFuture &future) 80 | { 81 | reinterpret_cast*>( 82 | &future) 83 | ->cancel(); 84 | } 85 | 86 | } // namespace evil 87 | 88 | #endif 89 | 90 | 91 | #else 92 | #warning "Exceptions are disabled. If you enable them, you'll open a whole new world" 93 | #endif 94 | 95 | } // namespace AsynQt 96 | 97 | #endif // ASYNQT_CONS_CANCELED_FUTURE_H 98 | 99 | -------------------------------------------------------------------------------- /src/operations/transform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_BASE_TRANSFORM_H 23 | #define ASYNQT_BASE_TRANSFORM_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "../private/operations/transform_p.h" 32 | 33 | namespace AsynQt { 34 | 35 | /** 36 | * This method applies the specified transformation function to 37 | * the value stored in the given future. Since the value might not 38 | * yet be present, it returns a future that will contain the 39 | * transformed value as soon as the original future is finished. 40 | * 41 | * If the original future is canceled, the transformation function 42 | * will not be invoked, and the resulting future will also be canceled. 43 | * 44 | * Example: 45 | * 46 | * 47 | * QFuture answer = meaningOfLife() 48 | * // answer will eventually contain 42 49 | * 50 | * QFuture text = transform(answer, toText) 51 | * // text will eventually contain the result of toText(42) 52 | * 53 | * 54 | * @arg future the future to transform 55 | * @arg transformation unary function to apply to the value in the future 56 | * @returns a future that will contain the transformed value 57 | */ 58 | template 59 | QFuture< 60 | typename detail::TransformFutureInterface<_In, _Transformation>::result_type 61 | > 62 | transform(const QFuture<_In> &future, _Transformation &&transormation) 63 | { 64 | using namespace detail; 65 | return transform_impl(future, std::forward<_Transformation>(transormation)); 66 | } 67 | 68 | namespace operators { 69 | 70 | template 71 | detail::operators::TransformationModifier<_Transformation> 72 | transform(_Transformation &&transormation) 73 | { 74 | return detail::operators::TransformationModifier<_Transformation>( 75 | std::forward<_Transformation>(transormation)); 76 | } 77 | 78 | } // namespace operators 79 | 80 | } // namespace AsynQt 81 | 82 | #endif // ASYNQT_BASE_TRANSFORM_H 83 | 84 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim:set softtabstop=3 shiftwidth=3 tabstop=3 expandtab: 2 | 3 | cmake_minimum_required (VERSION 2.8.11) 4 | 5 | project (AsynQt) 6 | 7 | set (REQUIRED_QT_VERSION 5.3.0) 8 | 9 | # We don't build in-source 10 | if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") 11 | message ( 12 | FATAL_ERROR 13 | "asynqt requires an out of source build. Please create a separate build directory and run 'cmake path_to_plasma [options]' there." 14 | ) 15 | endif () 16 | 17 | # Extra CMake stuff 18 | include (FeatureSummary) 19 | find_package (ECM 5.17.0 NO_MODULE) 20 | set_package_properties (ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") 21 | feature_summary (WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) 22 | 23 | set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) 24 | 25 | include (KDEInstallDirs) 26 | include (KDECMakeSettings) 27 | include (KDECompilerSettings) 28 | include (GenerateExportHeader) 29 | include (ECMGenerateHeaders) 30 | 31 | # Qt 32 | set (CMAKE_AUTOMOC ON) 33 | find_package (Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED COMPONENTS Core) 34 | 35 | # KDE Frameworks 36 | set(KF5_VERSION "5.18.0") # handled by release scripts 37 | set(KF5_DEP_VERSION "5.17.0") # handled by release scripts 38 | 39 | find_package (KF5I18n ${KF5_DEP_VERSION} CONFIG REQUIRED) 40 | find_package (KF5KIO ${KF5_DEP_VERSION} CONFIG REQUIRED) 41 | find_package (KF5Config ${KF5_DEP_VERSION} CONFIG REQUIRED) 42 | 43 | # Basic includes 44 | include (CPack) 45 | 46 | include (ECMPackageConfigHelpers) 47 | include (ECMSetupVersion) 48 | 49 | add_definitions (-DTRANSLATION_DOMAIN=\"asynqt5\") 50 | if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") 51 | ki18n_install (po) 52 | endif () 53 | 54 | # libAsynQt 55 | 56 | ecm_setup_version ( 57 | ${KF5_VERSION} 58 | VARIABLE_PREFIX ASYNQT 59 | VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/asynqt_version.h" 60 | PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5AsynQtConfigVersion.cmake" 61 | SOVERSION 5 62 | ) 63 | 64 | set (CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5AsynQt") 65 | 66 | install ( 67 | EXPORT KF5AsynQtLibraryTargets 68 | DESTINATION "${CMAKECONFIG_INSTALL_DIR}" 69 | FILE KF5AsynQtLibraryTargets.cmake 70 | NAMESPACE KF5:: 71 | ) 72 | 73 | ecm_configure_package_config_file ( 74 | "${CMAKE_CURRENT_SOURCE_DIR}/KF5AsynQtConfig.cmake.in" 75 | "${CMAKE_CURRENT_BINARY_DIR}/KF5AsynQtConfig.cmake" 76 | INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} 77 | PATH_VARS KF5_INCLUDE_INSTALL_DIR CMAKE_INSTALL_PREFIX 78 | ) 79 | 80 | install ( 81 | FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5AsynQtConfig.cmake" 82 | "${CMAKE_CURRENT_BINARY_DIR}/KF5AsynQtConfigVersion.cmake" 83 | DESTINATION "${CMAKECONFIG_INSTALL_DIR}" 84 | COMPONENT Devel 85 | ) 86 | 87 | install ( 88 | FILES ${CMAKE_CURRENT_BINARY_DIR}/asynqt_version.h 89 | DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel 90 | ) 91 | 92 | add_subdirectory (src) 93 | add_subdirectory (autotests) 94 | add_subdirectory (tests) 95 | 96 | # Write out the features 97 | feature_summary (WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 98 | 99 | -------------------------------------------------------------------------------- /src/private/wrappers/process_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | namespace AsynQt { 34 | namespace detail { 35 | 36 | template 37 | class ProcessFutureInterface : public QObject, 38 | public QFutureInterface<_Result> { 39 | 40 | public: 41 | ProcessFutureInterface(QProcess *process, _Function map) 42 | : m_process(process) 43 | , m_map(map) 44 | { 45 | } 46 | 47 | void error() 48 | { 49 | this->reportCanceled(); 50 | } 51 | 52 | QFuture<_Result> start() 53 | { 54 | QObject::connect( 55 | m_process, 56 | // Pretty new Qt connect syntax :) 57 | (void (QProcess::*)(QProcess::ProcessError)) &QProcess::error, 58 | this, [this] (QProcess::ProcessError) { 59 | this->error(); 60 | }); 61 | 62 | QObject::connect( 63 | m_process, 64 | // Pretty new Qt connect syntax :) 65 | (void (QProcess::*)(int, QProcess::ExitStatus)) &QProcess::finished, 66 | this, [this] (int, QProcess::ExitStatus) { 67 | this->finished(); 68 | }); 69 | 70 | this->reportStarted(); 71 | 72 | m_process->start(); 73 | 74 | return this->future(); 75 | } 76 | 77 | void finished(); 78 | 79 | 80 | private: 81 | QProcess *m_process; 82 | _Function m_map; 83 | 84 | }; 85 | 86 | template 87 | void ProcessFutureInterface<_Result, _Function>::finished() 88 | { 89 | if (m_process->exitCode() == 0 90 | && m_process->exitStatus() == QProcess::NormalExit) { 91 | 92 | this->reportResult(m_map(m_process)); 93 | this->reportFinished(); 94 | 95 | } else { 96 | this->reportCanceled(); 97 | } 98 | } 99 | 100 | } // namespace detail 101 | } // namespace AsynQt 102 | 103 | -------------------------------------------------------------------------------- /src/basic/delayedfuture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_CONS_DELAYED_FUTURE_H 23 | #define ASYNQT_CONS_DELAYED_FUTURE_H 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "../private/basic/delayedfuture_p.h" 33 | 34 | namespace AsynQt { 35 | 36 | /** 37 | * Creates a future that will arrive in the specified number of milliseconds, 38 | * and contain the specified value. 39 | * @arg value value to return 40 | * @arg milliseconds how much to wait in milliseconds until the future arrives 41 | */ 42 | template 43 | QFuture::type> makeDelayedFuture(_Result &&value, 44 | int milliseconds) 45 | { 46 | using namespace detail; 47 | 48 | return newDelayedFutureInterface(std::forward<_Result>(value), milliseconds) 49 | ->start(); 50 | } 51 | 52 | /** 53 | * Creates a void future that will arrive in the specified 54 | * number of milliseconds. 55 | */ 56 | ASYNQT_EXPORT 57 | QFuture makeDelayedFuture(int milliseconds); 58 | 59 | } // namespace AsynQt 60 | 61 | #ifndef ASYNQT_DISABLE_STD_CHRONO 62 | 63 | #include 64 | 65 | namespace AsynQt { 66 | 67 | /** 68 | * Convenience method for using with std::chrono library. It allows 69 | * type-safe syntax for specifying the duration (as of C++14) 70 | * 71 | * 72 | * makeDelayedFuture(42, 500ms); 73 | * makeDelayedFuture(42, 1h + 30min); 74 | * 75 | */ 76 | template 77 | QFuture::type> makeDelayedFuture(_Result &&value, 78 | std::chrono::duration duration) 79 | { 80 | using namespace std::chrono; 81 | 82 | return makeDelayedFuture(std::forward<_Result>(value), 83 | duration_cast(duration).count()); 84 | } 85 | 86 | /** 87 | * Convenience method for using with std::chrono library. It allows 88 | * type-safe syntax for specifying the duration (as of C++14) 89 | * 90 | * 91 | * makeDelayedFuture(500ms); 92 | * makeDelayedFuture(1h + 30min); 93 | * 94 | */ 95 | template 96 | QFuture makeDelayedFuture(std::chrono::duration duration) 97 | { 98 | using namespace std::chrono; 99 | 100 | return makeDelayedFuture(duration_cast(duration).count()); 101 | } 102 | 103 | } // namespace AsynQt 104 | 105 | #endif // ASYNQT_DISABLE_STD_CHRONO 106 | 107 | 108 | #endif // ASYNQT_CONS_DELAYED_FUTURE_H 109 | 110 | -------------------------------------------------------------------------------- /src/wrappers/process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef ASYNQT_CONS_PROCESS_H 23 | #define ASYNQT_CONS_PROCESS_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "../private/wrappers/process_p.h" 32 | 33 | namespace AsynQt { 34 | 35 | /** 36 | * Creates a future that will be completed when the process finishes. 37 | * @arg process process to wrap inside a future 38 | * @arg map function that extracts the needed information from the process 39 | * 40 | * 41 | * // If we want to get the exit code of the process 42 | * makeFuture(process, [] (QProcess *p) { return p->exitCode(); }) 43 | * 44 | * // If we want to get the output of the process 45 | * makeFuture(process, [] (QProcess *p) { return p->readAllStandardOutput(); }) 46 | * 47 | */ 48 | template 49 | auto makeFuture(QProcess *process, _Function map) 50 | -> QFuture 51 | { 52 | using namespace detail; 53 | 54 | auto futureInterface = 55 | new ProcessFutureInterface 56 | (process, map); 57 | 58 | return futureInterface->start(); 59 | } 60 | 61 | namespace Process { 62 | 63 | /** 64 | * Executes the specified command, with the specified arguments. 65 | */ 66 | template 67 | auto exec(const QString &command, const QStringList &arguments, 68 | _Function &&map) 69 | -> QFuture 70 | { 71 | // TODO: Where to delete this process? 72 | auto process = new QProcess(); 73 | 74 | // process->setProcessChannelMode(QProcess::ForwardedChannels); 75 | process->setProgram(command); 76 | process->setArguments(arguments); 77 | 78 | return AsynQt::makeFuture(process, std::forward<_Function>(map)); 79 | } 80 | 81 | /** 82 | * Executes the specified command, with the specified arguments, 83 | * and returns the future containing the process it created. 84 | */ 85 | ASYNQT_EXPORT 86 | QFuture exec(const QString &command, 87 | const QStringList &arguments); 88 | 89 | /** 90 | * Executes the specified command, with the specified arguments, 91 | * and it returns a future containing the output of that command. 92 | */ 93 | ASYNQT_EXPORT 94 | QFuture getOutput(const QString &command, 95 | const QStringList &arguments); 96 | 97 | } // namespace Process 98 | 99 | } // namespace qfuture 100 | 101 | #endif // ASYNQT_CONS_PROCESS_H 102 | 103 | -------------------------------------------------------------------------------- /src/private/operations/filter_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | #include 34 | 35 | #include "../utils_p.h" 36 | 37 | namespace AsynQt { 38 | namespace detail { 39 | 40 | template 41 | class FilterFutureInterface 42 | : public QObject 43 | , public QFutureInterface<_Type> { 44 | 45 | public: 46 | 47 | FilterFutureInterface(QFuture<_Type> future, 48 | _Predicate predicate) 49 | : m_future(future) 50 | , m_predicate(predicate) 51 | { 52 | } 53 | 54 | QFuture<_Type> start() 55 | { 56 | m_futureWatcher.reset(new QFutureWatcher<_Type>()); 57 | 58 | onFinished(m_futureWatcher, [this]() { 59 | this->reportFinished(); 60 | }); 61 | 62 | onCanceled(m_futureWatcher, [this]() { this->reportCanceled(); }); 63 | 64 | onResultReadyAt(m_futureWatcher, [this](int index) { 65 | auto result = m_future.resultAt(index); 66 | if (m_predicate(result)) { 67 | this->reportResult(result); 68 | } 69 | }); 70 | 71 | m_futureWatcher->setFuture(m_future); 72 | 73 | this->reportStarted(); 74 | 75 | return this->future(); 76 | } 77 | 78 | private: 79 | QFuture<_Type> m_future; 80 | _Predicate m_predicate; 81 | std::unique_ptr> m_futureWatcher; 82 | }; 83 | 84 | template 85 | QFuture<_Type> 86 | filter_impl(const QFuture<_Type> &future, _Predicate &&predicate) 87 | { 88 | return (new FilterFutureInterface<_Type, _Predicate>( 89 | future, std::forward<_Predicate>(predicate))) 90 | ->start(); 91 | } 92 | 93 | 94 | namespace operators { 95 | 96 | 97 | template 98 | class FilterModifier { 99 | public: 100 | FilterModifier(_Predicate predicate) 101 | : m_predicate(predicate) 102 | { 103 | } 104 | 105 | _Predicate m_predicate; 106 | }; 107 | 108 | template 109 | auto operator | (const QFuture<_Type> &future, 110 | FilterModifier<_Predicate> &&modifier) 111 | -> decltype(filter_impl(future, modifier.m_predicate)) 112 | { 113 | return filter_impl(future, modifier.m_predicate); 114 | } 115 | 116 | } // namespace operators 117 | 118 | } // namespace detail 119 | } // namespace AsynQt 120 | 121 | -------------------------------------------------------------------------------- /autotests/base/continuewith_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "continuewith_test.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "common.h" 33 | 34 | using namespace AsynQt; 35 | 36 | namespace base { 37 | 38 | ContinueWithTest::ContinueWithTest() 39 | { 40 | } 41 | 42 | void ContinueWithTest::testContinueWith() 43 | { 44 | TEST_CHUNK("Connecting a declared future to a continuation") 45 | { 46 | auto future = common::execHelloKde(); 47 | auto connectedFuture = continueWith(future, common::execEcho); 48 | 49 | COMPARE_FINISHED_BEFORE(connectedFuture, common::helloKdeMessage(), 1 _seconds); 50 | VERIFY_TYPE(future, QFuture); 51 | VERIFY_TYPE(connectedFuture, QFuture); 52 | } 53 | 54 | TEST_CHUNK("Connecting a temporary future to a continuation") 55 | { 56 | auto connectedFuture = 57 | continueWith(common::execHelloKde(), common::execEcho); 58 | 59 | COMPARE_FINISHED_BEFORE(connectedFuture, common::helloKdeMessage(), 1 _seconds); 60 | VERIFY_TYPE(connectedFuture, QFuture); 61 | } 62 | } 63 | 64 | void ContinueWithTest::testContinueWithOperator() 65 | { 66 | using namespace AsynQt::operators; 67 | 68 | TEST_CHUNK("Connecting a declared future to a continuation") 69 | { 70 | auto future = common::execHelloKde(); 71 | auto connectedFuture = future | common::execEcho; 72 | 73 | COMPARE_FINISHED_BEFORE(connectedFuture, common::helloKdeMessage(), 1 _seconds); 74 | VERIFY_TYPE(future, QFuture); 75 | VERIFY_TYPE(connectedFuture, QFuture); 76 | } 77 | 78 | TEST_CHUNK("Connecting a temporary future to a continuation") 79 | { 80 | auto connectedFuture = common::execHelloKde() | common::execEcho; 81 | 82 | COMPARE_FINISHED_BEFORE(connectedFuture, common::helloKdeMessage(), 1 _seconds); 83 | VERIFY_TYPE(connectedFuture, QFuture); 84 | } 85 | } 86 | 87 | void ContinueWithTest::testContinueWithFailures() 88 | { 89 | using namespace AsynQt::operators; 90 | 91 | TEST_CHUNK("Success connected to a failure") 92 | { 93 | auto future = common::execHelloKde(); 94 | auto connectedFuture = future | common::fail; 95 | 96 | VERIFY_CANCELED_AROUND(connectedFuture, 1 _seconds); 97 | VERIFY_TYPE(future, QFuture); 98 | VERIFY_TYPE(connectedFuture, QFuture); 99 | } 100 | 101 | TEST_CHUNK("Failure connected to a success") 102 | { 103 | auto connectedFuture = common::fail(QString()) | common::execEcho; 104 | 105 | VERIFY_CANCELED_AROUND(connectedFuture, 1 _seconds); 106 | VERIFY_TYPE(connectedFuture, QFuture); 107 | } 108 | 109 | TEST_CHUNK("Fail twice just for the good measure") 110 | { 111 | auto connectedFuture = common::fail(QString()) | common::fail; 112 | 113 | VERIFY_CANCELED_AROUND(connectedFuture, 1 _seconds); 114 | VERIFY_TYPE(connectedFuture, QFuture); 115 | } 116 | 117 | } 118 | 119 | void ContinueWithTest::initTestCase() 120 | { 121 | } 122 | 123 | void ContinueWithTest::cleanupTestCase() 124 | { 125 | } 126 | 127 | } // namespace base 128 | 129 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # vim:set softtabstop=3 shiftwidth=3 tabstop=3 expandtab: 2 | 3 | # ======================================================= 4 | # Now that we finished with the boilerplate, start 5 | # with the library definition 6 | 7 | set ( 8 | AsynQt_LIB_SRCS 9 | 10 | version.cpp 11 | 12 | wrappers/process.cpp 13 | version.cpp 14 | basic/readyfuture.cpp 15 | basic/delayedfuture.cpp 16 | 17 | ) 18 | 19 | add_library ( 20 | KF5AsynQt SHARED 21 | ${AsynQt_LIB_SRCS} 22 | ) 23 | add_library (KF5::AsynQt ALIAS KF5AsynQt) 24 | 25 | include_directories ( 26 | ${CMAKE_CURRENT_BINARY_DIR} 27 | ) 28 | 29 | set_target_properties ( 30 | KF5AsynQt 31 | PROPERTIES 32 | VERSION ${ASYNQT_VERSION_STRING} 33 | SOVERSION ${ASYNQT_SOVERSION} 34 | EXPORT_NAME AsynQt 35 | ) 36 | 37 | target_link_libraries ( 38 | KF5AsynQt 39 | PUBLIC 40 | Qt5::Core 41 | PRIVATE 42 | KF5::ConfigCore 43 | KF5::I18n 44 | KF5::KIOCore 45 | ) 46 | 47 | target_include_directories ( 48 | KF5AsynQt 49 | INTERFACE "$" 50 | ) 51 | 52 | # install 53 | generate_export_header (KF5AsynQt BASE_NAME AsynQt) 54 | file ( 55 | COPY 56 | ${CMAKE_CURRENT_BINARY_DIR}/asynqt_export.h 57 | DESTINATION 58 | ${CMAKE_CURRENT_BINARY_DIR}/asynqt/ 59 | ) 60 | 61 | install ( 62 | FILES ${CMAKE_CURRENT_BINARY_DIR}/asynqt/asynqt_export.h 63 | DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt/asynqt 64 | COMPONENT Devel 65 | ) 66 | 67 | # Generate top level headers 68 | 69 | ecm_generate_headers ( 70 | AsynQt_CamelCase_HEADERS 71 | HEADER_NAMES 72 | Version 73 | PREFIX AsynQt 74 | ) 75 | 76 | install ( 77 | FILES ${AsynQt_CamelCase_HEADERS} 78 | DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt/AsynQt 79 | COMPONENT Devel 80 | ) 81 | 82 | # Generate basic headers 83 | 84 | ecm_generate_headers ( 85 | AsynQt_Basic_CamelCase_HEADERS 86 | HEADER_NAMES 87 | CanceledFuture 88 | DelayedFuture 89 | ReadyFuture 90 | PREFIX AsynQt/Basic 91 | RELATIVE basic 92 | ) 93 | 94 | install ( 95 | FILES ${AsynQt_Basic_CamelCase_HEADERS} 96 | DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt/AsynQt/Basic 97 | COMPONENT Devel 98 | ) 99 | 100 | # Generate operations headers 101 | 102 | ecm_generate_headers ( 103 | AsynQt_Operations_CamelCase_HEADERS 104 | HEADER_NAMES 105 | ContinueWith 106 | Flatten 107 | Transform 108 | PREFIX AsynQt/Operations 109 | RELATIVE operations 110 | ) 111 | 112 | install ( 113 | FILES ${AsynQt_Operations_CamelCase_HEADERS} 114 | DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt/AsynQt/Operations 115 | COMPONENT Devel 116 | ) 117 | 118 | # Generate wrappers headers 119 | 120 | ecm_generate_headers ( 121 | AsynQt_Wrappers_CamelCase_HEADERS 122 | HEADER_NAMES 123 | DBus 124 | Process 125 | PREFIX AsynQt/Wrappers 126 | RELATIVE wrappers 127 | ) 128 | 129 | install ( 130 | FILES ${AsynQt_Wrappers_CamelCase_HEADERS} 131 | DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt/AsynQt/Wrappers 132 | COMPONENT Devel 133 | ) 134 | 135 | 136 | # Install ugly headers 137 | 138 | set (AsynQt_Ugly_HEADERS 139 | private/wrappers/process_p.h 140 | private/wrappers/dbus_p.h 141 | private/basic/delayedfuture_p.h 142 | private/basic/canceledfuture_p.h 143 | private/basic/readyfuture_p.h 144 | private/operations/flatten_p.h 145 | private/operations/transform_p.h 146 | wrappers/dbus.h 147 | wrappers/process.h 148 | version.h 149 | basic/delayedfuture.h 150 | basic/readyfuture.h 151 | basic/canceledfuture.h 152 | basic/all.h 153 | operations/transform.h 154 | operations/flatten.h 155 | operations/continuewith.h 156 | ) 157 | 158 | foreach (header ${AsynQt_Ugly_HEADERS}) 159 | get_filename_component (dir ${header} DIRECTORY) 160 | install (FILES ${header} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt/asynqt/${dir}) 161 | endforeach() 162 | 163 | install ( 164 | TARGETS KF5AsynQt 165 | EXPORT KF5AsynQtLibraryTargets 166 | ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} 167 | ) 168 | 169 | if (NOT WIN32) 170 | configure_file ( 171 | ${CMAKE_CURRENT_SOURCE_DIR}/libAsynQt.pc.cmake 172 | ${CMAKE_CURRENT_BINARY_DIR}/libAsynQt.pc 173 | ) 174 | install ( 175 | FILES ${CMAKE_CURRENT_BINARY_DIR}/libAsynQt.pc 176 | DESTINATION ${KDE_INSTALL_LIBDIR}/pkgconfig 177 | ) 178 | endif () 179 | 180 | include (ECMGeneratePriFile) 181 | ecm_generate_pri_file ( 182 | BASE_NAME AsynQt 183 | LIB_NAME KF5AsynQt 184 | DEPS "KDBusAddons" 185 | FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/AsynQt 186 | ) 187 | install ( 188 | FILES ${PRI_FILENAME} 189 | DESTINATION ${ECM_MKSPECS_INSTALL_DIR} 190 | ) 191 | 192 | -------------------------------------------------------------------------------- /src/private/operations/flatten_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | #include 34 | 35 | #include "../utils_p.h" 36 | 37 | namespace AsynQt { 38 | namespace detail { 39 | 40 | template 41 | class FlattenFutureInterface : public QObject 42 | , public QFutureInterface<_Result> { 43 | public: 44 | 45 | FlattenFutureInterface(QFuture> future) 46 | : m_outerFuture(future) 47 | { 48 | } 49 | 50 | inline 51 | void setFutureResultAt(int, std::true_type /* _Result is void */) 52 | { 53 | // nothing to do 54 | } 55 | 56 | inline 57 | void setFutureResultAt(int index, std::false_type /* _Result is not void */) 58 | { 59 | this->reportResult(m_currentInnerFuture.resultAt(index)); 60 | } 61 | 62 | void processNextInnerFuture() 63 | { 64 | // Already processing something 65 | if (m_innerFutureWatcher) return; 66 | 67 | m_innerFutureWatcher.reset(new QFutureWatcher<_Result>()); 68 | m_currentInnerFuture = m_innerFutures.head(); 69 | 70 | onFinished(m_innerFutureWatcher, [this]() { 71 | dequeueInnerFuture(); 72 | }); 73 | 74 | onCanceled(m_innerFutureWatcher, [this]() { 75 | this->reportCanceled(); 76 | }); 77 | 78 | onResultReadyAt(m_innerFutureWatcher, [this](int index) { 79 | setFutureResultAt(index, typename std::is_void<_Result>::type()); 80 | }); 81 | 82 | m_innerFutureWatcher->setFuture(m_currentInnerFuture); 83 | 84 | this->reportStarted(); 85 | } 86 | 87 | void dequeueInnerFuture() 88 | { 89 | m_innerFutureWatcher.reset(); 90 | m_innerFutures.dequeue(); 91 | 92 | if (m_innerFutures.size() == 0) { 93 | if (m_outerFuture.isCanceled()) { 94 | this->reportCanceled(); 95 | } 96 | 97 | if (m_outerFuture.isFinished()) { 98 | this->reportFinished(); 99 | } 100 | 101 | } else { 102 | processNextInnerFuture(); 103 | } 104 | } 105 | 106 | QFuture<_Result> start() 107 | { 108 | m_outerFutureWatcher.reset(new QFutureWatcher>()); 109 | 110 | onFinished(m_outerFutureWatcher, [this]() { 111 | if (m_innerFutures.isEmpty()) { 112 | this->reportFinished(); 113 | } 114 | }); 115 | 116 | onCanceled(m_outerFutureWatcher, [this]() { 117 | if (m_innerFutures.isEmpty()) { 118 | this->reportCanceled(); 119 | } 120 | }); 121 | 122 | onResultReadyAt(m_outerFutureWatcher, [this](int index) { 123 | m_innerFutures.enqueue(m_outerFuture.resultAt(index)); 124 | processNextInnerFuture(); 125 | }); 126 | 127 | m_outerFutureWatcher->setFuture(m_outerFuture); 128 | 129 | this->reportStarted(); 130 | 131 | return this->future(); 132 | } 133 | 134 | private: 135 | QFuture> m_outerFuture; 136 | std::unique_ptr>> m_outerFutureWatcher; 137 | 138 | QFuture<_Result> m_currentInnerFuture; 139 | QQueue> m_innerFutures; 140 | std::unique_ptr> m_innerFutureWatcher; 141 | }; 142 | 143 | template 144 | QFuture<_Result> flatten_impl(const QFuture> &future) 145 | { 146 | return (new FlattenFutureInterface<_Result>(future))->start(); 147 | } 148 | 149 | namespace operators { 150 | 151 | struct FlattenModifier {}; 152 | 153 | template 154 | QFuture<_Result> operator | (const QFuture> &future, 155 | FlattenModifier) 156 | { 157 | return flatten_impl(future); 158 | } 159 | 160 | } // namespace operators 161 | 162 | } // namespace detail 163 | } // namespace AsynQt 164 | 165 | -------------------------------------------------------------------------------- /autotests/wrappers/basic_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "basic_test.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "common.h" 32 | 33 | namespace wrappers { 34 | 35 | BasicFuturesTest::BasicFuturesTest() 36 | { 37 | } 38 | 39 | void BasicFuturesTest::testReadyFutures() 40 | { 41 | TEST_CHUNK("Testing a ready int future") 42 | { 43 | auto future = AsynQt::makeReadyFuture(42); 44 | 45 | // Without waiting! 46 | QVERIFY(future.isFinished()); 47 | QVERIFY(!future.isCanceled()); 48 | QVERIFY(future.isResultReadyAt(0)); 49 | QCOMPARE(future.result(), 42); 50 | VERIFY_TYPE(future, QFuture); 51 | } 52 | 53 | TEST_CHUNK("Testing a ready void future") 54 | { 55 | auto future = AsynQt::makeReadyFuture(); 56 | 57 | // Without waiting! 58 | QVERIFY(future.isFinished()); 59 | QVERIFY(!future.isCanceled()); 60 | VERIFY_TYPE(future, QFuture); 61 | } 62 | } 63 | 64 | class TestException : public QException 65 | { 66 | public: 67 | void raise() const { throw *this; } 68 | TestException *clone() const { return new TestException(*this); } 69 | }; 70 | 71 | void BasicFuturesTest::testCanceledFutures() 72 | { 73 | TEST_CHUNK("Testing a canceled QString future") 74 | { 75 | auto future = AsynQt::makeCanceledFuture(); 76 | 77 | // Without waiting! 78 | QVERIFY(future.isCanceled()); 79 | QVERIFY(!future.isResultReadyAt(0)); 80 | VERIFY_TYPE(future, QFuture); 81 | } 82 | 83 | TEST_CHUNK("Testing a canceled void future") 84 | { 85 | auto future = AsynQt::makeCanceledFuture(); 86 | 87 | // Without waiting! 88 | QVERIFY(future.isCanceled()); 89 | VERIFY_TYPE(future, QFuture); 90 | } 91 | 92 | TEST_CHUNK("Testing a QString future with an exception") 93 | { 94 | auto future = AsynQt::makeCanceledFuture(TestException()); 95 | 96 | // Without waiting! 97 | evil::hasException(future); 98 | VERIFY_EXCEPTION_AROUND(future, TestException, 0 _seconds); 99 | QVERIFY(future.isCanceled()); 100 | VERIFY_TYPE(future, QFuture); 101 | } 102 | 103 | TEST_CHUNK("Testing a void future with an exception") 104 | { 105 | auto future = AsynQt::makeCanceledFuture(TestException()); 106 | 107 | // Without waiting! 108 | evil::hasException(future); 109 | VERIFY_EXCEPTION_AROUND(future, TestException, 0 _seconds); 110 | QVERIFY(future.isCanceled()); 111 | VERIFY_TYPE(future, QFuture); 112 | } 113 | } 114 | 115 | void BasicFuturesTest::testDelayedFutures() 116 | { 117 | auto delay = 1 _seconds; 118 | 119 | TEST_CHUNK("Testing a delayed int future") 120 | { 121 | auto future = AsynQt::makeDelayedFuture(42, delay); 122 | 123 | QVERIFY(!evil::hasException(future)); 124 | COMPARE_FINISHED_AROUND(future, 42, delay); 125 | VERIFY_TYPE(future, QFuture); 126 | } 127 | 128 | TEST_CHUNK("Testing a delayed void future") 129 | { 130 | auto future = AsynQt::makeDelayedFuture(delay); 131 | 132 | VERIFY_FINISHED_AROUND(future, delay); 133 | VERIFY_TYPE(future, QFuture); 134 | } 135 | } 136 | 137 | void BasicFuturesTest::testDelayedFuturesStdChrono() 138 | { 139 | using namespace std::chrono; 140 | auto delay = 1 _seconds; 141 | 142 | TEST_CHUNK("Testing a delayed int future with std::chrono") 143 | { 144 | auto future = AsynQt::makeDelayedFuture(42, seconds(1)); 145 | 146 | COMPARE_FINISHED_AROUND(future, 42, delay); 147 | VERIFY_TYPE(future, QFuture); 148 | } 149 | 150 | TEST_CHUNK("Testing a delayed void future with std::chrono") 151 | { 152 | auto future = AsynQt::makeDelayedFuture(milliseconds(1000)); 153 | 154 | VERIFY_FINISHED_AROUND(future, delay); 155 | VERIFY_TYPE(future, QFuture); 156 | } 157 | } 158 | 159 | void BasicFuturesTest::initTestCase() 160 | { 161 | } 162 | 163 | void BasicFuturesTest::cleanupTestCase() 164 | { 165 | } 166 | 167 | } // namespace wrappers 168 | 169 | -------------------------------------------------------------------------------- /autotests/base/filter_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "filter_test.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "common.h" 32 | 33 | namespace base { 34 | 35 | namespace { 36 | bool falsePredicate(const QString &message) 37 | { 38 | return false; 39 | } 40 | 41 | struct BoolPredicate { 42 | BoolPredicate(bool result) 43 | : m_result(result) 44 | { 45 | } 46 | 47 | int operator () (const QString &) 48 | { 49 | return m_result; 50 | } 51 | 52 | int operator () (const QByteArray &) 53 | { 54 | return m_result; 55 | } 56 | 57 | private: 58 | bool m_result; 59 | }; 60 | } 61 | 62 | FilterTest::FilterTest() 63 | { 64 | } 65 | 66 | void FilterTest::testFilterWithFunctions() 67 | { 68 | TEST_CHUNK("Filtered out") { 69 | auto future = common::execHelloKde(); 70 | 71 | auto filteredFuture 72 | = AsynQt::filter(future, falsePredicate); 73 | 74 | VERIFY_FINISHED_BEFORE(filteredFuture, 1 _seconds); 75 | QVERIFY(filteredFuture.resultCount() == 0); 76 | VERIFY_TYPE(future, QFuture); 77 | VERIFY_TYPE(filteredFuture, QFuture); 78 | } 79 | } 80 | 81 | void FilterTest::testFilterWithFunctionObjects() 82 | { 83 | TEST_CHUNK("Filtered out") { 84 | auto future = common::execHelloKde(); 85 | 86 | auto filteredFuture 87 | = AsynQt::filter(future, BoolPredicate(false)); 88 | 89 | VERIFY_FINISHED_BEFORE(filteredFuture, 1 _seconds); 90 | QVERIFY(filteredFuture.resultCount() == 0); 91 | VERIFY_TYPE(future, QFuture); 92 | VERIFY_TYPE(filteredFuture, QFuture); 93 | } 94 | 95 | TEST_CHUNK("Not filtered out") { 96 | auto future = common::execHelloKde(); 97 | 98 | auto filteredFuture 99 | = AsynQt::filter(future, BoolPredicate(true)); 100 | 101 | COMPARE_FINISHED_BEFORE(filteredFuture, common::helloKdeMessage(), 102 | 1 _seconds); 103 | VERIFY_TYPE(future, QFuture); 104 | VERIFY_TYPE(filteredFuture, QFuture); 105 | } 106 | } 107 | 108 | void FilterTest::testFilterWithLambdas() 109 | { 110 | TEST_CHUNK("Filtered out") { 111 | auto future = common::execHelloKde(); 112 | 113 | auto filteredFuture 114 | = AsynQt::filter(future, [](const QString &) { return false; }); 115 | 116 | VERIFY_FINISHED_BEFORE(filteredFuture, 1 _seconds); 117 | QVERIFY(filteredFuture.resultCount() == 0); 118 | VERIFY_TYPE(future, QFuture); 119 | VERIFY_TYPE(filteredFuture, QFuture); 120 | } 121 | 122 | TEST_CHUNK("Not filtered out") { 123 | auto future = common::execHelloKde(); 124 | 125 | auto filteredFuture 126 | = AsynQt::filter(future, [](const QString &) { return true; }); 127 | 128 | COMPARE_FINISHED_BEFORE(filteredFuture, common::helloKdeMessage(), 129 | 1 _seconds); 130 | VERIFY_TYPE(future, QFuture); 131 | VERIFY_TYPE(filteredFuture, QFuture); 132 | } 133 | } 134 | 135 | void FilterTest::testFilterWithPipeSyntax() 136 | { 137 | using namespace operators; 138 | 139 | TEST_CHUNK("Filtered out") { 140 | auto filteredFuture = common::execHelloKde() 141 | | filter([](const QString &) { return false; }); 142 | 143 | VERIFY_FINISHED_BEFORE(filteredFuture, 1 _seconds); 144 | QVERIFY(filteredFuture.resultCount() == 0); 145 | VERIFY_TYPE(filteredFuture, QFuture); 146 | } 147 | 148 | TEST_CHUNK("Not filtered out") { 149 | auto filteredFuture = common::execHelloKde() 150 | | filter([](const QString &) { return true; }); 151 | 152 | COMPARE_FINISHED_BEFORE(filteredFuture, common::helloKdeMessage(), 153 | 1 _seconds); 154 | VERIFY_TYPE(filteredFuture, QFuture); 155 | } 156 | } 157 | 158 | void FilterTest::testFilterWithCanceledFutures() 159 | { 160 | auto future = common::fail(QString()); 161 | 162 | auto filteredFuture = AsynQt::filter(future, falsePredicate); 163 | 164 | VERIFY_CANCELED_AROUND(filteredFuture, 100 _milliseconds); 165 | VERIFY_TYPE(future, QFuture); 166 | VERIFY_TYPE(filteredFuture, QFuture); 167 | } 168 | 169 | void FilterTest::testFilterWithReadyFutures() 170 | { 171 | auto future = makeReadyFuture(common::helloKdeMessage()); 172 | 173 | auto filteredFuture = AsynQt::filter(future, falsePredicate); 174 | 175 | VERIFY_FINISHED_AROUND(filteredFuture, 100 _milliseconds); 176 | QVERIFY(filteredFuture.resultCount() == 0); 177 | VERIFY_TYPE(future, QFuture); 178 | VERIFY_TYPE(filteredFuture, QFuture); 179 | } 180 | 181 | void FilterTest::initTestCase() 182 | { 183 | } 184 | 185 | void FilterTest::cleanupTestCase() 186 | { 187 | } 188 | 189 | } // namespace base 190 | 191 | -------------------------------------------------------------------------------- /autotests/base/flatten_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "flatten_test.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "common.h" 32 | 33 | namespace base { 34 | 35 | namespace { 36 | QFuture passOutputToEcho(QProcess *process) 37 | { 38 | return common::execEcho(QString::fromLatin1(process->readAllStandardOutput())); 39 | }; 40 | 41 | class PassOutputToEcho { 42 | public: 43 | QFuture operator () (QProcess *process) 44 | { 45 | return passOutputToEcho(process); 46 | } 47 | }; 48 | } 49 | 50 | FlattenTest::FlattenTest() 51 | { 52 | } 53 | 54 | void FlattenTest::testFlatten() 55 | { 56 | auto future = AsynQt::Process::exec( 57 | "echo", { "Hello KDE!" }, 58 | [] (QProcess *process) { 59 | return common::execEcho(QString::fromLatin1(process->readAllStandardOutput())); 60 | }); 61 | 62 | auto flattenFuture = AsynQt::flatten(future); 63 | 64 | COMPARE_FINISHED_BEFORE(flattenFuture, QByteArray("Hello KDE!\n"), 1 _seconds); 65 | 66 | VERIFY_TYPE(future, QFuture>); 67 | VERIFY_TYPE(flattenFuture, QFuture); 68 | } 69 | 70 | void FlattenTest::testFlattenWithPipeSyntax() 71 | { 72 | using namespace AsynQt::operators; 73 | 74 | TEST_CHUNK("Pipe with lambda") { 75 | auto future = AsynQt::Process::exec( 76 | "echo", { "Hello KDE!" }, 77 | [] (QProcess *process) { 78 | return common::execEcho(QString::fromLatin1(process->readAllStandardOutput())); 79 | }); 80 | 81 | auto flattenFuture = future | flatten(); 82 | 83 | COMPARE_FINISHED_BEFORE(flattenFuture, QByteArray("Hello KDE!\n"), 1 _seconds); 84 | 85 | VERIFY_TYPE(future, QFuture>); 86 | VERIFY_TYPE(flattenFuture, QFuture); 87 | } 88 | 89 | TEST_CHUNK("Pipe with function, no temporary future") { 90 | auto flattenFuture 91 | = AsynQt::Process::exec("echo", { "Hello KDE!" }, passOutputToEcho) 92 | | flatten(); 93 | 94 | COMPARE_FINISHED_BEFORE(flattenFuture, QByteArray("Hello KDE!\n"), 1 _seconds); 95 | 96 | VERIFY_TYPE(flattenFuture, QFuture); 97 | } 98 | 99 | TEST_CHUNK("Pipe with functional object, no temporary future") { 100 | auto flattenFuture 101 | = AsynQt::Process::exec("echo", { "Hello KDE!" }, PassOutputToEcho()) 102 | | flatten(); 103 | 104 | COMPARE_FINISHED_BEFORE(flattenFuture, QByteArray("Hello KDE!\n"), 1 _seconds); 105 | 106 | VERIFY_TYPE(flattenFuture, QFuture); 107 | } 108 | } 109 | 110 | void FlattenTest::testFlattenWithFailures() 111 | { 112 | TEST_CHUNK("Failure in the inner future") 113 | { 114 | auto future = AsynQt::Process::exec( 115 | "echo", { "Hello KDE!" }, 116 | [] (QProcess *process) { 117 | return common::fail(QString::fromLatin1(process->readAllStandardOutput())); 118 | }); 119 | 120 | auto flattenFuture = AsynQt::flatten(future); 121 | 122 | VERIFY_CANCELED_AROUND(flattenFuture, 1 _seconds); 123 | 124 | VERIFY_TYPE(future, QFuture>); 125 | VERIFY_TYPE(flattenFuture, QFuture); 126 | } 127 | 128 | TEST_CHUNK("Failure in the outer future") 129 | { 130 | auto future = AsynQt::makeCanceledFuture>(); 131 | 132 | auto flattenFuture = AsynQt::flatten(future); 133 | 134 | VERIFY_CANCELED_AROUND(flattenFuture, 1 _seconds); 135 | 136 | VERIFY_TYPE(future, QFuture>); 137 | VERIFY_TYPE(flattenFuture, QFuture); 138 | } 139 | } 140 | 141 | void FlattenTest::testFlattenVoid() 142 | { 143 | const auto delay = 1 _seconds; 144 | 145 | auto future = AsynQt::makeDelayedFuture( 146 | AsynQt::makeDelayedFuture(1 _seconds), 147 | 1 _seconds); 148 | 149 | auto flattenFuture = AsynQt::flatten(future); 150 | 151 | // These futures are running in-parallel, they will both 152 | // finish in 1 second 153 | VERIFY_FINISHED_AROUND(flattenFuture, delay); 154 | 155 | VERIFY_TYPE(future, QFuture>); 156 | VERIFY_TYPE(flattenFuture, QFuture); 157 | } 158 | 159 | void FlattenTest::testFlattenVoidWithFailures() 160 | { 161 | TEST_CHUNK("Failure in the inner future") 162 | { 163 | const auto delay = 1 _seconds; 164 | 165 | auto future = AsynQt::makeDelayedFuture( 166 | AsynQt::makeCanceledFuture(), 167 | delay); 168 | 169 | auto flattenFuture = AsynQt::flatten(future); 170 | 171 | // These futures are running in-parallel, they will both 172 | // finish in 1 second 173 | VERIFY_CANCELED_AROUND(flattenFuture, delay); 174 | 175 | VERIFY_TYPE(future, QFuture>); 176 | VERIFY_TYPE(flattenFuture, QFuture); 177 | } 178 | } 179 | 180 | void FlattenTest::initTestCase() 181 | { 182 | } 183 | 184 | void FlattenTest::cleanupTestCase() 185 | { 186 | } 187 | 188 | } // namespace base 189 | 190 | -------------------------------------------------------------------------------- /autotests/base/transform_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #include "transform_test.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "common.h" 32 | 33 | namespace base { 34 | 35 | namespace { 36 | int stringSize(const QString &input) 37 | { 38 | return input.size(); 39 | } 40 | 41 | struct SizeMultiplier { 42 | SizeMultiplier(int coef) 43 | : m_coef(coef) 44 | { 45 | } 46 | 47 | int operator () (const QString &input) 48 | { 49 | return m_coef * input.size(); 50 | } 51 | 52 | int operator () (const QByteArray &input) 53 | { 54 | return m_coef * input.size(); 55 | } 56 | 57 | private: 58 | int m_coef; 59 | }; 60 | } 61 | 62 | TransformTest::TransformTest() 63 | { 64 | } 65 | 66 | void TransformTest::testTransformWithFunctions() 67 | { 68 | auto future = common::execHelloKde(); 69 | 70 | auto transformedFuture = AsynQt::transform(future, stringSize); 71 | 72 | COMPARE_FINISHED_BEFORE(transformedFuture, 11, 1 _seconds); 73 | VERIFY_TYPE(future, QFuture); 74 | VERIFY_TYPE(transformedFuture, QFuture); 75 | } 76 | 77 | void TransformTest::testTransformWithFunctionObjects() 78 | { 79 | auto future = common::execHelloKde(); 80 | 81 | auto transformedFuture = AsynQt::transform(future, SizeMultiplier(2)); 82 | 83 | COMPARE_FINISHED_BEFORE(transformedFuture, 22, 1 _seconds); 84 | VERIFY_TYPE(future, QFuture); 85 | VERIFY_TYPE(transformedFuture, QFuture); 86 | } 87 | 88 | void TransformTest::testTransformWithLambdas() 89 | { 90 | auto future = common::execHelloKde(); 91 | 92 | auto transformedFuture = AsynQt::transform(future, 93 | [] (const QString &input) { 94 | qDebug() << "Result: " << input; 95 | return input.size(); 96 | }); 97 | 98 | COMPARE_FINISHED_BEFORE(transformedFuture, 11, 1 _seconds); 99 | VERIFY_TYPE(future, QFuture); 100 | VERIFY_TYPE(transformedFuture, QFuture); 101 | } 102 | 103 | void TransformTest::testTransformWithPipeSyntax() 104 | { 105 | using namespace AsynQt::operators; 106 | 107 | TEST_CHUNK("Pipe with lambda") { 108 | auto future = common::execHelloKde(); 109 | 110 | auto transformedFuture = future | transform( 111 | [] (const QString &input) { 112 | qDebug() << "Result: " << input; 113 | return input.size(); 114 | }); 115 | 116 | COMPARE_FINISHED_BEFORE(transformedFuture, 11, 1 _seconds); 117 | VERIFY_TYPE(future, QFuture); 118 | VERIFY_TYPE(transformedFuture, QFuture); 119 | } 120 | 121 | TEST_CHUNK("Pipe with functional object, no temporary future") { 122 | auto transformedFuture = 123 | common::execHelloKde() | transform(SizeMultiplier(2)); 124 | 125 | COMPARE_FINISHED_BEFORE(transformedFuture, 22, 1 _seconds); 126 | VERIFY_TYPE(transformedFuture, QFuture); 127 | } 128 | } 129 | 130 | void TransformTest::testTransformWithCanceledFutures() 131 | { 132 | auto future = common::fail(QString()); 133 | 134 | auto transformedFuture = AsynQt::transform(future, 135 | [] (const QString &input) { 136 | qDebug() << "Result: " << input; 137 | return input.size(); 138 | }); 139 | 140 | VERIFY_CANCELED_AROUND(transformedFuture, 100 _milliseconds); 141 | VERIFY_TYPE(future, QFuture); 142 | VERIFY_TYPE(transformedFuture, QFuture); 143 | } 144 | 145 | void TransformTest::testTransformWithReadyFutures() 146 | { 147 | auto future = makeReadyFuture(common::helloKdeMessage()); 148 | 149 | auto transformedFuture = AsynQt::transform(future, 150 | [] (const QString &input) { 151 | qDebug() << "Result: " << input; 152 | return input.size(); 153 | }); 154 | 155 | COMPARE_FINISHED_AROUND(transformedFuture, 11, 100 _milliseconds); 156 | VERIFY_TYPE(future, QFuture); 157 | VERIFY_TYPE(transformedFuture, QFuture); 158 | } 159 | 160 | void TransformTest::testTransformVoidToValueFuture() 161 | { 162 | const auto delay = 1 _seconds; 163 | auto future = makeDelayedFuture(delay); 164 | 165 | auto transformedFuture = AsynQt::transform(future, 166 | [] () { 167 | return 42; 168 | }); 169 | 170 | COMPARE_FINISHED_AROUND(transformedFuture, 42, delay); 171 | VERIFY_TYPE(future, QFuture); 172 | VERIFY_TYPE(transformedFuture, QFuture); 173 | } 174 | 175 | void TransformTest::testTransformValueToVoidFuture() 176 | { 177 | const auto delay = 1 _seconds; 178 | auto future = makeDelayedFuture(42, delay); 179 | 180 | auto transformedFuture = AsynQt::transform(future, 181 | [] (int) { 182 | }); 183 | 184 | VERIFY_FINISHED_AROUND(transformedFuture, delay); 185 | VERIFY_TYPE(future, QFuture); 186 | VERIFY_TYPE(transformedFuture, QFuture); 187 | } 188 | 189 | void TransformTest::testTransformVoidToVoidFuture() 190 | { 191 | bool done = false; 192 | const auto delay = 1 _seconds; 193 | auto future = makeDelayedFuture(delay); 194 | 195 | auto transformedFuture = AsynQt::transform(future, 196 | [&done] () { 197 | done = true; 198 | }); 199 | 200 | VERIFY_FINISHED_AROUND(transformedFuture, delay); 201 | VERIFY_TYPE(future, QFuture); 202 | VERIFY_TYPE(transformedFuture, QFuture); 203 | QVERIFY(done); 204 | } 205 | 206 | void TransformTest::initTestCase() 207 | { 208 | } 209 | 210 | void TransformTest::cleanupTestCase() 211 | { 212 | } 213 | 214 | } // namespace base 215 | 216 | -------------------------------------------------------------------------------- /src/private/operations/transform_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | // 23 | // W A R N I N G 24 | // ------------- 25 | // 26 | // This file is not part of the AsynQt API. It exists purely as an 27 | // implementation detail. This header file may change from version to 28 | // version without notice, or even be removed. 29 | // 30 | // We mean it. 31 | // 32 | 33 | #include 34 | 35 | #include "../utils_p.h" 36 | 37 | namespace AsynQt { 38 | namespace detail { 39 | 40 | template 41 | struct TransformFutureInterfaceHelper { 42 | typedef typename std::result_of<_Transformation&(_In&&)>::type result_type; 43 | }; 44 | 45 | template 46 | struct TransformFutureInterfaceHelper { 47 | typedef typename std::result_of<_Transformation&()>::type result_type; 48 | }; 49 | 50 | 51 | template 52 | class TransformFutureInterface 53 | : public QObject 54 | , public QFutureInterface< 55 | typename TransformFutureInterfaceHelper<_In, _Transformation>::result_type 56 | > { 57 | 58 | public: 59 | typedef typename TransformFutureInterfaceHelper<_In, _Transformation>::result_type result_type; 60 | typedef typename std::is_void<_In>::type in_type_is_void; 61 | typedef typename std::is_void result_type_is_void; 62 | 63 | TransformFutureInterface(QFuture<_In> future, 64 | _Transformation transormation) 65 | : m_future(future) 66 | , m_transormation(transormation) 67 | { 68 | } 69 | 70 | ~TransformFutureInterface() 71 | { 72 | } 73 | 74 | // If _In is void, we are never going to get a result, 75 | // so, we need to pretend like we got one when the 76 | // future is successfully finished 77 | inline 78 | void setFutureResultOnFinished( 79 | std::true_type, // _In is void 80 | std::true_type // result_type is void 81 | ) 82 | { 83 | qDebug() << "value to void"; 84 | // no value, no result to create, but we still 85 | // want to call the transformation function 86 | if (!m_future.isCanceled()) { 87 | m_transormation(); 88 | } 89 | } 90 | 91 | inline 92 | void setFutureResultOnFinished( 93 | std::true_type, // _In is void 94 | std::false_type // result_type is not void 95 | ) 96 | { 97 | qDebug() << "void to value"; 98 | if (!m_future.isCanceled()) { 99 | this->reportResult(m_transormation()); 100 | } 101 | } 102 | 103 | // Ignore id _In is not void 104 | template 105 | inline 106 | void setFutureResultOnFinished(std::false_type, T) {} 107 | 108 | // If _In is not void, then all is as it should be 109 | inline 110 | void setFutureResultAt( 111 | int index, 112 | std::false_type, // _In is not void 113 | std::true_type // result_type is void 114 | ) 115 | { 116 | qDebug() << "value to void"; 117 | // nothing to do with the value, but we still 118 | // want to call the transformation function 119 | m_transormation(m_future.resultAt(index)); 120 | } 121 | 122 | inline 123 | void setFutureResultAt( 124 | int index, 125 | std::false_type, // _In is not void 126 | std::false_type // result_type is not void 127 | ) 128 | { 129 | qDebug() << "value to value"; 130 | this->reportResult(m_transormation(m_future.resultAt(index))); 131 | } 132 | 133 | template 134 | inline 135 | void setFutureResultAt(int, std::true_type, T) {} 136 | 137 | 138 | QFuture start() 139 | { 140 | m_futureWatcher.reset(new QFutureWatcher<_In>()); 141 | 142 | onFinished(m_futureWatcher, [this]() { 143 | setFutureResultOnFinished(in_type_is_void(), result_type_is_void()); 144 | this->reportFinished(); 145 | }); 146 | 147 | onCanceled(m_futureWatcher, [this]() { this->reportCanceled(); }); 148 | 149 | onResultReadyAt(m_futureWatcher, [this](int index) { 150 | setFutureResultAt(index, in_type_is_void(), result_type_is_void()); 151 | }); 152 | 153 | m_futureWatcher->setFuture(m_future); 154 | 155 | this->reportStarted(); 156 | 157 | return this->future(); 158 | } 159 | 160 | private: 161 | QFuture<_In> m_future; 162 | _Transformation m_transormation; 163 | std::unique_ptr> m_futureWatcher; 164 | }; 165 | 166 | template 167 | QFuture< 168 | typename detail::TransformFutureInterface<_In, _Transformation>::result_type 169 | > 170 | transform_impl(const QFuture<_In> &future, _Transformation &&transormation) 171 | { 172 | return (new TransformFutureInterface<_In, _Transformation>( 173 | future, std::forward<_Transformation>(transormation))) 174 | ->start(); 175 | } 176 | 177 | 178 | namespace operators { 179 | 180 | template 181 | class TransformationModifier { 182 | public: 183 | TransformationModifier(_Transformation transormation) 184 | : m_transormation(transormation) 185 | { 186 | } 187 | 188 | _Transformation m_transormation; 189 | }; 190 | 191 | template 192 | auto operator | (const QFuture<_In> &future, 193 | TransformationModifier<_Transformation> &&modifier) 194 | -> decltype(transform_impl(future, modifier.m_transormation)) 195 | { 196 | return transform_impl(future, modifier.m_transormation); 197 | } 198 | 199 | } // namespace operators 200 | 201 | } // namespace detail 202 | } // namespace AsynQt 203 | 204 | -------------------------------------------------------------------------------- /autotests/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Ivan Cukic 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) version 3, or any 8 | * later version accepted by the membership of KDE e.V. (or its 9 | * successor approved by the membership of KDE e.V.), which shall 10 | * act as a proxy defined in Section 6 of version 3 of the license. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. 19 | * If not, see . 20 | */ 21 | 22 | #ifndef TESTS_COMMON_H 23 | #define TESTS_COMMON_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "basic/all.h" 31 | #include "wrappers/process.h" 32 | 33 | #define RUN_TEST(Type) \ 34 | if (QCoreApplication::arguments().size() < 2 \ 35 | || QCoreApplication::arguments().contains(#Type)) { \ 36 | Type test; \ 37 | QTest::qExec(&test); \ 38 | } else { \ 39 | qDebug() << "Test" << #Type << "is \033[1;33mdisabled\033[0m"; \ 40 | } 41 | 42 | // We can not use user-defined literals yet, but we want to make this 43 | // prettier 44 | 45 | #define _milliseconds 46 | #define _seconds * 1000 47 | 48 | template 49 | inline bool waitForFuture(Future f, int milliseconds) 50 | { 51 | QElapsedTimer timer; 52 | timer.start(); 53 | 54 | if (milliseconds < 0) milliseconds = 0; 55 | 56 | milliseconds += 100 _milliseconds; 57 | 58 | while (timer.elapsed() < milliseconds && !f.isFinished()) { 59 | QCoreApplication::processEvents(); 60 | } 61 | 62 | return f.isFinished(); 63 | } 64 | 65 | template 66 | inline bool waitForFuture(Future f, int minMilliseconds, int maxMilliseconds) 67 | { 68 | QElapsedTimer timer; 69 | timer.start(); 70 | 71 | while (timer.elapsed() < maxMilliseconds && !f.isFinished() && !f.isCanceled()) { 72 | QCoreApplication::processEvents(); 73 | } 74 | 75 | if (timer.elapsed() < minMilliseconds) { 76 | qWarning() << "Future came earlier than it was supposed to"; 77 | return false; 78 | } 79 | 80 | return f.isFinished(); 81 | } 82 | 83 | #define VERIFY_FINISHED_AROUND(Future, Time) \ 84 | QVERIFY(waitForFuture(Future, Time - 200, Time + 200)); \ 85 | QVERIFY(!Future.isCanceled()) 86 | 87 | #define COMPARE_FINISHED_AROUND(Future, Value, Time) \ 88 | QVERIFY(waitForFuture(Future, Time - 200, Time + 200)); \ 89 | QVERIFY(!Future.isCanceled()); \ 90 | QCOMPARE(Future.result(), Value) 91 | 92 | #define VERIFY_CANCELED_AROUND(Future, Time) \ 93 | waitForFuture(Future, Time - 200, Time + 200); \ 94 | QVERIFY(Future.isCanceled()) 95 | 96 | #define VERIFY_EXCEPTION_AROUND(Future, Exception, Time) \ 97 | waitForFuture(Future, Time - 200, Time + 200); \ 98 | QVERIFY(Future.isCanceled()); \ 99 | { \ 100 | bool exceptionCaught = false; \ 101 | try { \ 102 | Future.waitForFinished(); \ 103 | } catch (const Exception &e) { \ 104 | exceptionCaught = true; \ 105 | } \ 106 | QVERIFY(exceptionCaught); \ 107 | } 108 | 109 | #define VERIFY_FINISHED_BEFORE(Future, Time) \ 110 | QVERIFY(waitForFuture(Future, Time + 200)); \ 111 | QVERIFY(!Future.isCanceled()) 112 | 113 | #define COMPARE_FINISHED_BEFORE(Future, Value, Time) \ 114 | QVERIFY(waitForFuture(Future, Time + 200)); \ 115 | QVERIFY(!Future.isCanceled()); \ 116 | QCOMPARE(Future.result(), Value) 117 | 118 | #define VERIFY_CANCELED_BEFORE(Future, Time) \ 119 | waitForFuture(Future, Time + 200); \ 120 | QVERIFY(Future.isCanceled()) 121 | 122 | #define VERIFY_EXCEPTION_BEFORE(Future, Exception, Time) \ 123 | waitForFuture(Future, Time + 200); \ 124 | QVERIFY(Future.isCanceled()); \ 125 | { \ 126 | bool exceptionCaught = false; \ 127 | try { \ 128 | Future.waitForFinished(); \ 129 | } catch (const Exception &e) { \ 130 | exceptionCaught = true; \ 131 | } \ 132 | QVERIFY(exceptionCaught); \ 133 | } 134 | 135 | 136 | 137 | #define VERIFY_TYPE(Variable, Type) \ 138 | QVERIFY((std::is_same::value)) 139 | 140 | #define TEST_CHUNK(Name) qDebug() << "Test: " << Name; 141 | 142 | namespace { 143 | template 144 | struct debug_type; 145 | } 146 | 147 | #define DEBUG_TYPE(Variable) { debug_type error; } 148 | 149 | using namespace AsynQt; 150 | 151 | namespace common { 152 | QByteArray helloKdeMessage(); 153 | QFuture execHelloKde(); 154 | QFuture execEcho(const QString &message); 155 | QFuture fail(const QString &message); 156 | } 157 | 158 | #endif // TESTS_COMMON_H 159 | 160 | -------------------------------------------------------------------------------- /COPYING.LGPL-3: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /COPYING.LGPL-2: -------------------------------------------------------------------------------- 1 | GNU LIBRARY GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the library GPL. It is 10 | numbered 2 because it goes with version 2 of the ordinary GPL.] 11 | 12 | Preamble 13 | 14 | The licenses for most software are designed to take away your 15 | freedom to share and change it. By contrast, the GNU General Public 16 | Licenses are intended to guarantee your freedom to share and change 17 | free software--to make sure the software is free for all its users. 18 | 19 | This license, the Library General Public License, applies to some 20 | specially designated Free Software Foundation software, and to any 21 | other libraries whose authors decide to use it. You can use it for 22 | your libraries, too. 23 | 24 | When we speak of free software, we are referring to freedom, not 25 | price. Our General Public Licenses are designed to make sure that you 26 | have the freedom to distribute copies of free software (and charge for 27 | this service if you wish), that you receive source code or can get it 28 | if you want it, that you can change the software or use pieces of it 29 | in new free programs; and that you know you can do these things. 30 | 31 | To protect your rights, we need to make restrictions that forbid 32 | anyone to deny you these rights or to ask you to surrender the rights. 33 | These restrictions translate to certain responsibilities for you if 34 | you distribute copies of the library, or if you modify it. 35 | 36 | For example, if you distribute copies of the library, whether gratis 37 | or for a fee, you must give the recipients all the rights that we gave 38 | you. You must make sure that they, too, receive or can get the source 39 | code. If you link a program with the library, you must provide 40 | complete object files to the recipients so that they can relink them 41 | with the library, after making changes to the library and recompiling 42 | it. And you must show them these terms so they know their rights. 43 | 44 | Our method of protecting your rights has two steps: (1) copyright 45 | the library, and (2) offer you this license which gives you legal 46 | permission to copy, distribute and/or modify the library. 47 | 48 | Also, for each distributor's protection, we want to make certain 49 | that everyone understands that there is no warranty for this free 50 | library. If the library is modified by someone else and passed on, we 51 | want its recipients to know that what they have is not the original 52 | version, so that any problems introduced by others will not reflect on 53 | the original authors' reputations. 54 | 55 | Finally, any free program is threatened constantly by software 56 | patents. We wish to avoid the danger that companies distributing free 57 | software will individually obtain patent licenses, thus in effect 58 | transforming the program into proprietary software. To prevent this, 59 | we have made it clear that any patent must be licensed for everyone's 60 | free use or not licensed at all. 61 | 62 | Most GNU software, including some libraries, is covered by the ordinary 63 | GNU General Public License, which was designed for utility programs. This 64 | license, the GNU Library General Public License, applies to certain 65 | designated libraries. This license is quite different from the ordinary 66 | one; be sure to read it in full, and don't assume that anything in it is 67 | the same as in the ordinary license. 68 | 69 | The reason we have a separate public license for some libraries is that 70 | they blur the distinction we usually make between modifying or adding to a 71 | program and simply using it. Linking a program with a library, without 72 | changing the library, is in some sense simply using the library, and is 73 | analogous to running a utility program or application program. However, in 74 | a textual and legal sense, the linked executable is a combined work, a 75 | derivative of the original library, and the ordinary General Public License 76 | treats it as such. 77 | 78 | Because of this blurred distinction, using the ordinary General 79 | Public License for libraries did not effectively promote software 80 | sharing, because most developers did not use the libraries. We 81 | concluded that weaker conditions might promote sharing better. 82 | 83 | However, unrestricted linking of non-free programs would deprive the 84 | users of those programs of all benefit from the free status of the 85 | libraries themselves. This Library General Public License is intended to 86 | permit developers of non-free programs to use free libraries, while 87 | preserving your freedom as a user of such programs to change the free 88 | libraries that are incorporated in them. (We have not seen how to achieve 89 | this as regards changes in header files, but we have achieved it as regards 90 | changes in the actual functions of the Library.) The hope is that this 91 | will lead to faster development of free libraries. 92 | 93 | The precise terms and conditions for copying, distribution and 94 | modification follow. Pay close attention to the difference between a 95 | "work based on the library" and a "work that uses the library". The 96 | former contains code derived from the library, while the latter only 97 | works together with the library. 98 | 99 | Note that it is possible for a library to be covered by the ordinary 100 | General Public License rather than by this special one. 101 | 102 | GNU LIBRARY GENERAL PUBLIC LICENSE 103 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 104 | 105 | 0. This License Agreement applies to any software library which 106 | contains a notice placed by the copyright holder or other authorized 107 | party saying it may be distributed under the terms of this Library 108 | General Public License (also called "this License"). Each licensee is 109 | addressed as "you". 110 | 111 | A "library" means a collection of software functions and/or data 112 | prepared so as to be conveniently linked with application programs 113 | (which use some of those functions and data) to form executables. 114 | 115 | The "Library", below, refers to any such software library or work 116 | which has been distributed under these terms. A "work based on the 117 | Library" means either the Library or any derivative work under 118 | copyright law: that is to say, a work containing the Library or a 119 | portion of it, either verbatim or with modifications and/or translated 120 | straightforwardly into another language. (Hereinafter, translation is 121 | included without limitation in the term "modification".) 122 | 123 | "Source code" for a work means the preferred form of the work for 124 | making modifications to it. For a library, complete source code means 125 | all the source code for all modules it contains, plus any associated 126 | interface definition files, plus the scripts used to control compilation 127 | and installation of the library. 128 | 129 | Activities other than copying, distribution and modification are not 130 | covered by this License; they are outside its scope. The act of 131 | running a program using the Library is not restricted, and output from 132 | such a program is covered only if its contents constitute a work based 133 | on the Library (independent of the use of the Library in a tool for 134 | writing it). Whether that is true depends on what the Library does 135 | and what the program that uses the Library does. 136 | 137 | 1. You may copy and distribute verbatim copies of the Library's 138 | complete source code as you receive it, in any medium, provided that 139 | you conspicuously and appropriately publish on each copy an 140 | appropriate copyright notice and disclaimer of warranty; keep intact 141 | all the notices that refer to this License and to the absence of any 142 | warranty; and distribute a copy of this License along with the 143 | Library. 144 | 145 | You may charge a fee for the physical act of transferring a copy, 146 | and you may at your option offer warranty protection in exchange for a 147 | fee. 148 | 149 | 2. You may modify your copy or copies of the Library or any portion 150 | of it, thus forming a work based on the Library, and copy and 151 | distribute such modifications or work under the terms of Section 1 152 | above, provided that you also meet all of these conditions: 153 | 154 | a) The modified work must itself be a software library. 155 | 156 | b) You must cause the files modified to carry prominent notices 157 | stating that you changed the files and the date of any change. 158 | 159 | c) You must cause the whole of the work to be licensed at no 160 | charge to all third parties under the terms of this License. 161 | 162 | d) If a facility in the modified Library refers to a function or a 163 | table of data to be supplied by an application program that uses 164 | the facility, other than as an argument passed when the facility 165 | is invoked, then you must make a good faith effort to ensure that, 166 | in the event an application does not supply such function or 167 | table, the facility still operates, and performs whatever part of 168 | its purpose remains meaningful. 169 | 170 | (For example, a function in a library to compute square roots has 171 | a purpose that is entirely well-defined independent of the 172 | application. Therefore, Subsection 2d requires that any 173 | application-supplied function or table used by this function must 174 | be optional: if the application does not supply it, the square 175 | root function must still compute square roots.) 176 | 177 | These requirements apply to the modified work as a whole. If 178 | identifiable sections of that work are not derived from the Library, 179 | and can be reasonably considered independent and separate works in 180 | themselves, then this License, and its terms, do not apply to those 181 | sections when you distribute them as separate works. But when you 182 | distribute the same sections as part of a whole which is a work based 183 | on the Library, the distribution of the whole must be on the terms of 184 | this License, whose permissions for other licensees extend to the 185 | entire whole, and thus to each and every part regardless of who wrote 186 | it. 187 | 188 | Thus, it is not the intent of this section to claim rights or contest 189 | your rights to work written entirely by you; rather, the intent is to 190 | exercise the right to control the distribution of derivative or 191 | collective works based on the Library. 192 | 193 | In addition, mere aggregation of another work not based on the Library 194 | with the Library (or with a work based on the Library) on a volume of 195 | a storage or distribution medium does not bring the other work under 196 | the scope of this License. 197 | 198 | 3. You may opt to apply the terms of the ordinary GNU General Public 199 | License instead of this License to a given copy of the Library. To do 200 | this, you must alter all the notices that refer to this License, so 201 | that they refer to the ordinary GNU General Public License, version 2, 202 | instead of to this License. (If a newer version than version 2 of the 203 | ordinary GNU General Public License has appeared, then you can specify 204 | that version instead if you wish.) Do not make any other change in 205 | these notices. 206 | 207 | Once this change is made in a given copy, it is irreversible for 208 | that copy, so the ordinary GNU General Public License applies to all 209 | subsequent copies and derivative works made from that copy. 210 | 211 | This option is useful when you wish to copy part of the code of 212 | the Library into a program that is not a library. 213 | 214 | 4. You may copy and distribute the Library (or a portion or 215 | derivative of it, under Section 2) in object code or executable form 216 | under the terms of Sections 1 and 2 above provided that you accompany 217 | it with the complete corresponding machine-readable source code, which 218 | must be distributed under the terms of Sections 1 and 2 above on a 219 | medium customarily used for software interchange. 220 | 221 | If distribution of object code is made by offering access to copy 222 | from a designated place, then offering equivalent access to copy the 223 | source code from the same place satisfies the requirement to 224 | distribute the source code, even though third parties are not 225 | compelled to copy the source along with the object code. 226 | 227 | 5. A program that contains no derivative of any portion of the 228 | Library, but is designed to work with the Library by being compiled or 229 | linked with it, is called a "work that uses the Library". Such a 230 | work, in isolation, is not a derivative work of the Library, and 231 | therefore falls outside the scope of this License. 232 | 233 | However, linking a "work that uses the Library" with the Library 234 | creates an executable that is a derivative of the Library (because it 235 | contains portions of the Library), rather than a "work that uses the 236 | library". The executable is therefore covered by this License. 237 | Section 6 states terms for distribution of such executables. 238 | 239 | When a "work that uses the Library" uses material from a header file 240 | that is part of the Library, the object code for the work may be a 241 | derivative work of the Library even though the source code is not. 242 | Whether this is true is especially significant if the work can be 243 | linked without the Library, or if the work is itself a library. The 244 | threshold for this to be true is not precisely defined by law. 245 | 246 | If such an object file uses only numerical parameters, data 247 | structure layouts and accessors, and small macros and small inline 248 | functions (ten lines or less in length), then the use of the object 249 | file is unrestricted, regardless of whether it is legally a derivative 250 | work. (Executables containing this object code plus portions of the 251 | Library will still fall under Section 6.) 252 | 253 | Otherwise, if the work is a derivative of the Library, you may 254 | distribute the object code for the work under the terms of Section 6. 255 | Any executables containing that work also fall under Section 6, 256 | whether or not they are linked directly with the Library itself. 257 | 258 | 6. As an exception to the Sections above, you may also compile or 259 | link a "work that uses the Library" with the Library to produce a 260 | work containing portions of the Library, and distribute that work 261 | under terms of your choice, provided that the terms permit 262 | modification of the work for the customer's own use and reverse 263 | engineering for debugging such modifications. 264 | 265 | You must give prominent notice with each copy of the work that the 266 | Library is used in it and that the Library and its use are covered by 267 | this License. You must supply a copy of this License. If the work 268 | during execution displays copyright notices, you must include the 269 | copyright notice for the Library among them, as well as a reference 270 | directing the user to the copy of this License. Also, you must do one 271 | of these things: 272 | 273 | a) Accompany the work with the complete corresponding 274 | machine-readable source code for the Library including whatever 275 | changes were used in the work (which must be distributed under 276 | Sections 1 and 2 above); and, if the work is an executable linked 277 | with the Library, with the complete machine-readable "work that 278 | uses the Library", as object code and/or source code, so that the 279 | user can modify the Library and then relink to produce a modified 280 | executable containing the modified Library. (It is understood 281 | that the user who changes the contents of definitions files in the 282 | Library will not necessarily be able to recompile the application 283 | to use the modified definitions.) 284 | 285 | b) Accompany the work with a written offer, valid for at 286 | least three years, to give the same user the materials 287 | specified in Subsection 6a, above, for a charge no more 288 | than the cost of performing this distribution. 289 | 290 | c) If distribution of the work is made by offering access to copy 291 | from a designated place, offer equivalent access to copy the above 292 | specified materials from the same place. 293 | 294 | d) Verify that the user has already received a copy of these 295 | materials or that you have already sent this user a copy. 296 | 297 | For an executable, the required form of the "work that uses the 298 | Library" must include any data and utility programs needed for 299 | reproducing the executable from it. However, as a special exception, 300 | the source code distributed need not include anything that is normally 301 | distributed (in either source or binary form) with the major 302 | components (compiler, kernel, and so on) of the operating system on 303 | which the executable runs, unless that component itself accompanies 304 | the executable. 305 | 306 | It may happen that this requirement contradicts the license 307 | restrictions of other proprietary libraries that do not normally 308 | accompany the operating system. Such a contradiction means you cannot 309 | use both them and the Library together in an executable that you 310 | distribute. 311 | 312 | 7. You may place library facilities that are a work based on the 313 | Library side-by-side in a single library together with other library 314 | facilities not covered by this License, and distribute such a combined 315 | library, provided that the separate distribution of the work based on 316 | the Library and of the other library facilities is otherwise 317 | permitted, and provided that you do these two things: 318 | 319 | a) Accompany the combined library with a copy of the same work 320 | based on the Library, uncombined with any other library 321 | facilities. This must be distributed under the terms of the 322 | Sections above. 323 | 324 | b) Give prominent notice with the combined library of the fact 325 | that part of it is a work based on the Library, and explaining 326 | where to find the accompanying uncombined form of the same work. 327 | 328 | 8. You may not copy, modify, sublicense, link with, or distribute 329 | the Library except as expressly provided under this License. Any 330 | attempt otherwise to copy, modify, sublicense, link with, or 331 | distribute the Library is void, and will automatically terminate your 332 | rights under this License. However, parties who have received copies, 333 | or rights, from you under this License will not have their licenses 334 | terminated so long as such parties remain in full compliance. 335 | 336 | 9. You are not required to accept this License, since you have not 337 | signed it. However, nothing else grants you permission to modify or 338 | distribute the Library or its derivative works. These actions are 339 | prohibited by law if you do not accept this License. Therefore, by 340 | modifying or distributing the Library (or any work based on the 341 | Library), you indicate your acceptance of this License to do so, and 342 | all its terms and conditions for copying, distributing or modifying 343 | the Library or works based on it. 344 | 345 | 10. Each time you redistribute the Library (or any work based on the 346 | Library), the recipient automatically receives a license from the 347 | original licensor to copy, distribute, link with or modify the Library 348 | subject to these terms and conditions. You may not impose any further 349 | restrictions on the recipients' exercise of the rights granted herein. 350 | You are not responsible for enforcing compliance by third parties to 351 | this License. 352 | 353 | 11. If, as a consequence of a court judgment or allegation of patent 354 | infringement or for any other reason (not limited to patent issues), 355 | conditions are imposed on you (whether by court order, agreement or 356 | otherwise) that contradict the conditions of this License, they do not 357 | excuse you from the conditions of this License. If you cannot 358 | distribute so as to satisfy simultaneously your obligations under this 359 | License and any other pertinent obligations, then as a consequence you 360 | may not distribute the Library at all. For example, if a patent 361 | license would not permit royalty-free redistribution of the Library by 362 | all those who receive copies directly or indirectly through you, then 363 | the only way you could satisfy both it and this License would be to 364 | refrain entirely from distribution of the Library. 365 | 366 | If any portion of this section is held invalid or unenforceable under any 367 | particular circumstance, the balance of the section is intended to apply, 368 | and the section as a whole is intended to apply in other circumstances. 369 | 370 | It is not the purpose of this section to induce you to infringe any 371 | patents or other property right claims or to contest validity of any 372 | such claims; this section has the sole purpose of protecting the 373 | integrity of the free software distribution system which is 374 | implemented by public license practices. Many people have made 375 | generous contributions to the wide range of software distributed 376 | through that system in reliance on consistent application of that 377 | system; it is up to the author/donor to decide if he or she is willing 378 | to distribute software through any other system and a licensee cannot 379 | impose that choice. 380 | 381 | This section is intended to make thoroughly clear what is believed to 382 | be a consequence of the rest of this License. 383 | 384 | 12. If the distribution and/or use of the Library is restricted in 385 | certain countries either by patents or by copyrighted interfaces, the 386 | original copyright holder who places the Library under this License may add 387 | an explicit geographical distribution limitation excluding those countries, 388 | so that distribution is permitted only in or among countries not thus 389 | excluded. In such case, this License incorporates the limitation as if 390 | written in the body of this License. 391 | 392 | 13. The Free Software Foundation may publish revised and/or new 393 | versions of the Library General Public License from time to time. 394 | Such new versions will be similar in spirit to the present version, 395 | but may differ in detail to address new problems or concerns. 396 | 397 | Each version is given a distinguishing version number. If the Library 398 | specifies a version number of this License which applies to it and 399 | "any later version", you have the option of following the terms and 400 | conditions either of that version or of any later version published by 401 | the Free Software Foundation. If the Library does not specify a 402 | license version number, you may choose any version ever published by 403 | the Free Software Foundation. 404 | 405 | 14. If you wish to incorporate parts of the Library into other free 406 | programs whose distribution conditions are incompatible with these, 407 | write to the author to ask for permission. For software which is 408 | copyrighted by the Free Software Foundation, write to the Free 409 | Software Foundation; we sometimes make exceptions for this. Our 410 | decision will be guided by the two goals of preserving the free status 411 | of all derivatives of our free software and of promoting the sharing 412 | and reuse of software generally. 413 | 414 | NO WARRANTY 415 | 416 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 417 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 418 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 419 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 420 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 421 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 422 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 423 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 424 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 425 | 426 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 427 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 428 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 429 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 430 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 431 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 432 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 433 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 434 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 435 | DAMAGES. 436 | 437 | END OF TERMS AND CONDITIONS 438 | 439 | How to Apply These Terms to Your New Libraries 440 | 441 | If you develop a new library, and you want it to be of the greatest 442 | possible use to the public, we recommend making it free software that 443 | everyone can redistribute and change. You can do so by permitting 444 | redistribution under these terms (or, alternatively, under the terms of the 445 | ordinary General Public License). 446 | 447 | To apply these terms, attach the following notices to the library. It is 448 | safest to attach them to the start of each source file to most effectively 449 | convey the exclusion of warranty; and each file should have at least the 450 | "copyright" line and a pointer to where the full notice is found. 451 | 452 | 453 | Copyright (C) 454 | 455 | This library is free software; you can redistribute it and/or 456 | modify it under the terms of the GNU Library General Public 457 | License as published by the Free Software Foundation; either 458 | version 2 of the License, or (at your option) any later version. 459 | 460 | This library is distributed in the hope that it will be useful, 461 | but WITHOUT ANY WARRANTY; without even the implied warranty of 462 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 463 | Library General Public License for more details. 464 | 465 | You should have received a copy of the GNU Library General Public 466 | License along with this library; if not, write to the Free Software 467 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 468 | 469 | Also add information on how to contact you by electronic and paper mail. 470 | 471 | You should also get your employer (if you work as a programmer) or your 472 | school, if any, to sign a "copyright disclaimer" for the library, if 473 | necessary. Here is a sample; alter the names: 474 | 475 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 476 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 477 | 478 | , 1 April 1990 479 | Ty Coon, President of Vice 480 | 481 | That's all there is to it! 482 | -------------------------------------------------------------------------------- /COPYING.LGPL-2.1: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | --------------------------------------------------------------------------------