00001 00002 00003 00004 00005 00006 00007 // =========================================================== 00008 // 00009 // Copyright (C) 2005-2007, all rights reserved by 00010 // - Institute of Telematics, Universitaet Karlsruhe (TH) 00011 // 00012 // More information and contact: 00013 // https://projekte.tm.uka.de/trac/NSIS 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; version 2 of the License 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License along 00025 // with this program; if not, write to the Free Software Foundation, Inc., 00026 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00027 // 00028 // =========================================================== 00029 #ifndef CONNECTION_MAP_H 00030 #define CONNECTION_MAP_H 00031 00032 #include "assocdata.h" 00033 #include <boost/unordered_map.hpp> 00034 using boost::unordered_map; 00035 00036 namespace protlib { 00037 00038 00039 00040 /* @class ConnectionMap 00041 * maintains connection mapping of application addresses to sockets and vice versa 00042 * @ingroup network 00043 * @{ 00044 */ 00045 class ConnectionMap { 00046 public: 00047 // a constructor may be needed here in this class 00049 bool insert(AssocData* assoc); 00051 AssocData* lookup(socketfd_t socketfd) const; 00053 AssocData* lookup(associd_t associd) const; 00055 AssocData* lookup(const appladdress& addr) const; 00057 bool erase(socketfd_t socketfd); 00059 bool erase(associd_t associd); 00061 bool erase(AssocData* assoc); 00063 void clear(); 00065 size_t get_size() const; 00066 private: 00067 // this unordered_map uses the standard hashfunction on the first entry, int 00068 00069 // only typedefs 00070 typedef unordered_map<socketfd_t ,AssocData*> ass2data_t; 00071 typedef ass2data_t::const_iterator const_ass2data_it_t; 00072 typedef unordered_map<appladdress,AssocData*> addr2data_t; 00073 typedef addr2data_t::const_iterator const_addr2data_it_t; 00074 00075 // internal hashmaps 00076 ass2data_t ass2data; 00077 addr2data_t addr2data; 00078 public: 00080 typedef const_ass2data_it_t const_it_t; 00081 const_it_t begin() const; 00082 const_it_t end() const; 00083 }; // end class ConnectionMap 00084 00085 inline 00086 size_t 00087 ConnectionMap::get_size() const { return ass2data.size(); } 00088 00089 inline 00090 ConnectionMap::const_it_t ConnectionMap::begin() const { 00091 return ass2data.begin(); 00092 } // end begin 00093 00094 inline 00095 ConnectionMap::const_it_t ConnectionMap::end() const { 00096 return ass2data.end(); 00097 } // end end 00098 00099 inline 00100 bool 00101 ConnectionMap::erase(AssocData* assoc) { 00102 return assoc ? erase(assoc->socketfd) : false; 00103 } // end erase 00104 00106 00107 } // end namespace protlib 00108 #endif