Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

FeePacket.hpp

00001 #ifndef ZTT_DCS_FEE_PACKET_HPP
00002 #define ZTT_DCS_FEE_PACKET_HPP
00003 
00004 #include "feepacket_flags.h"
00005 #include <map>
00006 #include <vector>
00007 #include "boost/shared_ptr.hpp"
00008 
00009 namespace ztt { namespace dcs {
00010 
00014 typedef unsigned short FlagBits;
00015 
00019 #define FEE_PACKET_ID_SIZE          4
00020 
00023 #define FEE_PACKET_ERRORCODE_SIZE   2
00024 
00027 #define FEE_PACKET_FLAG_SIZE        2
00028 
00031 #define FEE_PACKET_CHECKSUM_SIZE    4
00032 
00036 #define FEE_PACKET_HEADER_SIZE  (FEE_PACKET_ID_SIZE + FEE_PACKET_ERRORCODE_SIZE + FEE_PACKET_FLAG_SIZE + FEE_PACKET_CHECKSUM_SIZE)
00037                      
00038 
00043 #define FEE_PACKET_MAX_ID           65530
00044 
00049 #define FEE_PACKET_NO_ERRORCODE     0
00050 
00051 
00056 #define ADLER_BASE 65521
00057 
00058 
00065 class FeePacket {
00066         private:
00068                 short mErrorCode;
00069 
00071                 unsigned int mId;
00072 
00074                 FlagBits mFlags;
00075 
00077                 unsigned int mChecksum;
00078 
00080                 char* mPayload;
00081 
00083                 int mPayloadSize;
00084 
00086         bool mValid;
00087 
00089                 static const int HEADER_SIZE;
00090 
00092         static unsigned int mLastID;
00094                 std::map<int, char*> calculatedAnswerRange;
00095 
00112                 unsigned int static calculateChecksum(unsigned char* input, int size);
00113 
00135                 FeePacket(unsigned int id, short errorCode, char* payload, bool legal,
00136                  int payloadSize, bool checksum = false,
00137                  FlagBits flags = NO_FLAGS, bool huffman = false);
00138                 
00159         void initFeePacket(unsigned int id, short errorCode, char* payload, 
00160                 int payloadSize, bool checksum, FlagBits flags, 
00161                 bool huffman, bool legal = true);
00162 
00163                 void initFeePacket(unsigned int id, short errorCode, char* payload, 
00164                 int payloadSize, bool checksum, std::vector<char*>* feeContainer,  FlagBits flags, 
00165                                 bool huffman, bool legal = true);
00166                 
00167         
00168 
00169         public:
00190                 FeePacket(short errorCode, char* payload, int payloadSize,
00191                  bool checksum = false, FlagBits flags = NO_FLAGS,
00192                  bool huffman = false);
00193 
00194                 FeePacket(short errorCode, char* payload, int payloadSize, std::vector<char*>* feeContainer, bool checksum = false,
00195                                  FlagBits flags = NO_FLAGS, bool huffman = false);
00199                 FeePacket(std::vector<char*>* feeContainer, int numberofTags = 1);
00203                 ~FeePacket();
00204                 
00209                 std::vector<char*> feeServerNames;
00210                 
00211 
00217                 unsigned int getId() const;
00218                 
00219 
00227                 short getErrorCode() const;
00228 
00234                 int getPayloadSize() const;
00235 
00241                 int getFeePacketSize() const;
00242 
00256                 FlagBits getFlags() const;
00257 
00263                 bool isHuffmanSet() const;
00264 
00270                 bool isChecksumSet() const;
00271 
00277         bool isValid() const;
00278                 
00279 
00286                 char* getPayload() const;
00287 
00295                 char* marshall();
00296 
00300                 void increaseID();
00304                 std::map<int,char*> getAnswerSet();
00305 
00318                 static FeePacket* unmarshall(char* marshalledFeePacket, int size);
00319 
00320 }; // end class
00321 inline std::map<int,char*> FeePacket::getAnswerSet(){
00322         return calculatedAnswerRange;
00323 }
00324 
00325 inline void FeePacket::increaseID(){
00326         ++mId;
00327         //++mLastID;
00328 }
00329 
00330 inline unsigned int FeePacket::getId() const {
00331         return mId;
00332 }
00333 
00334 inline short FeePacket::getErrorCode() const {
00335         return mErrorCode;
00336 }
00337 
00338 inline char* FeePacket::getPayload() const {
00339         return mPayload;
00340 }
00341 
00342 inline int FeePacket::getPayloadSize() const {
00343         return mPayloadSize;
00344 }
00345 
00346 inline int FeePacket::getFeePacketSize() const {
00347         return (mPayloadSize + HEADER_SIZE);
00348 }
00349 
00350 inline FlagBits FeePacket::getFlags() const {
00351         return mFlags;
00352 }
00353 
00354 inline bool FeePacket::isHuffmanSet() const {
00355         // > 0 means true
00356         return ((mFlags & HUFFMAN_FLAG) > NO_FLAGS) ? true : false;
00357 }
00358 
00359 inline bool FeePacket::isChecksumSet() const {
00360         // > 0 means true
00361         return ((mFlags & CHECKSUM_FLAG) > NO_FLAGS) ? true : false;
00362 }
00363 
00364 inline bool FeePacket::isValid() const {
00365     return mValid;
00366 }
00367 
00368 
00369 } } //end of namespace ztt::dcs
00370 
00371 #endif

Generated on Fri Mar 30 02:54:33 2007 for InterComLayer by doxygen 1.3.5