blob: 67c79324cd2a016820efd90283703d90b2ae4313 [file] [log] [blame]
Junxiao Shia4f2be82014-03-02 22:56:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi7b984c62014-07-17 22:18:34 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi7b984c62014-07-17 22:18:34 -070024 */
Junxiao Shia4f2be82014-03-02 22:56:41 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FW_FACE_TABLE_HPP
27#define NFD_DAEMON_FW_FACE_TABLE_HPP
Junxiao Shia4f2be82014-03-02 22:56:41 -070028
29#include "face/face.hpp"
Junxiao Shiafbd74d2014-11-29 21:18:17 -070030#include <boost/range/adaptor/map.hpp>
Junxiao Shia4f2be82014-03-02 22:56:41 -070031
Junxiao Shi1e064172014-12-14 19:37:46 -070032namespace nfd {
Junxiao Shia4f2be82014-03-02 22:56:41 -070033
34class Forwarder;
35
36/** \brief container of all Faces
37 */
Junxiao Shi7b984c62014-07-17 22:18:34 -070038class FaceTable : noncopyable
Junxiao Shia4f2be82014-03-02 22:56:41 -070039{
40public:
41 explicit
42 FaceTable(Forwarder& forwarder);
43
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070044 VIRTUAL_WITH_TESTS
45 ~FaceTable();
46
47 VIRTUAL_WITH_TESTS void
Junxiao Shia4f2be82014-03-02 22:56:41 -070048 add(shared_ptr<Face> face);
49
Junxiao Shi7b984c62014-07-17 22:18:34 -070050 /// add a special Face with a reserved FaceId
51 VIRTUAL_WITH_TESTS void
52 addReserved(shared_ptr<Face> face, FaceId faceId);
53
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070054 VIRTUAL_WITH_TESTS shared_ptr<Face>
Junxiao Shia4f2be82014-03-02 22:56:41 -070055 get(FaceId id) const;
56
57 size_t
58 size() const;
59
60public: // enumeration
Junxiao Shiafbd74d2014-11-29 21:18:17 -070061 typedef std::map<FaceId, shared_ptr<Face>> FaceMap;
62
63 typedef boost::select_second_const_range<FaceMap> ForwardRange;
Junxiao Shia4f2be82014-03-02 22:56:41 -070064
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070065 /** \brief ForwardIterator for shared_ptr<Face>
Junxiao Shia4f2be82014-03-02 22:56:41 -070066 */
Junxiao Shiafbd74d2014-11-29 21:18:17 -070067 typedef boost::range_iterator<ForwardRange>::type const_iterator;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070068
Junxiao Shia4f2be82014-03-02 22:56:41 -070069 const_iterator
70 begin() const;
71
72 const_iterator
73 end() const;
74
Junxiao Shi1e064172014-12-14 19:37:46 -070075public: // signals
Junxiao Shibd392bf2014-03-17 15:54:11 -070076 /** \brief fires after a Face is added
77 */
Junxiao Shi1e064172014-12-14 19:37:46 -070078 signal::Signal<FaceTable, shared_ptr<Face>> onAdd;
Junxiao Shibd392bf2014-03-17 15:54:11 -070079
80 /** \brief fires before a Face is removed
81 *
82 * FaceId is valid when this event is fired
83 */
Junxiao Shi1e064172014-12-14 19:37:46 -070084 signal::Signal<FaceTable, shared_ptr<Face>> onRemove;
Junxiao Shibd392bf2014-03-17 15:54:11 -070085
Junxiao Shia4f2be82014-03-02 22:56:41 -070086private:
Junxiao Shi7b984c62014-07-17 22:18:34 -070087 void
88 addImpl(shared_ptr<Face> face, FaceId faceId);
89
Davide Pesavento66ff0982015-01-29 22:39:00 +010090 // remove is private because it's a handler of face.onFail signal.
91 // face->close() closes the face and triggers .remove()
Junxiao Shic542b2b2014-03-16 21:45:52 -070092 void
Davide Pesavento66ff0982015-01-29 22:39:00 +010093 remove(shared_ptr<Face> face, const std::string& reason);
Junxiao Shic542b2b2014-03-16 21:45:52 -070094
Junxiao Shiafbd74d2014-11-29 21:18:17 -070095 ForwardRange
96 getForwardRange() const;
97
Junxiao Shic542b2b2014-03-16 21:45:52 -070098private:
Junxiao Shia4f2be82014-03-02 22:56:41 -070099 Forwarder& m_forwarder;
100 FaceId m_lastFaceId;
101 FaceMap m_faces;
102};
103
Junxiao Shia4f2be82014-03-02 22:56:41 -0700104} // namespace nfd
105
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700106#endif // NFD_DAEMON_FW_FACE_TABLE_HPP