tomwalters@509: /* tomwalters@509: oscpack -- Open Sound Control packet manipulation library tomwalters@509: http://www.audiomulch.com/~rossb/oscpack tomwalters@509: tomwalters@509: Copyright (c) 2004-2005 Ross Bencina tomwalters@509: tomwalters@509: Permission is hereby granted, free of charge, to any person obtaining tomwalters@509: a copy of this software and associated documentation files tomwalters@509: (the "Software"), to deal in the Software without restriction, tomwalters@509: including without limitation the rights to use, copy, modify, merge, tomwalters@509: publish, distribute, sublicense, and/or sell copies of the Software, tomwalters@509: and to permit persons to whom the Software is furnished to do so, tomwalters@509: subject to the following conditions: tomwalters@509: tomwalters@509: The above copyright notice and this permission notice shall be tomwalters@509: included in all copies or substantial portions of the Software. tomwalters@509: tomwalters@509: Any person wishing to distribute modifications to the Software is tomwalters@509: requested to send the modifications to the original developer so that tomwalters@509: they can be incorporated into the canonical version. tomwalters@509: tomwalters@509: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, tomwalters@509: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF tomwalters@509: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. tomwalters@509: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR tomwalters@509: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF tomwalters@509: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION tomwalters@509: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tomwalters@509: */ tomwalters@509: #ifndef INCLUDED_OSCOUTBOUNDPACKET_H tomwalters@509: #define INCLUDED_OSCOUTBOUNDPACKET_H tomwalters@509: tomwalters@509: #include "OscTypes.h" tomwalters@509: #include "OscException.h" tomwalters@509: tomwalters@509: tomwalters@509: namespace osc{ tomwalters@509: tomwalters@509: class OutOfBufferMemoryException : public Exception{ tomwalters@509: public: tomwalters@509: OutOfBufferMemoryException( const char *w="out of buffer memory" ) tomwalters@509: : Exception( w ) {} tomwalters@509: }; tomwalters@509: tomwalters@509: class BundleNotInProgressException : public Exception{ tomwalters@509: public: tomwalters@509: BundleNotInProgressException( tomwalters@509: const char *w="call to EndBundle when bundle is not in progress" ) tomwalters@509: : Exception( w ) {} tomwalters@509: }; tomwalters@509: tomwalters@509: class MessageInProgressException : public Exception{ tomwalters@509: public: tomwalters@509: MessageInProgressException( tomwalters@509: const char *w="opening or closing bundle or message while message is in progress" ) tomwalters@509: : Exception( w ) {} tomwalters@509: }; tomwalters@509: tomwalters@509: class MessageNotInProgressException : public Exception{ tomwalters@509: public: tomwalters@509: MessageNotInProgressException( tomwalters@509: const char *w="call to EndMessage when message is not in progress" ) tomwalters@509: : Exception( w ) {} tomwalters@509: }; tomwalters@509: tomwalters@509: tomwalters@509: class OutboundPacketStream{ tomwalters@509: public: tomwalters@509: OutboundPacketStream( char *buffer, unsigned long capacity ); tomwalters@509: ~OutboundPacketStream(); tomwalters@509: tomwalters@509: void Clear(); tomwalters@509: tomwalters@509: unsigned int Capacity() const; tomwalters@509: tomwalters@509: // invariant: size() is valid even while building a message. tomwalters@509: unsigned int Size() const; tomwalters@509: tomwalters@509: const char *Data() const; tomwalters@509: tomwalters@509: // indicates that all messages have been closed with a matching EndMessage tomwalters@509: // and all bundles have been closed with a matching EndBundle tomwalters@509: bool IsReady() const; tomwalters@509: tomwalters@509: bool IsMessageInProgress() const; tomwalters@509: bool IsBundleInProgress() const; tomwalters@509: tomwalters@509: OutboundPacketStream& operator<<( const BundleInitiator& rhs ); tomwalters@509: OutboundPacketStream& operator<<( const BundleTerminator& rhs ); tomwalters@509: tomwalters@509: OutboundPacketStream& operator<<( const BeginMessage& rhs ); tomwalters@509: OutboundPacketStream& operator<<( const MessageTerminator& rhs ); tomwalters@509: tomwalters@509: OutboundPacketStream& operator<<( bool rhs ); tomwalters@509: OutboundPacketStream& operator<<( const NilType& rhs ); tomwalters@509: OutboundPacketStream& operator<<( const InfinitumType& rhs ); tomwalters@509: OutboundPacketStream& operator<<( int32 rhs ); tomwalters@509: tomwalters@509: #ifndef x86_64 tomwalters@509: OutboundPacketStream& operator<<( int rhs ) tomwalters@509: { *this << (int32)rhs; return *this; } tomwalters@509: #endif tomwalters@509: tomwalters@509: OutboundPacketStream& operator<<( float rhs ); tomwalters@509: OutboundPacketStream& operator<<( char rhs ); tomwalters@509: OutboundPacketStream& operator<<( const RgbaColor& rhs ); tomwalters@509: OutboundPacketStream& operator<<( const MidiMessage& rhs ); tomwalters@509: OutboundPacketStream& operator<<( int64 rhs ); tomwalters@509: OutboundPacketStream& operator<<( const TimeTag& rhs ); tomwalters@509: OutboundPacketStream& operator<<( double rhs ); tomwalters@509: OutboundPacketStream& operator<<( const char* rhs ); tomwalters@509: OutboundPacketStream& operator<<( const Symbol& rhs ); tomwalters@509: OutboundPacketStream& operator<<( const Blob& rhs ); tomwalters@509: tomwalters@509: private: tomwalters@509: tomwalters@509: char *BeginElement( char *beginPtr ); tomwalters@509: void EndElement( char *endPtr ); tomwalters@509: tomwalters@509: bool ElementSizeSlotRequired() const; tomwalters@509: void CheckForAvailableBundleSpace(); tomwalters@509: void CheckForAvailableMessageSpace( const char *addressPattern ); tomwalters@509: void CheckForAvailableArgumentSpace( long argumentLength ); tomwalters@509: tomwalters@509: char *data_; tomwalters@509: char *end_; tomwalters@509: tomwalters@509: char *typeTagsCurrent_; // stored in reverse order tomwalters@509: char *messageCursor_; tomwalters@509: char *argumentCurrent_; tomwalters@509: tomwalters@509: // elementSizePtr_ has two special values: 0 indicates that a bundle tomwalters@509: // isn't open, and elementSizePtr_==data_ indicates that a bundle is tomwalters@509: // open but that it doesn't have a size slot (ie the outermost bundle) tomwalters@509: uint32 *elementSizePtr_; tomwalters@509: tomwalters@509: bool messageIsInProgress_; tomwalters@509: }; tomwalters@509: tomwalters@509: } // namespace osc tomwalters@509: tomwalters@509: #endif /* INCLUDED_OSC_OUTBOUND_PACKET_H */