oasys::TclCommandInterp Class Reference

#include <TclCommand.h>

Inheritance diagram for oasys::TclCommandInterp:

oasys::Logger List of all members.

Detailed Description

Command interpreter class.

Command files are Tcl scripts. When a module registers itself, the interpreter binds a new command with the module name.

Definition at line 73 of file TclCommand.h.

Public Member Functions

int exec_file (const char *file)
 Read in a configuration file and execute its contents.
int exec_command (const char *command)
 Parse a single command string.
void command_server (const char *prompt, in_addr_t addr, u_int16_t port)
 Run a command interpreter over tcp sockets on the given port.
void command_loop (const char *prompt)
 Run a command interpreter loop.
void event_loop ()
 Just run the event loop.
void exit_event_loop ()
 Bail out of the event loop or the command loop, whichever one happens to be running.
void reg (TclCommand *module)
 Register the command module.
bool lookup (const char *command, TclCommand **commandp=NULL)
 Check if there's a tcl command registered by the given name.
void reg_atexit (void(*fn)(void *), void *data)
 Register a function to be called at exit.
void set_result (const char *result)
 Set the TclResult string.
void set_objresult (Tcl_Obj *obj)
 Set an object for the TclResult.
void append_result (const char *result)
 Append the string to the TclResult.
void resultf (const char *fmt,...)
 Format and set the TclResult string.
void append_resultf (const char *fmt,...)
 Format and append the TclResult string.
void vresultf (const char *fmt, va_list ap, bool append)
 Format and set the TclResult string.
void wrong_num_args (int objc, const char **objv, int parsed, int min, int max)
 Useful function for generating error strings indicating that the wrong number of arguments were passed to the command.
void wrong_num_args (int objc, Tcl_Obj **objv, int parsed, int min, int max)
 Useful function for generating error strings indicating that the wrong number of arguments were passed to the command.
const char * get_result ()
 Get the TclResult string.
const TclCommandListcommands ()
 Return the list of registered commands.

Static Public Member Functions

static TclCommandInterpinstance ()
 Return the singleton instance of config.
static int init (char *objv0, bool no_default_cmds=false)
 Initialize the interpreter instance.
static void shutdown ()
 Shut down the interpreter.
static int tcl_cmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
 Static callback function from Tcl to execute the commands.
static void auto_reg (TclCommand *module)
 Schedule the auto-registration of a command module.

Protected Member Functions

 TclCommandInterp ()
 Constructor (does nothing).
int do_init (char *objv0, bool no_default_cmds)
 Do all of the actual initialization.
 ~TclCommandInterp ()
 Destructor to clean up and finalize.

Protected Attributes

Locklock_
 Lock for command execution.
Tcl_Interp * interp_
 Tcl interpreter.
TclCommandList commands_
 List of registered commands.

Static Protected Attributes

static TclCommandListauto_reg_
 List of commands to auto-register.
static TclCommandInterpinstance_
 Singleton instance.


Constructor & Destructor Documentation

oasys::TclCommandInterp::TclCommandInterp (  )  [protected]

Constructor (does nothing).

Definition at line 367 of file TclCommand.cc.

References oasys::StringBuffer::vappendf().

oasys::TclCommandInterp::~TclCommandInterp (  )  [protected]

Destructor to clean up and finalize.

Definition at line 430 of file TclCommand.cc.

References interp_.


Member Function Documentation

static TclCommandInterp* oasys::TclCommandInterp::instance (  )  [inline, static]

Return the singleton instance of config.

This should only ever be called after Command::init is called to initialize the instance, hence the assertion that instance_ isn't null.

Definition at line 80 of file TclCommand.h.

References ASSERT, and instance_.

Referenced by dtn::APIServer::APIServer(), oasys::TclCommand::append_result(), dtn::ShutdownCommand::call_exit(), dtn::TclRegistration::exec(), dtnsim::SimCommand::exec(), oasys::HelpCommand::exec(), exec_command(), dtn::TclRegistration::get_bundle_data(), dtn::TclRegistration::get_list_channel(), dtn::DTNServer::init_commands(), dtn::DTND::init_testcmd(), main(), dtn::DTND::main(), dtn::DTNServer::parse_conf_file(), dtn::DTND::run_console(), oasys::TclCommand::set_objresult(), oasys::TclCommand::set_result(), and oasys::TclCommand::wrong_num_args().

int oasys::TclCommandInterp::init ( char *  objv0,
bool  no_default_cmds = false 
) [static]

Initialize the interpreter instance.

Definition at line 460 of file TclCommand.cc.

Referenced by main(), and dtn::DTND::main().

void oasys::TclCommandInterp::shutdown (  )  [static]

Shut down the interpreter.

Definition at line 453 of file TclCommand.cc.

Referenced by main(), and dtn::DTND::main().

int oasys::TclCommandInterp::exec_file ( const char *  file  ) 

Read in a configuration file and execute its contents.

Returns:
0 if no error, -1 otherwise.

Definition at line 469 of file TclCommand.cc.

Referenced by main().

int oasys::TclCommandInterp::exec_command ( const char *  command  ) 

Parse a single command string.

Returns:
0 if no error, -1 otherwise

Definition at line 488 of file TclCommand.cc.

References instance(), and vresultf().

void oasys::TclCommandInterp::command_server ( const char *  prompt,
in_addr_t  addr,
u_int16_t  port 
)

Run a command interpreter over tcp sockets on the given port.

Definition at line 517 of file TclCommand.cc.

Referenced by main().

void oasys::TclCommandInterp::command_loop ( const char *  prompt  ) 

Run a command interpreter loop.

Doesn't return.

Definition at line 530 of file TclCommand.cc.

void oasys::TclCommandInterp::event_loop (  ) 

Just run the event loop.

Also doesn't return.

Definition at line 540 of file TclCommand.cc.

void oasys::TclCommandInterp::exit_event_loop (  ) 

Bail out of the event loop or the command loop, whichever one happens to be running.

Definition at line 548 of file TclCommand.cc.

References resultf().

int oasys::TclCommandInterp::tcl_cmd ( ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const *  objv 
) [static]

Static callback function from Tcl to execute the commands.

Parameters:
client_data Pointer to config module for which this command was registered.
interp Tcl interpreter
objc Argument count.
objv Argument values.

Definition at line 625 of file TclCommand.cc.

void oasys::TclCommandInterp::reg ( TclCommand module  ) 

Register the command module.

Definition at line 556 of file TclCommand.cc.

Referenced by dtnsim::SimCommand::exec(), dtn::DTNServer::init_commands(), and main().

bool oasys::TclCommandInterp::lookup ( const char *  command,
TclCommand **  commandp = NULL 
)

Check if there's a tcl command registered by the given name.

If so, return true. If the command is an instance of TclCommand, return it as well in the commandp parameter.

Definition at line 578 of file TclCommand.cc.

References resultf().

Referenced by dtnsim::SimCommand::exec().

void oasys::TclCommandInterp::auto_reg ( TclCommand module  )  [static]

Schedule the auto-registration of a command module.

This _must_ be called from a static initializer, before the Command instance is actually created.

Definition at line 603 of file TclCommand.cc.

Referenced by oasys::AutoTclCommand::AutoTclCommand().

void oasys::TclCommandInterp::reg_atexit ( void(*)(void *)  fn,
void *  data 
)

Register a function to be called at exit.

Definition at line 618 of file TclCommand.cc.

void oasys::TclCommandInterp::set_result ( const char *  result  ) 

Set the TclResult string.

Definition at line 653 of file TclCommand.cc.

Referenced by dtn::TclRegistration::get_list_channel(), and oasys::TclCommand::set_result().

void oasys::TclCommandInterp::set_objresult ( Tcl_Obj *  obj  ) 

Set an object for the TclResult.

Definition at line 659 of file TclCommand.cc.

Referenced by dtn::TclRegistration::get_bundle_data(), and oasys::TclCommand::set_objresult().

void oasys::TclCommandInterp::append_result ( const char *  result  ) 

Append the string to the TclResult.

Definition at line 665 of file TclCommand.cc.

Referenced by oasys::TclCommand::append_result().

void oasys::TclCommandInterp::resultf ( const char *  fmt,
  ... 
)

Format and set the TclResult string.

Definition at line 684 of file TclCommand.cc.

Referenced by dtn::TclRegistration::exec(), exit_event_loop(), and lookup().

void oasys::TclCommandInterp::append_resultf ( const char *  fmt,
  ... 
)

Format and append the TclResult string.

Definition at line 693 of file TclCommand.cc.

void oasys::TclCommandInterp::vresultf ( const char *  fmt,
va_list  ap,
bool  append 
)

Format and set the TclResult string.

Definition at line 671 of file TclCommand.cc.

Referenced by exec_command().

void oasys::TclCommandInterp::wrong_num_args ( int  objc,
const char **  objv,
int  parsed,
int  min,
int  max 
)

Useful function for generating error strings indicating that the wrong number of arguments were passed to the command.

Parameters:
objc original argument count to the command
objv original argument vector to the command
parsed number of args to include in error string
min minimum number of expected args
max maximum number of expected args (or INT_MAX)

Definition at line 702 of file TclCommand.cc.

Referenced by dtn::TclRegistration::exec().

void oasys::TclCommandInterp::wrong_num_args ( int  objc,
Tcl_Obj **  objv,
int  parsed,
int  min,
int  max 
)

Useful function for generating error strings indicating that the wrong number of arguments were passed to the command.

Parameters:
objc original argument count to the command
objv original argument vector to the command
parsed number of args to include in error string
min minimum number of expected args
max maximum number of expected args (or INT_MAX)

Definition at line 724 of file TclCommand.cc.

const char * oasys::TclCommandInterp::get_result (  ) 

Get the TclResult string.

Definition at line 735 of file TclCommand.cc.

const TclCommandList* oasys::TclCommandInterp::commands (  )  [inline]

Return the list of registered commands.

Definition at line 229 of file TclCommand.h.

References commands_.

Referenced by oasys::HelpCommand::exec().

int oasys::TclCommandInterp::do_init ( char *  objv0,
bool  no_default_cmds 
) [protected]

Do all of the actual initialization.

Definition at line 372 of file TclCommand.cc.


Member Data Documentation

Lock* oasys::TclCommandInterp::lock_ [protected]

Lock for command execution.

Definition at line 247 of file TclCommand.h.

Tcl_Interp* oasys::TclCommandInterp::interp_ [protected]

Tcl interpreter.

Definition at line 248 of file TclCommand.h.

Referenced by ~TclCommandInterp().

TclCommandList oasys::TclCommandInterp::commands_ [protected]

List of registered commands.

Definition at line 250 of file TclCommand.h.

Referenced by commands().

TclCommandList * oasys::TclCommandInterp::auto_reg_ [static, protected]

List of commands to auto-register.

Definition at line 251 of file TclCommand.h.

TclCommandInterp * oasys::TclCommandInterp::instance_ [static, protected]

Singleton instance.

Definition at line 253 of file TclCommand.h.

Referenced by instance().


The documentation for this class was generated from the following files:
Generated on Fri Dec 22 14:48:07 2006 for DTN Reference Implementation by  doxygen 1.5.1