source: source/ariba/utility/transport/tcpip/protlib/connectionmap.h@ 7038

Last change on this file since 7038 was 6922, checked in by mies, 14 years ago

replaced deprecated hash_map, hash_set classes with boost
added unsigned serialization
fixed more warnings
included -Wall to Makefile.am

File size: 3.6 KB
Line 
1/// ----------------------------------------*- mode: C++; -*--
2/// @file connectionmap.h
3/// maintains connection mapping of application addresses to sockets and vice versa
4/// ----------------------------------------------------------
5/// $Id: connectionmap.h 2549 2007-04-02 22:17:37Z bless $
6/// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/include/connectionmap.h $
7// ===========================================================
8//
9// Copyright (C) 2005-2007, all rights reserved by
10// - Institute of Telematics, Universitaet Karlsruhe (TH)
11//
12// More information and contact:
13// https://projekte.tm.uka.de/trac/NSIS
14//
15// This program is free software; you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation; version 2 of the License
18//
19// This program is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License along
25// with this program; if not, write to the Free Software Foundation, Inc.,
26// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27//
28// ===========================================================
29#ifndef CONNECTION_MAP_H
30#define CONNECTION_MAP_H
31
32#include "assocdata.h"
33#include <boost/unordered_map.hpp>
34using boost::unordered_map;
35
36namespace protlib {
37
38
39
40/* @class ConnectionMap
41 * maintains connection mapping of application addresses to sockets and vice versa
42 * @ingroup network
43 * @{
44 */
45class ConnectionMap {
46 public:
47 // a constructor may be needed here in this class
48 /// Insert a new AssocData element into the ConnectionMap
49 bool insert(AssocData* assoc);
50 /// Search for existing connections to this specific socket
51 AssocData* lookup(socketfd_t socketfd) const;
52 /// Search for existing connections to this specific assoc id
53 AssocData* lookup(associd_t associd) const;
54 ///Search for existing connections to this address
55 AssocData* lookup(const appladdress& addr) const;
56 /// Erase the AssocData-element associated with this socket
57 bool erase(socketfd_t socketfd);
58 /// Erase the AssocData-element associated with this socket
59 bool erase(associd_t associd);
60 /// Erase the AssocData-element
61 bool erase(AssocData* assoc);
62 /// clear all
63 void clear();
64 /// get number of records
65 size_t get_size() const;
66 private:
67 // this unordered_map uses the standard hashfunction on the first entry, int
68
69 // only typedefs
70 typedef unordered_map<socketfd_t ,AssocData*> ass2data_t;
71 typedef ass2data_t::const_iterator const_ass2data_it_t;
72 typedef unordered_map<appladdress,AssocData*> addr2data_t;
73 typedef addr2data_t::const_iterator const_addr2data_it_t;
74
75 // internal hashmaps
76 ass2data_t ass2data; ///< map: socket fd to association data
77 addr2data_t addr2data; ///< map: (application) address to association data
78 public:
79 /// connection map iterator
80 typedef const_ass2data_it_t const_it_t;
81 const_it_t begin() const;
82 const_it_t end() const;
83}; // end class ConnectionMap
84
85inline
86size_t
87ConnectionMap::get_size() const { return ass2data.size(); }
88
89inline
90ConnectionMap::const_it_t ConnectionMap::begin() const {
91 return ass2data.begin();
92} // end begin
93
94inline
95ConnectionMap::const_it_t ConnectionMap::end() const {
96 return ass2data.end();
97} // end end
98
99inline
100bool
101ConnectionMap::erase(AssocData* assoc) {
102 return assoc ? erase(assoc->socketfd) : false;
103} // end erase
104
105//@}
106
107} // end namespace protlib
108#endif
Note: See TracBrowser for help on using the repository browser.