blob: da0d649ffeadc567da8805475b05e49de6763427 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyev8722d872014-07-02 13:00:29 -07003 * Copyright (c) 2012-2014 University of California, Los Angeles
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08004 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07005 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08007 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07008 * 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 Afanasyev7a696fb2012-03-01 17:17:22 -080011 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070012 * 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 Afanasyev7a696fb2012-03-01 17:17:22 -080015 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070016 * 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 Afanasyev7a696fb2012-03-01 17:17:22 -080022 */
23
24#ifndef SYNC_DIFF_STATE_H
25#define SYNC_DIFF_STATE_H
26
27#include "sync-state.h"
Alexander Afanasyev64d50692012-03-07 20:48:35 -080028#include <iostream>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080029
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080030namespace Sync {
31
32class DiffState;
33typedef boost::shared_ptr<DiffState> DiffStatePtr;
34typedef boost::shared_ptr<DiffState> DiffStateConstPtr;
35
36/**
37 * @ingroup ccnx
38 * @brief Differential SYNC state
39 */
40class DiffState : public State
41{
42public:
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 Afanasyevd94542d2012-03-05 08:41:46 -080059 /**
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 Afanasyev7a696fb2012-03-01 17:17:22 -080065
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080066 /**
67 * @brief Get digest for the diff state
68 */
69 DigestConstPtr
70 getDigest () const { return m_digest; }
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070071
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080072 /**
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 Yu7c64e5c2014-04-30 14:06:37 -070088
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080089 // from State
Alexander Afanasyev750d1872012-03-12 15:33:56 -070090 virtual boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080091 update (NameInfoConstPtr info, const SeqNo &seq);
92
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070093 virtual bool
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080094 remove (NameInfoConstPtr info);
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070095
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080096private:
97 DiffStatePtr m_next;
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080098 DigestConstPtr m_digest;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080099};
100
101} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800102
103#endif // SYNC_DIFF_STATE_H