Add blib event callback to BaseUI, with a virtual method to be overridden by derived classes.

This commit is contained in:
Paul Davis 2020-11-29 12:46:01 -07:00
parent 8bd465fc61
commit b7d22508fa
2 changed files with 21 additions and 0 deletions

View File

@ -60,6 +60,7 @@ BaseUI::BaseUI (const string& loop_name)
, m_context(MainContext::get_default())
, run_loop_thread (0)
, request_channel (true)
, glib_event_callback (boost::bind (&BaseUI::event_loop_precall, this))
{
base_ui_instance = this;
request_channel.set_receive_handler (sigc::mem_fun (*this, &BaseUI::request_handler));
@ -120,6 +121,12 @@ BaseUI::run ()
_main_loop = MainLoop::create (m_context);
attach_request_source ();
/*
* every time the main loop runs (i.e. before any actual event handling)
*/
glib_event_callback.attach (m_context);
Glib::Threads::Mutex::Lock lm (_run_lock);
run_loop_thread = Glib::Threads::Thread::create (mem_fun (*this, &BaseUI::main_thread));
_running.wait (_run_lock);
@ -175,3 +182,8 @@ BaseUI::attach_request_source ()
DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: attach request source\n", event_loop_name()));
request_channel.attach (m_context);
}
void
BaseUI::event_loop_precall ()
{
}

View File

@ -33,6 +33,7 @@
#include "pbd/libpbd_visibility.h"
#include "pbd/crossthread.h"
#include "pbd/event_loop.h"
#include "pbd/glib_event_source.h"
#include "pbd/pthread_utils.h"
/** A BaseUI is an abstraction designed to be used with any "user
@ -75,6 +76,12 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
*/
void quit ();
/* derived classes can override this in order to call code once per
main loop iteration (i.e. before any event dispatching is done
within the main loop)
*/
virtual void event_loop_precall ();
protected:
bool _ok;
@ -122,6 +129,8 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
int setup_request_pipe ();
void main_thread ();
GlibEventLoopCallback glib_event_callback;
};
#endif /* __pbd_base_ui_h__ */