00001
00013 #ifndef FLAP_H
00014 #define FLAP_H
00015
00016 #include <string>
00017
00018 #include <bool.h>
00019 #include <bits.h>
00020
00021 class FLAP {
00022
00023 private:
00024
00028 int fd;
00029
00034 bool closeFileDescOnDestroy;
00035
00039 byte header[6];
00040
00045 byte *dataBuffer;
00046
00050 int bufferCapacity;
00051
00055 int bufferLength;
00056
00061 int nextOutSequenceNumber;
00062
00067 int seekPointer;
00068
00069 public:
00070
00074 struct SNAC {
00075 word familyID;
00076 word subTypeID;
00077 byte flags1;
00078 byte flags2;
00079 dword requestID;
00080 };
00081
00089 FLAP& resetData( );
00090
00099 FLAP& writeData ( const void *newData, int length );
00100
00109 FLAP& writeTLV ( word type, const string &data );
00110
00119 FLAP& writeTLV ( word type, word data );
00120
00131 FLAP& writeTLV ( word type, const void* data, int length );
00132
00144 FLAP& writeSNAC ( word familyID, word subTypeID, byte flags1, byte flags2, dword requestID );
00145
00154 FLAP& writeSNAC ( const SNAC& snac );
00155
00163 FLAP& writeByte ( byte aByte );
00164
00172 FLAP& writeWord ( word aWord );
00173
00181 FLAP& writeDword ( dword aDword );
00182
00194 FLAP& readData ( void *buffer, int length );
00195
00204 FLAP& read8LV ( string& data );
00205
00214 FLAP& readTLV ( word &type, string &data );
00215
00224 FLAP& readTLV ( word &type, word &data );
00225
00238 FLAP& readTLV ( word &type, void* data, int length, int& bytesWriten );
00239
00240 FLAP& readSNAC ( word& familyID, word& subTypeID, byte& flags1, byte& flags2, dword& requestID );
00241 FLAP& readSNAC ( SNAC& snac );
00242
00243 FLAP& readByte ( byte& aByte );
00244 FLAP& readWord ( word& aWord );
00245
00246 FLAP& peekTLVType ( word& type );
00247
00256 FLAP& setChannelID ( int value );
00257
00258
00259 static const int FLAP_SEEK_START = 0,
00260 FLAP_SEEK_CURRENT = 1;
00261
00273 FLAP& setSeek ( int value, int whence = 0 );
00274
00283 FLAP& skipBytes ( int value ) { return setSeek ( value, FLAP_SEEK_CURRENT ); }
00284
00290 FLAP& skipTLV ( );
00291
00299 FLAP& setFileDescriptor ( int newFd, bool newClose);
00300
00306 int getChannelID ( void ) const;
00307
00316 int getSequenceNumber ( void ) const;
00317
00318 int getDataFieldLength( void ) const;
00319 const byte *getDataField ( void ) const;
00320
00321 FLAP();
00322 ~FLAP();
00323
00329 bool receive ();
00330
00337 bool send ();
00338
00339 };
00340
00350 ostream& operator<< ( ostream& os, const FLAP& flap );
00351
00352 #endif