Add @thirtythreeforty's std::function<>
variant (#4892)
Also convert `batchqueue.cc` where applicable.
This commit is contained in:
parent
1d0c128209
commit
00b62d2b65
@ -39,25 +39,6 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace rtengine;
|
using namespace rtengine;
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
|
|
||||||
struct NLParams {
|
|
||||||
BatchQueueListener* listener;
|
|
||||||
int qsize;
|
|
||||||
bool queueEmptied;
|
|
||||||
bool queueError;
|
|
||||||
Glib::ustring queueErrorMessage;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool bqnotifylistenerUI(NLParams* params)
|
|
||||||
{
|
|
||||||
params->listener->queueSizeChanged (params->qsize, params->queueEmptied, params->queueError, params->queueErrorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr)
|
BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -604,14 +585,13 @@ void BatchQueue::setProgress(double p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No need to acquire the GUI, setProgressUI will do it
|
// No need to acquire the GUI, setProgressUI will do it
|
||||||
const auto func =
|
idle_register.add(
|
||||||
[](BatchQueue* bq) -> bool
|
[this]() -> bool
|
||||||
{
|
{
|
||||||
bq->redraw();
|
redraw();
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
);
|
||||||
idle_register.add<BatchQueue>(func, this, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::setProgressStr(const Glib::ustring& str)
|
void BatchQueue::setProgressStr(const Glib::ustring& str)
|
||||||
@ -636,12 +616,15 @@ void BatchQueue::error(const Glib::ustring& descr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (listener) {
|
if (listener) {
|
||||||
NLParams* params = new NLParams;
|
BatchQueueListener* const listener_copy = listener;
|
||||||
params->listener = listener;
|
|
||||||
params->queueEmptied = false;
|
idle_register.add(
|
||||||
params->queueError = true;
|
[listener_copy, descr]() -> bool
|
||||||
params->queueErrorMessage = descr;
|
{
|
||||||
idle_register.add<NLParams>(bqnotifylistenerUI, params, true);
|
listener_copy->queueSizeChanged(0, false, true, descr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,15 +958,21 @@ void BatchQueue::notifyListener (bool queueEmptied)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (listener) {
|
if (listener) {
|
||||||
NLParams* params = new NLParams;
|
BatchQueueListener* const listener_copy = listener;
|
||||||
params->listener = listener;
|
const std::size_t queue_size =
|
||||||
{
|
[](MyRWMutex& mutex, const std::vector<ThumbBrowserEntryBase*>& fd) -> std::size_t
|
||||||
MYREADERLOCK(l, entryRW);
|
{
|
||||||
params->qsize = fd.size();
|
MYREADERLOCK(l, mutex);
|
||||||
}
|
return fd.size();
|
||||||
params->queueEmptied = queueEmptied;
|
}(entryRW, fd);
|
||||||
params->queueError = false;
|
|
||||||
idle_register.add<NLParams>(bqnotifylistenerUI, params, true);
|
idle_register.add(
|
||||||
|
[listener_copy, queue_size, queueEmptied]() -> bool
|
||||||
|
{
|
||||||
|
listener_copy->queueSizeChanged(queue_size, queueEmptied, false, {});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,19 @@ IdleRegister::~IdleRegister()
|
|||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IdleRegister::add(std::function<bool ()> function, gint priority)
|
||||||
|
{
|
||||||
|
using Function = std::function<bool ()>;
|
||||||
|
|
||||||
|
const auto func =
|
||||||
|
[](Function* function)
|
||||||
|
{
|
||||||
|
return (*function)();
|
||||||
|
};
|
||||||
|
|
||||||
|
add<Function>(func, new Function(std::move(function)), true, priority);
|
||||||
|
}
|
||||||
|
|
||||||
void IdleRegister::destroy()
|
void IdleRegister::destroy()
|
||||||
{
|
{
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifndef __GUI_UTILS_
|
#ifndef __GUI_UTILS_
|
||||||
#define __GUI_UTILS_
|
#define __GUI_UTILS_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
@ -98,6 +99,7 @@ public:
|
|||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add(std::function<bool ()> function, gint priority = G_PRIORITY_DEFAULT_IDLE);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user