blob: fd80809a24d1fe76515813c92de28999ad8abebf [file] [log] [blame]
akmhoque66e66182014-02-21 17:56:03 -06001/* -*- 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>
Vince Lehman0a7da612014-10-29 14:39:29 -050020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
akmhoque66e66182014-02-21 17:56:03 -060021 */
22
23#ifndef SYNC_DIFF_STATE_H
24#define SYNC_DIFF_STATE_H
25
26#include "sync-state.h"
27#include <iostream>
28
29namespace Sync {
30
31class DiffState;
Vince Lehman0a7da612014-10-29 14:39:29 -050032typedef shared_ptr<DiffState> DiffStatePtr;
33typedef shared_ptr<DiffState> DiffStateConstPtr;
akmhoque66e66182014-02-21 17:56:03 -060034
35/**
36 * @ingroup ccnx
37 * @brief Differential SYNC state
38 */
39class DiffState : public State
40{
41public:
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; }
Vince Lehman0a7da612014-10-29 14:39:29 -050070
akmhoque66e66182014-02-21 17:56:03 -060071 /**
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);
Vince Lehman0a7da612014-10-29 14:39:29 -050087
akmhoque66e66182014-02-21 17:56:03 -060088 // from State
Vince Lehman0a7da612014-10-29 14:39:29 -050089 virtual tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
akmhoque66e66182014-02-21 17:56:03 -060090 update (NameInfoConstPtr info, const SeqNo &seq);
91
92 virtual bool
93 remove (NameInfoConstPtr info);
Vince Lehman0a7da612014-10-29 14:39:29 -050094
akmhoque66e66182014-02-21 17:56:03 -060095private:
96 DiffStatePtr m_next;
97 DigestConstPtr m_digest;
98};
99
100} // Sync
101
102#endif // SYNC_DIFF_STATE_H