andrew@0
|
1 /*
|
andrew@0
|
2
|
andrew@0
|
3 oscpack -- Open Sound Control packet manipulation library
|
andrew@0
|
4
|
andrew@0
|
5 http://www.audiomulch.com/~rossb/oscpack
|
andrew@0
|
6
|
andrew@0
|
7
|
andrew@0
|
8
|
andrew@0
|
9 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
|
andrew@0
|
10
|
andrew@0
|
11
|
andrew@0
|
12
|
andrew@0
|
13 Permission is hereby granted, free of charge, to any person obtaining
|
andrew@0
|
14
|
andrew@0
|
15 a copy of this software and associated documentation files
|
andrew@0
|
16
|
andrew@0
|
17 (the "Software"), to deal in the Software without restriction,
|
andrew@0
|
18
|
andrew@0
|
19 including without limitation the rights to use, copy, modify, merge,
|
andrew@0
|
20
|
andrew@0
|
21 publish, distribute, sublicense, and/or sell copies of the Software,
|
andrew@0
|
22
|
andrew@0
|
23 and to permit persons to whom the Software is furnished to do so,
|
andrew@0
|
24
|
andrew@0
|
25 subject to the following conditions:
|
andrew@0
|
26
|
andrew@0
|
27
|
andrew@0
|
28
|
andrew@0
|
29 The above copyright notice and this permission notice shall be
|
andrew@0
|
30
|
andrew@0
|
31 included in all copies or substantial portions of the Software.
|
andrew@0
|
32
|
andrew@0
|
33
|
andrew@0
|
34
|
andrew@0
|
35 Any person wishing to distribute modifications to the Software is
|
andrew@0
|
36
|
andrew@0
|
37 requested to send the modifications to the original developer so that
|
andrew@0
|
38
|
andrew@0
|
39 they can be incorporated into the canonical version.
|
andrew@0
|
40
|
andrew@0
|
41
|
andrew@0
|
42
|
andrew@0
|
43 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
andrew@0
|
44
|
andrew@0
|
45 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
andrew@0
|
46
|
andrew@0
|
47 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
andrew@0
|
48
|
andrew@0
|
49 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
andrew@0
|
50
|
andrew@0
|
51 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
andrew@0
|
52
|
andrew@0
|
53 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
andrew@0
|
54
|
andrew@0
|
55 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
andrew@0
|
56
|
andrew@0
|
57 */
|
andrew@0
|
58
|
andrew@0
|
59 #ifndef INCLUDED_OSCOUTBOUNDPACKET_H
|
andrew@0
|
60
|
andrew@0
|
61 #define INCLUDED_OSCOUTBOUNDPACKET_H
|
andrew@0
|
62
|
andrew@0
|
63
|
andrew@0
|
64
|
andrew@0
|
65 #include "OscTypes.h"
|
andrew@0
|
66
|
andrew@0
|
67 #include "OscException.h"
|
andrew@0
|
68
|
andrew@0
|
69
|
andrew@0
|
70
|
andrew@0
|
71
|
andrew@0
|
72
|
andrew@0
|
73 namespace osc{
|
andrew@0
|
74
|
andrew@0
|
75
|
andrew@0
|
76
|
andrew@0
|
77 class OutOfBufferMemoryException : public Exception{
|
andrew@0
|
78
|
andrew@0
|
79 public:
|
andrew@0
|
80
|
andrew@0
|
81 OutOfBufferMemoryException( const char *w="out of buffer memory" )
|
andrew@0
|
82
|
andrew@0
|
83 : Exception( w ) {}
|
andrew@0
|
84
|
andrew@0
|
85 };
|
andrew@0
|
86
|
andrew@0
|
87
|
andrew@0
|
88
|
andrew@0
|
89 class BundleNotInProgressException : public Exception{
|
andrew@0
|
90
|
andrew@0
|
91 public:
|
andrew@0
|
92
|
andrew@0
|
93 BundleNotInProgressException(
|
andrew@0
|
94
|
andrew@0
|
95 const char *w="call to EndBundle when bundle is not in progress" )
|
andrew@0
|
96
|
andrew@0
|
97 : Exception( w ) {}
|
andrew@0
|
98
|
andrew@0
|
99 };
|
andrew@0
|
100
|
andrew@0
|
101
|
andrew@0
|
102
|
andrew@0
|
103 class MessageInProgressException : public Exception{
|
andrew@0
|
104
|
andrew@0
|
105 public:
|
andrew@0
|
106
|
andrew@0
|
107 MessageInProgressException(
|
andrew@0
|
108
|
andrew@0
|
109 const char *w="opening or closing bundle or message while message is in progress" )
|
andrew@0
|
110
|
andrew@0
|
111 : Exception( w ) {}
|
andrew@0
|
112
|
andrew@0
|
113 };
|
andrew@0
|
114
|
andrew@0
|
115
|
andrew@0
|
116
|
andrew@0
|
117 class MessageNotInProgressException : public Exception{
|
andrew@0
|
118
|
andrew@0
|
119 public:
|
andrew@0
|
120
|
andrew@0
|
121 MessageNotInProgressException(
|
andrew@0
|
122
|
andrew@0
|
123 const char *w="call to EndMessage when message is not in progress" )
|
andrew@0
|
124
|
andrew@0
|
125 : Exception( w ) {}
|
andrew@0
|
126
|
andrew@0
|
127 };
|
andrew@0
|
128
|
andrew@0
|
129
|
andrew@0
|
130
|
andrew@0
|
131
|
andrew@0
|
132
|
andrew@0
|
133 class OutboundPacketStream{
|
andrew@0
|
134
|
andrew@0
|
135 public:
|
andrew@0
|
136
|
andrew@0
|
137 OutboundPacketStream( char *buffer, unsigned long capacity );
|
andrew@0
|
138
|
andrew@0
|
139 ~OutboundPacketStream();
|
andrew@0
|
140
|
andrew@0
|
141
|
andrew@0
|
142
|
andrew@0
|
143 void Clear();
|
andrew@0
|
144
|
andrew@0
|
145
|
andrew@0
|
146
|
andrew@0
|
147 unsigned int Capacity() const;
|
andrew@0
|
148
|
andrew@0
|
149
|
andrew@0
|
150
|
andrew@0
|
151 // invariant: size() is valid even while building a message.
|
andrew@0
|
152
|
andrew@0
|
153 unsigned int Size() const;
|
andrew@0
|
154
|
andrew@0
|
155
|
andrew@0
|
156
|
andrew@0
|
157 const char *Data() const;
|
andrew@0
|
158
|
andrew@0
|
159
|
andrew@0
|
160
|
andrew@0
|
161 // indicates that all messages have been closed with a matching EndMessage
|
andrew@0
|
162
|
andrew@0
|
163 // and all bundles have been closed with a matching EndBundle
|
andrew@0
|
164
|
andrew@0
|
165 bool IsReady() const;
|
andrew@0
|
166
|
andrew@0
|
167
|
andrew@0
|
168
|
andrew@0
|
169 bool IsMessageInProgress() const;
|
andrew@0
|
170
|
andrew@0
|
171 bool IsBundleInProgress() const;
|
andrew@0
|
172
|
andrew@0
|
173
|
andrew@0
|
174
|
andrew@0
|
175 OutboundPacketStream& operator<<( const BundleInitiator& rhs );
|
andrew@0
|
176
|
andrew@0
|
177 OutboundPacketStream& operator<<( const BundleTerminator& rhs );
|
andrew@0
|
178
|
andrew@0
|
179
|
andrew@0
|
180
|
andrew@0
|
181 OutboundPacketStream& operator<<( const BeginMessage& rhs );
|
andrew@0
|
182
|
andrew@0
|
183 OutboundPacketStream& operator<<( const MessageTerminator& rhs );
|
andrew@0
|
184
|
andrew@0
|
185
|
andrew@0
|
186
|
andrew@0
|
187 OutboundPacketStream& operator<<( bool rhs );
|
andrew@0
|
188
|
andrew@0
|
189 OutboundPacketStream& operator<<( const NilType& rhs );
|
andrew@0
|
190
|
andrew@0
|
191 OutboundPacketStream& operator<<( const InfinitumType& rhs );
|
andrew@0
|
192
|
andrew@0
|
193 OutboundPacketStream& operator<<( int32 rhs );
|
andrew@0
|
194
|
andrew@0
|
195
|
andrew@0
|
196
|
andrew@0
|
197 #ifndef __x86_64__
|
andrew@0
|
198
|
andrew@0
|
199 OutboundPacketStream& operator<<( int rhs )
|
andrew@0
|
200
|
andrew@0
|
201 { *this << (int32)rhs; return *this; }
|
andrew@0
|
202
|
andrew@0
|
203 #endif
|
andrew@0
|
204
|
andrew@0
|
205
|
andrew@0
|
206
|
andrew@0
|
207 OutboundPacketStream& operator<<( float rhs );
|
andrew@0
|
208
|
andrew@0
|
209 OutboundPacketStream& operator<<( char rhs );
|
andrew@0
|
210
|
andrew@0
|
211 OutboundPacketStream& operator<<( const RgbaColor& rhs );
|
andrew@0
|
212
|
andrew@0
|
213 OutboundPacketStream& operator<<( const MidiMessage& rhs );
|
andrew@0
|
214
|
andrew@0
|
215 OutboundPacketStream& operator<<( int64 rhs );
|
andrew@0
|
216
|
andrew@0
|
217 OutboundPacketStream& operator<<( const TimeTag& rhs );
|
andrew@0
|
218
|
andrew@0
|
219 OutboundPacketStream& operator<<( double rhs );
|
andrew@0
|
220
|
andrew@0
|
221 OutboundPacketStream& operator<<( const char* rhs );
|
andrew@0
|
222
|
andrew@0
|
223 OutboundPacketStream& operator<<( const Symbol& rhs );
|
andrew@0
|
224
|
andrew@0
|
225 OutboundPacketStream& operator<<( const Blob& rhs );
|
andrew@0
|
226
|
andrew@0
|
227
|
andrew@0
|
228
|
andrew@0
|
229 private:
|
andrew@0
|
230
|
andrew@0
|
231
|
andrew@0
|
232
|
andrew@0
|
233 char *BeginElement( char *beginPtr );
|
andrew@0
|
234
|
andrew@0
|
235 void EndElement( char *endPtr );
|
andrew@0
|
236
|
andrew@0
|
237
|
andrew@0
|
238
|
andrew@0
|
239 bool ElementSizeSlotRequired() const;
|
andrew@0
|
240
|
andrew@0
|
241 void CheckForAvailableBundleSpace();
|
andrew@0
|
242
|
andrew@0
|
243 void CheckForAvailableMessageSpace( const char *addressPattern );
|
andrew@0
|
244
|
andrew@0
|
245 void CheckForAvailableArgumentSpace( long argumentLength );
|
andrew@0
|
246
|
andrew@0
|
247
|
andrew@0
|
248
|
andrew@0
|
249 char *data_;
|
andrew@0
|
250
|
andrew@0
|
251 char *end_;
|
andrew@0
|
252
|
andrew@0
|
253
|
andrew@0
|
254
|
andrew@0
|
255 char *typeTagsCurrent_; // stored in reverse order
|
andrew@0
|
256
|
andrew@0
|
257 char *messageCursor_;
|
andrew@0
|
258
|
andrew@0
|
259 char *argumentCurrent_;
|
andrew@0
|
260
|
andrew@0
|
261
|
andrew@0
|
262
|
andrew@0
|
263 // elementSizePtr_ has two special values: 0 indicates that a bundle
|
andrew@0
|
264
|
andrew@0
|
265 // isn't open, and elementSizePtr_==data_ indicates that a bundle is
|
andrew@0
|
266
|
andrew@0
|
267 // open but that it doesn't have a size slot (ie the outermost bundle)
|
andrew@0
|
268
|
andrew@0
|
269 uint32 *elementSizePtr_;
|
andrew@0
|
270
|
andrew@0
|
271
|
andrew@0
|
272
|
andrew@0
|
273 bool messageIsInProgress_;
|
andrew@0
|
274
|
andrew@0
|
275 };
|
andrew@0
|
276
|
andrew@0
|
277
|
andrew@0
|
278
|
andrew@0
|
279 } // namespace osc
|
andrew@0
|
280
|
andrew@0
|
281
|
andrew@0
|
282
|
andrew@0
|
283 #endif /* INCLUDED_OSC_OUTBOUND_PACKET_H */
|
andrew@0
|
284
|