Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 3 | * Copyright (c) 2012-2021 University of California, Los Angeles |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
| 7 | * |
| 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
| 20 | * @author Chaoyi Bian <bcy@pku.edu.cn> |
| 21 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
| 22 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
| 23 | */ |
| 24 | |
| 25 | #ifndef CHRONOSYNC_LEAF_HPP |
| 26 | #define CHRONOSYNC_LEAF_HPP |
| 27 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 28 | #include "detail/common.hpp" |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 29 | |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/sha256.hpp> |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 31 | |
| 32 | namespace chronosync { |
| 33 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 34 | using SeqNo = uint64_t; |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * @brief Sync tree leaf |
| 38 | * |
| 39 | * The leaf node should be copyable when used to construct diff between two states. |
| 40 | */ |
| 41 | class Leaf |
| 42 | { |
| 43 | public: |
| 44 | Leaf(const Name& sessionName, const SeqNo& seq); |
| 45 | |
| 46 | Leaf(const Name& userPrefix, uint64_t session, const SeqNo& seq); |
| 47 | |
| 48 | virtual |
| 49 | ~Leaf(); |
| 50 | |
| 51 | const Name& |
| 52 | getSessionName() const |
| 53 | { |
| 54 | return m_sessionName; |
| 55 | } |
| 56 | |
| 57 | const SeqNo& |
| 58 | getSeq() const |
| 59 | { |
| 60 | return m_seq; |
| 61 | } |
| 62 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 63 | ConstBufferPtr |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 64 | getDigest() const; |
| 65 | |
| 66 | /** |
| 67 | * @brief Update sequence number of the leaf |
| 68 | * @param seq Sequence number |
| 69 | * |
| 70 | * If seq is no greater than getSeq(), this operation has no effect. |
| 71 | */ |
| 72 | virtual void |
| 73 | setSeq(const SeqNo& seq); |
| 74 | |
| 75 | private: |
| 76 | void |
| 77 | updateDigest(); |
| 78 | |
| 79 | private: |
| 80 | Name m_sessionName; |
| 81 | SeqNo m_seq; |
| 82 | |
| 83 | mutable ndn::util::Sha256 m_digest; |
| 84 | }; |
| 85 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 86 | using LeafPtr = shared_ptr<Leaf>; |
| 87 | using ConstLeafPtr = shared_ptr<const Leaf>; |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 88 | |
| 89 | std::ostream& |
| 90 | operator<<(std::ostream& os, const Leaf& leaf); |
| 91 | |
| 92 | } // namespace chronosync |
| 93 | |
| 94 | #endif // CHRONOSYNC_LEAF_HPP |