Ardour  9.2-320-gbc46a93144
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 #endif
37 #endif // PLATFORM_WINDOWS
38 
39 
50 public:
55  CrossThreadChannel(bool non_blocking);
57 
60  void wakeup();
61 
62  /* if the listening thread cares about the precise message
63  * it is being sent, then \ref deliver() can be used to send
64  * a single byte message rather than a simple wakeup. These
65  * two mechanisms should not be used on the same CrossThreadChannel
66  * because there is no way to know which byte value will be used
67  * for ::wakeup()
68  */
69  int deliver (char msg);
70 
78  int receive (char& msg, bool wait = false);
79 
87  void drain ();
88 
89  void set_receive_handler (sigc::slot<bool,Glib::IOCondition> s);
90  void attach (Glib::RefPtr<Glib::MainContext>);
91 
92 private:
93  friend gboolean cross_thread_channel_call_receive_slot (GIOChannel*, GIOCondition condition, void *data);
94 
95  GIOChannel* receive_channel;
96  GSource* receive_source;
97  sigc::slot<bool,Glib::IOCondition> receive_slot;
98 
100 
101 #ifndef PLATFORM_WINDOWS
102  int fds[2]; // current implementation uses a pipe/fifo
103 #else
104 
105  SOCKET send_socket;
106  SOCKET receive_socket;
107  struct sockaddr_in recv_address;
108 #endif
109 
110 };
111 
GIOChannel * receive_channel
Definition: crossthread.h:95
GSource * receive_source
Definition: crossthread.h:96
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:97
void set_receive_handler(sigc::slot< bool, Glib::IOCondition > s)
CrossThreadChannel(bool non_blocking)
#define LIBPBD_API