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