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 | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 3 | * 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 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 | |
| 32 | namespace nfd |
| 33 | { |
| 34 | |
| 35 | class Forwarder; |
| 36 | |
| 37 | /** \brief container of all Faces |
| 38 | */ |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 39 | class FaceTable : noncopyable |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | explicit |
| 43 | FaceTable(Forwarder& forwarder); |
| 44 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 45 | VIRTUAL_WITH_TESTS |
| 46 | ~FaceTable(); |
| 47 | |
| 48 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 49 | add(shared_ptr<Face> face); |
| 50 | |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 51 | /// add a special Face with a reserved FaceId |
| 52 | VIRTUAL_WITH_TESTS void |
| 53 | addReserved(shared_ptr<Face> face, FaceId faceId); |
| 54 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 55 | VIRTUAL_WITH_TESTS shared_ptr<Face> |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 56 | get(FaceId id) const; |
| 57 | |
| 58 | size_t |
| 59 | size() const; |
| 60 | |
| 61 | public: // enumeration |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 62 | typedef std::map<FaceId, shared_ptr<Face>> FaceMap; |
| 63 | |
| 64 | typedef boost::select_second_const_range<FaceMap> ForwardRange; |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 66 | /** \brief ForwardIterator for shared_ptr<Face> |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 67 | */ |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 68 | typedef boost::range_iterator<ForwardRange>::type const_iterator; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 70 | const_iterator |
| 71 | begin() const; |
| 72 | |
| 73 | const_iterator |
| 74 | end() const; |
| 75 | |
Junxiao Shi | bd392bf | 2014-03-17 15:54:11 -0700 | [diff] [blame] | 76 | public: // 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 Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 87 | private: |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 88 | void |
| 89 | addImpl(shared_ptr<Face> face, FaceId faceId); |
| 90 | |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 91 | // remove is private because it's a subscriber of face.onFail event. |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 92 | // face->close() closes a face and triggers .remove(face) |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 93 | void |
| 94 | remove(shared_ptr<Face> face); |
| 95 | |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 96 | ForwardRange |
| 97 | getForwardRange() const; |
| 98 | |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 99 | private: |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 100 | Forwarder& m_forwarder; |
| 101 | FaceId m_lastFaceId; |
| 102 | FaceMap m_faces; |
| 103 | }; |
| 104 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 105 | } // namespace nfd |
| 106 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 107 | #endif // NFD_DAEMON_FW_FACE_TABLE_HPP |