Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 31 | using namespace boost; |
| 32 | namespace ll = boost::lambda; |
| 33 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 34 | namespace Sync { |
| 35 | |
| 36 | |
| 37 | FullState::FullState () |
| 38 | : m_lastUpdated (0) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | FullState::~FullState () |
| 43 | { |
| 44 | } |
| 45 | |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame^] | 46 | ns3::Time |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 47 | FullState::getTimeFromLastUpdate () const |
| 48 | { |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame^] | 49 | return ns3::Simulator::Now () - m_lastUpdated; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // from State |
| 53 | void |
| 54 | FullState::update (NameInfoConstPtr info, const SeqNo &seq) |
| 55 | { |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame^] | 56 | m_lastUpdated = ns3::Simulator::Now (); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 58 | LeafContainer::iterator item = m_leaves.find (*info); |
| 59 | if (item == m_leaves.end ()) |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 60 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 61 | m_leaves.insert (make_shared<Leaf> (info, cref (seq))); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 62 | } |
| 63 | else |
| 64 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 65 | m_leaves.modify (item, ll::bind (&Leaf::setSeq, *ll::_1, seq)); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | FullState::remove (NameInfoConstPtr info) |
| 71 | { |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame^] | 72 | m_lastUpdated = ns3::Simulator::Now (); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 74 | m_leaves.erase (*info); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | } // Sync |