tomwalters@570
|
1 /*
|
tomwalters@570
|
2 oscpack -- Open Sound Control packet manipulation library
|
tomwalters@570
|
3 http://www.audiomulch.com/~rossb/oscpack
|
tomwalters@570
|
4
|
tomwalters@570
|
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
|
tomwalters@570
|
6
|
tomwalters@570
|
7 Permission is hereby granted, free of charge, to any person obtaining
|
tomwalters@570
|
8 a copy of this software and associated documentation files
|
tomwalters@570
|
9 (the "Software"), to deal in the Software without restriction,
|
tomwalters@570
|
10 including without limitation the rights to use, copy, modify, merge,
|
tomwalters@570
|
11 publish, distribute, sublicense, and/or sell copies of the Software,
|
tomwalters@570
|
12 and to permit persons to whom the Software is furnished to do so,
|
tomwalters@570
|
13 subject to the following conditions:
|
tomwalters@570
|
14
|
tomwalters@570
|
15 The above copyright notice and this permission notice shall be
|
tomwalters@570
|
16 included in all copies or substantial portions of the Software.
|
tomwalters@570
|
17
|
tomwalters@570
|
18 Any person wishing to distribute modifications to the Software is
|
tomwalters@570
|
19 requested to send the modifications to the original developer so that
|
tomwalters@570
|
20 they can be incorporated into the canonical version.
|
tomwalters@570
|
21
|
tomwalters@570
|
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
tomwalters@570
|
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
tomwalters@570
|
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
tomwalters@570
|
25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
tomwalters@570
|
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
tomwalters@570
|
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
tomwalters@570
|
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
tomwalters@570
|
29 */
|
tomwalters@570
|
30 #ifndef INCLUDED_OSCOUTBOUNDPACKET_H
|
tomwalters@570
|
31 #define INCLUDED_OSCOUTBOUNDPACKET_H
|
tomwalters@570
|
32
|
tomwalters@570
|
33 #include "OscTypes.h"
|
tomwalters@570
|
34 #include "OscException.h"
|
tomwalters@570
|
35
|
tomwalters@570
|
36
|
tomwalters@570
|
37 namespace osc{
|
tomwalters@570
|
38
|
tomwalters@570
|
39 class OutOfBufferMemoryException : public Exception{
|
tomwalters@570
|
40 public:
|
tomwalters@570
|
41 OutOfBufferMemoryException( const char *w="out of buffer memory" )
|
tomwalters@570
|
42 : Exception( w ) {}
|
tomwalters@570
|
43 };
|
tomwalters@570
|
44
|
tomwalters@570
|
45 class BundleNotInProgressException : public Exception{
|
tomwalters@570
|
46 public:
|
tomwalters@570
|
47 BundleNotInProgressException(
|
tomwalters@570
|
48 const char *w="call to EndBundle when bundle is not in progress" )
|
tomwalters@570
|
49 : Exception( w ) {}
|
tomwalters@570
|
50 };
|
tomwalters@570
|
51
|
tomwalters@570
|
52 class MessageInProgressException : public Exception{
|
tomwalters@570
|
53 public:
|
tomwalters@570
|
54 MessageInProgressException(
|
tomwalters@570
|
55 const char *w="opening or closing bundle or message while message is in progress" )
|
tomwalters@570
|
56 : Exception( w ) {}
|
tomwalters@570
|
57 };
|
tomwalters@570
|
58
|
tomwalters@570
|
59 class MessageNotInProgressException : public Exception{
|
tomwalters@570
|
60 public:
|
tomwalters@570
|
61 MessageNotInProgressException(
|
tomwalters@570
|
62 const char *w="call to EndMessage when message is not in progress" )
|
tomwalters@570
|
63 : Exception( w ) {}
|
tomwalters@570
|
64 };
|
tomwalters@570
|
65
|
tomwalters@570
|
66
|
tomwalters@570
|
67 class OutboundPacketStream{
|
tomwalters@570
|
68 public:
|
tomwalters@570
|
69 OutboundPacketStream( char *buffer, unsigned long capacity );
|
tomwalters@570
|
70 ~OutboundPacketStream();
|
tomwalters@570
|
71
|
tomwalters@570
|
72 void Clear();
|
tomwalters@570
|
73
|
tomwalters@570
|
74 unsigned int Capacity() const;
|
tomwalters@570
|
75
|
tomwalters@570
|
76 // invariant: size() is valid even while building a message.
|
tomwalters@570
|
77 unsigned int Size() const;
|
tomwalters@570
|
78
|
tomwalters@570
|
79 const char *Data() const;
|
tomwalters@570
|
80
|
tomwalters@570
|
81 // indicates that all messages have been closed with a matching EndMessage
|
tomwalters@570
|
82 // and all bundles have been closed with a matching EndBundle
|
tomwalters@570
|
83 bool IsReady() const;
|
tomwalters@570
|
84
|
tomwalters@570
|
85 bool IsMessageInProgress() const;
|
tomwalters@570
|
86 bool IsBundleInProgress() const;
|
tomwalters@570
|
87
|
tomwalters@570
|
88 OutboundPacketStream& operator<<( const BundleInitiator& rhs );
|
tomwalters@570
|
89 OutboundPacketStream& operator<<( const BundleTerminator& rhs );
|
tomwalters@570
|
90
|
tomwalters@570
|
91 OutboundPacketStream& operator<<( const BeginMessage& rhs );
|
tomwalters@570
|
92 OutboundPacketStream& operator<<( const MessageTerminator& rhs );
|
tomwalters@570
|
93
|
tomwalters@570
|
94 OutboundPacketStream& operator<<( bool rhs );
|
tomwalters@570
|
95 OutboundPacketStream& operator<<( const NilType& rhs );
|
tomwalters@570
|
96 OutboundPacketStream& operator<<( const InfinitumType& rhs );
|
tomwalters@570
|
97 OutboundPacketStream& operator<<( int32 rhs );
|
tomwalters@570
|
98
|
tomwalters@570
|
99 #ifndef x86_64
|
tomwalters@570
|
100 OutboundPacketStream& operator<<( int rhs )
|
tomwalters@570
|
101 { *this << (int32)rhs; return *this; }
|
tomwalters@570
|
102 #endif
|
tomwalters@570
|
103
|
tomwalters@570
|
104 OutboundPacketStream& operator<<( float rhs );
|
tomwalters@570
|
105 OutboundPacketStream& operator<<( char rhs );
|
tomwalters@570
|
106 OutboundPacketStream& operator<<( const RgbaColor& rhs );
|
tomwalters@570
|
107 OutboundPacketStream& operator<<( const MidiMessage& rhs );
|
tomwalters@570
|
108 OutboundPacketStream& operator<<( int64 rhs );
|
tomwalters@570
|
109 OutboundPacketStream& operator<<( const TimeTag& rhs );
|
tomwalters@570
|
110 OutboundPacketStream& operator<<( double rhs );
|
tomwalters@570
|
111 OutboundPacketStream& operator<<( const char* rhs );
|
tomwalters@570
|
112 OutboundPacketStream& operator<<( const Symbol& rhs );
|
tomwalters@570
|
113 OutboundPacketStream& operator<<( const Blob& rhs );
|
tomwalters@570
|
114
|
tomwalters@570
|
115 private:
|
tomwalters@570
|
116
|
tomwalters@570
|
117 char *BeginElement( char *beginPtr );
|
tomwalters@570
|
118 void EndElement( char *endPtr );
|
tomwalters@570
|
119
|
tomwalters@570
|
120 bool ElementSizeSlotRequired() const;
|
tomwalters@570
|
121 void CheckForAvailableBundleSpace();
|
tomwalters@570
|
122 void CheckForAvailableMessageSpace( const char *addressPattern );
|
tomwalters@570
|
123 void CheckForAvailableArgumentSpace( long argumentLength );
|
tomwalters@570
|
124
|
tomwalters@570
|
125 char *data_;
|
tomwalters@570
|
126 char *end_;
|
tomwalters@570
|
127
|
tomwalters@570
|
128 char *typeTagsCurrent_; // stored in reverse order
|
tomwalters@570
|
129 char *messageCursor_;
|
tomwalters@570
|
130 char *argumentCurrent_;
|
tomwalters@570
|
131
|
tomwalters@570
|
132 // elementSizePtr_ has two special values: 0 indicates that a bundle
|
tomwalters@570
|
133 // isn't open, and elementSizePtr_==data_ indicates that a bundle is
|
tomwalters@570
|
134 // open but that it doesn't have a size slot (ie the outermost bundle)
|
tomwalters@570
|
135 uint32 *elementSizePtr_;
|
tomwalters@570
|
136
|
tomwalters@570
|
137 bool messageIsInProgress_;
|
tomwalters@570
|
138 };
|
tomwalters@570
|
139
|
tomwalters@570
|
140 } // namespace osc
|
tomwalters@570
|
141
|
tomwalters@570
|
142 #endif /* INCLUDED_OSC_OUTBOUND_PACKET_H */
|