Solved. You must use global variables to acces them inside the "doLETJOIN"
instproc.

Also, I recommend you to follow my tutorial, and learn how to simplify the
code for debugging... for instance, the C++ part is only causing confusion
on the debugging process. See below how I've done without depending on c++.
When the Tcl code is ok, you should then start from tcl!

Also, on C++ you should use as follows:

 Tcl::instance().evalf( "$app(%d) %d %d %d %d", src, src, des, master,
object);




------


set ns        [new Simulator]

global ns  tcp app

for {set j 0} {$j < 13} {incr j} {
        set tcp($j) [new Agent/TCP/SimpleTcp]
        #$ns attach-agent $node($j) $tcp($j)            ;# DISABLED, as this
test script do not creates the nodes
} 

set app(0) [new Application/TcpApp $tcp(0) source 0]

for {set k 1} {$k < 13} {incr k} {
  set app($k) [new Application/TcpApp $tcp($k) common $k]
}

proc doLETJOIN {src des master object} {
        global ns tcp app                               ;# this is essential
!!!

  $ns at [$ns now] "$ns connect $tcp($src) $tcp($des)"
  $ns at [$ns now] "$tcp($src) listen"
  $ns at [$ns now] "$tcp($des) listen"
  $ns at [$ns now] "$app($src) connect $app($des)"
  $ns at [$ns now] "$$src letjoin $src $des $master"
}


proc my_test {} {
        global ns

        puts "inside test"

        doLETJOIN 0 1 0 4

}

$ns at "1" "my_test"

$ns run







> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> Of Brian Liu
> Sent: quarta-feira, 21 de Novembro de 2007 1:35
> To: ns-users@ISI.EDU
> Subject: [ns] About callback from C++ code to OTcl (Brian LIU)
> 
> 
> 
> Emergency Help!!!!!!!!!
> Hi, buddies
> 
> This problem troubles me long times, please help me to tackle this. Thanks
> a
> lot.
> 
> i use:
> static char* catLETJOIN(const char* src, const char* des, const char*
> master, const char* object)
> {   // $app(src) doLETJOIN src des master object
>     int len = strlen(src)*2 + strlen(des) + strlen(master) +
> strlen(object)
> + 21;
>     char* callback = new char[len];
>     strcpy(callback, "$app(");
>     strcat(callback, src);
>     strcat(callback, ") doLETJOIN ");
>     strcat(callback, src);
>     strcat(callback, " ");
>     strcat(callback, des);
>     strcat(callback, " ");
>     strcat(callback, master);
>     strcat(callback, " ");
>     strcat(callback, object);
>     return callback;
> }
> 
> in one function, i callback to Otcl:
> Tcl::instance().eval(catLETJOIN("0", "1", "0", "4"));
> 
> In Otcl, i have this:
> ......
> ......
> for {set j 0} {$j < 13} {incr j} {
>   set tcp($j) [new Agent/TCP/SimpleTcp]
>   $ns attach-agent $node($j) $tcp($j)
> }
> 
> set app(0) [new Application/TcpApp $tcp(0) source 0]
> 
> for {set k 1} {$k < 13} {incr k} {
>   set app($k) [new Application/TcpApp $tcp($k) common $k]
> }
> 
> Application/TcpApp instproc doLETJOIN {src des master object} {
>   global ns
>   $ns at [$ns now] "$ns connect $tcp($src) $tcp($des)"
>   $ns at [$ns now] "$tcp($src) listen"
>   $ns at [$ns now] "$tcp($des) listen"
>   $ns at [$ns now] "$app($src) connect $app($des)"
>   $ns at [$ns now] "$$src letjoin $src $des $master"
> }
> 
> why the following error happen?
> 
> ns: $app(0) doLETJOIN 0 1 0 4: can't read "tcp(0)": no such variable
>     while executing
> "$ns at [$ns now] "$ns connect $tcp($src) $tcp($des)""
>     (procedure "_o315" line 3)
>     (Application/TcpApp doLETJOIN line 3)
>     invoked from within
> "$app(0) doLETJOIN 0 1 0 4"
> 
> 
> help me, please.....
> 
> 
> Sincerely,
> 
> Brian Liu
> 
> Graduate School of Information,Production,Systems
> WASEDA UNIVERSITY
> 
> Hibikino 2-6-416, Wakamatsu-ku,
> Kitakyushu-shi, Fukuoka,
> JAPAN 808-0135
> 



Reply via email to