Ardour  8.12
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 #ifndef __pbd__crossthread_h__
21 #define __pbd__crossthread_h__
22 
23 #ifdef check
24 #undef check
25 #endif
26 
27 #include <glibmm/main.h>
28 
29 #include "pbd/libpbd_visibility.h"
30 
31 #ifdef PLATFORM_WINDOWS
32 #include <windows.h>
33 #endif // PLATFORM_WINDOWS
34 
35 
46 public:
51  CrossThreadChannel(bool non_blocking);
53 
56  void wakeup();
57 
58  /* if the listening thread cares about the precise message
59  * it is being sent, then \ref deliver() can be used to send
60  * a single byte message rather than a simple wakeup. These
61  * two mechanisms should not be used on the same CrossThreadChannel
62  * because there is no way to know which byte value will be used
63  * for ::wakeup()
64  */
65  int deliver (char msg);
66 
74  int receive (char& msg, bool wait = false);
75 
83  void drain ();
84 
85  void set_receive_handler (sigc::slot<bool,Glib::IOCondition> s);
86  void attach (Glib::RefPtr<Glib::MainContext>);
87 
88 private:
89  friend gboolean cross_thread_channel_call_receive_slot (GIOChannel*, GIOCondition condition, void *data);
90 
91  GIOChannel* receive_channel;
92  GSource* receive_source;
93  sigc::slot<bool,Glib::IOCondition> receive_slot;
94 
96 
97 #ifndef PLATFORM_WINDOWS
98  int fds[2]; // current implementation uses a pipe/fifo
99 #else
100 
101  SOCKET send_socket;
102  SOCKET receive_socket;
103  struct sockaddr_in recv_address;
104 #endif
105 
106 };
107 
108 #endif /* __pbd__crossthread_h__ */
GIOChannel * receive_channel
Definition: crossthread.h:91
GSource * receive_source
Definition: crossthread.h:92
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:93
void set_receive_handler(sigc::slot< bool, Glib::IOCondition > s)
CrossThreadChannel(bool non_blocking)
#define LIBPBD_API