2022-05-16 17:41:56 -04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-05-16 17:23:42 -04:00
|
|
|
#include "pbd/glib_event_source.h"
|
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
GlibEventLoopCallback::GlibEventLoopCallback (std::function<void()> callback)
|
2022-05-20 00:24:22 -04:00
|
|
|
: _callback (callback)
|
2022-05-16 17:23:42 -04:00
|
|
|
{
|
2022-05-20 00:24:22 -04:00
|
|
|
funcs.prepare = c_prepare;;
|
|
|
|
funcs.check = NULL;
|
|
|
|
funcs.dispatch = NULL;
|
|
|
|
funcs.finalize = NULL;
|
|
|
|
|
|
|
|
gsource = (GSourceWithParent*) g_source_new (&funcs, sizeof (GSourceWithParent));
|
|
|
|
gsource->cpp = this;
|
2022-05-16 17:23:42 -04:00
|
|
|
}
|
|
|
|
|
2022-05-20 00:24:22 -04:00
|
|
|
GlibEventLoopCallback::~GlibEventLoopCallback ()
|
2022-05-16 17:23:42 -04:00
|
|
|
{
|
2022-05-20 00:24:22 -04:00
|
|
|
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 ();
|
2022-05-16 17:23:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2022-05-20 00:24:22 -04:00
|
|
|
GlibEventLoopCallback::cpp_prepare ()
|
2022-05-16 17:23:42 -04:00
|
|
|
{
|
2022-05-20 00:24:22 -04:00
|
|
|
_callback();
|
2022-05-16 17:23:42 -04:00
|
|
|
return false;
|
|
|
|
}
|
2022-05-20 00:24:22 -04:00
|
|
|
|