00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #ifndef __CRITICALPACKET_H__
00021 #define __CRITICALPACKET_H__
00022 
00023 
00024 
00025 
00026 
00027 
00028 class CriticalPacket
00029 {
00030 public:
00031   CriticalPacket(void);
00032   ~CriticalPacket(void);
00033 
00034 public:
00035   
00036   bool    WritePacket(DiskFile &diskfile, u64 fileoffset) const;
00037 
00038   
00039   size_t  PacketLength(void) const;
00040 
00041   
00042   void*   AllocatePacket(size_t length, size_t extra = 0);
00043 
00044   
00045   void    FinishPacket(const MD5Hash &set_id_hash);
00046 
00047 protected:
00048   u8     *packetdata;
00049   size_t  packetlength;
00050 };
00051 
00052 inline CriticalPacket::CriticalPacket(void)
00053 {
00054   
00055   packetdata = 0;
00056   packetlength = 0;
00057 }
00058 
00059 inline CriticalPacket::~CriticalPacket(void)
00060 {
00061   
00062   delete [] packetdata;
00063 }
00064 
00065 inline size_t CriticalPacket::PacketLength(void) const
00066 {
00067   return packetlength;
00068 }
00069 
00070 inline void* CriticalPacket::AllocatePacket(size_t length, size_t extra)
00071 {
00072   
00073   assert(packetlength == 0 && packetdata == 0);
00074 
00075   
00076   packetlength = length;
00077 
00078   
00079   packetdata = new u8[length+extra];
00080   memset(packetdata, 0, length+extra);
00081 
00082   return packetdata;
00083 }
00084 
00085 
00086 
00087 
00088 class CriticalPacketEntry
00089 {
00090 public:
00091   CriticalPacketEntry(DiskFile *_diskfile, 
00092                       u64 _offset, 
00093                       const CriticalPacket *_packet)
00094     : diskfile(_diskfile)
00095     , offset(_offset)
00096     , packet(_packet)
00097   {}
00098   CriticalPacketEntry(void)
00099     : diskfile(0)
00100     , offset(0)
00101     , packet(0)
00102   {}
00103   CriticalPacketEntry(const CriticalPacketEntry &other)
00104     : diskfile(other.diskfile)
00105     , offset(other.offset)
00106     , packet(other.packet)
00107   {}
00108   CriticalPacketEntry& operator=(const CriticalPacketEntry &other)
00109   {
00110     diskfile = other.diskfile;
00111     offset = other.offset;
00112     packet = other.packet;
00113     return *this;
00114   }
00115 
00116 public:
00117   
00118   bool   WritePacket(void) const;
00119 
00120   
00121   u64    PacketLength(void) const;
00122 
00123 protected:
00124   DiskFile             *diskfile;
00125   u64                   offset;
00126   const CriticalPacket *packet;
00127 };
00128 
00129 inline bool CriticalPacketEntry::WritePacket(void) const
00130 {
00131   assert(packet != 0 && diskfile != 0);
00132 
00133   
00134   return packet->WritePacket(*diskfile, offset);
00135 }
00136 
00137 inline u64 CriticalPacketEntry::PacketLength(void) const
00138 {
00139   assert(packet != 0);
00140 
00141   
00142   return packet->PacketLength();
00143 }
00144 
00145 #endif // __CRITICALPACKET_H__