From 5584ba0e9f2dfa42f988e94ff056d5f2d29c3473 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 28 Aug 2014 15:21:41 +0400 Subject: [PATCH] update to use submodules --- .gitmodules | 9 + sources/3rdparty/pdebug | 1 + sources/3rdparty/task | 1 + sources/3rdparty/task/README.md | 41 --- sources/3rdparty/task/task.h | 385 ------------------------ sources/3rdparty/task/taskadds.cpp | 34 --- sources/3rdparty/task/taskadds.h | 35 --- sources/3rdparty/tasks | 1 + sources/desktop-panel/desktop-panel.cpp | 15 +- 9 files changed, 19 insertions(+), 503 deletions(-) create mode 100644 .gitmodules create mode 160000 sources/3rdparty/pdebug create mode 160000 sources/3rdparty/task delete mode 100644 sources/3rdparty/task/README.md delete mode 100644 sources/3rdparty/task/task.h delete mode 100644 sources/3rdparty/task/taskadds.cpp delete mode 100644 sources/3rdparty/task/taskadds.h create mode 160000 sources/3rdparty/tasks diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ec3e2b6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "sources/3rdparty/pdebug"] + path = sources/3rdparty/pdebug + url = https://github.com/arcan1s/qtadds-pdebug.git +[submodule "sources/3rdparty/task"] + path = sources/3rdparty/task + url = https://github.com/arcan1s/qtadds-taskadds-qprocess.git +[submodule "sources/3rdparty/tasks"] + path = sources/3rdparty/tasks + url = https://github.com/mhogomchungu/tasks.git diff --git a/sources/3rdparty/pdebug b/sources/3rdparty/pdebug new file mode 160000 index 0000000..294a590 --- /dev/null +++ b/sources/3rdparty/pdebug @@ -0,0 +1 @@ +Subproject commit 294a590bb966fd79eb2e93a7b02377ca57731cd5 diff --git a/sources/3rdparty/task b/sources/3rdparty/task new file mode 160000 index 0000000..d279820 --- /dev/null +++ b/sources/3rdparty/task @@ -0,0 +1 @@ +Subproject commit d2798204a1a84a23a9510aeda73d5b9b75d2c8eb diff --git a/sources/3rdparty/task/README.md b/sources/3rdparty/task/README.md deleted file mode 100644 index c375afb..0000000 --- a/sources/3rdparty/task/README.md +++ /dev/null @@ -1,41 +0,0 @@ - - -Asynchronous programming in Qt/C++ using tasks,continuations and resumable functions. - -This project is inspired by this[1] video on channel9. - -The project seeks to do async based programming in Qt/C++ using modern C++ with lambdas. - -The project has two sets of APIs. - -1. Task::run().then() API provides async based programming with continuation[4]. - -2. Task::await() API provides the first API presented in a different way[5]. - -Under certain use cases,they can be used interchangeably, and in others,only one or the other can be used.Some of the problems -the first API causes and solved by the second API are discussed in this[7] youtube video. - -Example use case for the Task::run().then() API can be found here[0]. Additional example is [2] where an API is -declared and [3] where the declared API is used. - -Example use case of the Task::await() API is here[6] where a function call "blocks" waiting for a result without "hanging" the entire GUI application. - -A short tutorial on task/async/await as implemented in C# can be viewed from this[8] link. - -[0] https://github.com/mhogomchungu/tasks/blob/master/example.cpp - -[1] http://channel9.msdn.com/Blogs/Charles/Asynchronous-Programming-for-C-Developers-PPL-Tasks-and-Windows-8 - -[2] https://github.com/mhogomchungu/zuluCrypt/blob/d0439a4e36521e42fa9392b82dcefd3224d53334/zuluMount-gui/zulumounttask.h#L61 - -[3] https://github.com/mhogomchungu/zuluCrypt/blob/d0439a4e36521e42fa9392b82dcefd3224d53334/zuluMount-gui/mainwindow.cpp#L812 - -[4] Disscussion about this can be found on the following link among other places: http://isocpp.org/files/papers/N3558.pdf - -[5] Disscussion about this can be found on the following link among other places: http://isocpp.org/files/papers/N3564.pdf - -[6] https://github.com/mhogomchungu/zuluCrypt/blob/7123e3c3a7c8c5b3b3b6958464fd92a7f780d827/zuluMount-gui/keydialog.cpp#L511 - -[7] https://www.youtube.com/watch?v=Y475RshtAHA - -[8] http://www.youtube.com/watch?v=DqjIQiZ_ql4 diff --git a/sources/3rdparty/task/task.h b/sources/3rdparty/task/task.h deleted file mode 100644 index bc1259e..0000000 --- a/sources/3rdparty/task/task.h +++ /dev/null @@ -1,385 +0,0 @@ -/* - * copyright: 2014 - * name : mhogo mchungu - * email: mhogomchungu@gmail.com - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef __TASK_H_INCLUDED__ -#define __TASK_H_INCLUDED__ - -#include -#include -#include -#include -#include - -/* - * - * Examples on how to use the library are at the end of this file. - * - */ - -namespace Task -{ - class Thread : public QThread - { - Q_OBJECT - public: - Thread() - { - connect( this,SIGNAL( finished() ),this,SLOT( deleteLater() ) ) ; - } - protected: - virtual ~Thread() - { - } - private: - virtual void run( void ) - { - } - }; - - template< typename T > - class future - { - public: - future() : m_function( []( T t ){ Q_UNUSED( t ) ; } ) - { - } - void setActions( std::function< void( void ) > start, - std::function< void( void ) > cancel, - std::function< T ( void ) > get ) - { - m_start = std::move( start ) ; - m_cancel = std::move( cancel ) ; - m_get = std::move( get ) ; - } - void then( std::function< void( T ) > function ) - { - m_function = std::move( function ) ; - m_start() ; - } - T get() - { - return m_get() ; - } - T await() - { - QEventLoop p ; - - T q ; - - m_function = [ & ]( T r ){ q = std::move( r ) ; p.exit() ; } ; - - m_start() ; - - p.exec() ; - - return q ; - } - void start() - { - m_start() ; - } - void cancel() - { - m_cancel() ; - } - void run( T r ) - { - m_function( std::move( r ) ) ; - } - private: - std::function< void( T ) > m_function ; - std::function< void( void ) > m_start ; - std::function< void( void ) > m_cancel ; - std::function< T ( void ) > m_get ; - }; - - template< typename T > - class ThreadHelper : public Thread - { - public: - ThreadHelper( std::function< T ( void ) >&& function ) : m_function( std::move( function ) ) - { - } - future& Future( void ) - { - m_future.setActions( [ this ](){ this->start() ; }, - [ this ](){ this->deleteLater() ; }, - [ this ](){ T r = m_function() ; this->deleteLater() ; return r ; } ) ; - return m_future ; - } - private: - ~ThreadHelper() - { - m_future.run( std::move( m_cargo ) ) ; - } - void run( void ) - { - m_cargo = m_function() ; - } - std::function< T ( void ) > m_function ; - future m_future ; - T m_cargo ; - }; - - class future_1 - { - public: - future_1() : m_function( [](){} ) - { - } - void setActions( std::function< void( void ) > start, - std::function< void( void ) > cancel, - std::function< void( void ) > get ) - { - m_start = std::move( start ) ; - m_cancel = std::move( cancel ) ; - m_get = std::move( get ) ; - } - void then( std::function< void( void ) > function ) - { - m_function = std::move( function ) ; - m_start() ; - } - void get() - { - m_get() ; - } - void await() - { - QEventLoop p ; - - m_function = [ & ](){ p.exit() ; } ; - - m_start() ; - - p.exec() ; - } - void start() - { - m_start() ; - } - void run() - { - m_function() ; - } - void cancel() - { - m_cancel() ; - } - private: - std::function< void( void ) > m_function ; - std::function< void( void ) > m_start ; - std::function< void( void ) > m_cancel ; - std::function< void( void ) > m_get ; - }; - - class ThreadHelper_1 : public Thread - { - public: - ThreadHelper_1( std::function< void ( void ) >&& function ) : m_function( std::move( function ) ) - { - } - future_1& Future( void ) - { - m_future.setActions( [ this ](){ this->start() ; }, - [ this ](){ this->deleteLater() ; }, - [ this ](){ m_function() ; this->deleteLater() ; } ) ; - return m_future ; - } - private: - ~ThreadHelper_1() - { - m_future.run() ; - } - void run( void ) - { - m_function() ; - } - std::function< void ( void ) > m_function ; - future_1 m_future ; - }; - - /* - * Below APIs runs two tasks,the first one will run in a different thread and - * the second one will be run on the original thread after the completion of the - * first one. - */ - - template< typename T > - future& run( std::function< T ( void ) > function ) - { - auto t = new ThreadHelper( std::move( function ) ) ; - return t->Future() ; - } - - static inline future_1& run( std::function< void( void ) > function ) - { - auto t = new ThreadHelper_1( std::move( function ) ) ; - return t->Future() ; - } - - static inline void exec( std::function< void( void ) > function ) - { - Task::run( std::move( function ) ).start() ; - } - - /* - * Below APIs implements resumable functions where a function will be "blocked" - * waiting for the function to return without "hanging" the current thread. - * - * recommending reading up on C#'s await keyword to get a sense of what is being - * discussed below. - */ - - static inline void await( Task::future_1& e ) - { - e.await() ; - } - - static inline void await( std::function< void( void ) > function ) - { - Task::run( std::move( function ) ).await() ; - } - - template< typename T > - T await( std::function< T ( void ) > function ) - { - return Task::run( std::move( function ) ).await() ; - } - - template< typename T > - T await( Task::future& e ) - { - return e.await() ; - } - - template< typename T > - T await( std::future&& t ) - { - return Task::await( [ & ](){ return t.get() ; } ) ; - } -} - -#if 0 - -/* - * Examples on how to use the library - */ -/* - * templated version that passes a return value of one function to another function - */ -auto _a = [](){ - /* - * task _a does what task _a does here. - * - * This function body will run on a different thread - */ - return 0 ; -} - -auto _b = []( int r ){ - /* - * - * task _b does what task _b does here. - * - * r is a const reference to a value returned by _a - * - * This function body will run on the original thread - */ -} - -Task::run( _a ).then( _b ) ; - -alternatively, - -Task::future& e = Task::run( _a ) ; - -e.then( _b ) ; - -/* - * Non templated version that does not pass around return value - */ -auto _c = [](){ - /* - * task _a does what task _a does here. - * - * This function body will run on a different thread - */ -} - -auto _d = [](){ - /* - * task _b does what task _b does here. - * - * r is a const reference to a value returned by _a - * - * This function body will run on the original thread - */ -} - -Task::run( _c ).then( _d ) ; - -/* - * if no continuation - */ -Task::exec( _c ) ; - -/* - * Task::await() is used to "block" without "hanging" the calling thread until the function returns. - * - * Its use case is to do sync programming without hanging the calling thread. - * - * example use case for it is to "block" on function in a GUI thread withough blocking the GUI thread - * hanging the application. - */ - -/* - * await example when the called function return no result - */ -Task::await( _c ) ; - -/* - * await example when the called function return a result - */ -int r = Task::await( _a ) ; - -alternatively, - -Task::future& e = Task::run( _a ) ; - -int r = e.await() ; - -alternatively, - -int r = Task::run( _a ).await() ; - -#endif - -#endif //__TASK_H_INCLUDED__ diff --git a/sources/3rdparty/task/taskadds.cpp b/sources/3rdparty/task/taskadds.cpp deleted file mode 100644 index b8a8165..0000000 --- a/sources/3rdparty/task/taskadds.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * This file is part of netctl-gui * - * * - * netctl-gui is free software: you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation, either version 3 of the * - * License, or (at your option) any later version. * - * * - * netctl-gui is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * - ***************************************************************************/ - - -#include "taskadds.h" - - -TaskResult runTask(const QString cmd) -{ - return Task::await( [ & ]() { - QProcess command; - command.start(cmd); - command.waitForFinished(-1); - TaskResult r; - r.exitCode = command.exitCode(); - r.output = command.readAllStandardOutput(); - - return r; - }); -} diff --git a/sources/3rdparty/task/taskadds.h b/sources/3rdparty/task/taskadds.h deleted file mode 100644 index 6de905b..0000000 --- a/sources/3rdparty/task/taskadds.h +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * This file is part of netctl-gui * - * * - * netctl-gui is free software: you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation, either version 3 of the * - * License, or (at your option) any later version. * - * * - * netctl-gui is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * - ***************************************************************************/ - - -#ifndef TASKADDS_H -#define TASKADDS_H - -#include - -#include "task.h" - - -struct TaskResult -{ - int exitCode; - QByteArray output; -}; -TaskResult runTask(const QString cmd); - - -#endif /* TASKADDS_H */ diff --git a/sources/3rdparty/tasks b/sources/3rdparty/tasks new file mode 160000 index 0000000..f78c18d --- /dev/null +++ b/sources/3rdparty/tasks @@ -0,0 +1 @@ +Subproject commit f78c18d38156e8f7dd0d342d9f8779bed8b7f84e diff --git a/sources/desktop-panel/desktop-panel.cpp b/sources/desktop-panel/desktop-panel.cpp index 8457472..966a1d8 100644 --- a/sources/desktop-panel/desktop-panel.cpp +++ b/sources/desktop-panel/desktop-panel.cpp @@ -19,14 +19,13 @@ #include "ui_appearance.h" #include "ui_widget.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include #include