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 54 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 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_ = NULL
 List of commands to auto-register.
static TclCommandInterpinstance_
 Singleton instance.

Constructor & Destructor Documentation

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

Constructor (does nothing).

Definition at line 375 of file TclCommand.cc.

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

Destructor to clean up and finalize.

Definition at line 438 of file TclCommand.cc.


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 61 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(), 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(), shutdown(), 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 468 of file TclCommand.cc.

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

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

Shut down the interpreter.

Definition at line 461 of file TclCommand.cc.

References append_result(), oasys::StringBuffer::c_str(), instance(), and STRINGBUFFER_VAPPENDF.

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 477 of file TclCommand.cc.

References oasys::StringBuffer::appendf().

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 496 of file TclCommand.cc.

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 525 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 538 of file TclCommand.cc.

void oasys::TclCommandInterp::event_loop (  ) 

Just run the event loop.

Also doesn't return.

Definition at line 552 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 560 of file TclCommand.cc.

References log_warn.

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 637 of file TclCommand.cc.

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

Register the command module.

Definition at line 568 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 590 of file TclCommand.cc.

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 615 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 630 of file TclCommand.cc.

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

Set the TclResult string.

Definition at line 661 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 667 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 673 of file TclCommand.cc.

Referenced by oasys::TclCommand::append_result(), and shutdown().

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

Format and set the TclResult string.

Definition at line 679 of file TclCommand.cc.

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

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

Format and append the TclResult string.

Definition at line 687 of file TclCommand.cc.

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 695 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 717 of file TclCommand.cc.

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

Get the TclResult string.

Definition at line 728 of file TclCommand.cc.

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

Return the list of registered commands.

Definition at line 205 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 380 of file TclCommand.cc.


Member Data Documentation

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

Lock for command execution.

Definition at line 223 of file TclCommand.h.

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

Tcl interpreter.

Definition at line 224 of file TclCommand.h.

TclCommandList oasys::TclCommandInterp::commands_ [protected]

List of registered commands.

Definition at line 226 of file TclCommand.h.

Referenced by commands().

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

List of commands to auto-register.

Definition at line 227 of file TclCommand.h.

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

Singleton instance.

Definition at line 229 of file TclCommand.h.

Referenced by instance().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:36:26 2007 for DTN Reference Implementation by  doxygen 1.5.3