netThread.h

Go to the documentation of this file.
00001 /*
00002  * netThread.h
00003  *
00004  *  Created on: Jan 10, 2012
00005  *      Author: sushil
00006  */
00007 
00008 #ifndef NETTHREAD_H_
00009 #define NETTHREAD_H_
00010 
00011 #include <deque>
00012 
00013 //#include <engine.h>
00014 #include <boost/asio.hpp>
00015 #include <boost/thread.hpp>
00016 //#include <boost/date_time/posix_time/posix_time.hpp>
00017 
00018 #include <messages.h>
00019 #include <listener.h>
00020 #include <sender.h>
00021 
00022 #include <boost/date_time/posix_time/posix_time.hpp>
00023 using namespace boost::posix_time;
00024 
00025 
00026 using boost::asio::ip::udp;
00027 
00028 namespace FastEcslent {
00029 
00030         class Engine;
00031 
00032         class NetThread { //package and copy sim state to/from broadcaster and listener threads
00033 
00034         private:
00035                 void runThread();
00036                 boost::thread netThread;
00037                 boost::posix_time::milliseconds *serverSleepTime;
00038                 ptime  startTime;
00039                 bool quit;
00040 
00041 
00042         protected:
00043                 udp::endpoint getMyIP();
00044                 int port;
00045                 bool isServer;
00046                 udp::endpoint myIP;
00047 
00048         public:
00049                 Engine* engine;
00050                 /*
00051                 std::deque <Message *> recBuffer;
00052                 std::deque <Message *> sendBuffer;
00053                 void queMessage(Message *m);
00054                 Message *dequeMessage();
00055 */
00056                 Listener*    listener;
00057                 Sender*      sender;
00058 
00059                 NetThread(Engine* eng) {
00060                         engine = eng;
00061                 }
00062                 void run();
00063                 void init();
00064                 void stopAndJoin();
00065                 void stop();
00066 
00067                 //helpers
00068                 void clientTick();
00069                      void updateState();
00070                      void sendCommands();
00071 
00072                 void serverTick();
00073                         void handleClientMessages();
00074                                 Message* getMessage();
00075                                 void handleMessage(Message *m);
00076                                 void sendInfo(Message *m);
00077 
00078                         void serve();
00079 
00080         };
00081 
00082 }
00083 
00084 #endif /* NETTHREAD_H_ */

Generated on Fri Dec 13 14:54:16 2013 for FastECSLent by  doxygen 1.5.4