A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fourth.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 */
15
16#include "ns3/object.h"
17#include "ns3/simulator.h"
18#include "ns3/trace-source-accessor.h"
19#include "ns3/traced-value.h"
20#include "ns3/uinteger.h"
21
22#include <iostream>
23
24using namespace ns3;
25
26/**
27 * Tutorial 4 - a simple Object to show how to hook a trace.
28 */
29class MyObject : public Object
30{
31 public:
32 /**
33 * Register this type.
34 * \return The TypeId.
35 */
37 {
38 static TypeId tid = TypeId("MyObject")
40 .SetGroupName("Tutorial")
41 .AddConstructor<MyObject>()
42 .AddTraceSource("MyInteger",
43 "An integer value to trace.",
45 "ns3::TracedValueCallback::Int32");
46 return tid;
47 }
48
50 {
51 }
52
53 TracedValue<int32_t> m_myInt; //!< The traced value.
54};
55
56void
57IntTrace(int32_t oldValue, int32_t newValue)
58{
59 std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
60}
61
62int
63main(int argc, char* argv[])
64{
65 Ptr<MyObject> myObject = CreateObject<MyObject>();
66 myObject->TraceConnectWithoutContext("MyInteger", MakeCallback(&IntTrace));
67
68 myObject->m_myInt = 1234;
69
70 return 0;
71}
Tutorial 4 - a simple Object to show how to hook a trace.
Definition: fourth.cc:30
MyObject()
Definition: fourth.cc:49
TracedValue< int32_t > m_myInt
The traced value.
Definition: fourth.cc:53
static TypeId GetTypeId()
Register this type.
Definition: fourth.cc:36
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
void IntTrace(int32_t oldValue, int32_t newValue)
Definition: fourth.cc:57
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:706