blob: 4119c959131b7270f3344a8f704082bd2f8f79ae [file] [log] [blame]
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2014 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
*
* ChronoSync is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
* @author Chaoyi Bian <bcy@pku.edu.cn>
* @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
*/
#ifndef SYNC_STATE_H
#define SYNC_STATE_H
#include "sync-state-leaf-container.h"
#include <boost/exception/all.hpp>
#include "boost/tuple/tuple.hpp"
#include "sync-state.pb.h"
/**
* \defgroup sync SYNC protocol
*
* Implementation of SYNC protocol
*/
namespace Sync {
/**
* \ingroup sync
* @brief this prefix will be used for the dummy node which increases its sequence number whenever
* a remove operation happens; this is to prevent the reversion of root digest when we prune
* a branch, i.e. help the root digest to be forward only
* No corresponding data msg would be published and no attempt would be made to retrieve the
* data msg
*/
const std::string forwarderPrefix = "/d0n0t18ak/t0ps8cr8t";
class State;
typedef boost::shared_ptr<State> StatePtr;
typedef boost::shared_ptr<State> StateConstPtr;
/**
* \ingroup sync
* @brief Container for state leaves and definition of the abstract interface to work with State objects
*/
class State
{
public:
virtual ~State () { };
/**
* @brief Add or update leaf to the state tree
*
* @param info name of the leaf
* @param seq sequence number of the leaf
*/
virtual boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
update (NameInfoConstPtr info, const SeqNo &seq) = 0;
/**
* @brief Remove leaf from the state tree
* @param info name of the leaf
*/
virtual bool
remove (NameInfoConstPtr info) = 0;
/**
* @brief Get state leaves
*/
const LeafContainer &
getLeaves () const
{ return m_leaves; }
protected:
LeafContainer m_leaves;
};
/**
* @brief Formats a protobuf SyncStateMsg msg
* @param oss output SyncStateMsg msg
* @param state state
* @returns output SyncStateMsg msg
*/
SyncStateMsg &
operator << (SyncStateMsg &ossm, const State &state);
/**
* @brief Parse a protobuf SyncStateMsg msg
* @param iss input SyncStateMsg msg
* @param state state
* @returns SyncStateMsg msg
*/
SyncStateMsg &
operator >> (SyncStateMsg &issm, State &state);
namespace Error {
/**
* @brief Will be thrown when data cannot be properly decoded to SyncStateMsg
*/
struct SyncStateMsgDecodingFailure : virtual boost::exception, virtual std::exception { };
}
} // Sync
#endif // SYNC_STATE_H