1*2ae4404aSPhilippe Houdoin /*=--------------------------------------------------------------------------=* 2*2ae4404aSPhilippe Houdoin * NetBuffer.h -- Interface definition for the BNetBuffer class. 3*2ae4404aSPhilippe Houdoin * 4*2ae4404aSPhilippe Houdoin * Written by S.T. Mansfield (thephantom@mac.com) 5*2ae4404aSPhilippe Houdoin *=--------------------------------------------------------------------------=* 6*2ae4404aSPhilippe Houdoin * Copyright (c) 2002, The OpenBeOS project. 7*2ae4404aSPhilippe Houdoin * 8*2ae4404aSPhilippe Houdoin * Permission is hereby granted, free of charge, to any person obtaining a 9*2ae4404aSPhilippe Houdoin * copy of this software and associated documentation files (the "Software"), 10*2ae4404aSPhilippe Houdoin * to deal in the Software without restriction, including without limitation 11*2ae4404aSPhilippe Houdoin * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12*2ae4404aSPhilippe Houdoin * and/or sell copies of the Software, and to permit persons to whom the 13*2ae4404aSPhilippe Houdoin * Software is furnished to do so, subject to the following conditions: 14*2ae4404aSPhilippe Houdoin * 15*2ae4404aSPhilippe Houdoin * The above copyright notice and this permission notice shall be included in 16*2ae4404aSPhilippe Houdoin * all copies or substantial portions of the Software. 17*2ae4404aSPhilippe Houdoin * 18*2ae4404aSPhilippe Houdoin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19*2ae4404aSPhilippe Houdoin * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20*2ae4404aSPhilippe Houdoin * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21*2ae4404aSPhilippe Houdoin * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22*2ae4404aSPhilippe Houdoin * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23*2ae4404aSPhilippe Houdoin * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24*2ae4404aSPhilippe Houdoin * DEALINGS IN THE SOFTWARE. 25*2ae4404aSPhilippe Houdoin *=--------------------------------------------------------------------------=* 26*2ae4404aSPhilippe Houdoin */ 274c44e39aSPhilippe Houdoin 284c44e39aSPhilippe Houdoin #ifndef _NETBUFFER_H 294c44e39aSPhilippe Houdoin #define _NETBUFFER_H 304c44e39aSPhilippe Houdoin 314c44e39aSPhilippe Houdoin #include <BeBuild.h> 324c44e39aSPhilippe Houdoin #include <SupportDefs.h> 334c44e39aSPhilippe Houdoin #include <Archivable.h> 34*2ae4404aSPhilippe Houdoin #include <socket.h> 354c44e39aSPhilippe Houdoin 364c44e39aSPhilippe Houdoin /* 37*2ae4404aSPhilippe Houdoin * Empty forward declaration to satisfy the GetImpl method. 384c44e39aSPhilippe Houdoin */ 394c44e39aSPhilippe Houdoin class NLPacket; 404c44e39aSPhilippe Houdoin 414c44e39aSPhilippe Houdoin class BNetBuffer : public BArchivable 424c44e39aSPhilippe Houdoin { 434c44e39aSPhilippe Houdoin public: 444c44e39aSPhilippe Houdoin BNetBuffer( size_t size = 0 ); 45*2ae4404aSPhilippe Houdoin virtual ~BNetBuffer( void ); 464c44e39aSPhilippe Houdoin 47*2ae4404aSPhilippe Houdoin status_t InitCheck( void ); 484c44e39aSPhilippe Houdoin 49*2ae4404aSPhilippe Houdoin BNetBuffer( BMessage* Archive ); 504c44e39aSPhilippe Houdoin virtual status_t Archive( BMessage* into, bool deep = true ) const; 514c44e39aSPhilippe Houdoin static BArchivable* Instantiate( BMessage* archive ); 524c44e39aSPhilippe Houdoin 534c44e39aSPhilippe Houdoin BNetBuffer( const BNetBuffer& ); 544c44e39aSPhilippe Houdoin BNetBuffer& operator=( const BNetBuffer& ); 554c44e39aSPhilippe Houdoin 56*2ae4404aSPhilippe Houdoin // Mutators. 574c44e39aSPhilippe Houdoin status_t AppendInt8( int8 ); 584c44e39aSPhilippe Houdoin status_t AppendUint8( uint8 ); 594c44e39aSPhilippe Houdoin status_t AppendInt16( int16 ); 604c44e39aSPhilippe Houdoin status_t AppendUint16( uint16 ); 614c44e39aSPhilippe Houdoin status_t AppendInt32( int32 ); 624c44e39aSPhilippe Houdoin status_t AppendUint32( uint32 ); 634c44e39aSPhilippe Houdoin status_t AppendFloat( float ); 644c44e39aSPhilippe Houdoin status_t AppendDouble( double ); 654c44e39aSPhilippe Houdoin status_t AppendString( const char* ); 664c44e39aSPhilippe Houdoin status_t AppendData( const void*, size_t ); 674c44e39aSPhilippe Houdoin status_t AppendMessage( const BMessage& ); 684c44e39aSPhilippe Houdoin status_t AppendInt64( int64 ); 694c44e39aSPhilippe Houdoin status_t AppendUint64( uint64 ); 704c44e39aSPhilippe Houdoin 714c44e39aSPhilippe Houdoin status_t RemoveInt8( int8& ); 724c44e39aSPhilippe Houdoin status_t RemoveUint8( uint8& ); 734c44e39aSPhilippe Houdoin status_t RemoveInt16( int16& ); 744c44e39aSPhilippe Houdoin status_t RemoveUint16( uint16& ); 754c44e39aSPhilippe Houdoin status_t RemoveInt32( int32& ); 764c44e39aSPhilippe Houdoin status_t RemoveUint32( uint32& ); 774c44e39aSPhilippe Houdoin status_t RemoveFloat( float& ); 784c44e39aSPhilippe Houdoin status_t RemoveDouble( double& ); 794c44e39aSPhilippe Houdoin status_t RemoveString( char*, size_t ); 804c44e39aSPhilippe Houdoin status_t RemoveData( void*, size_t ); 814c44e39aSPhilippe Houdoin status_t RemoveMessage( BMessage& ); 824c44e39aSPhilippe Houdoin status_t RemoveInt64( int64& ); 834c44e39aSPhilippe Houdoin status_t RemoveUint64( uint64& ); 844c44e39aSPhilippe Houdoin 85*2ae4404aSPhilippe Houdoin // Accessors. 86*2ae4404aSPhilippe Houdoin unsigned char* Data( void ) const; 87*2ae4404aSPhilippe Houdoin size_t Size( void ) const; 88*2ae4404aSPhilippe Houdoin size_t BytesRemaining( void ) const; 894c44e39aSPhilippe Houdoin 90*2ae4404aSPhilippe Houdoin inline NLPacket *GetImpl( void ) const; 914c44e39aSPhilippe Houdoin 924c44e39aSPhilippe Houdoin protected: 93*2ae4404aSPhilippe Houdoin // Attributes. 94*2ae4404aSPhilippe Houdoin status_t fInitialized; 95*2ae4404aSPhilippe Houdoin unsigned char* fData; 96*2ae4404aSPhilippe Houdoin int32 fDataSize; 97*2ae4404aSPhilippe Houdoin int32 fStackSize; 98*2ae4404aSPhilippe Houdoin int32 fCapacity; 994c44e39aSPhilippe Houdoin 1004c44e39aSPhilippe Houdoin private: 101*2ae4404aSPhilippe Houdoin // Private class helpers. 102*2ae4404aSPhilippe Houdoin status_t clone( const BNetBuffer& ); 103*2ae4404aSPhilippe Houdoin status_t dpop( int32, int32, void* ); 104*2ae4404aSPhilippe Houdoin status_t dpush( int32, int32, const void* ); 105*2ae4404aSPhilippe Houdoin status_t resize( int32 NewSize, bool RegenStack = false ); 1064c44e39aSPhilippe Houdoin 107*2ae4404aSPhilippe Houdoin // Not used, here to maintain R5 binary compatiblilty. 108*2ae4404aSPhilippe Houdoin int32 fPrivateData[5]; 1094c44e39aSPhilippe Houdoin }; 1104c44e39aSPhilippe Houdoin 1114c44e39aSPhilippe Houdoin 112*2ae4404aSPhilippe Houdoin // WARNING: This method, as it stands, breaks R5 compatibility *STM*. 113*2ae4404aSPhilippe Houdoin inline NLPacket* BNetBuffer::GetImpl( void ) const 1144c44e39aSPhilippe Houdoin { 115*2ae4404aSPhilippe Houdoin return NULL; // Cheeky, yes; but no Nettle stuff is allowed... 1164c44e39aSPhilippe Houdoin } 1174c44e39aSPhilippe Houdoin 118*2ae4404aSPhilippe Houdoin #endif // <-- #ifndef _NETBUFFER_H 1194c44e39aSPhilippe Houdoin 120*2ae4404aSPhilippe Houdoin 121*2ae4404aSPhilippe Houdoin /*=------------------------------------------------------------------- End -=*/ 122