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