Ardour  9.10-25-gb111bf379e
crossthread.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #ifdef check
23 #undef check
24 #endif
25 
26 #include <glibmm/main.h>
27 
28 #include "pbd/libpbd_visibility.h"
29 
30 #ifdef PLATFORM_WINDOWS
31 
32 #if defined(COMPILER_MSVC) && defined (WAF_BUILD)
33 #include <winsock2.h>
34 #else
35 #include <windows.h>
36 #include <winsock2.h>
37 #endif
38 #endif // PLATFORM_WINDOWS
39 
40 
51 public:
56  CrossThreadChannel(bool non_blocking);
58 
61  void wakeup();
62 
63  /* if the listening thread cares about the precise message
64  * it is being sent, then \ref deliver() can be used to send
65  * a single byte message rather than a simple wakeup. These
66  * two mechanisms should not be used on the same CrossThreadChannel
67  * because there is no way to know which byte value will be used
68  * for ::wakeup()
69  */
70  int deliver (char msg);
71 
79  int receive (char& msg, bool wait = false);
80 
88  void drain ();
89 
90  void set_receive_handler (sigc::slot<bool,Glib::IOCondition> s);
91  void attach (Glib::RefPtr<Glib::MainContext>);
92 
93 private:
94  friend gboolean cross_thread_channel_call_receive_slot (GIOChannel*, GIOCondition condition, void *data);
95 
96  GIOChannel* receive_channel;
97  GSource* receive_source;
98  sigc::slot<bool,Glib::IOCondition> receive_slot;
99 
101 
102 #ifndef PLATFORM_WINDOWS
103  int fds[2]; // current implementation uses a pipe/fifo
104 #else
105 
106  SOCKET send_socket;
107  SOCKET receive_socket;
108  struct sockaddr_in recv_address;
109 #endif
110 
111 };
112 
GIOChannel * receive_channel
Definition: crossthread.h:96
GSource * receive_source
Definition: crossthread.h:97
friend gboolean cross_thread_channel_call_receive_slot(GIOChannel *, GIOCondition condition, void *data)
int receive(char &msg, bool wait=false)
void attach(Glib::RefPtr< Glib::MainContext >)
int deliver(char msg)
sigc::slot< bool, Glib::IOCondition > receive_slot
Definition: crossthread.h:98
void set_receive_handler(sigc::slot< bool, Glib::IOCondition > s)
CrossThreadChannel(bool non_blocking)
#define LIBPBD_API