Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, 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. |
| 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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "core/logger.hpp" |
| 27 | #include "propagated-entry.hpp" |
| 28 | |
| 29 | namespace nfd { |
| 30 | namespace rib { |
| 31 | |
| 32 | void |
| 33 | operator<<(std::ostream& out, PropagationStatus status) |
| 34 | { |
| 35 | switch (status) { |
| 36 | case PropagationStatus::NEW: |
| 37 | out << "NEW"; |
| 38 | break; |
| 39 | case PropagationStatus::PROPAGATING: |
| 40 | out << "PROPAGATING"; |
| 41 | break; |
| 42 | case PropagationStatus::PROPAGATED: |
| 43 | out << "PROPAGATED"; |
| 44 | break; |
| 45 | case PropagationStatus::PROPAGATE_FAIL: |
| 46 | out << "PROPAGATE_FAIL"; |
| 47 | break; |
| 48 | default: |
| 49 | out << "undefined status"; |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | PropagatedEntry::PropagatedEntry() |
| 55 | : m_propagationStatus(PropagationStatus::NEW) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | PropagatedEntry::PropagatedEntry(const PropagatedEntry& other) |
| 60 | : m_signingIdentity(other.m_signingIdentity) |
| 61 | , m_propagationStatus(other.m_propagationStatus) |
| 62 | { |
| 63 | BOOST_ASSERT(!other.isPropagated() && !other.isPropagateFail()); |
| 64 | } |
| 65 | |
| 66 | PropagatedEntry& |
| 67 | PropagatedEntry::setSigningIdentity(const Name& identity) |
| 68 | { |
| 69 | m_signingIdentity = identity; |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | const Name& |
| 74 | PropagatedEntry::getSigningIdentity() const |
| 75 | { |
| 76 | return m_signingIdentity; |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | PropagatedEntry::startPropagation() |
| 81 | { |
| 82 | m_propagationStatus = PropagationStatus::PROPAGATING; |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | PropagatedEntry::succeed(const scheduler::EventId& event) |
| 87 | { |
| 88 | m_propagationStatus = PropagationStatus::PROPAGATED; |
| 89 | m_rePropagateEvent = event; |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | PropagatedEntry::fail(const scheduler::EventId& event) |
| 94 | { |
| 95 | m_propagationStatus = PropagationStatus::PROPAGATE_FAIL; |
| 96 | m_rePropagateEvent = event; |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | PropagatedEntry::initialize() |
| 101 | { |
| 102 | m_propagationStatus = PropagationStatus::NEW; |
| 103 | m_rePropagateEvent.cancel(); |
| 104 | } |
| 105 | |
| 106 | bool |
| 107 | PropagatedEntry::isNew() const |
| 108 | { |
| 109 | return PropagationStatus::NEW == m_propagationStatus; |
| 110 | } |
| 111 | |
| 112 | bool |
| 113 | PropagatedEntry::isPropagating() const |
| 114 | { |
| 115 | return PropagationStatus::PROPAGATING == m_propagationStatus; |
| 116 | } |
| 117 | |
| 118 | bool |
| 119 | PropagatedEntry::isPropagated() const |
| 120 | { |
| 121 | return PropagationStatus::PROPAGATED == m_propagationStatus; |
| 122 | } |
| 123 | |
| 124 | bool |
| 125 | PropagatedEntry::isPropagateFail() const |
| 126 | { |
| 127 | return PropagationStatus::PROPAGATE_FAIL == m_propagationStatus; |
| 128 | } |
| 129 | |
| 130 | } // namespace rib |
| 131 | } // namespace nfd |