Bug 50 - The example code on the page Low-level tracing page does not compile
The example code on the page Low-level tracing page does not compile
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: documentation
pre-release
PC Linux
: P3 major
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-07-13 15:11 EDT by Emmanuelle Laprise
Modified: 2007-07-18 10:37 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emmanuelle Laprise 2007-07-13 15:11:33 EDT
I am trying to create a trace sink to do some tracing. I tried to follow the example on the Low-level tracing page in the Doxygen documentation.

There are two problems:
1) The code:
 void MyTraceSink (TraceContext const &context, Packet &packet)
 {
   NodeList::Index index;
   context.Get (index);
   std::cout << "node id=" << NodeList::GetNode (index)->GetId () << std::endl;
 }

Should be changed to:


 void MyTraceSink (TraceContext const &context, Packet &packet)
 {
   NodeList::NodeIndex index;
   context.Get (index);
   std::cout << "node id=" << NodeList::GetNode (index)->GetId () << std::endl;
 }

2) The command:
   TraceRoot::Connect ("/nodes/ * / Ipv4 / *", MakeCallback (&TraceSink::MyTraceSink));
Which I assume can be put in the main file gives the following compile error:
examples/simple-multipoint.cc:154: error: no matching function for call to 'MakeCallback(void (ns3::TraceSink::*)(const ns3::TraceContext&, ns3::Packet&))'

Now, if I have that command in another class, I can use:
TraceRoot::Connect ("/nodes/ * / Ipv4 / *", MakeCallback (&TraceSink::MyTraceSink, this));

What does the "this" do?

Thanks,

Emmanuelle
Comment 1 Mathieu Lacage 2007-07-14 05:51:15 EDT
(In reply to comment #0)
> I am trying to create a trace sink to do some tracing. I tried to follow the
> example on the Low-level tracing page in the Doxygen documentation.
> 
> There are two problems:
> 1) The code:
>  void MyTraceSink (TraceContext const &context, Packet &packet)
>  {
>    NodeList::Index index;
>    context.Get (index);
>    std::cout << "node id=" << NodeList::GetNode (index)->GetId () << std::endl;
>  }
> 
> Should be changed to:
> 
> 
>  void MyTraceSink (TraceContext const &context, Packet &packet)
>  {
>    NodeList::NodeIndex index;
>    context.Get (index);
>    std::cout << "node id=" << NodeList::GetNode (index)->GetId () << std::endl;
>  }

can you push a patch which fixes this ?

> 
> 2) The command:
>    TraceRoot::Connect ("/nodes/ * / Ipv4 / *", MakeCallback
> (&TraceSink::MyTraceSink));
> Which I assume can be put in the main file gives the following compile error:
> examples/simple-multipoint.cc:154: error: no matching function for call to
> 'MakeCallback(void (ns3::TraceSink::*)(const ns3::TraceContext&,
> ns3::Packet&))'
> 
> Now, if I have that command in another class, I can use:
> TraceRoot::Connect ("/nodes/ * / Ipv4 / *", MakeCallback
> (&TraceSink::MyTraceSink, this));
> 
> What does the "this" do?

I suspect that you have defined MyTraceSink as a member method rather than as a standalone function (which the same code you reference did). If this is the case, the member method needs to be invoked on an object instance and the "this" argument here is just a pointer to that object instance which is required to make a callback which references that specific method on that specific object instance.
Comment 2 Emmanuelle Laprise 2007-07-16 17:16:39 EDT
For the patch, I still can't push to ns-3-dev, only to laprisee/ns-3-mp.

Thank you for the explanation of this in the make callback, you could add that to the Doxygen page for that function because I couldn't find that there.

Emmanuelle
Comment 3 Emmanuelle Laprise 2007-07-18 10:31:27 EDT
Made the change in the trace_root.h file. Change was pushed to ns-3-dev. Documentation will need to be regenerated. Is that done automatically? Will close, once the documentation on the web is up to date.
Comment 4 Mathieu Lacage 2007-07-18 10:37:56 EDT
no need to wait until the documentation is updated (the update process relies on tom's manual intervention). Closing now.