Ardour  9.0-pre0-582-g084a23a80d
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 #include <windows.h>
32 #endif // PLATFORM_WINDOWS
33 
34 
45 public:
50  CrossThreadChannel(bool non_blocking);
52 
55  void wakeup();
56 
57  /* if the listening thread cares about the precise message
58  * it is being sent, then \ref deliver() can be used to send
59  * a single byte message rather than a simple wakeup. These
60  * two mechanisms should not be used on the same CrossThreadChannel
61  * because there is no way to know which byte value will be used
62  * for ::wakeup()
63  */
64  int deliver (char msg);
65 
73  int receive (char& msg, bool wait = false);
74 
82  void drain ();
83 
84  void set_receive_handler (sigc::slot<bool,Glib::IOCondition> s);
85  void attach (Glib::RefPtr<Glib::MainContext>);
86 
87 private:
88  friend gboolean cross_thread_channel_call_receive_slot (GIOChannel*, GIOCondition condition, void *data);
89 
90  GIOChannel* receive_channel;
91  GSource* receive_source;
92  sigc::slot<bool,Glib::IOCondition> receive_slot;
93 
95 
96 #ifndef PLATFORM_WINDOWS
97  int fds[2]; // current implementation uses a pipe/fifo
98 #else
99 
100  SOCKET send_socket;
101  SOCKET receive_socket;
102  struct sockaddr_in recv_address;
103 #endif
104 
105 };
106 
GIOChannel * receive_channel
Definition: crossthread.h:90
GSource * receive_source
Definition: crossthread.h:91
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:92
void set_receive_handler(sigc::slot< bool, Glib::IOCondition > s)
CrossThreadChannel(bool non_blocking)
#define LIBPBD_API