00001 // ---------------------------------------------------------------------------- 00002 // 00003 // $Id$ 00004 // 00005 // Copyright 2008, 2009, 2010, 2011, 2012 Antonio Franchi and Paolo Stegagno 00006 // 00007 // This file is part of MIP. 00008 // 00009 // MIP is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // MIP is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it 00023 // 00024 // ---------------------------------------------------------------------------- 00025 00032 00033 00034 #ifndef __IP_COMM_MODULE_H_ 00035 #define __IP_COMM_MODULE_H_ 00036 00037 #ifdef MIP_HOST_APPLE 00038 #include <applePatch.h> 00039 #endif 00040 00041 #include <socketUDP.h> 00042 #include "CommModule.h" 00043 #include "YellowPages.h" 00044 00045 00046 namespace MipResources{ 00047 00049 /* @{ */ 00050 00051 00052 00056 class IPCommModuleOptions : public Options { 00057 public: 00058 DecimalOption *pollTime; 00059 00061 IPCommModuleOptions(); 00062 00063 string getObjectName() const { 00064 return "IPCommModuleOptions"; 00065 } 00066 }; 00067 00071 class IPCommModule : public CommModule { 00072 00073 private: 00074 00075 pthread_mutex_t _mutex; 00076 Time _mutexTimeout; 00077 00078 YellowPages *yellowpages; 00079 00080 ListenerUDP *listener; 00081 ListenerUDP *myListener; 00082 00083 BroadcasterUDP *broadcaster; 00084 00086 vector<CommStoredPacketString> _storedPacketStrings; 00088 map<int,SenderUDP*> sockets; 00089 00090 IPCommModuleOptions _options; 00091 /*static constants*/ 00092 // static const int SENDERS_RESERV_SIZE = 100; ///< TODO */ 00093 00094 static const ResourcePlate _plate = CM_IP_RES; 00095 00096 protected: 00097 00098 Thread _IPThread; 00099 00100 public: 00101 00103 IPCommModule(int argc, const char* argv[]); 00104 00106 // IPCommModule(ScenarioType scen, int id,int argc, const char* argv[]); 00107 00109 ~IPCommModule(){ 00110 00111 delete yellowpages; 00112 00113 _storedPacketStrings.clear(); 00114 00115 delete listener; 00116 delete myListener; 00117 00118 delete broadcaster; 00119 00120 for (uint i = 0; i<sockets.size(); i++){ 00121 delete sockets[i]; 00122 } 00123 } 00124 00127 ResourcePlate getPlate() const { 00128 return _plate; 00129 } 00130 00137 void getIPAddr(int robot, IPProtocol proto, string & IPAddr, int & port); 00138 00142 SenderUDP* getSocket(int robot); 00143 00148 void IPSendPacketString(string& packetString, SenderUDP* socket); 00149 00153 void IPSendPacketString(string& packetString); 00154 00158 void IPSendPacketString(CommStoredPacketString& storedPacketString); 00159 00161 void IPReceive(); 00162 00164 void IPSend(); 00165 00169 bool sendPacketString(string& packetString, CommNode recipient); 00170 }; 00171 00172 /* @} */ 00173 00174 };// end namespace MipResources{ 00175 00176 00177 #endif 00178 00179 00180 00181 00182 00183