Protocol.h

Go to the documentation of this file.
00001 // file      : ace/RMCast/Protocol.h
00002 // author    : Boris Kolpackov <boris@kolpackov.net>
00003 // cvs-id    : Protocol.h,v 1.23 2006/03/01 23:48:42 shuston Exp
00004 
00005 #ifndef ACE_RMCAST_PROTOCOL_H
00006 #define ACE_RMCAST_PROTOCOL_H
00007 
00008 #include "ace/Refcounted_Auto_Ptr.h"
00009 
00010 #include "ace/Vector_T.h"
00011 #include "ace/Hash_Map_Manager.h"
00012 
00013 #include "ace/CDR_Stream.h"
00014 #include "ace/CDR_Size.h"
00015 
00016 #include "ace/INET_Addr.h"
00017 #include "ace/Null_Mutex.h"
00018 
00019 #include "ace/OS_NS_string.h"
00020 #include "ace/OS_NS_stdlib.h"
00021 
00022 #include "Bits.h"
00023 
00024 /*
00025 #include <iostream>
00026 */
00027 
00028 namespace ACE_RMCast
00029 {
00030   // Basic types.
00031   //
00032   typedef ACE_CDR::UShort u16;
00033   typedef ACE_CDR::ULong u32;
00034   typedef ACE_CDR::ULongLong u64;
00035 
00036   // Protocol parameters
00037   //
00038   //
00039   unsigned short const max_service_size = 60;  // service profiles (Part, SN,
00040                                                // etc), sizes plus message size.
00041 
00042   //
00043   //
00044   //
00045   typedef ACE_INET_Addr Address;
00046 
00047   struct AddressHasher
00048   {
00049     unsigned long
00050     operator() (Address const& a) const
00051     {
00052       unsigned long port (a.get_port_number ());
00053       unsigned long ip (a.get_ip_address ());
00054 
00055       port <<= sizeof (unsigned long) - sizeof (unsigned short);
00056 
00057       return port ^ ip;
00058     }
00059   };
00060 
00061   //@@ Provide stream<< (Address const&)
00062   //
00063 
00064   typedef ACE_OutputCDR ostream;
00065   typedef ACE_SizeCDR sstream;
00066   typedef ACE_InputCDR istream;
00067 
00068   struct Profile;
00069 
00070   typedef
00071   ACE_Refcounted_Auto_Ptr<Profile, Mutex>
00072   Profile_ptr;
00073 
00074   struct Profile
00075   {
00076   public:
00077     class Header
00078     {
00079     public:
00080       Header (u16 id, u16 size)
00081           : id_ (id), size_ (size)
00082       {
00083       }
00084 
00085       Header (istream& is)
00086       {
00087         (void) (is >> id_ >> size_);
00088       }
00089 
00090     public:
00091       u16
00092       id () const
00093       {
00094         return id_;
00095       }
00096 
00097       u16
00098       size () const
00099       {
00100         return size_;
00101       }
00102 
00103     protected:
00104       void
00105       size (u16 s)
00106       {
00107         size_ = s;
00108       }
00109 
00110       friend struct Profile;
00111 
00112     private:
00113       u16 id_;
00114       u16 size_;
00115     };
00116 
00117   public:
00118     virtual
00119     ~Profile ()
00120     {
00121     }
00122 
00123     Profile_ptr
00124     clone ()
00125     {
00126       return clone_ ();
00127     }
00128 
00129   protected:
00130     Profile (u16 id)
00131         : header_ (id, 0)
00132     {
00133     }
00134 
00135     Profile (Header const& h)
00136         : header_ (h)
00137     {
00138     }
00139 
00140     virtual Profile_ptr
00141     clone_ () = 0;
00142 
00143   private:
00144     Profile&
00145     operator= (Profile const&);
00146 
00147   public:
00148     u16
00149     id () const
00150     {
00151       return header_.id ();
00152     }
00153 
00154     u16
00155     size () const
00156     {
00157       return header_.size ();
00158     }
00159 
00160   protected:
00161     void
00162     size (u16 s)
00163     {
00164       header_.size (s);
00165     }
00166 
00167     u16
00168     calculate_size ()
00169     {
00170       sstream ss;
00171 
00172       serialize_body (ss);
00173 
00174       return static_cast<u16> (ss.total_length ());
00175     }
00176 
00177   public:
00178     virtual void
00179     serialize_body (ostream&) const = 0;
00180 
00181     virtual void
00182     serialize_body (sstream&) const = 0;
00183 
00184     friend
00185     ostream&
00186     operator<< (ostream& os, Profile const& p);
00187 
00188     friend
00189     sstream&
00190     operator<< (sstream& ss, Profile const& p);
00191 
00192   private:
00193     Header header_;
00194   };
00195 
00196   inline
00197   ostream&
00198   operator<< (ostream& os, Profile::Header const& hdr)
00199   {
00200     os << hdr.id ();
00201     os << hdr.size ();
00202 
00203     return os;
00204   }
00205 
00206   inline
00207   sstream&
00208   operator<< (sstream& ss, Profile::Header const& hdr)
00209   {
00210     ss << hdr.id ();
00211     ss << hdr.size ();
00212 
00213     return ss;
00214   }
00215 
00216   inline
00217   ostream&
00218   operator<< (ostream& os, Profile const& p)
00219   {
00220     os << p.header_;
00221     p.serialize_body (os);
00222 
00223     return os;
00224   }
00225 
00226   inline
00227   sstream&
00228   operator<< (sstream& ss, Profile const& p)
00229   {
00230     ss << p.header_;
00231     p.serialize_body (ss);
00232 
00233     return ss;
00234   }
00235 
00236 
00237   //
00238   //
00239   //
00240   class Message;
00241 
00242   typedef
00243   ACE_Refcounted_Auto_Ptr<Message, Mutex>
00244   Message_ptr;
00245 
00246   class Message
00247   {
00248     typedef
00249     ACE_Hash_Map_Manager<u16, Profile_ptr, ACE_Null_Mutex>
00250     Profiles;
00251 
00252   public:
00253     Message ()
00254         : profiles_ (4)
00255     {
00256     }
00257 
00258     Message_ptr
00259     clone ()
00260     {
00261       return new Message (*this);
00262     }
00263 
00264   protected:
00265     Message (Message const& m)
00266         : profiles_ (4)
00267     {
00268       for (Profiles::const_iterator i (m.profiles_); !i.done (); i.advance ())
00269       {
00270         // Shallow copy of profiles. This implies that profiles are not
00271         // modified as they go up/down the stack.
00272         //
00273         profiles_.bind ((*i).ext_id_, (*i).int_id_);
00274       }
00275     }
00276 
00277   private:
00278     Message&
00279     operator= (Message const&);
00280 
00281   public:
00282     bool
00283     add (Profile_ptr p)
00284     {
00285       u16 id (p->id ());
00286 
00287       if (profiles_.find (id) == 0)
00288       {
00289         return false;
00290       }
00291 
00292       profiles_.bind (id, p);
00293 
00294       return true;
00295     }
00296 
00297     void
00298     replace (Profile_ptr p)
00299     {
00300       profiles_.rebind (p->id (), p);
00301     }
00302 
00303     void
00304     remove (u16 id)
00305     {
00306       profiles_.unbind (id);
00307     }
00308 
00309     Profile const*
00310     find (u16 id) const
00311     {
00312       Profiles::ENTRY* e = 0;
00313 
00314       if (profiles_.find (id, e) == -1) return 0;
00315 
00316       return e->int_id_.get ();
00317     }
00318 
00319     typedef
00320     Profiles::const_iterator
00321     ProfileIterator;
00322 
00323     ProfileIterator
00324     begin () const
00325     {
00326       return ProfileIterator (profiles_);
00327     }
00328 
00329   public:
00330     size_t
00331     size () const
00332     {
00333       sstream ss;
00334 
00335       u32 s (0);
00336 
00337       ss << s;
00338 
00339       for (Profiles::const_iterator i (profiles_); !i.done (); i.advance ())
00340       {
00341         ss << *((*i).int_id_);
00342       }
00343 
00344       return ss.total_length ();
00345     }
00346 
00347     friend
00348     ostream&
00349     operator<< (ostream& os, Message const& m)
00350     {
00351       u32 s (m.size ());
00352 
00353       os << s;
00354 
00355       for (Profiles::const_iterator i (m.profiles_); !i.done (); i.advance ())
00356       {
00357         os << *((*i).int_id_);
00358       }
00359 
00360       return os;
00361     }
00362 
00363   private:
00364     Profiles profiles_;
00365   };
00366 
00367   typedef ACE_Vector<Message_ptr, ACE_VECTOR_DEFAULT_SIZE> Messages;
00368 
00369   //
00370   //
00371   //
00372   struct From;
00373 
00374   typedef
00375   ACE_Refcounted_Auto_Ptr<From, Mutex>
00376   From_ptr;
00377 
00378   struct From : Profile
00379   {
00380     static u16 const id;
00381 
00382   public:
00383     From (Header const& h, istream& is)
00384         : Profile (h)
00385     {
00386       u32 addr;
00387       u16 port;
00388 
00389       is >> addr;
00390       is >> port;
00391 
00392       address_ = Address (port, addr);
00393     }
00394 
00395     From (Address const& addr)
00396         : Profile (id), address_ (addr)
00397     {
00398       size (calculate_size ());
00399     }
00400 
00401     From_ptr
00402     clone ()
00403     {
00404       return From_ptr (static_cast<From*> (clone_ ().release ()));
00405     }
00406 
00407   protected:
00408     virtual Profile_ptr
00409     clone_ ()
00410     {
00411       return new From (*this);
00412     }
00413 
00414     From (From const& from)
00415         : Profile (from),
00416           address_ (from.address_)
00417     {
00418     }
00419 
00420   public:
00421     Address const&
00422     address () const
00423     {
00424       return address_;
00425     }
00426 
00427   public:
00428     virtual void
00429     serialize_body (ostream& os) const
00430     {
00431       u32 addr (address_.get_ip_address ());
00432       u16 port (address_.get_port_number ());
00433 
00434       os << addr;
00435       os << port;
00436     }
00437 
00438     virtual void
00439     serialize_body (sstream& ss) const
00440     {
00441       u32 addr (0);
00442       u16 port (0);
00443 
00444       ss << addr;
00445       ss << port;
00446     }
00447 
00448   private:
00449     Address address_;
00450   };
00451 
00452 
00453   //
00454   //
00455   //
00456   struct To;
00457 
00458   typedef
00459   ACE_Refcounted_Auto_Ptr<To, Mutex>
00460   To_ptr;
00461 
00462   struct To : Profile
00463   {
00464     static u16 const id;
00465 
00466   public:
00467     To (Header const& h, istream& is)
00468         : Profile (h)
00469     {
00470       u32 addr;
00471       u16 port;
00472 
00473       is >> addr;
00474       is >> port;
00475 
00476       address_ = Address (port, addr);
00477     }
00478 
00479     To (Address const& addr)
00480         : Profile (id), address_ (addr)
00481     {
00482       size (calculate_size ());
00483     }
00484 
00485     To_ptr
00486     clone ()
00487     {
00488       return To_ptr (static_cast<To*> (clone_ ().release ()));
00489     }
00490 
00491   protected:
00492     virtual Profile_ptr
00493     clone_ ()
00494     {
00495       return new To (*this);
00496     }
00497 
00498     To (To const& to)
00499         : Profile (to),
00500           address_ (to.address_)
00501     {
00502     }
00503 
00504   public:
00505     Address const&
00506     address () const
00507     {
00508       return address_;
00509     }
00510 
00511   public:
00512     virtual void
00513     serialize_body (ostream& os) const
00514     {
00515       u32 addr (address_.get_ip_address ());
00516       u16 port (address_.get_port_number ());
00517 
00518       os << addr;
00519       os << port;
00520     }
00521 
00522     virtual void
00523     serialize_body (sstream& ss) const
00524     {
00525       u32 addr (0);
00526       u16 port (0);
00527 
00528       ss << addr;
00529       ss << port;
00530     }
00531 
00532   private:
00533     Address address_;
00534   };
00535 
00536 
00537   //
00538   //
00539   //
00540   struct Data;
00541 
00542   typedef
00543   ACE_Refcounted_Auto_Ptr<Data, Mutex>
00544   Data_ptr;
00545 
00546   struct Data : Profile
00547   {
00548     static u16 const id;
00549 
00550   public:
00551     virtual
00552     ~Data ()
00553     {
00554       if (buf_)
00555         operator delete (buf_);
00556     }
00557 
00558     Data (Header const& h, istream& is)
00559         : Profile (h),
00560           buf_ (0),
00561           size_ (h.size ()),
00562           capacity_ (size_)
00563     {
00564       if (size_)
00565       {
00566         buf_ = reinterpret_cast<char*> (operator new (capacity_));
00567         is.read_char_array (buf_, size_);
00568       }
00569     }
00570 
00571     Data (void const* buf, size_t s, size_t capacity = 0)
00572         : Profile (id),
00573           buf_ (0),
00574           size_ (s),
00575           capacity_ (capacity < size_ ? size_ : capacity)
00576     {
00577       if (size_)
00578       {
00579         buf_ = reinterpret_cast<char*> (operator new (capacity_));
00580         ACE_OS::memcpy (buf_, buf, size_);
00581       }
00582 
00583       Profile::size (calculate_size ());
00584     }
00585 
00586     Data_ptr
00587     clone ()
00588     {
00589       return Data_ptr (static_cast<Data*> (clone_ ().release ()));
00590     }
00591 
00592   protected:
00593     virtual Profile_ptr
00594     clone_ ()
00595     {
00596       return new Data (*this);
00597     }
00598 
00599     Data (Data const& d)
00600         : Profile (d),
00601           buf_ (0),
00602           size_ (d.size_),
00603           capacity_ (d.capacity_)
00604     {
00605       if (size_)
00606       {
00607         buf_ = reinterpret_cast<char*> (operator new (capacity_));
00608         ACE_OS::memcpy (buf_, d.buf_, size_);
00609       }
00610 
00611       Profile::size (calculate_size ());
00612     }
00613 
00614   public:
00615     char const*
00616     buf () const
00617     {
00618       return buf_;
00619     }
00620 
00621     char*
00622     buf ()
00623     {
00624       return buf_;
00625     }
00626 
00627     size_t
00628     size () const
00629     {
00630       return size_;
00631     }
00632 
00633     void
00634     size (size_t s)
00635     {
00636       if (s > capacity_)
00637         ACE_OS::abort ();
00638 
00639       size_ = s;
00640 
00641       Profile::size (calculate_size ());
00642     }
00643 
00644     size_t
00645     capacity () const
00646     {
00647       return capacity_;
00648     }
00649 
00650   public:
00651     virtual void
00652     serialize_body (ostream& os) const
00653     {
00654       os.write_char_array (buf_, size_);
00655     }
00656 
00657     virtual void
00658     serialize_body (sstream& ss) const
00659     {
00660       ss.write_char_array (buf_, size_);
00661     }
00662 
00663   private:
00664     char* buf_;
00665     size_t size_;
00666     size_t capacity_;
00667   };
00668 
00669 
00670   //
00671   //
00672   //
00673   struct SN;
00674 
00675   typedef
00676   ACE_Refcounted_Auto_Ptr<SN, Mutex>
00677   SN_ptr;
00678 
00679   struct SN : Profile
00680   {
00681     static u16 const id;
00682 
00683   public:
00684     SN (Header const& h, istream& is)
00685         : Profile (h)
00686     {
00687       is >> n_;
00688     }
00689 
00690     SN (u64 n)
00691         : Profile (id), n_ (n)
00692     {
00693       size (calculate_size ());
00694     }
00695 
00696     SN_ptr
00697     clone ()
00698     {
00699       return SN_ptr (static_cast<SN*> (clone_ ().release ()));
00700     }
00701 
00702   protected:
00703     virtual Profile_ptr
00704     clone_ ()
00705     {
00706       return new SN (*this);
00707     }
00708 
00709     SN (SN const& sn)
00710         : Profile (sn),
00711           n_ (sn.n_)
00712     {
00713     }
00714 
00715   public:
00716     u64
00717     num () const
00718     {
00719       return n_;
00720     }
00721 
00722   public:
00723     virtual void
00724     serialize_body (ostream& os) const
00725     {
00726       os << n_;
00727     }
00728 
00729     virtual void
00730     serialize_body (sstream& ss) const
00731     {
00732       ss << n_;
00733     }
00734 
00735   private:
00736     u64 n_;
00737   };
00738 
00739 
00740   //
00741   //
00742   //
00743   class NAK;
00744 
00745   typedef
00746   ACE_Refcounted_Auto_Ptr<NAK, Mutex>
00747   NAK_ptr;
00748 
00749   class NAK : public Profile
00750   {
00751   public:
00752 
00753     static u16 const id;
00754 
00755     typedef ACE_Vector<u64, ACE_VECTOR_DEFAULT_SIZE> SerialNumbers;
00756     typedef SerialNumbers::Iterator iterator;
00757 
00758     NAK (Header const& h, istream& is)
00759         : Profile (h)
00760     {
00761       u64 sn (0);
00762       u32 addr (0);
00763       u16 port (0);
00764 
00765       sstream ss;
00766 
00767       ss << sn;
00768       size_t sn_size (ss.total_length ());
00769 
00770       ss.reset ();
00771 
00772       ss << addr;
00773       ss << port;
00774 
00775       size_t addr_size (ss.total_length ());
00776 
00777 
00778       is >> addr;
00779       is >> port;
00780 
00781       // num_of_sns = (size - addr_size) / sn_size
00782       //
00783       for (unsigned long i (0); i < ((h.size () - addr_size) / sn_size); ++i)
00784       {
00785         is >> sn;
00786         sns_.push_back (sn);
00787       }
00788 
00789 
00790       address_ = Address (port, addr);
00791     }
00792 
00793     NAK (Address const& src)
00794         : Profile (id), address_ (src)
00795     {
00796       size (calculate_size ());
00797     }
00798 
00799     NAK_ptr
00800     clone ()
00801     {
00802       return NAK_ptr (static_cast<NAK*> (clone_ ().release ()));
00803     }
00804 
00805   protected:
00806     virtual Profile_ptr
00807     clone_ ()
00808     {
00809       return new NAK (*this);
00810     }
00811 
00812     NAK (NAK const& nak)
00813         : Profile (nak),
00814           address_ (nak.address_),
00815           sns_ (nak.sns_)
00816     {
00817     }
00818 
00819   public:
00820     void
00821     add (u64 sn)
00822     {
00823       sns_.push_back (sn);
00824       size (calculate_size ());
00825     }
00826 
00827   public:
00828     Address const&
00829     address () const
00830     {
00831       return address_;
00832     }
00833 
00834 
00835     iterator
00836     begin () /* const */
00837     {
00838       return iterator (sns_);
00839     }
00840 
00841     /*
00842     iterator
00843     end ()  const
00844     {
00845       return sns_.end ();
00846     }
00847     */
00848 
00849     size_t
00850     count () const
00851     {
00852       return sns_.size ();
00853     }
00854 
00855   public:
00856     // Count max number of elements that will fit into NAK profile
00857     // with size <= max_size.
00858     //
00859     static u32
00860     max_count (u32 max_size)
00861     {
00862       u32 n (0);
00863 
00864       sstream ss;
00865 
00866       Profile::Header hdr (0, 0);
00867       ss << hdr;
00868 
00869       u32 addr (0);
00870       u16 port (0);
00871       ss << addr;
00872       ss << port;
00873 
00874       while (true)
00875       {
00876         u64 sn (0);
00877         ss << sn;
00878 
00879         if (ss.total_length () <= max_size)
00880           ++n;
00881 
00882         if (ss.total_length () >= max_size)
00883           break;
00884       }
00885 
00886       return n;
00887     }
00888 
00889   public:
00890     virtual void
00891     serialize_body (ostream& os) const
00892     {
00893       NAK& this_ = const_cast<NAK&> (*this); // Don't put in ROM.
00894 
00895       u32 addr (address_.get_ip_address ());
00896       u16 port (address_.get_port_number ());
00897 
00898       os << addr;
00899       os << port;
00900 
00901       // Stone age iteration.
00902       //
00903       for (iterator i (this_.begin ()); !i.done (); i.advance ())
00904       {
00905         u64* psn;
00906         i.next (psn);
00907         os << *psn;
00908       }
00909     }
00910 
00911     virtual void
00912     serialize_body (sstream& ss) const
00913     {
00914       NAK& this_ = const_cast<NAK&> (*this); // Don't put in ROM.
00915 
00916       u32 addr (0);
00917       u16 port (0);
00918 
00919       ss << addr;
00920       ss << port;
00921 
00922       // Stone age iteration.
00923       //
00924       for (iterator i (this_.begin ()); !i.done (); i.advance ())
00925       {
00926         u64 sn (0);
00927         ss << sn;
00928       }
00929     }
00930 
00931   private:
00932     Address address_;
00933     SerialNumbers sns_;
00934   };
00935 
00936   //
00937   //
00938   //
00939   struct NRTM;
00940 
00941   typedef
00942   ACE_Refcounted_Auto_Ptr<NRTM, Mutex>
00943   NRTM_ptr;
00944 
00945   struct NRTM : Profile
00946   {
00947     static u16 const id;
00948 
00949   public:
00950     NRTM (Header const& h, istream& is)
00951         : Profile (h), map_ (10)
00952     {
00953       u32 addr (0);
00954       u16 port (0);
00955       u64 sn (0);
00956 
00957       sstream ss;
00958 
00959       ss << sn;
00960       ss << addr;
00961       ss << port;
00962 
00963       size_t block_size (ss.total_length ());
00964 
00965 
00966       // num_of_blocks = size / block_size
00967       //
00968       for (size_t i (0); i < (h.size () / block_size); ++i)
00969       {
00970         is >> sn;
00971         is >> addr;
00972         is >> port;
00973 
00974         map_.bind (Address (port, addr), sn);
00975       }
00976     }
00977 
00978     NRTM ()
00979         : Profile (id), map_ (10)
00980     {
00981       size (calculate_size ());
00982     }
00983 
00984     NRTM_ptr
00985     clone ()
00986     {
00987       return NRTM_ptr (static_cast<NRTM*> (clone_ ().release ()));
00988     }
00989 
00990   protected:
00991     virtual Profile_ptr
00992     clone_ ()
00993     {
00994       return new NRTM (*this);
00995     }
00996 
00997     NRTM (NRTM const& nrtm)
00998         : Profile (nrtm)
00999     {
01000       for (Map::const_iterator i (nrtm.map_); !i.done (); i.advance ())
01001       {
01002         map_.bind ((*i).ext_id_, (*i).int_id_);
01003       }
01004     }
01005 
01006   public:
01007     void
01008     insert (Address const& addr, u64 sn)
01009     {
01010       map_.bind (addr, sn);
01011 
01012       size (calculate_size ());
01013     }
01014 
01015     u64
01016     find (Address const& addr) const
01017     {
01018       u64 sn;
01019 
01020       if (map_.find (addr, sn) == -1) return 0;
01021 
01022       return sn;
01023     }
01024 
01025     bool
01026     empty () const
01027     {
01028       return map_.current_size () == 0;
01029     }
01030 
01031   public:
01032     // Count max number of elements that will fit into NRTM profile
01033     // with size <= max_size.
01034     //
01035     static u32
01036     max_count (u32 max_size)
01037     {
01038       u32 n (0);
01039 
01040       sstream ss;
01041 
01042       Profile::Header hdr (0, 0);
01043       ss << hdr;
01044 
01045       while (true)
01046       {
01047         u32 addr (0);
01048         u16 port (0);
01049         u64 sn (0);
01050 
01051         ss << sn;
01052         ss << addr;
01053         ss << port;
01054 
01055         if (ss.total_length () <= max_size)
01056           ++n;
01057 
01058         if (ss.total_length () >= max_size)
01059           break;
01060       }
01061 
01062       return n;
01063     }
01064 
01065   public:
01066     virtual void
01067     serialize_body (ostream& os) const
01068     {
01069       for (Map::const_iterator i (map_), e (map_, 1); i != e; ++i)
01070       {
01071         u32 addr ((*i).ext_id_.get_ip_address ());
01072         u16 port ((*i).ext_id_.get_port_number ());
01073         u64 sn ((*i).int_id_);
01074 
01075         os << sn;
01076         os << addr;
01077         os << port;
01078 
01079       }
01080     }
01081 
01082     virtual void
01083     serialize_body (sstream& ss) const
01084     {
01085       for (Map::const_iterator i (map_), e (map_, 1); i != e; ++i)
01086       {
01087         u32 addr (0);
01088         u16 port (0);
01089         u64 sn (0);
01090 
01091         ss << sn;
01092         ss << addr;
01093         ss << port;
01094       }
01095     }
01096 
01097   private:
01098     typedef
01099     ACE_Hash_Map_Manager_Ex<Address,
01100                             u64,
01101                             AddressHasher,
01102                             ACE_Equal_To<Address>,
01103                             ACE_Null_Mutex>
01104     Map;
01105 
01106     Map map_;
01107   };
01108 
01109 
01110   //
01111   //
01112   //
01113   struct NoData;
01114 
01115   typedef
01116   ACE_Refcounted_Auto_Ptr<NoData, Mutex>
01117   NoData_ptr;
01118 
01119   struct NoData : Profile
01120   {
01121     static u16 const id;
01122 
01123   public:
01124     NoData (Header const& h, istream&)
01125         : Profile (h)
01126     {
01127     }
01128 
01129     NoData ()
01130         : Profile (id)
01131     {
01132       Profile::size (0);
01133     }
01134 
01135     NoData_ptr
01136     clone ()
01137     {
01138       return NoData_ptr (static_cast<NoData*> (clone_ ().release ()));
01139     }
01140 
01141   protected:
01142     virtual Profile_ptr
01143     clone_ ()
01144     {
01145       return new NoData (*this);
01146     }
01147 
01148     NoData (NoData const& no_data)
01149         : Profile (no_data)
01150     {
01151     }
01152 
01153   public:
01154     virtual void
01155     serialize_body (ostream&) const
01156     {
01157     }
01158 
01159     virtual void
01160     serialize_body (sstream&) const
01161     {
01162     }
01163   };
01164 
01165 
01166   //
01167   //
01168   //
01169   struct Part;
01170 
01171   typedef
01172   ACE_Refcounted_Auto_Ptr<Part, Mutex>
01173   Part_ptr;
01174 
01175   struct Part : Profile
01176   {
01177     static u16 const id;
01178 
01179   public:
01180     Part (Header const& h, istream& is)
01181         : Profile (h)
01182     {
01183       is >> num_;
01184       is >> of_;
01185       is >> total_size_;
01186     }
01187 
01188     Part (u32 num, u32 of, u64 total_size)
01189         : Profile (id),
01190           num_ (num),
01191           of_ (of),
01192           total_size_ (total_size)
01193     {
01194       size (calculate_size ());
01195     }
01196 
01197     Part_ptr
01198     clone ()
01199     {
01200       return Part_ptr (static_cast<Part*> (clone_ ().release ()));
01201     }
01202 
01203   protected:
01204     virtual Profile_ptr
01205     clone_ ()
01206     {
01207       return new Part (*this);
01208     }
01209 
01210     Part (Part const& part)
01211         : Profile (part),
01212           num_ (part.num_),
01213           of_ (part.of_),
01214           total_size_ (part.total_size_)
01215     {
01216     }
01217 
01218   public:
01219     u32
01220     num () const
01221     {
01222       return num_;
01223     }
01224 
01225     u32
01226     of () const
01227     {
01228       return of_;
01229     }
01230 
01231     u64
01232     total_size () const
01233     {
01234       return total_size_;
01235     }
01236 
01237   public:
01238     virtual void
01239     serialize_body (ostream& os) const
01240     {
01241       os << num_;
01242       os << of_;
01243       os << total_size_;
01244     }
01245 
01246     virtual void
01247     serialize_body (sstream& ss) const
01248     {
01249       ss << num_;
01250       ss << of_;
01251       ss << total_size_;
01252     }
01253 
01254 
01255   private:
01256     u32 num_;
01257     u32 of_;
01258     u64 total_size_;
01259   };
01260 
01261 }
01262 
01263 /*
01264 inline
01265 std::ostream&
01266 operator<< (std::ostream& os, ACE_RMCast::Address const& a)
01267 {
01268   char buf[64];
01269   a.addr_to_string (buf, 64, 1);
01270   return os << buf;
01271 }
01272 */
01273 
01274 #endif  // ACE_RMCAST_PROTOCOL_H

Generated on Thu Nov 9 11:40:41 2006 for ACE_RMCast by doxygen 1.3.6