use a local version (copy) of the G_SOURCE_FUNC macro, since it is not available...
[ardour.git] / libs / pbd / crossthread.cc
1 /*
2  * Copyright (C) 2009-2015 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19
20 #include <cstdlib>
21 #include <cerrno>
22 #include <cstring>
23 #include <fcntl.h>
24 #include <unistd.h>
25
26 #ifdef PLATFORM_WINDOWS
27 #include <winsock2.h>
28 #include <ws2tcpip.h>
29 #endif
30
31 #include "pbd/error.h"
32 #include "pbd/crossthread.h"
33
34 using namespace std;
35 using namespace PBD;
36 using namespace Glib;
37
38 #ifndef PLATFORM_WINDOWS
39 #include "crossthread.posix.cc"
40 #else
41 #include "crossthread.win.cc"
42 #endif
43
44 #ifndef G_SOURCE_FUNC
45 #define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f))
46 #endif
47
48 gboolean
49 cross_thread_channel_call_receive_slot (GIOChannel*, GIOCondition condition, void *data)
50 {
51         CrossThreadChannel* ctc = static_cast<CrossThreadChannel*>(data);
52         return ctc->receive_slot (Glib::IOCondition (condition));
53 }
54
55 void
56 CrossThreadChannel::set_receive_handler (sigc::slot<bool,Glib::IOCondition> s)
57 {
58         receive_slot = s;
59 }
60
61 void
62 CrossThreadChannel::attach (Glib::RefPtr<Glib::MainContext> context)
63 {
64         receive_source = g_io_create_watch (receive_channel, GIOCondition(G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL));
65
66         g_source_set_callback (receive_source, G_SOURCE_FUNC(cross_thread_channel_call_receive_slot), this, NULL);
67         g_source_attach (receive_source, context->gobj());
68 }