blob: 0e0e237cd5b3787d0ebd6cab94c902b90e2438c2 [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_STATE_H
24#define SYNC_STATE_H
25
26#include "sync-state-leaf-container.h"
27#include <boost/exception/all.hpp>
akmhoque66e66182014-02-21 17:56:03 -060028#include "sync-state.pb.h"
29
30/**
31 * \defgroup sync SYNC protocol
32 *
33 * Implementation of SYNC protocol
34 */
35namespace Sync {
36
37/**
38 * \ingroup sync
39 * @brief this prefix will be used for the dummy node which increases its sequence number whenever
Vince Lehman0a7da612014-10-29 14:39:29 -050040 * a remove operation happens; this is to prevent the reversion of root digest when we prune
akmhoque66e66182014-02-21 17:56:03 -060041 * a branch, i.e. help the root digest to be forward only
Vince Lehman0a7da612014-10-29 14:39:29 -050042 * No corresponding data msg would be published and no attempt would be made to retrieve the
akmhoque66e66182014-02-21 17:56:03 -060043 * data msg
44 */
45const std::string forwarderPrefix = "/d0n0t18ak/t0ps8cr8t";
46
47class State;
Vince Lehman0a7da612014-10-29 14:39:29 -050048typedef shared_ptr<State> StatePtr;
49typedef shared_ptr<State> StateConstPtr;
akmhoque66e66182014-02-21 17:56:03 -060050
51/**
52 * \ingroup sync
53 * @brief Container for state leaves and definition of the abstract interface to work with State objects
54 */
55class State
56{
57public:
58 virtual ~State () { };
Vince Lehman0a7da612014-10-29 14:39:29 -050059
akmhoque66e66182014-02-21 17:56:03 -060060 /**
61 * @brief Add or update leaf to the state tree
62 *
63 * @param info name of the leaf
64 * @param seq sequence number of the leaf
65 */
Vince Lehman0a7da612014-10-29 14:39:29 -050066 virtual tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
akmhoque66e66182014-02-21 17:56:03 -060067 update (NameInfoConstPtr info, const SeqNo &seq) = 0;
68
69 /**
70 * @brief Remove leaf from the state tree
71 * @param info name of the leaf
72 */
73 virtual bool
74 remove (NameInfoConstPtr info) = 0;
75
76 /**
77 * @brief Get state leaves
78 */
79 const LeafContainer &
Vince Lehman0a7da612014-10-29 14:39:29 -050080 getLeaves () const
akmhoque66e66182014-02-21 17:56:03 -060081 { return m_leaves; }
Vince Lehman0a7da612014-10-29 14:39:29 -050082
akmhoque66e66182014-02-21 17:56:03 -060083protected:
84 LeafContainer m_leaves;
85};
86
87
88/**
89 * @brief Formats a protobuf SyncStateMsg msg
90 * @param oss output SyncStateMsg msg
91 * @param state state
92 * @returns output SyncStateMsg msg
93 */
94SyncStateMsg &
95operator << (SyncStateMsg &ossm, const State &state);
96
97
98/**
99 * @brief Parse a protobuf SyncStateMsg msg
100 * @param iss input SyncStateMsg msg
101 * @param state state
102 * @returns SyncStateMsg msg
103 */
104SyncStateMsg &
105operator >> (SyncStateMsg &issm, State &state);
106
107namespace Error {
108/**
109 * @brief Will be thrown when data cannot be properly decoded to SyncStateMsg
110 */
111struct SyncStateMsgDecodingFailure : virtual boost::exception, virtual std::exception { };
112}
113
114} // Sync
115
116#endif // SYNC_STATE_H