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

Re: Problem in creating a new Agent



Hello Anotai,

> I had tried unsuccessfully in creating a new Agent in NS. 
> The new class constructor declaration is in C++ and some default 
> parameters and functions are in OTCL.
> I rebuilt the NS which include the new class file. 
> The building process is successfully done but when I tried to call it 
> via OTCL, NS doesn't recognize the new created class.  
> If anyone experiences this problem, please kindly help me. 

My guess is that you did not register your newly created C++-Class with OTcl. 
You need to associate a C++ Constructor with the corresponding OTcl class. 
This causes the C++ constructor to be called as well whenever you instantiate 
your OTcl class (i.e. with "set yourInstance [new YourClass]"). Once you have 
done this, calling C++ functions is done like this: "$yourInstance cmd xyz 3 
5". This will call YourClass::command(argc, argv) with argv[1]="xyz", 
argv[2]="3" and argv[3]="5".

Here's an example of how to register:

static class YourClass : public TclClass {
public:
    YourClass() : TclClass("Agent/YourClass") {}
    TclObject* create(int, const char*const*) {
        return (new YourClass());
    }
} dummy;

The variable dummy is never used actually - it's all just a trick to ensure 
the compiler calls the constructor of YourClass once all by itself.



     Hope this will help,

          -Chris.