akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [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" |
| 27 | #include <iostream> |
| 28 | |
| 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 | |
| 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; } |
| 64 | |
| 65 | /** |
| 66 | * @brief Get digest for the diff state |
| 67 | */ |
| 68 | DigestConstPtr |
| 69 | getDigest () const { return m_digest; } |
| 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 boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/> |
| 90 | update (NameInfoConstPtr info, const SeqNo &seq); |
| 91 | |
| 92 | virtual bool |
| 93 | remove (NameInfoConstPtr info); |
| 94 | |
| 95 | private: |
| 96 | DiffStatePtr m_next; |
| 97 | DigestConstPtr m_digest; |
| 98 | }; |
| 99 | |
| 100 | } // Sync |
| 101 | |
| 102 | #endif // SYNC_DIFF_STATE_H |