Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #ifndef SYNC_DIFF_STATE_H |
| 24 | #define SYNC_DIFF_STATE_H |
| 25 | |
| 26 | #include "sync-state.h" |
Alexander Afanasyev | 64d5069 | 2012-03-07 20:48:35 -0800 | [diff] [blame] | 27 | #include <iostream> |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 29 | namespace Sync { |
| 30 | |
| 31 | class DiffState; |
| 32 | typedef boost::shared_ptr<DiffState> DiffStatePtr; |
| 33 | typedef boost::shared_ptr<DiffState> DiffStateConstPtr; |
| 34 | |
| 35 | /** |
| 36 | * @ingroup ccnx |
| 37 | * @brief Differential SYNC state |
| 38 | */ |
| 39 | class DiffState : public State |
| 40 | { |
| 41 | public: |
| 42 | /** |
| 43 | * @see Default constructor |
| 44 | */ |
| 45 | DiffState (); |
| 46 | virtual ~DiffState (); |
| 47 | |
| 48 | /** |
| 49 | * @brief Set successor for the diff state |
| 50 | * @param next successor state |
| 51 | */ |
| 52 | void |
| 53 | setNext (DiffStatePtr next) |
| 54 | { |
| 55 | m_next = next; |
| 56 | } |
| 57 | |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 58 | /** |
| 59 | * @brief Set digest for the diff state (obtained from a corresponding full state) |
| 60 | * @param digest A read only smart pointer to a digest object (that should be unmodified anywhere else) |
| 61 | */ |
| 62 | void |
| 63 | setDigest (DigestConstPtr digest) { m_digest = digest; } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 65 | /** |
| 66 | * @brief Get digest for the diff state |
| 67 | */ |
| 68 | DigestConstPtr |
| 69 | getDigest () const { return m_digest; } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @brief Accumulate differences from `this' state to the most current state |
| 73 | * @returns Accumulated differences from `this' state to the most current state |
| 74 | */ |
| 75 | DiffStatePtr |
| 76 | diff () const; |
| 77 | |
| 78 | /** |
| 79 | * @brief Combine differences from `this' and `state' |
| 80 | * @param state Differential state to combine with |
| 81 | * @return Combined differences |
| 82 | * |
| 83 | * In case of collisions, `this' leaf will be replaced with the leaf of `state' |
| 84 | */ |
| 85 | DiffState& |
| 86 | operator += (const DiffState &state); |
| 87 | |
| 88 | // from State |
| 89 | virtual void |
| 90 | update (NameInfoConstPtr info, const SeqNo &seq); |
| 91 | |
| 92 | virtual void |
| 93 | remove (NameInfoConstPtr info); |
| 94 | |
| 95 | private: |
| 96 | DiffStatePtr m_next; |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 97 | DigestConstPtr m_digest; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
Alexander Afanasyev | 64d5069 | 2012-03-07 20:48:35 -0800 | [diff] [blame] | 100 | /** |
| 101 | * @brief Formats an XML representation of the diff state |
| 102 | * @param os output stream |
| 103 | * @param state state |
| 104 | * @returns output stream |
| 105 | */ |
| 106 | std::ostream & |
| 107 | operator << (std::ostream &os, const DiffState &state); |
| 108 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 109 | } // Sync |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 110 | |
| 111 | #endif // SYNC_DIFF_STATE_H |