root / tbeta / Windows / addons / ofxOsc / libs / oscpack / include / osc / OscOutboundPacketStream.h @ 2

View | Annotate | Download (4.9 KB)

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