mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
755 B
36 lines
755 B
|
8 years ago
|
#pragma once
|
||
|
6 years ago
|
#include "mutex.hpp"
|
||
|
8 years ago
|
#include <functional>
|
||
|
8 years ago
|
#include <gtkmm.h>
|
||
|
8 years ago
|
#include <list>
|
||
|
10 years ago
|
|
||
|
|
class Dispatcher {
|
||
|
|
private:
|
||
|
7 years ago
|
Mutex functions_mutex;
|
||
|
|
std::list<std::function<void()>> functions GUARDED_BY(functions_mutex);
|
||
|
10 years ago
|
Glib::Dispatcher dispatcher;
|
||
|
|
sigc::connection connection;
|
||
|
8 years ago
|
|
||
|
7 years ago
|
void connect();
|
||
|
|
|
||
|
10 years ago
|
public:
|
||
|
7 years ago
|
/// Must be called from main GUI thread
|
||
|
10 years ago
|
Dispatcher();
|
||
|
|
~Dispatcher();
|
||
|
8 years ago
|
|
||
|
7 years ago
|
/// Queue function to main GUI thread.
|
||
|
|
/// Can be called from any thread.
|
||
|
8 years ago
|
template <typename T>
|
||
|
8 years ago
|
void post(T &&function) {
|
||
|
7 years ago
|
LockGuard lock(functions_mutex);
|
||
|
7 years ago
|
functions.emplace_back(std::forward<T>(function));
|
||
|
8 years ago
|
dispatcher();
|
||
|
|
}
|
||
|
8 years ago
|
|
||
|
7 years ago
|
/// Must be called from main GUI thread
|
||
|
10 years ago
|
void disconnect();
|
||
|
7 years ago
|
|
||
|
|
/// Must be called from main GUI thread
|
||
|
|
void reset();
|
||
|
10 years ago
|
};
|