sorry for this very late answer,
On Sun, Aug 30, 2009 at 3:22 PM, Antti Mäkelä <zar...@gmail.com> wrote:
>
> Hey,
>
> I want to do some traces, and I'm utilizing the trace/sink
> functionality for that. However, it seems that Config::Connect
> (TraceAccessor, MakeCallBack(&MyFunc)) doesn't allow me to specify any
> additional parameters - the connected callback function has to be of
> type "void foo (string context, bool tracedbool)".
>
There are two ways you can use to add additional context to a callback:
1) use a member method as a callback
2) use MakeBoundCallback on a static non-member function
1) goes along like this:
class MyContext
{
public:
void Setup (int n) {
std::ostringstream oss;
oss << "/Names/app" << n << "/Connected"
Config::Connect (oss.str (), MakeCallback (this,
&MyContext::MyCallbackMethod));
}
private:
void MyCallbackMethod (string context) {
// use m_mycontext here
}
int m_mycontext;
// more context
};
and, then, client code looks like this:
MyContext * ctx = new MyContext ();
ctx->Setup (5);
2) is a bit more complicated to do. There is sample code in
samples/main-ns2-mob.cc
Mathieu
--
Mathieu Lacage <mathieu...@gmail.com>
No problem, actually the other thread (linked in bug 665) provided
On Sep 15, 11:56 am, Mathieu Lacage <mathieu.lac...@gmail.com> wrote:
> hi,
>
> sorry for this very late answer,
lots of insight (including the possiblity to define
TracedCallback<Type1, Type2, ...>). Better documentation would help a
lot of course.
Anyway, the first idea of pointing the callback to a member function
of the object itself doesn't really work in my case since I'm hoping
to aggregate information from multiple objects.
I am using static non-
member function now, but MakeBoundCallback vs. MakeCallback is new to
me. In Doxygen, http://www.nsnam.org/doxygen/functions_0x6d.html#index_m
doesn't actually show any info on either method actually... -
http://www.nsnam.org/doxygen/group___make_callback.html only is about
MakeCallback and MakeNullCallback, nothing about Bound...
There is nothing which makes it impossible to connect multiple trace
sources to different methods on the same object.
> member function now, but MakeBoundCallback vs. MakeCallback is new to
> me. In Doxygen, http://www.nsnam.org/doxygen/functions_0x6d.html#index_m
> doesn't actually show any info on either method actually... -
> http://www.nsnam.org/doxygen/group___make_callback.html only is about
> MakeCallback and MakeNullCallback, nothing about Bound...
Yes, it's undocumented because it's not really for public consumption
because it's fairly tricky to use right. It works well if you know how
to use it though.