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