blob: 2f692eed76765bb905db8c10c42e067494c55515 [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_LEAF_H
25#define SYNC_DIFF_LEAF_H
26
27#include "sync-leaf.h"
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080028#include <boost/exception/all.hpp>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080029
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080030namespace Sync {
31
32/**
33 * @ingroup sync
34 * @brief Annotation for SYNC leaf
35 */
36enum Operation
37 {
38 UPDATE, ///< @brief Leaf was added or updated
39 REMOVE ///< @brief Leaf was removed
40 };
41
42/**
43 * @ingroup sync
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070044 * @brief Annotated SYNC leaf
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080045 */
46class DiffLeaf : public Leaf
47{
48public:
49 /**
50 * @brief Constructor to create an UPDATE diff leaf
51 * @param info Smart pointer to leaf's name
52 * @param seq Initial sequence number of the pointer
53 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080054 DiffLeaf (NameInfoConstPtr info, const SeqNo &seq);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080055
56 /**
57 * @brief Constructor to create an REMOVE diff leaf
58 * @param info Smart pointer to leaf's name
59 *
60 * This constructor creates a leaf with phony sequence number
61 * with 0 session ID and 0 sequence number
62 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080063 DiffLeaf (NameInfoConstPtr info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080064
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080065 virtual ~DiffLeaf () { }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080066
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080067 /**
68 * @brief Get diff leaf type
69 */
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080070 Operation
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080071 getOperation () const { return m_op; }
72
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080073private:
74 Operation m_op;
75};
76
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080077typedef boost::shared_ptr<DiffLeaf> DiffLeafPtr;
Alexander Afanasyev750d1872012-03-12 15:33:56 -070078typedef boost::shared_ptr<const DiffLeaf> DiffLeafConstPtr;
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080079
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080080std::ostream &
81operator << (std::ostream &os, Operation op);
82
83std::istream &
84operator >> (std::istream &is, Operation &op);
85
Alexander Afanasyevc1030192012-03-08 22:21:28 -080086namespace Error {
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080087struct SyncDiffLeafOperationParseError : virtual boost::exception, virtual std::exception { };
Alexander Afanasyevc1030192012-03-08 22:21:28 -080088} // Error
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080089
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080090} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080091
92#endif // SYNC_DIFF_LEAF_H