A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
13
using namespace
ns3
;
14
15
/**
16
* Tutorial 4 - a simple Object to show how to hook a trace.
17
*/
18
class
MyObject
:
public
Object
19
{
20
public
:
21
/**
22
* Register this type.
23
* \return The TypeId.
24
*/
25
static
TypeId
GetTypeId
()
26
{
27
static
TypeId
tid =
TypeId
(
"MyObject"
)
28
.
SetParent
<
Object
>()
29
.SetGroupName(
"Tutorial"
)
30
.AddConstructor<
MyObject
>()
31
.AddTraceSource(
"MyInteger"
,
32
"An integer value to trace."
,
33
MakeTraceSourceAccessor
(&
MyObject::m_myInt
),
34
"ns3::TracedValueCallback::Int32"
);
35
return
tid;
36
}
37
38
MyObject
()
39
{
40
}
41
42
TracedValue<int32_t>
m_myInt
;
//!< The traced value.
43
};
44
45
void
46
IntTrace
(
int32_t
oldValue,
int32_t
newValue)
47
{
48
std::cout <<
"Traced "
<< oldValue <<
" to "
<< newValue << std::endl;
49
}
50
51
int
52
main(
int
argc,
char
* argv[])
53
{
54
Ptr<MyObject>
myObject =
CreateObject<MyObject>
();
55
myObject->TraceConnectWithoutContext(
"MyInteger"
,
MakeCallback
(&
IntTrace
));
56
57
myObject->m_myInt = 1234;
58
59
return
0;
60
}
MyObject
Tutorial 4 - a simple Object to show how to hook a trace.
Definition
fourth.cc:19
MyObject::MyObject
MyObject()
Definition
fourth.cc:38
MyObject::m_myInt
TracedValue< int32_t > m_myInt
The traced value.
Definition
fourth.cc:42
MyObject::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
fourth.cc:25
int32_t
ns3::Object
A base class which provides memory management and object aggregation.
Definition
object.h:78
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::TracedValue
Trace classes with value semantics.
Definition
traced-value.h:105
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
IntTrace
void IntTrace(int32_t oldValue, int32_t newValue)
Definition
fourth.cc:46
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition
trace-source-accessor.h:198
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MakeCallback
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
examples
tutorial
fourth.cc
Generated on Fri Nov 8 2024 13:58:58 for ns-3 by
1.11.0