A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
24
using namespace
ns3
;
25
29
class
MyObject
:
public
Object
30
{
31
public
:
36
static
TypeId
GetTypeId
()
37
{
38
static
TypeId
tid =
TypeId
(
"MyObject"
)
39
.
SetParent
<
Object
>()
40
.SetGroupName(
"Tutorial"
)
41
.AddConstructor<
MyObject
>()
42
.AddTraceSource(
"MyInteger"
,
43
"An integer value to trace."
,
44
MakeTraceSourceAccessor
(&
MyObject::m_myInt
),
45
"ns3::TracedValueCallback::Int32"
);
46
return
tid;
47
}
48
49
MyObject
()
50
{
51
}
52
53
TracedValue<int32_t>
m_myInt
;
54
};
55
56
void
57
IntTrace
(int32_t oldValue, int32_t newValue)
58
{
59
std::cout <<
"Traced "
<< oldValue <<
" to "
<< newValue << std::endl;
60
}
61
62
int
63
main(
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
}
MyObject
Tutorial 4 - a simple Object to show how to hook a trace.
Definition:
fourth.cc:30
MyObject::MyObject
MyObject()
Definition:
fourth.cc:49
MyObject::m_myInt
TracedValue< int32_t > m_myInt
The traced value.
Definition:
fourth.cc:53
MyObject::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
fourth.cc:36
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:89
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::TracedValue< int32_t >
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
IntTrace
void IntTrace(int32_t oldValue, int32_t newValue)
Definition:
fourth.cc:57
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:209
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:704
examples
tutorial
fourth.cc
Generated on Sun Mar 3 2024 17:10:52 for ns-3 by
1.9.1