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