blob: 70ceb11c527c61c283a9c0545eaad54bc9c1ddae [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
32namespace nfd
33{
34
35class Forwarder;
36
37/** \brief container of all Faces
38 */
Junxiao Shi7b984c62014-07-17 22:18:34 -070039class FaceTable : noncopyable
Junxiao Shia4f2be82014-03-02 22:56:41 -070040{
41public:
42 explicit
43 FaceTable(Forwarder& forwarder);
44
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070045 VIRTUAL_WITH_TESTS
46 ~FaceTable();
47
48 VIRTUAL_WITH_TESTS void
Junxiao Shia4f2be82014-03-02 22:56:41 -070049 add(shared_ptr<Face> face);
50
Junxiao Shi7b984c62014-07-17 22:18:34 -070051 /// add a special Face with a reserved FaceId
52 VIRTUAL_WITH_TESTS void
53 addReserved(shared_ptr<Face> face, FaceId faceId);
54
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070055 VIRTUAL_WITH_TESTS shared_ptr<Face>
Junxiao Shia4f2be82014-03-02 22:56:41 -070056 get(FaceId id) const;
57
58 size_t
59 size() const;
60
61public: // enumeration
Junxiao Shiafbd74d2014-11-29 21:18:17 -070062 typedef std::map<FaceId, shared_ptr<Face>> FaceMap;
63
64 typedef boost::select_second_const_range<FaceMap> ForwardRange;
Junxiao Shia4f2be82014-03-02 22:56:41 -070065
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070066 /** \brief ForwardIterator for shared_ptr<Face>
Junxiao Shia4f2be82014-03-02 22:56:41 -070067 */
Junxiao Shiafbd74d2014-11-29 21:18:17 -070068 typedef boost::range_iterator<ForwardRange>::type const_iterator;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070069
Junxiao Shia4f2be82014-03-02 22:56:41 -070070 const_iterator
71 begin() const;
72
73 const_iterator
74 end() const;
75
Junxiao Shibd392bf2014-03-17 15:54:11 -070076public: // events
77 /** \brief fires after a Face is added
78 */
79 EventEmitter<shared_ptr<Face> > onAdd;
80
81 /** \brief fires before a Face is removed
82 *
83 * FaceId is valid when this event is fired
84 */
85 EventEmitter<shared_ptr<Face> > onRemove;
86
Junxiao Shia4f2be82014-03-02 22:56:41 -070087private:
Junxiao Shi7b984c62014-07-17 22:18:34 -070088 void
89 addImpl(shared_ptr<Face> face, FaceId faceId);
90
Junxiao Shic542b2b2014-03-16 21:45:52 -070091 // remove is private because it's a subscriber of face.onFail event.
Junxiao Shi7b984c62014-07-17 22:18:34 -070092 // face->close() closes a face and triggers .remove(face)
Junxiao Shic542b2b2014-03-16 21:45:52 -070093 void
94 remove(shared_ptr<Face> face);
95
Junxiao Shiafbd74d2014-11-29 21:18:17 -070096 ForwardRange
97 getForwardRange() const;
98
Junxiao Shic542b2b2014-03-16 21:45:52 -070099private:
Junxiao Shia4f2be82014-03-02 22:56:41 -0700100 Forwarder& m_forwarder;
101 FaceId m_lastFaceId;
102 FaceMap m_faces;
103};
104
Junxiao Shia4f2be82014-03-02 22:56:41 -0700105} // namespace nfd
106
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700107#endif // NFD_DAEMON_FW_FACE_TABLE_HPP