mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 07:45:00 +01:00
libpbd: change GlibEventLoopCallback to use C API not C++
We discovered in the past that the C++ API for GSource/Glib::Source has some fatal and unfixable flaws. Copy similar code and just use the C API for GSource instead
This commit is contained in:
parent
04aaf23851
commit
e1f5fb0206
2 changed files with 45 additions and 26 deletions
|
|
@ -18,20 +18,41 @@
|
||||||
|
|
||||||
#include "pbd/glib_event_source.h"
|
#include "pbd/glib_event_source.h"
|
||||||
|
|
||||||
bool
|
GlibEventLoopCallback::GlibEventLoopCallback (boost::function<void()> callback)
|
||||||
GlibEventLoopSource::prepare (int& timeout)
|
: _callback (callback)
|
||||||
{
|
{
|
||||||
return false;
|
funcs.prepare = c_prepare;;
|
||||||
|
funcs.check = NULL;
|
||||||
|
funcs.dispatch = NULL;
|
||||||
|
funcs.finalize = NULL;
|
||||||
|
|
||||||
|
gsource = (GSourceWithParent*) g_source_new (&funcs, sizeof (GSourceWithParent));
|
||||||
|
gsource->cpp = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlibEventLoopCallback::~GlibEventLoopCallback ()
|
||||||
|
{
|
||||||
|
g_source_destroy ((GSource*) gsource);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GlibEventLoopCallback::attach (Glib::RefPtr<Glib::MainContext> ctxt)
|
||||||
|
{
|
||||||
|
g_source_attach ((GSource*) gsource, ctxt->gobj());
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
GlibEventLoopCallback::c_prepare (GSource* gsrc, int* timeout)
|
||||||
|
{
|
||||||
|
GSourceWithParent* gwp = reinterpret_cast<GSourceWithParent*> (gsrc);
|
||||||
|
GlibEventLoopCallback* cpp = gwp->cpp;
|
||||||
|
return cpp->cpp_prepare ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlibEventLoopSource::check ()
|
GlibEventLoopCallback::cpp_prepare ()
|
||||||
{
|
{
|
||||||
|
_callback();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
GlibEventLoopSource::dispatch (sigc::slot_base*)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -21,31 +21,29 @@
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <glibmm/main.h>
|
#include <glibmm/main.h>
|
||||||
#include "pbd/libpbd_visibility.h"
|
#include "pbd/libpbd_visibility.h"
|
||||||
|
|
||||||
class LIBPBD_API GlibEventLoopSource : public Glib::Source
|
class LIBPBD_API GlibEventLoopCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlibEventLoopSource () {};
|
GlibEventLoopCallback (boost::function<void()> callback);
|
||||||
|
~GlibEventLoopCallback();
|
||||||
|
|
||||||
bool prepare (int& timeout);
|
static gboolean c_prepare (GSource*, gint* timeout);
|
||||||
bool check();
|
void attach (Glib::RefPtr<Glib::MainContext>);
|
||||||
bool dispatch (sigc::slot_base*);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LIBPBD_API GlibEventLoopCallback : public GlibEventLoopSource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GlibEventLoopCallback (boost::function<void()> callback) : _callback (callback) {}
|
|
||||||
|
|
||||||
bool check() {
|
|
||||||
_callback();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct GSourceWithParent {
|
||||||
|
GSource c;
|
||||||
|
GlibEventLoopCallback* cpp;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool cpp_prepare();
|
||||||
|
|
||||||
|
GSourceWithParent* gsource;
|
||||||
|
GSourceFuncs funcs;
|
||||||
boost::function<void()> _callback;
|
boost::function<void()> _callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue