A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fourth.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "ns3/object.h"
6#include "ns3/simulator.h"
7#include "ns3/trace-source-accessor.h"
8#include "ns3/traced-value.h"
9#include "ns3/uinteger.h"
10
11#include <iostream>
12
13using namespace ns3;
14
15/**
16 * Tutorial 4 - a simple Object to show how to hook a trace.
17 */
18class MyObject : public Object
19{
20 public:
21 /**
22 * Register this type.
23 * \return The TypeId.
24 */
26 {
27 static TypeId tid = TypeId("MyObject")
29 .SetGroupName("Tutorial")
30 .AddConstructor<MyObject>()
31 .AddTraceSource("MyInteger",
32 "An integer value to trace.",
34 "ns3::TracedValueCallback::Int32");
35 return tid;
36 }
37
39 {
40 }
41
42 TracedValue<int32_t> m_myInt; //!< The traced value.
43};
44
45void
46IntTrace(int32_t oldValue, int32_t newValue)
47{
48 std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
49}
50
51int
52main(int argc, char* argv[])
53{
55 myObject->TraceConnectWithoutContext("MyInteger", MakeCallback(&IntTrace));
56
57 myObject->m_myInt = 1234;
58
59 return 0;
60}
Tutorial 4 - a simple Object to show how to hook a trace.
Definition fourth.cc:19
MyObject()
Definition fourth.cc:38
TracedValue< int32_t > m_myInt
The traced value.
Definition fourth.cc:42
static TypeId GetTypeId()
Register this type.
Definition fourth.cc:25
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Trace classes with value semantics.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
void IntTrace(int32_t oldValue, int32_t newValue)
Definition fourth.cc:46
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
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:684