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
|
@ -18,20 +18,41 @@
|
|||
|
||||
#include "pbd/glib_event_source.h"
|
||||
|
||||
bool
|
||||
GlibEventLoopSource::prepare (int& timeout)
|
||||
GlibEventLoopCallback::GlibEventLoopCallback (boost::function<void()> callback)
|
||||
: _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
|
||||
GlibEventLoopSource::check ()
|
||||
GlibEventLoopCallback::cpp_prepare ()
|
||||
{
|
||||
_callback();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
GlibEventLoopSource::dispatch (sigc::slot_base*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,31 +21,29 @@
|
|||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glibmm/main.h>
|
||||
#include "pbd/libpbd_visibility.h"
|
||||
|
||||
class LIBPBD_API GlibEventLoopSource : public Glib::Source
|
||||
class LIBPBD_API GlibEventLoopCallback
|
||||
{
|
||||
public:
|
||||
GlibEventLoopSource () {};
|
||||
GlibEventLoopCallback (boost::function<void()> callback);
|
||||
~GlibEventLoopCallback();
|
||||
|
||||
bool prepare (int& timeout);
|
||||
bool check();
|
||||
bool dispatch (sigc::slot_base*);
|
||||
};
|
||||
|
||||
|
||||
class LIBPBD_API GlibEventLoopCallback : public GlibEventLoopSource
|
||||
{
|
||||
public:
|
||||
GlibEventLoopCallback (boost::function<void()> callback) : _callback (callback) {}
|
||||
|
||||
bool check() {
|
||||
_callback();
|
||||
return false;
|
||||
}
|
||||
static gboolean c_prepare (GSource*, gint* timeout);
|
||||
void attach (Glib::RefPtr<Glib::MainContext>);
|
||||
|
||||
private:
|
||||
struct GSourceWithParent {
|
||||
GSource c;
|
||||
GlibEventLoopCallback* cpp;
|
||||
};
|
||||
|
||||
bool cpp_prepare();
|
||||
|
||||
GSourceWithParent* gsource;
|
||||
GSourceFuncs funcs;
|
||||
boost::function<void()> _callback;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user