spirosmastorakis | 0e2b197 | 2016-03-27 20:54:41 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of the nTorrent codebase. |
| 6 | * |
| 7 | * nTorrent 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 | * nTorrent 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 nTorrent, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS for complete list of nTorrent authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include <ndn-cxx/name.hpp> |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ntorrent { |
| 26 | |
| 27 | /** |
| 28 | * @brief Represents a record of the stats table |
| 29 | */ |
| 30 | class StatsTableRecord { |
| 31 | public: |
| 32 | class Error : public std::runtime_error |
| 33 | { |
| 34 | public: |
| 35 | explicit |
| 36 | Error(const std::string& what) |
| 37 | : std::runtime_error(what) |
| 38 | { |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * @brief Create a new empty record |
| 44 | */ |
| 45 | StatsTableRecord() = default; |
| 46 | |
| 47 | /** |
| 48 | * @brief Create a new record |
| 49 | * @param recordName The name of this record |
| 50 | */ |
| 51 | StatsTableRecord(const Name& recordName); |
| 52 | |
| 53 | /** |
| 54 | * @brief Copy constructor |
| 55 | * @param record An StatsTableRecord object |
| 56 | */ |
| 57 | StatsTableRecord(const StatsTableRecord& record); |
| 58 | |
| 59 | ~StatsTableRecord() = default; |
| 60 | |
| 61 | /** |
| 62 | * @brief Get the name of a record |
| 63 | */ |
| 64 | const Name& |
| 65 | getRecordName() const; |
| 66 | |
| 67 | /** |
| 68 | * @brief Get the number of sent interests of a record |
| 69 | */ |
| 70 | uint64_t |
| 71 | getRecordSentInterests() const; |
| 72 | |
| 73 | /** |
| 74 | * @brief Get the number of received data packets of a record |
| 75 | */ |
| 76 | uint64_t |
| 77 | getRecordReceivedData() const; |
| 78 | |
| 79 | /** |
| 80 | * @brief Get the success rate of a record |
| 81 | */ |
| 82 | double |
| 83 | getRecordSuccessRate() const; |
| 84 | |
| 85 | /** |
| 86 | * @brief Increment the number of sent interests for a record |
| 87 | */ |
| 88 | void |
| 89 | incrementSentInterests(); |
| 90 | |
| 91 | /** |
| 92 | * @brief Increment the number of received data packets for a record |
| 93 | */ |
| 94 | void |
| 95 | incrementReceivedData(); |
| 96 | |
| 97 | /** |
| 98 | * @brief Assignment operator |
| 99 | */ |
| 100 | StatsTableRecord& |
| 101 | operator=(const StatsTableRecord& other); |
| 102 | |
| 103 | private: |
| 104 | Name m_recordName; |
| 105 | uint64_t m_sentInterests; |
| 106 | uint64_t m_receivedData; |
| 107 | double m_successRate; |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * @brief Equality operator |
| 112 | */ |
| 113 | bool |
| 114 | operator==(const StatsTableRecord& lhs, const StatsTableRecord& rhs); |
| 115 | |
| 116 | /** |
| 117 | * @brief Inequality operator |
| 118 | */ |
| 119 | bool |
| 120 | operator!=(const StatsTableRecord& lhs, const StatsTableRecord& rhs); |
| 121 | |
| 122 | inline const Name& |
| 123 | StatsTableRecord::getRecordName() const |
| 124 | { |
| 125 | return m_recordName; |
| 126 | } |
| 127 | |
| 128 | inline uint64_t |
| 129 | StatsTableRecord::getRecordSentInterests() const |
| 130 | { |
| 131 | return m_sentInterests; |
| 132 | } |
| 133 | |
| 134 | inline uint64_t |
| 135 | StatsTableRecord::getRecordReceivedData() const |
| 136 | { |
| 137 | return m_receivedData; |
| 138 | } |
| 139 | |
| 140 | inline double |
| 141 | StatsTableRecord::getRecordSuccessRate() const |
| 142 | { |
| 143 | return m_successRate; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | } // namespace ntorrent |
| 148 | } // namespace ndn |