RTFX  0.3
Real time special effects collaborative visualization and production library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
RTFXClient.h
Go to the documentation of this file.
1 #ifndef __RTFX_CLIENT__
2 #define __RTFX_CLIENT__
3 
12 #include <cstdlib>
13 #include <deque>
14 #include <iostream>
15 #include <vector>
16 
17 #include "RTFXBoostIncludes.h"
18 #include "RTFXParcel.h"
19 #include "RTFXMailbox.h"
20 #include "RTFXPostOffice.h"
21 #include "RTFX_API.h"
22 
23 
24 using boost::asio::ip::tcp;
25 using namespace std;
26 
27 namespace RTFX
28 {
30  typedef std::deque<RTFXParcel> RTFXParcelQueue;
35  class RTFXAPI RTFXClient
36  {
37  public:
38 
40  RTFXClient( boost::asio::io_service &_ioService, tcp::resolver::iterator _endpointIterator, char * _mailboxName ) : ioService( _ioService ), socket( _ioService )
41  {
42  compressionType = NONE;
43 
44  areYouKeepingDataAtServer = true;
45 
46  isBeingDeleted = false;
47  isConnected = false;
48  hasMailboxNameBeenSent = false;
49  wasIDReceived = false;
50  isNewDataAvailable = false;
51  isBinaryData = true;
52 
53  mailboxName = new char[16];
54  memcpy( mailboxName, _mailboxName, 16 * sizeof( char ) );
55 
56  tcp::endpoint endpoint_ = *_endpointIterator;
57 
58  socket.async_connect( endpoint_,
59  boost::bind( &RTFXClient::HandleConnect, this,
60  boost::asio::placeholders::error, ++_endpointIterator ) );
61  }
62 
65  {
66  isBeingDeleted = true;
67  delete [] mailboxName;
68  };
69 
71  void Reconnect()
72  {
73  // TODO
74  }
75 
77  void SetArchiveType( bool _isBinaryData )
78  {
79  isBinaryData = _isBinaryData;
80  }
81 
83  bool GetArchiveType()
84  {
85  return isBinaryData;
86  }
87 
89  void Close();
90 
92  void Send( RTFXData * _dataToSend );
93 
95  void Send( string &_dataToSend, bool _isDataRTFX );
96 
98  void SendUpdates();
99 
101  RTFXMailbox * GetMailbox() { return &mailbox; }
102 
104  RTFXData * GetData()
105  {
106  boost::lock_guard<boost::mutex> lock( clientLock );
107  return mailbox.GetPointerToMailbox();
108  }
109 
111  void SetID( boost::uuids::uuid _id ) { id = _id; }
112 
114  boost::uuids::uuid GetID() { return id; }
115 
117  void SetMailboxName( string _mailboxName )
118  {
119  MakeMailboxIDFromString( _mailboxName, mailboxName );
120  }
121 
122 
124  char * GetMailboxName() { return mailboxName; }
125 
127  void SetFrame( AXISFRAME _frame )
128  {
129  localFrame = _frame;
130  }
131 
133  AXISFRAME GetFrame() { return localFrame; }
134 
136  void SetConnected( bool _connected ) { isConnected = _connected; }
137 
139  bool GetConnected() { return isConnected; }
140 
142  void Write( const RTFXParcel& _msg );
143 
145  bool HasNewDataArrived() { return isNewDataAvailable; }
146 
148  void SetNewDataArrived( bool _value ) { isNewDataAvailable = _value; }
149 
151  void SetDefaultCompressionType( COMPRESSIONTYPE _tmp )
152  {
153  compressionType = _tmp;
154  mailbox.SetDefaultCompressionType( _tmp );
155  }
156 
158  COMPRESSIONTYPE GetDefaultCompressionType() { return compressionType; }
159 
161  void SetServerKeepData( bool _keepData )
162  {
163  areYouKeepingDataAtServer = _keepData;
164  }
165 
167  bool GetServerKeepData()
168  {
169  return areYouKeepingDataAtServer;
170  }
171 
172  private:
175 
179 
182 
184  boost::mutex clientLock;
185 
187  void HandleConnect( const boost::system::error_code &_error, tcp::resolver::iterator _endpointIterator );
188 
190  void HandleReadHeader( const boost::system::error_code &_error );
191 
193  void HandleReadBody( const boost::system::error_code &_error );
194 
196  void DoWrite( RTFXParcel _msg );
197 
199  void HandleWrite( const boost::system::error_code &_error );
200 
202  void DoClose();
203 
206  std::map<boost::uuids::uuid, vector<RTFXParcel> > parcelCollection;
207 
209  boost::asio::io_service &ioService;
210 
212  tcp::socket socket;
213 
216 
219 
222 
224  boost::uuids::uuid id;
225 
227  char * mailboxName;
228 
230  AXISFRAME localFrame;
231 
235 
239 
242 
246 
249 
252  };
253 }
254 
255 #endif