author | Peter D. Barnes, Jr. <barnes26@llnl.gov> |
Thu, 02 Oct 2014 21:17:48 -0700 | |
changeset 10978 | 754c8256c35c |
parent 7256 | b04ba6772f8c |
child 11432 | d2656819dd54 |
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: |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
static TypeId GetTypeId (void) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
static TypeId tid = TypeId ("MyObject") |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
.SetParent (Object::GetTypeId ()) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
.AddConstructor<MyObject> () |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
.AddTraceSource ("MyInteger", |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
"An integer value to trace.", |
10978
754c8256c35c
TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
7256
diff
changeset
|
36 |
MakeTraceSourceAccessor (&MyObject::m_myInt), |
754c8256c35c
TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
7256
diff
changeset
|
37 |
"ns3::TracedValue::Int32Callback") |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
5382
diff
changeset
|
38 |
; |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
return tid; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
} |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
5382
diff
changeset
|
41 |
|
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
MyObject () {} |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
TracedValue<int32_t> m_myInt; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
}; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
void |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
IntTrace (int32_t oldValue, int32_t newValue) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
std::cout << "Traced " << oldValue << " to " << newValue << std::endl; |
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 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
int |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
main (int argc, char *argv[]) |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
{ |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
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
|
56 |
myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback (&IntTrace)); |
5382
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
|
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
myObject->m_myInt = 1234; |
0a46f4d86040
Words about tracing in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
} |