RE: [ns] Retrieve C++ variable in TCL code
Johan Uijen
johanclio at hotmail.com
Thu Apr 23 11:48:39 PDT 2009
Hi Kavan,
I have changed the following:
From:
$ns at ($z+0.1) "puts \"qsize_: $sipalice qsize_\""
To:
$ns at ($z+0.1) "puts \"qsize_: $sipalice set qsize_\""
The output is now:
'qsize_: _o249 set qsize_'
where it should be: 'qsize_: 0'
Thanks for the support until now.
Regards,
Johan
________________________________
> Date: Thu, 23 Apr 2009 23:13:12 +0530
> Subject: Re: [ns] Retrieve C++ variable in TCL code
> From: shethkavan at gmail.com
> To: johanclio at hotmail.com
>
> Hi Johan,
>
> In Tcl to set a variable of a object you need to write
> $object_name set variable_name value
> if you just want to retrieve value of variable use
> $object_name set variable_name
>
> try this and see whether it is working or not
>
>
> Regards,
> Kavan Sheth
> DA-IICT,
> India
>
> 2009/4/23 Johan Uijen>
>
>
>
>
>
> Hi,
>
>
>
> I have now changed the following:
>
> in ns-default.tcl I added:
>
> Agent/SIPUA set qsize_ 0
>
>
>
> in a headerfile:
>
> int qsize;
>
>
>
> then in the class constrcutor:
>
> qsize_ = 0;
>
> bind("qsize_",&qsize_);
>
>
>
> In the script I am calling the variable by:
>
> $ns at ($z+0.1) "puts \"qsize_: $sipalice qsize_\""
>
>
>
> then I did a 'make'
>
>
>
> When i execute the script, it output is then as follows:
>
> ...
>
> qsize_: _o249 qsize_
>
> ...
>
>
>
> it should be:
>
> qsize_ : 0
>
>
>
> I seems that this also is not working. Am I calling the variable is the right way, so '$sipalice qsize_'?
>
>
>
> Regards,
>
>
>
> Johan
>
> ________________________________
>
>> Date: Thu, 23 Apr 2009 12:05:49 +0530
>
>> Subject: Re: [ns] Retrieve C++ variable in TCL code
>
>> From: shethkavan at gmail.com
>
>> To: johanclio at hotmail.com
>
>>
>
>> Hi Jo,
>
>> If you wan't to evaluate a tcl command or retrive a value of tcl variable from your C++ code then use eval() functions.
>
>> if you wan't to access value of C++ variable in tcl code then use bind() function. using the bind() function you can bind your c++ variable with a tcl variable. So just read about binding from initial chapters of NS manual.
>
>
>>
>
>>
>
>> Kavan Sheth
>
>> DA-IICT
>
>> india
>
>>
>
>>
>
>> 2009/4/21 Johan Uijen>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> Hi,
>
>>
>
>>
>
>>
>
>> I am using ns 2.33 on a solaris/intel machine. In the ns2 TCL script I want to use a variable defined in C++. The variable is used for looping control as follows:
>
>>
>
>>
>
>>
>
>> while {$x < 16.0} {
>
>>
>
>> ...
>
>>
>
>> for {set y 1.0} {$y < $ns at $x "$sipalice getSize"} {set y [expr (0.5+$y)]} {
>
>>
>
>> ...
>
>>
>
>> }
>
>>
>
>> ...
>
>>
>
>> }
>
>>
>
>>
>
>>
>
>> The statement $ns at $x "$sipalice getSize" returns now some weird integerid. The command getSize is defined here:
>
>>
>
>> ...
>
>>
>
>> } else if (!strcmp(argv[1], "getSize")){
>
>>
>
>> Tcl& tcl = Tcl::instance();
>
>>
>
>> sprintf(tcl.buffer(),"%d",SIPSingleton::getInstance()->getSize());
>
>>
>
>> tcl.result(tcl.buffer());
>
>>
>
>> return(TCL_OK);
>
>>
>
>> }
>
>>
>
>> ...
>
>>
>
>> I think the tcl.result is overwritten by the Scheduler::command(..) function...
>
>>
>
>> Is it in in any way possible to return a variable to the tcl script when the scheduler is started? I know it is possible without timing (without the "$ns at x" part), but I have to use the timing otherwise statements are executed too early.
>
>
>>
>
>>
>
>>
>
>>
>
>> Regards,
>
>>
>
>>
>
>>
>
>> Jo
>
>>
>
>> _________________________________________________________________
>
>>
>
>> Rediscover Hotmail®: Get e-mail storage that grows with you.
>
>>
>
>> http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Storage2_042009
>
>>
>
>>
>
>>
>
>>
>
>
>
> _________________________________________________________________
>
> Windows Live™ SkyDrive™: Get 25 GB of free online storage.
>
> http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_skydrive_042009
>
>
_________________________________________________________________
Rediscover Hotmail®: Get quick friend updates right in your inbox.
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009
More information about the Ns-users
mailing list