Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | d701e5b | 2017-07-26 01:30:41 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #ifndef NDN_LINK_HPP |
| 23 | #define NDN_LINK_HPP |
| 24 | |
| 25 | #include "data.hpp" |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 26 | #include "delegation-list.hpp" |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 30 | /** @brief represents a Link object |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 31 | */ |
| 32 | class Link : public Data |
| 33 | { |
| 34 | public: |
| 35 | class Error : public Data::Error |
| 36 | { |
| 37 | public: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 38 | using Data::Error::Error; |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 41 | /** @brief Create an empty Link object |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 42 | * |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 43 | * Note that in certain contexts that use Link::shared_from_this(), Link must be |
| 44 | * created using `make_shared`: |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 45 | * |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 46 | * shared_ptr<Link> linkObject = make_shared<Link>(); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 47 | */ |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 48 | Link(); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 49 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 50 | /** @brief Decode a Link object from a Block |
| 51 | * @param wire a TLV block |
| 52 | * @param wantSort if false, relative order among delegations is preserved |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 53 | * |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 54 | * Note that in certain contexts that use Link::shared_from_this(), Link must be |
| 55 | * created using `make_shared`: |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 56 | * |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 57 | * shared_ptr<Link> linkObject = make_shared<Link>(block); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 58 | */ |
| 59 | explicit |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 60 | Link(const Block& wire, bool wantSort = true); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 62 | /** @brief Create a Link object with the given name and delegations |
| 63 | * @param name A reference to the name of the redirected namespace |
| 64 | * @param dels Delegations in payload |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 65 | * |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 66 | * Note that in certain contexts that use Link::shared_from_this(), Link must be |
| 67 | * created using `make_shared`: |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 68 | * |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 69 | * shared_ptr<Link> link = make_shared<Link>(name, dels); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 70 | */ |
| 71 | explicit |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 72 | Link(const Name& name, std::initializer_list<Delegation> dels = {}); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 73 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 74 | /** @brief Decode from the wire format |
| 75 | * @param wire a TLV block |
| 76 | * @param wantSort if false, relative order among delegations is preserved |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 77 | */ |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 78 | void |
| 79 | wireDecode(const Block& wire, bool wantSort = true); |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 81 | /** @brief Get the delegations |
| 82 | */ |
| 83 | const DelegationList& |
| 84 | getDelegationList() const |
| 85 | { |
| 86 | return m_delList; |
| 87 | } |
| 88 | |
| 89 | /** @brief Set the delegations |
| 90 | * @note This is more efficient than multiple addDelegation and removeDelegation invocations. |
| 91 | */ |
| 92 | void |
| 93 | setDelegationList(const DelegationList& dels); |
| 94 | |
| 95 | /** @brief Add a delegation in the format of <Name, Preference> |
| 96 | * @param preference The preference of the delegation to be added |
| 97 | * @param name The name of the delegation to be added |
| 98 | * @note If a delegation with @p name exists, its preference will be updated |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 99 | */ |
| 100 | void |
| 101 | addDelegation(uint32_t preference, const Name& name); |
| 102 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 103 | /** @brief Remove a delegation whose name is @p name |
| 104 | * @param name The name of the delegation to be removed |
| 105 | * @return true if delegation is removed, otherwise false |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 106 | */ |
| 107 | bool |
| 108 | removeDelegation(const Name& name); |
| 109 | |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 110 | private: |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 111 | void |
| 112 | encodeContent(); |
| 113 | |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 114 | private: |
Junxiao Shi | d21abd3 | 2017-06-30 02:56:40 +0000 | [diff] [blame] | 115 | DelegationList m_delList; |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } // namespace ndn |
| 119 | |
| 120 | #endif // NDN_LINK_HPP |