2 Copyright (c) Grame 2009
4 This library is free software; you can redistribute it and modify it under
5 the terms of the GNU Library General Public License as published by the
6 Free Software Foundation version 2 of the License, or any later version.
8 This library is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
13 You should have received a copy of the GNU Library General Public License
14 along with this library; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
28 #include "osc/OscOutboundPacketStream.h"
29 #include "ip/UdpSocket.h"
34 //--------------------------------------------------------------------------
35 typedef struct OSCStart
{
38 OSCStart(const char* a
) : fAddress(a
) {}
41 typedef struct OSCErr
: public OSCStart
{
42 OSCErr() : OSCStart("error:") {}
45 typedef struct OSCWarn
: public OSCStart
{
46 OSCWarn() : OSCStart("warning:") {}
49 typedef struct OSCEnd
{} OSCEnd
;
51 #define kLocalhost 0x7f000001
53 //--------------------------------------------------------------------------
55 \brief OSC output streams
59 enum { kOutBufferSize
= 16384 };
60 enum state
{ kIdle
, kInProgress
};
63 int fPort
; // the destination UDP port
64 unsigned long fAddress
; // the destination IP address
65 char fBuffer
[kOutBufferSize
];
67 osc::OutboundPacketStream fOutStream
;
77 OSCStream(UdpSocket
* socket
)
78 : fState(kIdle
), fPort(1024), fAddress(kLocalhost
), fOutStream(fBuffer
, kOutBufferSize
), fSocket(socket
) {}
79 virtual ~OSCStream() {}
81 osc::OutboundPacketStream
& stream() { return fOutStream
; }
82 int getPort () const { return fPort
; }
83 unsigned long getAddress () const { return fAddress
; }
84 UdpSocket
* socket() { return fSocket
; }
85 int state() const { return fState
; }
87 OSCStream
& start(const char * address
);
90 void setPort (int port
) { fPort
= port
; }
91 void setAddress (unsigned long address
) { fAddress
= address
; }
92 void setAddress (const std::string
& address
);
95 OSCStream
& operator <<(OSCStream
& s
, OSCEnd val
);
96 OSCStream
& operator <<(OSCStream
& s
, const OSCStart
& val
);
97 OSCStream
& operator <<(OSCStream
& s
, const OSCErr
& val
);
98 OSCStream
& operator <<(OSCStream
& s
, const OSCWarn
& val
);
99 OSCStream
& operator <<(OSCStream
& s
, const std::string
& val
);
100 template <typename T
> OSCStream
& operator <<(OSCStream
& s
, T val
) { s
.stream() << val
; return s
; }
101 template <typename T
> OSCStream
& operator <<(OSCStream
& s
, const std::vector
<T
>& val
)
103 for (unsigned int i
=0; i
< val
.size(); i
++) s
<< val
[i
];
108 extern OSCStream
* _oscout
; // OSC standard output stream
109 extern OSCStream
* _oscerr
; // OSC standard input stream
111 #define oscout (*_oscout)
112 #define oscerr (*_oscerr)