Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FW_FACE_TABLE_HPP |
| 27 | #define NFD_DAEMON_FW_FACE_TABLE_HPP |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 28 | |
| 29 | #include "face/face.hpp" |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 30 | #include <boost/range/adaptor/map.hpp> |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 31 | |
Junxiao Shi | 1e06417 | 2014-12-14 19:37:46 -0700 | [diff] [blame] | 32 | namespace nfd { |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 33 | |
| 34 | class Forwarder; |
| 35 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame^] | 36 | /** \brief container of all faces |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 37 | */ |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 38 | class FaceTable : noncopyable |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | explicit |
| 42 | FaceTable(Forwarder& forwarder); |
| 43 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 44 | VIRTUAL_WITH_TESTS |
| 45 | ~FaceTable(); |
| 46 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame^] | 47 | /** \brief add a face |
| 48 | * |
| 49 | * FaceTable obtains shared ownership of the face. |
| 50 | * The channel or protocol factory that creates the face may retain ownership. |
| 51 | */ |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 52 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 53 | add(shared_ptr<Face> face); |
| 54 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame^] | 55 | /** \brief add a special Face with a reserved FaceId |
| 56 | */ |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 57 | VIRTUAL_WITH_TESTS void |
| 58 | addReserved(shared_ptr<Face> face, FaceId faceId); |
| 59 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame^] | 60 | /** \brief get face by FaceId |
| 61 | * \return a face if found, nullptr if not found; |
| 62 | * face->shared_from_this() can be used if shared_ptr<Face> is desired |
| 63 | */ |
| 64 | VIRTUAL_WITH_TESTS Face* |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 65 | get(FaceId id) const; |
| 66 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame^] | 67 | /** \return count of faces |
| 68 | */ |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 69 | size_t |
| 70 | size() const; |
| 71 | |
| 72 | public: // enumeration |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 73 | typedef std::map<FaceId, shared_ptr<Face>> FaceMap; |
| 74 | |
| 75 | typedef boost::select_second_const_range<FaceMap> ForwardRange; |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 77 | /** \brief ForwardIterator for shared_ptr<Face> |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 78 | */ |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 79 | typedef boost::range_iterator<ForwardRange>::type const_iterator; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 81 | const_iterator |
| 82 | begin() const; |
| 83 | |
| 84 | const_iterator |
| 85 | end() const; |
| 86 | |
Junxiao Shi | 1e06417 | 2014-12-14 19:37:46 -0700 | [diff] [blame] | 87 | public: // signals |
Junxiao Shi | bd392bf | 2014-03-17 15:54:11 -0700 | [diff] [blame] | 88 | /** \brief fires after a Face is added |
| 89 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 90 | signal::Signal<FaceTable, shared_ptr<Face>> afterAdd; |
Junxiao Shi | bd392bf | 2014-03-17 15:54:11 -0700 | [diff] [blame] | 91 | |
| 92 | /** \brief fires before a Face is removed |
| 93 | * |
| 94 | * FaceId is valid when this event is fired |
| 95 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 96 | signal::Signal<FaceTable, shared_ptr<Face>> beforeRemove; |
Junxiao Shi | bd392bf | 2014-03-17 15:54:11 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 98 | private: |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 99 | void |
| 100 | addImpl(shared_ptr<Face> face, FaceId faceId); |
| 101 | |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 102 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 103 | remove(shared_ptr<Face> face); |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 104 | |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 105 | ForwardRange |
| 106 | getForwardRange() const; |
| 107 | |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 108 | private: |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 109 | Forwarder& m_forwarder; |
| 110 | FaceId m_lastFaceId; |
| 111 | FaceMap m_faces; |
| 112 | }; |
| 113 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 114 | } // namespace nfd |
| 115 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 116 | #endif // NFD_DAEMON_FW_FACE_TABLE_HPP |