[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] problems with "create" functionS




Andrea,


At the end of this mail  are some excerpts from my  personal ns manual reading
notes. If things are still not clear after that, take a look at the
whole stuff at http://www.ce.chalmers.se/staff/otel/misc/Notes-ns 
(sorry for the excesively long lines, i just _love_ grep. Also excuse
the casual language... >-)

If that doesn't help either.... "use the source Luke".

Florian


P.S. All: If you care to take a look at that ad you find smth you
think it's worng/inaccurate  _please_ do send me a comment. TIA.

> Hi all,
> i have some problems (due partly to my tcl/c++
> ignorance) in understanding how a new SplitObject is
> created:

> taking as example the one quoted in the ns manual:

> set srm [new Agent/SRM/Adaptive]
> ................................
> From ~tclcl/tcl-object.tcl

> proc new { className args } {
>   set o [SplitObject getid]
>   if [catch "$className create $o $args" msg]
>  ..............................................

> *) The manual says that the "create" procedure
> referred to in the code is the one defined on the c++
> side for the classes derived from TclClass 

> TclObject* create(int argc, const char*const* argv)

> How is it possible ? is there an invocation to the
> command method ?

> Thanks in advance,
>                     Andrea.

----------------------------------------------------------------------------

[...]
When ns starts, there are some static objects (i.e. objects belonging
to static classes) (in ~/ns-2/*.cc e.g. ~/ns-2/tcp-reno.cc,
~/ns-2/srm.cc). The objects are constructed when ns starts. This calls
the TclClass constructor which inserts this static object into a
linked list of TclClass objects. For each such object TclClass::bind()
is called (~/tclcl/Tcl.cc). TclClass::bind() calls tcl.evalf() (where
tcl is the return value of Tcl::instance() i.e. "get a handle of the
interpreter") to invoke (the OTcl) SplitObject::register{} method with
the name of the class to be registered e.g. "A/B/C". register{} then
creates all the necessary classes and subclasses, under SplitObject
root class (~/tclcl/tcl-object.tcl).  After that TclClass::bind() also
installs the hook for create-shadow{} such that create-shadow {} with
the interpreted class as argument calls the corresponding compiled
TclClass subclass create_shadow () method. E.g. set tcp [new
Agent/TCP/Reno] ends up calling create-shadow{} in the SplitObject
init instproc w/ the argument "Agent/TCP/Reno"
(~/tclcl/tcl-object.tcl) . This is hooked to the mirror RenoTcpClass
inherited static member function TclClass::create_shadow()
(~/tclcl/Tcl.cc). This calls the object's method create() method. The
arguments passed are as described at page 28 in the manual. Most
importantly, the argv[3] is "create-shadow"). This creates the
corresponding compiled class object, RenoTCPAgent in this case. Note:
The constructor of this compile-in mirrored object (i.e. a TclObject
descendent) also does the appropriate instvar bindings, as per page 24
in the manual. After returning from create() object method
create_shadow() installs the hooks for the OTcl object cmd{} proc as
the C++ TclObject object's command() method
(i.e. RenoTCPAgent::command() for the example above) and for the
instvar{} proc as ....... Described in section 3.8. Used for assuring
consistency between interpreted variables and shadow (C++) objects.

[...]