update to use submodules

This commit is contained in:
arcan1s 2014-08-28 15:21:41 +04:00
parent 2c35031549
commit 5584ba0e9f
9 changed files with 19 additions and 503 deletions

9
.gitmodules vendored Normal file
View File

@ -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

1
sources/3rdparty/pdebug vendored Submodule

@ -0,0 +1 @@
Subproject commit 294a590bb966fd79eb2e93a7b02377ca57731cd5

1
sources/3rdparty/task vendored Submodule

@ -0,0 +1 @@
Subproject commit d2798204a1a84a23a9510aeda73d5b9b75d2c8eb

View File

@ -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

View File

@ -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 <utility>
#include <future>
#include <functional>
#include <QThread>
#include <QEventLoop>
/*
*
* 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<T>& 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<T> 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<T>& run( std::function< T ( void ) > function )
{
auto t = new ThreadHelper<T>( 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<T>( std::move( function ) ).await() ;
}
template< typename T >
T await( Task::future<T>& e )
{
return e.await() ;
}
template< typename T >
T await( std::future<T>&& t )
{
return Task::await<T>( [ & ](){ 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<int>( _a ).then( _b ) ;
alternatively,
Task::future<int>& 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<int>( _a ) ;
alternatively,
Task::future<int>& e = Task::run<int>( _a ) ;
int r = e.await() ;
alternatively,
int r = Task::run<int>( _a ).await() ;
#endif
#endif //__TASK_H_INCLUDED__

View File

@ -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<TaskResult>( [ & ]() {
QProcess command;
command.start(cmd);
command.waitForFinished(-1);
TaskResult r;
r.exitCode = command.exitCode();
r.output = command.readAllStandardOutput();
return r;
});
}

View File

@ -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 <QProcess>
#include "task.h"
struct TaskResult
{
int exitCode;
QByteArray output;
};
TaskResult runTask(const QString cmd);
#endif /* TASKADDS_H */

1
sources/3rdparty/tasks vendored Submodule

@ -0,0 +1 @@
Subproject commit f78c18d38156e8f7dd0d342d9f8779bed8b7f84e

View File

@ -19,14 +19,13 @@
#include "ui_appearance.h" #include "ui_appearance.h"
#include "ui_widget.h" #include "ui_widget.h"
#include <KDE/KConfigDialog> #include <KConfigDialog>
#include <KDE/KGlobal> #include <KGlobal>
#include <KDE/KStandardDirs> #include <KStandardDirs>
#include <KDE/Plasma/Containment> #include <KWindowSystem>
#include <KDE/Plasma/Corona> #include <Plasma/Containment>
#include <KDE/Plasma/Theme> #include <Plasma/Corona>
#include <KDE/KWindowInfo> #include <Plasma/Theme>
#include <KDE/KWindowSystem>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QGraphicsLinearLayout> #include <QGraphicsLinearLayout>