13
0
livetrax/libs/pbd/glib_event_source.cc
Paul Davis e1f5fb0206 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
2022-05-19 22:24:43 -06:00

59 lines
1.6 KiB
C++

/*
* Copyright (C) 2022 Paul Davis <paul@linuxaudiosystems.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "pbd/glib_event_source.h"
GlibEventLoopCallback::GlibEventLoopCallback (boost::function<void()> callback)
: _callback (callback)
{
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
GlibEventLoopCallback::cpp_prepare ()
{
_callback();
return false;
}