Skip to content

Commit

Permalink
investing for the future
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Nov 3, 2022
1 parent c67ba6b commit 69dabc6
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 10 deletions.
34 changes: 28 additions & 6 deletions src/qcheckgmail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ qCheckGMail::qCheckGMail( const qCheckGMail::args& args ) :
m_networkRequest.setRawHeader( "Content-Type","application/x-www-form-urlencoded" ) ;
m_dbusConnection.connect( a,b,c,"NotificationClosed",
this,SLOT( handleSignal( quint32,quint32 ) ) ) ;

class foo{

public:
void sss()
{
qDebug() << QThread::currentThreadId() ;
}

int qqq()
{
qDebug() << QThread::currentThreadId() ;

return 5 ;
}
void www( int )
{
qDebug() << QThread::currentThreadId() ;

}
};

auto m = new foo() ;

utils::qthread::run( m,&foo::sss,&foo::sss ) ;
utils::qthread::run( m,&foo::qqq,&foo::www ) ;

}

qCheckGMail::~qCheckGMail()
Expand Down Expand Up @@ -545,19 +572,14 @@ void qCheckGMail::updateUi( int counter,
m_accountsStatus ) ;
}



if( m_audioNotify ){

this->audioNotify() ;
}

if( m_visualNotify ){

utils::qthread::run( [ this ](){

this->visualNotify() ;
} ) ;
utils::qthread::run( this,&qCheckGMail::visualNotify ) ;
}
}else{
this->changeIcon( m_noEmailIcon ) ;
Expand Down
84 changes: 80 additions & 4 deletions src/utils/threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace utils
{
namespace details{
#if __cplusplus >= 201703L
template<typename Function>
using result_of = std::invoke_result_t<Function> ;
template< typename Function,typename ... Args >
using result_of = std::invoke_result_t< Function,Args ... > ;
#else
template<typename Function>
using result_of = std::result_of_t< Function() > ;
template< typename Function,typename ... Args >
using result_of = std::result_of_t< Function( Args ... ) > ;
#endif
}

Expand Down Expand Up @@ -110,6 +110,82 @@ namespace utils
},[]( int ){} ) ;
}

template< typename Object,
typename Method,
typename std::enable_if< std::is_pointer< Object >::value,int >::type = 0,
typename std::enable_if< std::is_member_function_pointer< Method >::value,int >::type = 0 >
void run( Object obj,Method method )
{
run( [ obj,method ](){ ( obj->*method )() ; } ) ;
}

namespace details
{
template< typename Obj,typename M >
auto function( Obj o,M m )
{
return ( o->*m )() ;
}
template< typename Function,
typename Obj1,
typename M1,
typename Obj2,
typename M2,
typename std::enable_if< std::is_void< details::result_of< Function,Obj1,M1 > >::value,int >::type = 0 >
void run1( Function,Obj1 obj,M1 method,Obj2 obj1,M2 method1 )
{
run( [ obj,method ](){

( obj->*method )() ;

},[ obj1,method1 ]() {

( obj1->*method1 )() ;
} ) ;
}
template< typename Function,
typename Obj1,
typename M1,
typename Obj2,
typename M2,
typename std::enable_if< !std::is_void< details::result_of< Function,Obj1,M1 > >::value,int >::type = 0 >
void run1( Function,Obj1 obj,M1 method,Obj2 obj1,M2 method1 )
{
run( [ obj,method ](){

return ( obj->*method )() ;

},[ obj1,method1 ]( details::result_of< Function,Obj1,M1 >&& value ) {

( obj1->*method1 )( std::move( value ) ) ;
} ) ;
}
}

template< typename ObjectUiThread,
typename MethodUiThread,
typename ObjectBGThread,
typename MethodBGThread,
typename std::enable_if< std::is_pointer< ObjectUiThread >::value,int >::type = 0,
typename std::enable_if< std::is_member_function_pointer< MethodUiThread >::value,int >::type = 0,
typename std::enable_if< std::is_pointer< ObjectBGThread >::value,int >::type = 0,
typename std::enable_if< std::is_member_function_pointer< MethodBGThread >::value,int >::type = 0 >
void run( ObjectUiThread obj,MethodUiThread method,ObjectBGThread obj1,MethodBGThread method1 )
{
details::run1( details::function< ObjectUiThread,MethodUiThread >,obj,method,obj1,method1 ) ;
}

template< typename ObjectUiThread,
typename MethodUiThread,
typename MethodBGThread,
typename std::enable_if< std::is_pointer< ObjectUiThread >::value,int >::type = 0,
typename std::enable_if< std::is_member_function_pointer< MethodUiThread >::value,int >::type = 0,
typename std::enable_if< std::is_member_function_pointer< MethodBGThread >::value,int >::type = 0 >
void run( ObjectUiThread obj,MethodUiThread method,MethodBGThread method1 )
{
details::run1( details::function< ObjectUiThread,MethodUiThread >,obj,method,obj,method1 ) ;
}

template< typename BackGroundTask,
typename std::enable_if< !std::is_void< details::result_of< BackGroundTask > >::value,int >::type = 0 >
details::result_of< BackGroundTask > await( BackGroundTask bgt )
Expand Down

0 comments on commit 69dabc6

Please sign in to comment.