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

[ns] Date: Thu, 24 May 2001 15:27:04 +0900



I created a new Application Object (subclass of Application). I followed the procedure, creating a subclass of TclClass as well :
 
static class PhoneAppClass : public TclClass {
 public:
  PhoneAppClass() : TclClass("Application/Phone") {}
  TclObject* create(int, const char*const* c) {
   return(new PhoneApp());
  }
} class_phoneapp;
 

PhoneApp::PhoneApp() : Application(), packetizer(NULL,&source),
     sender(NULL,&source,&packetizer), receiver(&received_recorder,this) {
 
 call_in_progress_ = FALSE;
 file_extension = "";
}
 
I encountered two problems :
1) I got a segmentation fault while creating this object through the tcl interpreter because I was binding variables in my constructor (commenting out those instructions just had it work), so I got rid of those instructions and Everything seemed to work perfectly.
 
2) Now, with a new Tcl script using this object I encounter the same segmentation fault at the creation of this PhoneApp. If I add a puts "whatever" instruction line in my Tcl script I do not get this error anymore . The code follows. If I uncomment one of the two commented out puts lines, it works perfectly, If I comment both of them out, I get a segmentation fault after the creation of 2 pairs:
 
for {set j 0} {$j <= $max_phone} {incr j} {
 set node($j) [$ns node]
# puts "creating phone-pair $j"
 $ns duplex-link $node($j) $n0 1Mb 10ms DropTail
 set phone_pair [create_phone $node($j) $n1]
# puts "OK"
 set phone0($j) [lindex $phone_pair 0]
 set phone1($j) [lindex $phone_pair 1]
 puts "phone-pair $j created with names $phone0($j) and $phone1($j)"
}
 
proc create_phone { node_source node_sink } {
 
#Get instance of Simulator
set ns [Simulator instance]
 
#Create a UDP agent and attach it to node_source
set udp0 [new Agent/dataUDP]
$ns attach-agent $node_source $udp0
 
#Create a UDP agent at the other end
set udp1 [new Agent/dataUDP]
$ns attach-agent $node_sink $udp1
 
# Create two phones and attach them to udp0 and udp1
set phone0 [new Application/Phone]
set phone1 [new Application/Phone]
$phone0 attach-agent $udp0
$phone1 attach-agent $udp1
 
#Connect the two phones
$ns connect $udp0 $udp1
 
#return handlers
return [list $phone0 $phone1]
}
 
Please help me on this because I really don't understand what is going on
Thank you
BP