00001 /* 00002 * sender.h 00003 * 00004 * Created on: Jan 10, 2012 00005 * Author: sushil 00006 */ 00007 00008 #ifndef SENDER_H_ 00009 #define SENDER_H_ 00010 00011 #include <boost/asio.hpp> 00012 #include <boost/thread.hpp> 00013 using boost::asio::ip::udp; 00014 00015 #include <deque> 00016 00017 #include <messages.h> 00018 00019 namespace FastEcslent { 00020 00021 class Engine; 00022 00023 class Sender { //receive update 00024 private: 00025 00026 boost::thread senderThread; 00027 udp::socket *socket;//(netService); 00028 udp::endpoint myIP;; 00029 int port; 00030 bool isServer; 00031 void runThread(); 00032 bool quit; 00033 00034 int SERVER_SLEEP_TIME; 00035 int CLIENT_SLEEP_TIME; 00036 boost::posix_time::milliseconds *sleepTime; 00037 00038 boost::mutex quitLock; 00039 // helpers 00040 00041 //ThreadTester *gimPtr; 00042 00043 public: 00044 std::deque<Message *> sendBuffer; 00045 Sender(udp::endpoint ip, int prt, bool isserv){ 00046 myIP = ip; 00047 port = prt; 00048 isServer = isserv; 00049 } 00050 void init(); 00051 void run(); 00052 void join(); 00053 void stop(); 00054 void kill(); 00055 00056 //helpers 00057 //threadsafe helpers 00058 void addMessage(Message *); 00059 void addPriorityMessage(Message *); 00060 Message* dequeMessage(); 00061 }; 00062 00063 } 00064 00065 #endif /* SENDER_H_ */