blob: 4a469695b71065e45fa444d44eac4a6db8788a59 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- 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
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080028namespace Sync {
29
30class DiffState;
31typedef boost::shared_ptr<DiffState> DiffStatePtr;
32typedef boost::shared_ptr<DiffState> DiffStateConstPtr;
33
34/**
35 * @ingroup ccnx
36 * @brief Differential SYNC state
37 */
38class DiffState : public State
39{
40public:
41 /**
42 * @see Default constructor
43 */
44 DiffState ();
45 virtual ~DiffState ();
46
47 /**
48 * @brief Set successor for the diff state
49 * @param next successor state
50 */
51 void
52 setNext (DiffStatePtr next)
53 {
54 m_next = next;
55 }
56
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080057 /**
58 * @brief Set digest for the diff state (obtained from a corresponding full state)
59 * @param digest A read only smart pointer to a digest object (that should be unmodified anywhere else)
60 */
61 void
62 setDigest (DigestConstPtr digest) { m_digest = digest; }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080063
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080064 /**
65 * @brief Get digest for the diff state
66 */
67 DigestConstPtr
68 getDigest () const { return m_digest; }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080069
70 /**
71 * @brief Accumulate differences from `this' state to the most current state
72 * @returns Accumulated differences from `this' state to the most current state
73 */
74 DiffStatePtr
75 diff () const;
76
77 /**
78 * @brief Combine differences from `this' and `state'
79 * @param state Differential state to combine with
80 * @return Combined differences
81 *
82 * In case of collisions, `this' leaf will be replaced with the leaf of `state'
83 */
84 DiffState&
85 operator += (const DiffState &state);
86
87 // from State
88 virtual void
89 update (NameInfoConstPtr info, const SeqNo &seq);
90
91 virtual void
92 remove (NameInfoConstPtr info);
93
94private:
95 DiffStatePtr m_next;
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080096 DigestConstPtr m_digest;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080097};
98
99} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800100
101#endif // SYNC_DIFF_STATE_H