blob: 635c0875e96408c8e2a2064b0b350cb745ffe3fe [file] [log] [blame]
Yingdi Yudea99be2014-08-15 10:45:43 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012-2014 University of California, Los Angeles
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
28#include "common.hpp"
29#include <ndn-cxx/util/digest.hpp>
30
31namespace chronosync {
32
33typedef uint64_t SeqNo;
34
35/**
36 * @brief Sync tree leaf
37 *
38 * The leaf node should be copyable when used to construct diff between two states.
39 */
40class Leaf
41{
42public:
43 Leaf(const Name& sessionName, const SeqNo& seq);
44
45 Leaf(const Name& userPrefix, uint64_t session, const SeqNo& seq);
46
47 virtual
48 ~Leaf();
49
50 const Name&
51 getSessionName() const
52 {
53 return m_sessionName;
54 }
55
56 const SeqNo&
57 getSeq() const
58 {
59 return m_seq;
60 }
61
62 ndn::ConstBufferPtr
63 getDigest() const;
64
65 /**
66 * @brief Update sequence number of the leaf
67 * @param seq Sequence number
68 *
69 * If seq is no greater than getSeq(), this operation has no effect.
70 */
71 virtual void
72 setSeq(const SeqNo& seq);
73
74private:
75 void
76 updateDigest();
77
78private:
79 Name m_sessionName;
80 SeqNo m_seq;
81
82 mutable ndn::util::Sha256 m_digest;
83};
84
85typedef boost::shared_ptr<Leaf> LeafPtr;
86typedef boost::shared_ptr<const Leaf> ConstLeafPtr;
87
88std::ostream&
89operator<<(std::ostream& os, const Leaf& leaf);
90
91} // namespace chronosync
92
93#endif // CHRONOSYNC_LEAF_HPP