blob: 826e84db6962a934d56f37c6fcc7689efe44caa2 [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>
Chaoyi Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_STATE_H
24#define SYNC_STATE_H
25
26#include "sync-state-leaf-container.h"
Alexander Afanasyev44a5fbe2012-03-08 14:15:25 -080027#include <boost/exception/all.hpp>
Alexander Afanasyev750d1872012-03-12 15:33:56 -070028#include "boost/tuple/tuple.hpp"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080029
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080030/**
31 * \defgroup sync SYNC protocol
32 *
33 * Implementation of SYNC protocol
34 */
35namespace Sync {
36
Alexander Afanasyevf3c03a92012-05-09 12:00:37 -070037class State;
38typedef boost::shared_ptr<State> StatePtr;
39typedef boost::shared_ptr<State> StateConstPtr;
40
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080041/**
42 * \ingroup sync
43 * @brief Container for state leaves and definition of the abstract interface to work with State objects
44 */
45class State
46{
47public:
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080048 virtual ~State () { };
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080049
50 /**
51 * @brief Add or update leaf to the state tree
52 *
53 * @param info name of the leaf
54 * @param seq sequence number of the leaf
55 */
Alexander Afanasyev750d1872012-03-12 15:33:56 -070056 virtual boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080057 update (NameInfoConstPtr info, const SeqNo &seq) = 0;
58
59 /**
60 * @brief Remove leaf from the state tree
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080061 * @param info name of the leaf
62 */
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070063 virtual bool
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080064 remove (NameInfoConstPtr info) = 0;
65
Alexander Afanasyeva5625322012-03-06 00:03:41 -080066 /**
67 * @brief Get state leaves
68 */
69 const LeafContainer &
70 getLeaves () const
71 { return m_leaves; }
72
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080073protected:
74 LeafContainer m_leaves;
75};
76
Alexander Afanasyev44a5fbe2012-03-08 14:15:25 -080077/**
78 * @brief Formats an XML representation of the state
79 * @param os output stream
80 * @param state state
81 * @returns output stream
82 */
83std::ostream &
84operator << (std::ostream &os, const State &state);
85
86/**
87 * @brief Parses an XML representation to the state
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080088 * @param in input data stream
Alexander Afanasyev44a5fbe2012-03-08 14:15:25 -080089 * @param state state
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080090 * @returns input stream
Alexander Afanasyev44a5fbe2012-03-08 14:15:25 -080091 */
Alexander Afanasyev44a5fbe2012-03-08 14:15:25 -080092std::istream &
93operator >> (std::istream &in, State &state);
94
Alexander Afanasyevc1030192012-03-08 22:21:28 -080095namespace Error {
Alexander Afanasyev44a5fbe2012-03-08 14:15:25 -080096/**
97 * @brief Will be thrown when XML cannot be properly decoded to State
98 */
99struct SyncXmlDecodingFailure : virtual boost::exception, virtual std::exception { };
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800100}
Alexander Afanasyev64d50692012-03-07 20:48:35 -0800101
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800102} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800103
104#endif // SYNC_STATE_H