Bugzilla – Bug 50
The example code on the page Low-level tracing page does not compile
Last modified: 2007-07-18 10:37:56 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
(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.
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
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.
no need to wait until the documentation is updated (the update process relies on tom's manual intervention). Closing now.