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.

39 lines
825 B

#pragma once
#include "mutex.hpp"
#include "python_bind.h"
#include <functional>
#include <gtkmm.h>
#include <list>
class Dispatcher {
private:
Mutex functions_mutex;
std::list<std::function<void()>> functions GUARDED_BY(functions_mutex);
Glib::Dispatcher dispatcher;
sigc::connection connection;
void connect();
public:
/// Must be called from main GUI thread
Dispatcher();
~Dispatcher();
/// Queue function to main GUI thread.
/// Can be called from any thread.
template <typename T>
void post(T &&function) {
LockGuard lock(functions_mutex);
functions.emplace_back(std::forward<T>(function));
dispatcher();
}
/// Must be called from main GUI thread
void disconnect();
/// Must be called from main GUI thread
void reset();
static void init_module(py::module &api);
};