| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2014-2022, Regents of the University of California, |
| * Arizona Board of Regents, |
| * Colorado State University, |
| * University Pierre & Marie Curie, Sorbonne University, |
| * Washington University in St. Louis, |
| * Beijing Institute of Technology, |
| * The University of Memphis. |
| * |
| * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| * See AUTHORS.md for complete list of NFD authors and contributors. |
| * |
| * NFD is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #ifndef NFD_DAEMON_FW_FACE_TABLE_HPP |
| #define NFD_DAEMON_FW_FACE_TABLE_HPP |
| |
| #include "face/face.hpp" |
| |
| #include <boost/range/adaptor/indirected.hpp> |
| #include <boost/range/adaptor/map.hpp> |
| |
| namespace nfd { |
| |
| /** |
| * \brief Container of all faces. |
| */ |
| class FaceTable : noncopyable |
| { |
| public: |
| /** \brief Add a face. |
| * |
| * FaceTable obtains shared ownership of the face. |
| * The channel or protocol factory that creates the face may retain ownership. |
| */ |
| void |
| add(shared_ptr<Face> face); |
| |
| /** \brief Add a special face with a reserved FaceId. |
| */ |
| void |
| addReserved(shared_ptr<Face> face, FaceId faceId); |
| |
| /** \brief Get face by FaceId. |
| * \return A pointer to the face if found, nullptr otherwise; |
| * `face->shared_from_this()` can be used if a `shared_ptr` is desired. |
| */ |
| Face* |
| get(FaceId id) const noexcept; |
| |
| /** \brief Return the total number of faces. |
| */ |
| size_t |
| size() const noexcept; |
| |
| public: // enumeration |
| using FaceMap = std::map<FaceId, shared_ptr<Face>>; |
| using ForwardRange = boost::indirected_range<const boost::select_second_const_range<FaceMap>>; |
| using const_iterator = boost::range_iterator<ForwardRange>::type; |
| |
| const_iterator |
| begin() const; |
| |
| const_iterator |
| end() const; |
| |
| public: // signals |
| /** \brief Fires immediately after a face is added. |
| */ |
| signal::Signal<FaceTable, Face> afterAdd; |
| |
| /** \brief Fires immediately before a face is removed. |
| * |
| * When this signal is emitted, the face is still in FaceTable and has a valid FaceId. |
| */ |
| signal::Signal<FaceTable, Face> beforeRemove; |
| |
| private: |
| void |
| addImpl(shared_ptr<Face> face, FaceId faceId); |
| |
| void |
| remove(FaceId faceId); |
| |
| ForwardRange |
| getForwardRange() const; |
| |
| private: |
| FaceId m_lastFaceId = face::FACEID_RESERVED_MAX; |
| FaceMap m_faces; |
| }; |
| |
| } // namespace nfd |
| |
| #endif // NFD_DAEMON_FW_FACE_TABLE_HPP |