2010-10-20 23:50:49 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file InGuiThread.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Peter Kümmel
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INGUITHREAD_H
|
|
|
|
#define INGUITHREAD_H
|
|
|
|
|
2010-10-21 21:29:08 +00:00
|
|
|
#include <QMutex>
|
2010-10-20 23:50:49 +00:00
|
|
|
#include <QObject>
|
2010-10-21 21:29:08 +00:00
|
|
|
#include <QWaitCondition>
|
2010-10-20 23:50:49 +00:00
|
|
|
|
|
|
|
#include "support/bind.h"
|
|
|
|
#include "support/functional.h"
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
class IntoGuiThreadMover : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
IntoGuiThreadMover();
|
|
|
|
|
|
|
|
void callInGuiThread();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2010-10-21 21:29:08 +00:00
|
|
|
void triggerFunctionCall();
|
2010-10-20 23:50:49 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void doFunctionCall();
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void synchronousFunctionCall() = 0;
|
2010-10-21 21:29:08 +00:00
|
|
|
|
|
|
|
QWaitCondition condition_;
|
|
|
|
QMutex sync_mutex_;
|
2010-10-20 23:50:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class InGuiThread : private IntoGuiThreadMover
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-06-12 04:12:03 +00:00
|
|
|
// please coverity by explicitly initalizing this variable.
|
|
|
|
InGuiThread() : return_value_(R()) {}
|
2010-10-20 23:50:49 +00:00
|
|
|
|
|
|
|
template<class F>
|
|
|
|
R call(F f)
|
|
|
|
{
|
|
|
|
func_ = f;
|
2010-11-01 21:32:59 +00:00
|
|
|
callInGuiThread();
|
2010-10-20 23:50:49 +00:00
|
|
|
return return_value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1>
|
2010-10-23 00:06:22 +00:00
|
|
|
R call(F f, P1& p1)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
return call(lyx::bind(f, lyx::ref(p1)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1, class P2>
|
2010-10-23 00:06:22 +00:00
|
|
|
R call(F f, P1& p1, P2& p2)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1, class P2, class P3>
|
2010-10-23 00:06:22 +00:00
|
|
|
R call(F f, P1& p1, P2& p2, P3& p3)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1, class P2, class P3, class P4>
|
2010-10-23 00:06:22 +00:00
|
|
|
R call(F f, P1& p1, P2& p2, P3& p3, P4& p4)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
...
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<class F, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
|
2010-10-23 00:06:22 +00:00
|
|
|
R call(F f, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2017-07-03 17:45:58 +00:00
|
|
|
return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4),
|
2012-10-08 19:28:55 +00:00
|
|
|
lyx::ref(p5), lyx::ref(p6), lyx::ref(p7), lyx::ref(p8)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void synchronousFunctionCall()
|
|
|
|
{
|
|
|
|
return_value_ = func_();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
R return_value_;
|
|
|
|
function<R()> func_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// void specialisation
|
|
|
|
template<>
|
|
|
|
class InGuiThread<void> : private IntoGuiThreadMover
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
InGuiThread() {}
|
|
|
|
|
|
|
|
template<class F>
|
|
|
|
void call(F f)
|
|
|
|
{
|
|
|
|
func_ = f;
|
2010-11-01 21:32:59 +00:00
|
|
|
callInGuiThread();
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1>
|
2010-10-23 00:06:22 +00:00
|
|
|
void call(F f, P1& p1)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
call(lyx::bind(f, lyx::ref(p1)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1, class P2>
|
2010-10-23 00:06:22 +00:00
|
|
|
void call(F f, P1& p1, P2& p2)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1, class P2, class P3>
|
2010-10-23 00:06:22 +00:00
|
|
|
void call(F f, P1& p1, P2& p2, P3& p3)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class F, class P1, class P2, class P3, class P4>
|
2010-10-23 00:06:22 +00:00
|
|
|
void call(F f, P1& p1, P2& p2, P3& p3, P4& p4)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
...
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<class F, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
|
2010-10-23 00:06:22 +00:00
|
|
|
void call(F f, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8)
|
2010-10-20 23:50:49 +00:00
|
|
|
{
|
2012-10-08 19:28:55 +00:00
|
|
|
call(bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4), lyx::ref(p5),
|
|
|
|
lyx::ref(p6), lyx::ref(p7), lyx::ref(p8)));
|
2010-10-20 23:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void synchronousFunctionCall()
|
|
|
|
{
|
|
|
|
func_();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
function<void()> func_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2010-10-21 22:04:06 +00:00
|
|
|
#endif // INGUITHREAD_H
|