RTFX  0.3
Real time special effects collaborative visualization and production library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
RTFXPostOffice.h
Go to the documentation of this file.
1 #ifndef __RTFX_POSTOFFICE__
2 #define __RTFX_POSTOFFICE__
3 
13 #include <set>
14 #include <queue>
15 #include <boost/bind.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/enable_shared_from_this.hpp>
18 #include <boost/asio.hpp>
19 
20 #include "RTFXDebug.h"
21 
22 #include "RTFXParcel.h"
23 #include "RTFXParticipant.h"
24 #include "RTFXMailbox.h"
25 #include "RTFXBoostIncludes.h"
26 
27 
28 using boost::asio::ip::tcp;
29 
30 namespace RTFX
31 {
32  typedef boost::shared_ptr<RTFXParticipant> RTFXParticipant_ptr;
33  typedef std::deque<RTFXParcel> RTFXParcelQueue;
34 
37  {
38  bool operator() ( const char * a, const char * b ) const
39  {
40  if ( memcmp( a, b, 16 ) < 0 ) return true;
41  return false;
42  }
43  };
44 
51  class RTFXAPI RTFXPostOffice
52  {
53  public:
54 
57  {
58  debug( ostringstream().flush() << "RTFXPostOffice Constructor" << endl );
59  compressionType = NONE;
60  }
61 
64  {
65  map<const char *, RTFXMailbox *, MailboxNameComparison>::iterator iter_ = mailboxes.begin();
66  while ( iter_ != mailboxes.end() )
67  {
68  RTFXMailbox * ptr_ = ( *iter_ ).second;
69  mailboxes.erase( iter_ );
70  delete ptr_;
71 
72  iter_ ++;
73  }
74  }
75 
81  void Join( RTFXParticipant_ptr _participant );
82 
86  void Leave( RTFXParticipant_ptr _particpant );
87 
89  void Deliver( RTFXParcel &_parcel );
90 
92  void RemoveAll( boost::uuids::uuid _owner, char * _mailboxName );
93 
95  void SendMailbox( RTFXParticipant_ptr _participant );
96 
98  RTFXMailbox * GetMailbox( char * _mailboxName )
99  {
100  if ( mailboxes.find( _mailboxName ) == mailboxes.end() )
101  return NULL;
102  return mailboxes[ _mailboxName ];
103  }
104 
107  void SetDefaultCompressionType( COMPRESSIONTYPE _tmp )
108  {
109  compressionType = _tmp;
110  map<const char *, RTFXMailbox *, MailboxNameComparison >::iterator iter_ = mailboxes.begin();
111  while ( iter_ != mailboxes.end() )
112  {
113  ((*iter_).second)->SetDefaultCompressionType( compressionType );
114  iter_ ++;
115  }
116  }
117 
119  void SetOwnerID( boost::uuids::uuid _id )
120  {
121  ownerID = _id;
122  }
123 
125  boost::uuids::uuid GetOwnerID()
126  {
127  return ownerID;
128  }
129 
130  private:
132  boost::uuids::uuid ownerID;
133 
136 
138  std::string postOfficeName;
139 
141  boost::uuids::uuid id;
142 
144  std::set<RTFXParticipant_ptr> participants;
145 
147  std::map<const char *, RTFXMailbox *, MailboxNameComparison > mailboxes;
148 
150  RTFXParticipant_ptr newParticipant;
151 
154 
157  };
158 }
159 
160 #endif