Making buildable under OpenBSD.
[ardour.git] / libs / midi++2 / midi++ / ipmidi_port.h
1 /*
2     Copyright (C) 1998-2010 Paul Barton-Davis
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation; either version 2 of the License, or
6     (at your option) any later version.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 */
18
19 #ifndef  __libmidi_ipmidi_port_h__
20 #define  __libmidi_ipmidi_port_h__
21
22 #include <string>
23 #include <iostream>
24 #if defined(PLATFORM_WINDOWS)
25 #include <winsock.h>
26 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
27 #include <netinet/in.h>
28 #include <sys/socket.h>
29 #if defined(__FreeBSD__)
30 #include <sys/_sockaddr_storage.h>
31 #endif
32 #include <arpa/inet.h>
33 #include <netinet/ip_carp.h>
34 #include <sys/types.h>
35 #include <sys/time.h>
36 #include <sys/socket.h>
37 #include <net/if.h>
38 #include <net/route.h>
39 #else
40 #include <arpa/inet.h>
41 #include <net/if.h>
42 #endif
43
44 #include <glibmm/threads.h>
45
46 #include "pbd/xml++.h"
47 #include "pbd/crossthread.h"
48 #include "pbd/signals.h"
49 #include "pbd/ringbuffer.h"
50
51 #include "midi++/libmidi_visibility.h"
52 #include "midi++/types.h"
53 #include "midi++/parser.h"
54 #include "midi++/port.h"
55
56 namespace MIDI {
57
58 class LIBMIDIPP_API IPMIDIPort : public Port {
59   public:
60     IPMIDIPort (int base_port = lowest_ipmidi_port_default, const std::string& ifname = std::string());
61     IPMIDIPort (const XMLNode&);
62     ~IPMIDIPort ();
63
64     XMLNode& get_state () const;
65     void set_state (const XMLNode&);
66
67     int write (const byte *msg, size_t msglen, timestamp_t timestamp);
68     int read (byte *buf, size_t bufsize);
69     void parse (framecnt_t timestamp);
70     int selectable () const;
71
72     static const int lowest_ipmidi_port_default = 21928;
73
74 private:
75     int sockin;
76     int sockout;
77     struct sockaddr_in addrout;
78     Glib::Threads::Mutex write_lock;
79
80     bool open_sockets (int base_port, const std::string& ifname);
81     void close_sockets ();
82
83     void init (std::string const &, Flags);
84 };
85
86 } // namespace MIDI
87
88 #endif // __libmidi_ipmidi_port_h__