blob: ffd3120ce19a85f7df9bf011acff5a17d450d5f3 [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#include "sync-full-state.h"
24
25#include "ns3/simulator.h"
26
27#include <boost/make_shared.hpp>
28#include <boost/lambda/lambda.hpp>
29#include <boost/lambda/bind.hpp>
30
31using namespace boost;
32namespace ll = boost::lambda;
33
34namespace ns3 {
35namespace Sync {
36
37
38FullState::FullState ()
39 : m_lastUpdated (0)
40{
41}
42
43FullState::~FullState ()
44{
45}
46
47Time
48FullState::getTimeFromLastUpdate () const
49{
50 return Simulator::Now () - m_lastUpdated;
51}
52
53// from State
54void
55FullState::update (NameInfoConstPtr info, const SeqNo &seq)
56{
57 m_lastUpdated = Simulator::Now ();
58
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080059 LeafContainer::iterator item = m_leaves.find (*info);
60 if (item == m_leaves.end ())
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080061 {
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080062 m_leaves.insert (make_shared<Leaf> (info, cref (seq)));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080063 }
64 else
65 {
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080066 m_leaves.modify (item, ll::bind (&Leaf::setSeq, *ll::_1, seq));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080067 }
68}
69
70void
71FullState::remove (NameInfoConstPtr info)
72{
73 m_lastUpdated = Simulator::Now ();
74
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080075 m_leaves.erase (*info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080076}
77
78
79} // Sync
80} // ns3