I tried Binding a Static Variable, based on how it is described in the 
ns-documentation section 3.5.1, but it is not working.
The simulator is not recognizing the Classname that I am giving.
Here is what I tried
 
>I added the static variable in snoop.h in the class Snoop declaration in 
>snoop.h
 
static int bufsize_;
 
>I defined it in the snoop.cc file
 
int Snoop::bufsize_;
 
>I did this
 
class SnoopBufferClass : public TclClass {
protected:
SnoopBufferClass(const char* classname, int bufsize);
TclObject* create(int argc, const char*const* argv);
/* These two implements OTcl class access methods */
virtual void bind();
virtual int method(int argc, const char*const* argv);
};
 
void SnoopBufferClass::bind()
{
/* Call to base class bind() must precede add_method() */
TclClass::bind();
add_method("bufsize");
}
 
int SnoopBufferClass::method(int ac, const char*const* av)
{
Tcl& tcl = Tcl::instance();
/* Notice this argument translation; we can then handle them as if in 
TclObject::command() */
int argc = ac - 2;
const char*const* argv = av + 2;
if (argc == 2) {
if (strcmp(argv[1], "bufsize") == 0) {
tcl.resultf("%d", Snoop::bufsize_);
return (TCL_OK);
}
} else if (argc == 3) {
if (strcmp(argv[1], "bufsize") == 0) {
Snoop::bufsize_ = atoi(argv[2]);
return (TCL_OK);
}
}
return TclClass::method(ac, av);
}
 
After this, I tried to use the following OTcl command to access and change 
values of Snoop::bufsize__:
 
SnoopBuffer bufsize 120
set i [SnoopBuffer bufsize]
set i [SnoopBuffer set bufsize]
 
RESULT: invalid command "SnoopBuffer"
 
After this, I tried to use the following OTcl command to access and change 
values of Snoop::bufsize__:
 
SnoopBufferClass bufsize 120
set i [SnoopBufferClass bufsize]
set i [SnoopBufferClass set bufsize]
 
RESULT: invalid command "SnoopBufferClass"
 
I even tried to add a constructor in snoop.cc
 
SnoopBufferClass::SnoopBufferClass(const char* classname, int 
bufsize):TclClass("SnoopBuffer"), bufsize_(0)
{
 return 0;
}
 
 
Still same reply
 
Please Help me out with this
 
If you have a working example of binding a static variable please refer it to 
me.
(Except the offset variable in PacketHeader, I cannot understand what is going 
on over there)
The main goal is to get the interpreter to recognise the classname I am 
creating.
 
Any help or suggestions you can give me will be appreciated.
 
thanks in advance
 
pankaj
_________________________________________________________________
Search for videos of Bollywood, Hollywood, Mollywood and every other wood, only 
on Live.com 
http://www.live.com/?scope=video&form=MICOAL

Reply via email to