A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
time-series-adaptor.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 University of Washington
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: Mitch Watrous (watrous@u.washington.edu)
19  */
20 
21 #include <cmath>
22 #include <cfloat>
23 
24 #include "ns3/time-series-adaptor.h"
25 #include "ns3/object.h"
26 #include "ns3/traced-value.h"
27 #include "ns3/log.h"
28 #include "ns3/simulator.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("TimeSeriesAdaptor");
31 
32 namespace ns3 {
33 
34 NS_OBJECT_ENSURE_REGISTERED (TimeSeriesAdaptor);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::TimeSeriesAdaptor")
41  .AddConstructor<TimeSeriesAdaptor> ()
42  .AddTraceSource ( "Output",
43  "The current simulation time versus the current value converted to a double",
45  ;
46  return tid;
47 }
48 
50 {
51  NS_LOG_FUNCTION (this);
52 }
53 
55 {
56  NS_LOG_FUNCTION (this);
57 }
58 
59 void
60 TimeSeriesAdaptor::TraceSinkDouble (double oldData, double newData)
61 {
62  NS_LOG_FUNCTION (this << oldData << newData);
63 
64  // Don't do anything if the time series adaptor is not enabled.
65  if (!IsEnabled ())
66  {
67  NS_LOG_DEBUG ("Time series adaptor not enabled");
68  return;
69  }
70 
71  // Time stamp the value with the current time in seconds.
72  m_output (Simulator::Now ().GetSeconds (), newData);
73 }
74 
75 void
76 TimeSeriesAdaptor::TraceSinkBoolean (bool oldData, bool newData)
77 {
78  NS_LOG_FUNCTION (this << oldData << newData);
79 
80  // Call the trace sink that actually does something.
81  TraceSinkDouble (oldData, newData);
82 }
83 
84 void
85 TimeSeriesAdaptor::TraceSinkUinteger8 (uint8_t oldData, uint8_t newData)
86 {
87  NS_LOG_FUNCTION (this << oldData << newData);
88 
89  // Call the trace sink that actually does something.
90  TraceSinkDouble (oldData, newData);
91 }
92 
93 void
94 TimeSeriesAdaptor::TraceSinkUinteger16 (uint16_t oldData, uint16_t newData)
95 {
96  NS_LOG_FUNCTION (this << oldData << newData);
97 
98  // Call the trace sink that actually does something.
99  TraceSinkDouble (oldData, newData);
100 }
101 
102 void
103 TimeSeriesAdaptor::TraceSinkUinteger32 (uint32_t oldData, uint32_t newData)
104 {
105  NS_LOG_FUNCTION (this << oldData << newData);
106 
107  // Call the trace sink that actually does something.
108  TraceSinkDouble (oldData, newData);
109 }
110 
111 } // namespace ns3
112