blob: b7e948fd20aa9d51253be32e4d19abb30e15adf4 [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
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080034namespace Sync {
35
36
37FullState::FullState ()
38 : m_lastUpdated (0)
39{
40}
41
42FullState::~FullState ()
43{
44}
45
Alexander Afanasyev017784c2012-03-02 11:44:13 -080046ns3::Time
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080047FullState::getTimeFromLastUpdate () const
48{
Alexander Afanasyev017784c2012-03-02 11:44:13 -080049 return ns3::Simulator::Now () - m_lastUpdated;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080050}
51
52// from State
53void
54FullState::update (NameInfoConstPtr info, const SeqNo &seq)
55{
Alexander Afanasyev017784c2012-03-02 11:44:13 -080056 m_lastUpdated = ns3::Simulator::Now ();
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080057
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080058 LeafContainer::iterator item = m_leaves.find (*info);
59 if (item == m_leaves.end ())
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080060 {
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080061 m_leaves.insert (make_shared<Leaf> (info, cref (seq)));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080062 }
63 else
64 {
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080065 m_leaves.modify (item, ll::bind (&Leaf::setSeq, *ll::_1, seq));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080066 }
67}
68
69void
70FullState::remove (NameInfoConstPtr info)
71{
Alexander Afanasyev017784c2012-03-02 11:44:13 -080072 m_lastUpdated = ns3::Simulator::Now ();
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080073
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080074 m_leaves.erase (*info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080075}
76
77
78} // Sync