Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 3 | * Copyright (c) 2012-2014 University of California, Los Angeles |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 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. |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 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. |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 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> |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef SYNC_DIFF_STATE_H |
| 25 | #define SYNC_DIFF_STATE_H |
| 26 | |
| 27 | #include "sync-state.h" |
Alexander Afanasyev | 64d5069 | 2012-03-07 20:48:35 -0800 | [diff] [blame] | 28 | #include <iostream> |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 30 | namespace Sync { |
| 31 | |
| 32 | class DiffState; |
| 33 | typedef boost::shared_ptr<DiffState> DiffStatePtr; |
| 34 | typedef boost::shared_ptr<DiffState> DiffStateConstPtr; |
| 35 | |
| 36 | /** |
| 37 | * @ingroup ccnx |
| 38 | * @brief Differential SYNC state |
| 39 | */ |
| 40 | class DiffState : public State |
| 41 | { |
| 42 | public: |
| 43 | /** |
| 44 | * @see Default constructor |
| 45 | */ |
| 46 | DiffState (); |
| 47 | virtual ~DiffState (); |
| 48 | |
| 49 | /** |
| 50 | * @brief Set successor for the diff state |
| 51 | * @param next successor state |
| 52 | */ |
| 53 | void |
| 54 | setNext (DiffStatePtr next) |
| 55 | { |
| 56 | m_next = next; |
| 57 | } |
| 58 | |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 59 | /** |
| 60 | * @brief Set digest for the diff state (obtained from a corresponding full state) |
| 61 | * @param digest A read only smart pointer to a digest object (that should be unmodified anywhere else) |
| 62 | */ |
| 63 | void |
| 64 | setDigest (DigestConstPtr digest) { m_digest = digest; } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 66 | /** |
| 67 | * @brief Get digest for the diff state |
| 68 | */ |
| 69 | DigestConstPtr |
| 70 | getDigest () const { return m_digest; } |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 72 | /** |
| 73 | * @brief Accumulate differences from `this' state to the most current state |
| 74 | * @returns Accumulated differences from `this' state to the most current state |
| 75 | */ |
| 76 | DiffStatePtr |
| 77 | diff () const; |
| 78 | |
| 79 | /** |
| 80 | * @brief Combine differences from `this' and `state' |
| 81 | * @param state Differential state to combine with |
| 82 | * @return Combined differences |
| 83 | * |
| 84 | * In case of collisions, `this' leaf will be replaced with the leaf of `state' |
| 85 | */ |
| 86 | DiffState& |
| 87 | operator += (const DiffState &state); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 89 | // from State |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 90 | virtual boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/> |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 91 | update (NameInfoConstPtr info, const SeqNo &seq); |
| 92 | |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 93 | virtual bool |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 94 | remove (NameInfoConstPtr info); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 96 | private: |
| 97 | DiffStatePtr m_next; |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 98 | DigestConstPtr m_digest; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // Sync |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 102 | |
| 103 | #endif // SYNC_DIFF_STATE_H |