[Ns-bugs] [Bug 127] Add trace callback type information for Python bindings
code@nsnam.ece.gatech.edu
code at nsnam.ece.gatech.edu
Fri Jan 9 15:00:56 PST 2009
http://www.nsnam.org/bugzilla/show_bug.cgi?id=127
--- Comment #5 from Gustavo J. A. M. Carneiro <gjcarneiro at gmail.com> 2009-01-09 18:00:56 EDT ---
(In reply to comment #4)
> (In reply to comment #3)
> > This is still an issue AFAIK. Not P1 because Python bindings will be merged
> > after ns 3.1.
> >
>
> Gustavo, can you clarify the status of this? My understanding is that:
>
> 1) if a callback is exported explicitly at the API, it is possible to register
> a python method with it, thereby enabling people to write python code for ns-3
>
> 2) but due to this bug, we just can't hook them through the trace hooks
> obtained through the trace path
>
> If I am correct, are there any examples (even a small sample program for
> samples/ directory) of how to do this? Someone here at UW would like to try
> writing some Python ns-3 code.
>
The problem is that 1) in Python we cannot introspect the signature of a
"callable" (i.e. function or method, or class instance with a __call__ method),
and 2) NS-3 also does not provide an API that says what is the expected
callback type for a certain trace path, but it eventually checks in runtime
whether supplied callbacks are of the correct type. Although the
Config::Connect API accepts a generic callback type (CallbackBase) as
parameter, it later matches it against one of the concrete callback types
(Callback<R,T1,T2,...>). So the Python bindings have to supply a concrete
callback wrapper based on a Python callable for which I cannot obtain signature
information.
I can think of two possible and contrasting ways to move forward:
1- Add a new NS-3 API to give back callback type(s) regarding trace path. The
Python bindings could work things out and the Python API would turn out to be
simple:
def my_callback(packet):
print packet
ns3.Config.Connect("/NodeList/*/....", my_callback)
2- Force the Python programmer to tell the NS-3 Python bindings what is the
callback signature via a decorator design pattern, e.g.:
def my_callback(packet):
print packet
ns3.Config.Connect("/NodeList/*/....",
ns3.Callback__lt__Ptr__lt__Packet__gt____gt__(my_callback))
Obviously I would prefer option 1 because it is much simpler to the NS-3
programmer. I wonder if there isn't some Match API already in the works that
could be used as basis for this?...
--
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the Ns-bugs
mailing list