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 <ext/hash_map> 00034 00035 namespace protlib { 00036 00037 /* @class ConnectionMap 00038 * maintains connection mapping of application addresses to sockets and vice versa 00039 * @ingroup network 00040 * @{ 00041 */ 00042 class ConnectionMap { 00043 public: 00044 // a constructor may be needed here in this class 00046 bool insert(AssocData* assoc); 00048 AssocData* lookup(socketfd_t socketfd) const; 00050 AssocData* lookup(associd_t associd) const; 00052 AssocData* lookup(const appladdress& addr) const; 00054 bool erase(socketfd_t socketfd); 00056 bool erase(associd_t associd); 00058 bool erase(AssocData* assoc); 00060 void clear(); 00062 size_t get_size() const; 00063 private: 00064 // this hash_map uses the standard hashfunction on the first entry, int 00065 00066 // only typedefs 00067 typedef hash_map<socketfd_t ,AssocData*> ass2data_t; 00068 typedef ass2data_t::const_iterator const_ass2data_it_t; 00069 typedef hash_map<appladdress,AssocData*> addr2data_t; 00070 typedef addr2data_t::const_iterator const_addr2data_it_t; 00071 00072 // internal hashmaps 00073 ass2data_t ass2data; 00074 addr2data_t addr2data; 00075 public: 00077 typedef const_ass2data_it_t const_it_t; 00078 const_it_t begin() const; 00079 const_it_t end() const; 00080 }; // end class ConnectionMap 00081 00082 inline 00083 size_t 00084 ConnectionMap::get_size() const { return ass2data.size(); } 00085 00086 inline 00087 ConnectionMap::const_it_t ConnectionMap::begin() const { 00088 return ass2data.begin(); 00089 } // end begin 00090 00091 inline 00092 ConnectionMap::const_it_t ConnectionMap::end() const { 00093 return ass2data.end(); 00094 } // end end 00095 00096 inline 00097 bool 00098 ConnectionMap::erase(AssocData* assoc) { 00099 return assoc ? erase(assoc->socketfd) : false; 00100 } // end erase 00101 00103 00104 } // end namespace protlib 00105 #endif