[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] tcl command could not work
I think you need to modify you code with an else statement that returns
TCL_OK. Otherwise the
TclObject::command() function is called an it is probably not matching
anything to "record-rtp-file".
For Example:
if(strcmp(argv[1], "record-rtp-file") == 0) {
if((fdw_ = fopen(argv[2], "w")) == NULL) {
tcl.resultf("cannot create packet-arrival file \"%s\"", argv[2]);
return(TCL_ERROR);
} else {
// fdw_ opened the file ok
return TCL_OK;
}
}
return (TclObject::command(argc, argv));
cheng_wx wrote:
>
> Hi:
> I want to add some Tcl command in the C++. I add some code in the command function as the
> example in the manual. But I get the wrong information as such:
> (_o120 cmd line 1)
> invoked from within
> "_o120 cmd record-rtp-file temp.out"
> invoked from within
> "catch "$self cmd $args" ret"
> (procedure "_o120" line 2)
> (SplitObject unknown line 2)
> invoked from within
> "$self record-rtp-file $tempfile"
> (procedure "_o120" line 3)
> (Session/RTP record_file line 3)
> invoked from within
> "$s0 record_file "temp.out""
> (file "simple-rtp.tcl" line 83)
>
> it seems my functions does not work.
> this is my code:
>
> int RTPSession::command(int argc, const char*const* argv)
> {
> Tcl& tcl = Tcl::instance();
>
> if (argc == 3) {
> if (strcmp(argv[1], "enter") == 0) {
> RTPSource* s = (RTPSource*)TclObject::lookup(argv[2]);
> enter(s);
> return (TCL_OK);
> }
> if (strcmp(argv[1], "localsrc") == 0) {
> localsrc_ = (RTPSource*)TclObject::lookup(argv[2]);
> enter(localsrc_);
> return (TCL_OK);
> }
>
>
> if(strcmp(argv[1], "record-rtp-file") == 0) {
> if((fdw_ = fopen(argv[2], "w")) == NULL) {
> tcl.resultf("cannot create packet-arrival file \"%s\"", argv[2]);
> return(TCL_ERROR);
> }
> }
> }
> return (TclObject::command(argc, argv));
> }
>
> It seems right.But it doesn't work.
> Could anybody help me?