oasys::TclCommand Class Reference

#include <TclCommand.h>

Inheritance diagram for oasys::TclCommand:

oasys::Logger dtn::APICommand dtn::BundleCommand dtn::InterfaceCommand dtn::LinkCommand dtn::ParamCommand dtn::RegistrationCommand dtn::RouteCommand dtn::ShutdownCommand dtn::StorageCommand dtn::TestCommand DTNBindCommand DTNCloseCommand DTNOpenCommand DTNRecvCommand DTNRegisterCommand DTNSendCommand dtnsim::ConnCommand dtnsim::NodeCommand dtnsim::SimCommand DTNUnbindCommand DTNUnregisterCommand oasys::AutoTclCommand oasys::ConsoleCommand oasys::DebugCommand oasys::HelpCommand oasys::LogCommand ShutdownCommand List of all members.

Detailed Description

Extend this class to provide the command hooks for a specific module.

Register commands with Command::instance()->reg() or use the AutoTclCommand class.

The "set" command is automatically defined for a module. Set is used to change the value of variable which are bound using the bind_* functions defined below.

Definition at line 265 of file TclCommand.h.

Public Member Functions

 TclCommand (const char *name, const char *theNamespace=0)
 Constructor.
virtual ~TclCommand ()
virtual int exec (int objc, Tcl_Obj **objv, Tcl_Interp *interp)
 Override this to get the arguments as raw tcl objects.
virtual int exec (int argc, const char **argv, Tcl_Interp *interp)
 Override this to parse the list of arguments as strings.
virtual int cmd_info (Tcl_Interp *interp)
 Handles the "info" command which prints out the value of the bound variables for a TclCommand.
virtual int cmd_set (int objc, Tcl_Obj **objv, Tcl_Interp *interp)
 Internal handling of the "set" command.
const char * name () const
 Get the name of the module.
virtual const char * help_string ()
 Return the help string for this command.
bool hasBindings ()
 Does this command have any bindings?

Protected Types

enum  type_t {
  BINDING_INVALID = -1, BINDING_INT = 1, BINDING_INT16, BINDING_DOUBLE,
  BINDING_BOOL, BINDING_STRING, BINDING_ADDR
}
 Binding type constants. More...
typedef std::map< std::string,
Binding * > 
BindingTable
 Type for the table of bindings.

Protected Member Functions

void bind_i (const char *name, int *val, const char *help=NULL)
 Bind an integer to the set command.
void bind_i (const char *name, int *val, int initval, const char *help=NULL)
void bind_i (const char *name, int16_t *val, const char *help=NULL)
 Bind a 16 bit integer to the set command.
void bind_i (const char *name, int16_t *val, int16_t initval, const char *help=NULL)
void bind_d (const char *name, double *val, const char *help=NULL)
 Bind a double to the set command.
void bind_d (const char *name, double *val, double initval, const char *help=NULL)
void bind_b (const char *name, bool *val, const char *help=NULL)
 Bind a boolean to the set command.
void bind_b (const char *name, bool *val, bool initval, const char *help=NULL)
void bind_s (const char *name, std::string *str, const char *initval, const char *help)
 Bind a string to the set command.
void bind_s (const char *name, std::string *str, const char *help=NULL)
void bind_addr (const char *name, in_addr_t *addrp, const char *help=NULL)
 Bind an ip addr for the set command, allowing the user to pass a hostname and/or a dotted quad style address.
void bind_addr (const char *name, in_addr_t *addrp, in_addr_t initval, const char *help=NULL)
void unbind (const char *name)
 Unbind a variable.
void set_result (const char *result)
 Set the TclResult string.
void set_objresult (Tcl_Obj *obj)
 Set a Tcl_Obj as the result.
void append_result (const char *result)
 Append the TclResult string.
void resultf (const char *fmt,...)
 Format and set the TclResult string.
void append_resultf (const char *fmt,...)
 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.
void add_to_help (const char *subcmd, const char *help_str)
 Append the given information to the current help string, typically used for a set of alternatives for subcommands.
void bind_i (const char *name, unsigned int *val, const char *help=NULL)
 Unsigned / signed aliases for other integer types.
void bind_i (const char *name, unsigned int *val, unsigned int initval, const char *help=NULL)
 Unsigned / signed aliases for other integer types.
void bind_i (const char *name, u_int16_t *val, const char *help=NULL)
 Unsigned / signed aliases for other integer types.
void bind_i (const char *name, u_int16_t *val, u_int16_t initval, const char *help=NULL)
 Unsigned / signed aliases for other integer types.

Protected Attributes

std::string name_
 Name of the module.
StringBuffer help_
 Help string.
bool do_builtins_
 Set to false if a module doesn't want builtin commands like "set".
BindingTable bindings_
 The table of registered bindings.

Friends

class TclCommandInterp

Classes

struct  Binding
 Internal structure for bindings. More...


Member Typedef Documentation

typedef std::map<std::string, Binding*> oasys::TclCommand::BindingTable [protected]

Type for the table of bindings.

Definition at line 379 of file TclCommand.h.


Member Enumeration Documentation

enum oasys::TclCommand::type_t [protected]

Binding type constants.

Enumerator:
BINDING_INVALID 
BINDING_INT 
BINDING_INT16 
BINDING_DOUBLE 
BINDING_BOOL 
BINDING_STRING 
BINDING_ADDR 

Definition at line 343 of file TclCommand.h.


Constructor & Destructor Documentation

oasys::TclCommand::TclCommand ( const char *  name,
const char *  theNamespace = 0 
)

Constructor.

Parameters:
name Name of the module
theNamespace Optional tcl namespace

Definition at line 745 of file TclCommand.cc.

oasys::TclCommand::~TclCommand (  )  [virtual]

Definition at line 758 of file TclCommand.cc.


Member Function Documentation

int oasys::TclCommand::exec ( int  objc,
Tcl_Obj **  objv,
Tcl_Interp *  interp 
) [virtual]

Override this to get the arguments as raw tcl objects.

Parameters:
objc Argument count
objv Argument values
interp Tcl interpreter
Returns:
0 on success, -1 on error

Reimplemented in dtn::BundleCommand.

Definition at line 768 of file TclCommand.cc.

int oasys::TclCommand::exec ( int  argc,
const char **  argv,
Tcl_Interp *  interp 
) [virtual]

Override this to parse the list of arguments as strings.

Parameters:
argc Argument count
argv Argument values
interp Tcl interpreter
Returns:
0 on success, -1 on error

Reimplemented in DTNOpenCommand, DTNCloseCommand, DTNRegisterCommand, DTNUnregisterCommand, DTNSendCommand, DTNBindCommand, DTNUnbindCommand, DTNRecvCommand, ShutdownCommand, oasys::DebugCommand, oasys::HelpCommand, oasys::LogCommand, dtn::InterfaceCommand, dtn::LinkCommand, dtn::RegistrationCommand, dtn::RouteCommand, dtn::ShutdownCommand, dtn::TestCommand, dtnsim::ConnCommand, dtnsim::NodeCommand, dtnsim::SimCommand, and dtnsim::Simdtn2Command.

Definition at line 782 of file TclCommand.cc.

int oasys::TclCommand::cmd_info ( Tcl_Interp *  interp  )  [virtual]

Handles the "info" command which prints out the value of the bound variables for a TclCommand.

Parameters:
interp Tcl interperter

Definition at line 811 of file TclCommand.cc.

int oasys::TclCommand::cmd_set ( int  objc,
Tcl_Obj **  objv,
Tcl_Interp *  interp 
) [virtual]

Internal handling of the "set" command.

Parameters:
objc Argument count
objv Argument values
interp Tcl interpreter
Returns:
0 on success, -1 on error

Definition at line 828 of file TclCommand.cc.

const char* oasys::TclCommand::name (  )  const [inline]

Get the name of the module.

Definition at line 320 of file TclCommand.h.

References name_.

Referenced by add_to_help(), dtnsim::SimCommand::exec(), dtn::RouteCommand::exec(), dtnsim::NodeCommand::exec(), dtn::LinkCommand::exec(), and dtn::InterfaceCommand::exec().

virtual const char* oasys::TclCommand::help_string (  )  [inline, virtual]

Return the help string for this command.

Definition at line 325 of file TclCommand.h.

References oasys::StringBuffer::c_str(), and help_.

bool oasys::TclCommand::hasBindings (  )  [inline]

Does this command have any bindings?

Definition at line 330 of file TclCommand.h.

References bindings_.

void oasys::TclCommand::bind_i ( const char *  name,
int *  val,
const char *  help = NULL 
) [protected]

Bind an integer to the set command.

Referenced by dtn::APICommand::APICommand(), bind_i(), dtn::TestCommand::bind_vars(), oasys::ConsoleCommand::ConsoleCommand(), dtn::ParamCommand::ParamCommand(), dtn::RouteCommand::RouteCommand(), and dtn::StorageCommand::StorageCommand().

void oasys::TclCommand::bind_i ( const char *  name,
int *  val,
int  initval,
const char *  help = NULL 
) [protected]

void oasys::TclCommand::bind_i ( const char *  name,
int16_t *  val,
const char *  help = NULL 
) [protected]

Bind a 16 bit integer to the set command.

void oasys::TclCommand::bind_i ( const char *  name,
int16_t *  val,
int16_t  initval,
const char *  help = NULL 
) [protected]

void oasys::TclCommand::bind_i ( const char *  name,
unsigned int *  val,
const char *  help = NULL 
) [inline, protected]

Unsigned / signed aliases for other integer types.

Definition at line 404 of file TclCommand.h.

References bind_i().

void oasys::TclCommand::bind_i ( const char *  name,
unsigned int *  val,
unsigned int  initval,
const char *  help = NULL 
) [inline, protected]

Unsigned / signed aliases for other integer types.

Definition at line 410 of file TclCommand.h.

References bind_i().

void oasys::TclCommand::bind_i ( const char *  name,
u_int16_t *  val,
const char *  help = NULL 
) [inline, protected]

Unsigned / signed aliases for other integer types.

Definition at line 416 of file TclCommand.h.

References bind_i().

void oasys::TclCommand::bind_i ( const char *  name,
u_int16_t *  val,
u_int16_t  initval,
const char *  help = NULL 
) [inline, protected]

Unsigned / signed aliases for other integer types.

Definition at line 422 of file TclCommand.h.

References bind_i().

void oasys::TclCommand::bind_d ( const char *  name,
double *  val,
const char *  help = NULL 
) [protected]

Bind a double to the set command.

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

void oasys::TclCommand::bind_d ( const char *  name,
double *  val,
double  initval,
const char *  help = NULL 
) [protected]

void oasys::TclCommand::bind_b ( const char *  name,
bool val,
const char *  help = NULL 
) [protected]

Bind a boolean to the set command.

Referenced by dtn::TestCommand::bind_vars(), oasys::ConsoleCommand::ConsoleCommand(), dtn::ParamCommand::ParamCommand(), dtn::RouteCommand::RouteCommand(), and dtn::StorageCommand::StorageCommand().

void oasys::TclCommand::bind_b ( const char *  name,
bool val,
bool  initval,
const char *  help = NULL 
) [protected]

void oasys::TclCommand::bind_s ( const char *  name,
std::string *  str,
const char *  initval,
const char *  help 
) [protected]

Bind a string to the set command.

Definition at line 1012 of file TclCommand.cc.

Referenced by dtnsim::Simdtn2Command::at_reg(), bind_s(), dtn::TestCommand::bind_vars(), dtnsim::ConnCommand::ConnCommand(), oasys::ConsoleCommand::ConsoleCommand(), oasys::LogCommand::LogCommand(), dtn::RouteCommand::RouteCommand(), dtnsim::SimCommand::SimCommand(), and dtn::StorageCommand::StorageCommand().

void oasys::TclCommand::bind_s ( const char *  name,
std::string *  str,
const char *  help = NULL 
) [inline, protected]

Definition at line 450 of file TclCommand.h.

References bind_s().

void oasys::TclCommand::bind_addr ( const char *  name,
in_addr_t *  addrp,
const char *  help = NULL 
) [protected]

Bind an ip addr for the set command, allowing the user to pass a hostname and/or a dotted quad style address.

Referenced by dtn::APICommand::APICommand(), and oasys::ConsoleCommand::ConsoleCommand().

void oasys::TclCommand::bind_addr ( const char *  name,
in_addr_t *  addrp,
in_addr_t  initval,
const char *  help = NULL 
) [protected]

void oasys::TclCommand::unbind ( const char *  name  )  [protected]

Unbind a variable.

Definition at line 1034 of file TclCommand.cc.

void oasys::TclCommand::set_result ( const char *  result  )  [inline, protected]

Set the TclResult string.

Definition at line 473 of file TclCommand.h.

References oasys::TclCommandInterp::instance(), and oasys::TclCommandInterp::set_result().

Referenced by dtn::RouteCommand::exec(), dtn::RegistrationCommand::exec(), dtnsim::NodeCommand::exec(), oasys::LogCommand::exec(), dtn::LinkCommand::exec(), dtn::InterfaceCommand::exec(), oasys::HelpCommand::exec(), and dtn::BundleCommand::exec().

void oasys::TclCommand::set_objresult ( Tcl_Obj *  obj  )  [inline, protected]

Set a Tcl_Obj as the result.

Definition at line 481 of file TclCommand.h.

References oasys::TclCommandInterp::instance(), and oasys::TclCommandInterp::set_objresult().

Referenced by dtn::RegistrationCommand::exec(), and dtn::BundleCommand::exec().

void oasys::TclCommand::append_result ( const char *  result  )  [inline, protected]

Append the TclResult string.

Definition at line 489 of file TclCommand.h.

References oasys::TclCommandInterp::append_result(), and oasys::TclCommandInterp::instance().

void oasys::TclCommand::resultf ( const char *  fmt,
  ... 
) [protected]

Format and set the TclResult string.

Definition at line 792 of file TclCommand.cc.

Referenced by dtn::TestCommand::exec(), dtnsim::SimCommand::exec(), dtn::RouteCommand::exec(), dtn::RegistrationCommand::exec(), dtnsim::NodeCommand::exec(), oasys::LogCommand::exec(), dtn::LinkCommand::exec(), dtn::InterfaceCommand::exec(), oasys::HelpCommand::exec(), DTNRecvCommand::exec(), DTNUnbindCommand::exec(), DTNBindCommand::exec(), DTNSendCommand::exec(), DTNUnregisterCommand::exec(), DTNRegisterCommand::exec(), DTNCloseCommand::exec(), DTNOpenCommand::exec(), oasys::DebugCommand::exec(), dtnsim::ConnCommand::exec(), and dtn::BundleCommand::exec().

void oasys::TclCommand::append_resultf ( const char *  fmt,
  ... 
) [protected]

Format and set the TclResult string.

Definition at line 801 of file TclCommand.cc.

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

void oasys::TclCommand::wrong_num_args ( int  objc,
const char **  objv,
int  parsed,
int  min,
int  max 
) [inline, protected]

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 514 of file TclCommand.h.

References oasys::TclCommandInterp::instance().

Referenced by dtnsim::Simdtn2Command::exec(), dtnsim::SimCommand::exec(), dtn::ShutdownCommand::exec(), dtn::RouteCommand::exec(), dtn::RegistrationCommand::exec(), dtnsim::NodeCommand::exec(), oasys::LogCommand::exec(), dtn::LinkCommand::exec(), dtn::InterfaceCommand::exec(), oasys::HelpCommand::exec(), DTNRecvCommand::exec(), DTNUnbindCommand::exec(), DTNBindCommand::exec(), DTNSendCommand::exec(), DTNUnregisterCommand::exec(), DTNRegisterCommand::exec(), DTNCloseCommand::exec(), DTNOpenCommand::exec(), dtnsim::ConnCommand::exec(), dtn::BundleCommand::exec(), and wrong_num_args().

void oasys::TclCommand::wrong_num_args ( int  objc,
Tcl_Obj **  objv,
int  parsed,
int  min,
int  max 
) [inline, protected]

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 531 of file TclCommand.h.

References oasys::TclCommandInterp::instance(), and wrong_num_args().

void oasys::TclCommand::add_to_help ( const char *  subcmd,
const char *  help_str 
) [inline, protected]

Append the given information to the current help string, typically used for a set of alternatives for subcommands.

Definition at line 542 of file TclCommand.h.

References oasys::StringBuffer::append(), oasys::StringBuffer::appendf(), help_, and name().

Referenced by dtn::BundleCommand::BundleCommand(), dtnsim::ConnCommand::ConnCommand(), oasys::DebugCommand::DebugCommand(), oasys::HelpCommand::HelpCommand(), dtn::InterfaceCommand::InterfaceCommand(), dtn::LinkCommand::LinkCommand(), oasys::LogCommand::LogCommand(), dtnsim::NodeCommand::NodeCommand(), dtn::RegistrationCommand::RegistrationCommand(), dtn::RouteCommand::RouteCommand(), dtn::ShutdownCommand::ShutdownCommand(), and dtn::TestCommand::TestCommand().


Friends And Related Function Documentation

friend class TclCommandInterp [friend]

Definition at line 333 of file TclCommand.h.


Member Data Documentation

std::string oasys::TclCommand::name_ [protected]

Name of the module.

Definition at line 335 of file TclCommand.h.

Referenced by name().

StringBuffer oasys::TclCommand::help_ [protected]

Help string.

Definition at line 336 of file TclCommand.h.

Referenced by add_to_help(), and help_string().

bool oasys::TclCommand::do_builtins_ [protected]

Set to false if a module doesn't want builtin commands like "set".

Definition at line 337 of file TclCommand.h.

BindingTable oasys::TclCommand::bindings_ [protected]

The table of registered bindings.

Definition at line 384 of file TclCommand.h.

Referenced by hasBindings().


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