OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2015 Bucknell University |
| 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: Li Li (ll024@bucknell.edu) |
| 19 */ |
| 20 |
| 21 #include "ns3/object.h" |
| 22 #include "ns3/log.h" |
| 23 #include "ns3/simulator.h" |
| 24 #include "ns3/event-driven-collector.h" |
| 25 |
| 26 |
| 27 NS_LOG_COMPONENT_DEFINE ("EventDrivenCollector"); |
| 28 |
| 29 namespace ns3 { |
| 30 |
| 31 NS_OBJECT_ENSURE_REGISTERED (EventDrivenCollector); |
| 32 |
| 33 TypeId |
| 34 EventDrivenCollector::GetTypeId (void) |
| 35 { |
| 36 static TypeId tid = TypeId ("ns3::EventDrivenCollector") |
| 37 .SetParent<Collector> () |
| 38 .AddConstructor<EventDrivenCollector> () |
| 39 .AddTraceSource ("Output", |
| 40 "The double value received by the trace sink", |
| 41 MakeTraceSourceAccessor (&EventDrivenCollector::m_output), |
| 42 "ns3::DataCollectionObject::CollectorTraceCallback") |
| 43 ; |
| 44 return tid; |
| 45 } |
| 46 |
| 47 EventDrivenCollector::EventDrivenCollector () |
| 48 : Collector () |
| 49 { |
| 50 NS_LOG_FUNCTION (this); |
| 51 } |
| 52 |
| 53 EventDrivenCollector::~EventDrivenCollector () |
| 54 { |
| 55 NS_LOG_FUNCTION (this); |
| 56 } |
| 57 |
| 58 void |
| 59 EventDrivenCollector::TraceSinkDouble (double oldValue, double newValue) |
| 60 { |
| 61 NS_LOG_FUNCTION (this << oldValue << newValue); |
| 62 if (!IsEnabled ()) |
| 63 { |
| 64 NS_LOG_DEBUG ("Collector not enabled"); |
| 65 return; |
| 66 } |
| 67 m_doubleValue = newValue; |
| 68 |
| 69 // Report data to downstream objects |
| 70 ReportData (); |
| 71 } |
| 72 |
| 73 void |
| 74 EventDrivenCollector::ReportData (void) |
| 75 { |
| 76 NS_LOG_FUNCTION (this); |
| 77 if (!IsEnabled ()) |
| 78 { |
| 79 return; |
| 80 } |
| 81 // get current simulation time |
| 82 double time = Simulator::Now ().GetSeconds (); |
| 83 |
| 84 // report the time and the newly received value to downstream |
| 85 // objects |
| 86 m_output (time, m_doubleValue); |
| 87 } |
| 88 |
| 89 } // namespace ns3 |
OLD | NEW |