blob: 96597d08c02253ae5d01ce669134a4d89357be75 [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>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_FULL_STATE_H
24#define SYNC_FULL_STATE_H
25
Alexander Afanasyev146a51b2012-03-05 10:47:35 -080026#ifndef STANDALONE
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080027#include "ns3/nstime.h"
Alexander Afanasyev146a51b2012-03-05 10:47:35 -080028typedef ns3::Time TimeType;
29typedef ns3::Time TimeDurationType;
30#else
31#include <boost/date_time/posix_time/posix_time_types.hpp>
32typedef boost::posix_time::ptime TimeType;
33typedef boost::posix_time::time_duration TimeDurationType;
34#endif // STANDALONE
35
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080036#include "sync-state.h"
37
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080038namespace Sync {
39
40/**
41 * \ingroup sync
42 * @brief Cumulative SYNC state
43 */
44class FullState : public State
45{
46public:
47 /**
48 * @brief Default constructor
49 */
50 FullState ();
51 virtual ~FullState ();
52
53 /**
54 * @brief Get time period since last state update
55 *
56 * This value can be used to randomize reconciliation waiting time in SyncApp
57 */
Alexander Afanasyev146a51b2012-03-05 10:47:35 -080058 TimeDurationType
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080059 getTimeFromLastUpdate () const;
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080060
61 /**
62 * @brief Obtain a read-only copy of the digest
63 *
64 * If m_digest is 0, then it is automatically created. On every update and removal, m_digest is reset to 0
65 */
66 DigestConstPtr
67 getDigest ();
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080068
69 // from State
70 virtual void
71 update (NameInfoConstPtr info, const SeqNo &seq);
72
73 virtual void
74 remove (NameInfoConstPtr info);
75
76private:
Alexander Afanasyev146a51b2012-03-05 10:47:35 -080077 TimeType m_lastUpdated; ///< @brief Time when state was updated last time
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080078 DigestPtr m_digest;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080079};
80
Alexander Afanasyev64d50692012-03-07 20:48:35 -080081/**
82 * @brief Formats an XML representation of the full state
83 * @param os output stream
84 * @param state state
85 * @returns output stream
86 */
87std::ostream &
88operator << (std::ostream &os, const FullState &state);
89
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080090
91} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080092
93#endif // SYNC_STATE_H