author | Tom Henderson <tomh@tomh.org> |
Thu, 01 Oct 2015 11:07:22 -0700 | |
changeset 11677 | 1e2add816314 |
parent 11598 | b4d1339b4913 |
permissions | -rw-r--r-- |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
*/ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
#include "ns3/object.h" |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
#include "ns3/uinteger.h" |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#include "ns3/traced-value.h" |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
#include "ns3/trace-source-accessor.h" |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include <iostream> |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
5382
diff
changeset
|
23 |
|
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
using namespace ns3; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
class MyObject : public Object |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
public: |
11432
d2656819dd54
Fix parents, group names, and missing constructors in GetTypeId definitions.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10978
diff
changeset
|
29 |
/** |
d2656819dd54
Fix parents, group names, and missing constructors in GetTypeId definitions.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10978
diff
changeset
|
30 |
* Register this type. |
d2656819dd54
Fix parents, group names, and missing constructors in GetTypeId definitions.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10978
diff
changeset
|
31 |
* \return The TypeId. |
d2656819dd54
Fix parents, group names, and missing constructors in GetTypeId definitions.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10978
diff
changeset
|
32 |
*/ |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
static TypeId GetTypeId (void) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
static TypeId tid = TypeId ("MyObject") |
11432
d2656819dd54
Fix parents, group names, and missing constructors in GetTypeId definitions.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10978
diff
changeset
|
36 |
.SetParent<Object> () |
d2656819dd54
Fix parents, group names, and missing constructors in GetTypeId definitions.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10978
diff
changeset
|
37 |
.SetGroupName ("Tutorial") |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
.AddConstructor<MyObject> () |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
.AddTraceSource ("MyInteger", |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
"An integer value to trace.", |
10978
754c8256c35c
TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
7256
diff
changeset
|
41 |
MakeTraceSourceAccessor (&MyObject::m_myInt), |
11598
b4d1339b4913
Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
11432
diff
changeset
|
42 |
"ns3::TracedValueCallback::Int32") |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
5382
diff
changeset
|
43 |
; |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
return tid; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
} |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
5382
diff
changeset
|
46 |
|
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
MyObject () {} |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
TracedValue<int32_t> m_myInt; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
}; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
void |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
IntTrace (int32_t oldValue, int32_t newValue) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
std::cout << "Traced " << oldValue << " to " << newValue << std::endl; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
} |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
int |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
main (int argc, char *argv[]) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
Ptr<MyObject> myObject = CreateObject<MyObject> (); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
61 |
myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback (&IntTrace)); |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
myObject->m_myInt = 1234; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
} |