PCLISocket Class Reference

Command Line Interpreter over TCP sockets. More...

`#include <cli.h>`

Inheritance diagram for PCLISocket:

## Public Member Functions

Construction
| PCLISocket (WORD port=0, const char *prompt=NULL, bool singleThreadForAll=false)
| ~PCLISocket ()
Overrides from PCLI
virtual bool | Start (bool runInBackground=true)
| Start a command line interpreter. More...
virtual void | Stop ()
| Stop and clean up command line interpreters. More...
virtual Context * | AddContext (Context *context=NULL)
| Add a command line interpreter context to the system. More...
virtual void | RemoveContext (Context *context)
| Remove the command line interpreter context. More...
Operations
bool | Listen (WORD port=0)
| Start listening socket. More...
WORD | GetPort () const
| Get the port we are listing on. More...
Public Member Functions inherited from PCLI
virtual Context * | StartForeground ()
| Initialise a foreground context and return it. More...
virtual bool | RunContext (Context *context)
| Run a context. More...
| PCLI (const char *prompt=NULL)
| Contracut a new command line interpreter. More...
virtual | ~PCLI ()
| Destroy the command line interpreter. More...
bool | StartContext (PChannel *channel, bool autoDelete=true, bool runInBackground=true)
| Open a command line interpreter context. More...
bool | StartContext (PChannel *readChannel, PChannel *writeChannel, bool autoDeleteRead=true, bool autoDeleteWrite=true, bool runInBackground=true)
virtual Context * | CreateContext ()
| Create a new context. More...
virtual Context * | AddContext (Context *context=NULL)
| Add a command line interpreter context to the system. More...
virtual void | RemoveContext (Context *context)
| Remove the command line interpreter context. More...
virtual void | GarbageCollection ()
| Remove any closed command line interpreter contexts. More...
virtual void | OnReceivedLine (Arguments &line)
| Received a completed command line. More...
virtual bool | OnLogIn (const PString &username, const PString &password)
| Received a login name/pasword to be verified. More...
void | Broadcast (const PString &message) const
| Set a string to all command line interpreter contexts. More...
bool | SetCommand (const char *command, const PNotifier &notifier, const char *help=NULL, const char *usage=NULL)
| Register a new command to be interpreted. More...
void | ShowHelp (Context &context)
| Show help for registered commands to the context. More...
const PString & | GetNewLine () const
| Get new line string output at the end of every line. More...
void | SetNewLine (const PString &newLine)
| Set new line string output at the end of every line. More...
bool | GetRequireEcho () const
| Get flag for echo is required for entered characters. More...
void | SetRequireEcho (bool requireEcho)
| Set flag for echo is required for entered characters. More...
const PString & | GetEditCharacters () const
| Get characters used for editing (backspace/delete) command lines. More...
void | SetEditCharacters (const PString &editCharacters)
| Set characters used for editing (backspace/delete) command lines. More...
const PString & | GetPrompt () const
| Get prompt used for command line interpreter. More...
void | SetPrompt (const PString &prompt)
| Set prompt used for command line interpreter. More...
const PString & | GetUsernamePrompt () const
| Get prompt used for login (if enabled). More...
void | SetUsernamePrompt (const PString &prompt)
| Set prompt used for login (if enabled). More...
const PString & | GetPasswordPrompt () const
| Get prompt used for password (if enabled). More...
void | SetPasswordPrompt (const PString &prompt)
| Set prompt used for password (if enabled). More...
const PString & | GetUsername () const
| Get username for log in validation. More...
void | SetUsername (const PString &username)
| Set username for log in validation. More...
const PString & | GetPassword () const
| Get password for log in validation. More...
void | SetPassword (const PString &password)
| Set password for log in validation. More...
const PCaselessString & | GetExitCommand () const
| Get command to be used to exit session. More...
void | SetExitCommand (const PCaselessString &exitCommand)
| Set command to be used to exit session. More...
const PCaselessString & | GetHelpCommand () const
| Get command to be used to display help. More...
void | SetHelpCommand (const PCaselessString &helpCommand)
| Set command to be used to display help. More...
const PString & | GetHelpOnHelp () const
| Get help on help. More...
void | SetHelpOnHelp (const PCaselessString &helpOnHelp)
| Set help on help. More...
const PCaselessString & | GetRepeatCommand () const
| Get the command to be used to repeat the last executed command. More...
void | SetRepeatCommand (const PCaselessString &repeatCommand)
| Set the command to be used to repeat the last executed command. More...
const PCaselessString & | GetHistoryCommand () const
| Get command that will list/execute command history. More...
void | SetHistoryCommand (const PCaselessString &historyCommand)
| Set command that will list/execute command history. More...
const PString & | GetNoHistoryError () const
| Get error message for if there is no history. More...
void | SetNoHistoryError (const PString &noHistoryError)
| Set error message for if there is no history. More...
const PString & | GetCommandUsagePrefix () const
| Get usage prefix for if Arguments::WriteUsage() called. More...
void | SetCommandUsagePrefix (const PString &commandUsagePrefix)
| Set usage prefix for if Arguments::WriteUsage() called. More...
const PString & | GetCommandErrorPrefix () const
| Get error prefix for if Arguments::WriteError() called. More...
void | SetCommandErrorPrefix (const PString &commandErrorPrefix)
| Set error prefix for if Arguments::WriteError() called. More...
const PString & | GetUnknownCommandError () const
| Get error message for if unknown command is entered. More...
void | SetUnknownCommandError (const PString &unknownCommandError)
| Set error message for if unknown command is entered. More...
Public Member Functions inherited from PObject
virtual | ~PObject ()
virtual PObject * | Clone () const
| Create a copy of the class on the heap. More...
virtual PINDEX | HashFunction () const
| This function yields a hash value required by the `PDictionary` class. More...
virtual Comparison | Compare (const PObject &obj) const
| Compare the two objects and return their relative rank. More...
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const
| Determine the byte wise comparison of two objects. More...
bool | operator== (const PObject &obj) const
| Compare the two objects. More...
bool | operator!= (const PObject &obj) const
| Compare the two objects. More...
bool | operator< (const PObject &obj) const
| Compare the two objects. More...
bool | operator> (const PObject &obj) const
| Compare the two objects. More...
bool | operator<= (const PObject &obj) const
| Compare the two objects. More...
bool | operator>= (const PObject &obj) const
| Compare the two objects. More...
virtual const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. More...
virtual void | PrintOn (ostream &strm) const
| Output the contents of the object to the stream. More...
virtual void | ReadFrom (istream &strm)
| Input the contents of the object from the stream. More...

## Protected Types

typedef std::map< PSocket *, Context * > | ContextMap_t
Protected Types inherited from PCLI
typedef std::map< PString, InternalCommand > | CommandMap_t
typedef std::list< Context * > | ContextList_t

## Protected Member Functions

| PDECLARE_NOTIFIER (PThread, PCLISocket, ThreadMain)
bool | HandleSingleThreadForAll ()
bool | HandleIncoming ()
virtual PTCPSocket * | CreateSocket ()
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## Protected Attributes

bool | m_singleThreadForAll
PTCPSocket | m_listenSocket
PThread * | m_thread
ContextMap_t | m_contextBySocket
Protected Attributes inherited from PCLI
PString | m_newLine
bool | m_requireEcho
PString | m_editCharacters
PString | m_prompt
PString | m_usernamePrompt
PString | m_passwordPrompt
PString | m_username
PString | m_password
PCaselessString | m_exitCommand
PCaselessString | m_helpCommand
PString | m_helpOnHelp
PCaselessString | m_repeatCommand
PCaselessString | m_historyCommand
PString | m_noHistoryError
PString | m_commandUsagePrefix
PString | m_commandErrorPrefix
PString | m_unknownCommandError
CommandMap_t | m_commands
ContextList_t | m_contextList
PMutex | m_contextMutex

## Additional Inherited Members

Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...
Static Public Member Functions inherited from PObject
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
| Internal function caled from CompareObjectMemoryDirect() More...
static const char * | Class ()
| Get the name of the class as a C string. More...

## Detailed Description

Command Line Interpreter over TCP sockets.

This class allows for access and automatic creation of command line interpreter contexts from incoming TCP connections on a listening port.

## Member Typedef Documentation

typedef std::map<PSocket *, Context *> PCLISocket::ContextMap_t

protected

## Constructor & Destructor Documentation

PCLISocket::PCLISocket | ( | WORD | port = `0`,
|  | const char * | prompt = `NULL`,
|  | bool | singleThreadForAll = `false`
| ) |  |

PCLISocket::~PCLISocket | ( |  | ) |

## Member Function Documentation

virtual Context* PCLISocket::AddContext | ( | Context * | context = `NULL` | ) |

virtual

Add a command line interpreter context to the system.

If context is NULL then CreateContext() is called to create one.

virtual PTCPSocket* PCLISocket::CreateSocket | ( |  | ) |

protected virtual

Reimplemented in PCLITelnet.

WORD PCLISocket::GetPort | ( |  | ) | const

inline

Get the port we are listing on.

References PSocket::GetPort(), and m_listenSocket.

bool PCLISocket::HandleIncoming | ( |  | ) |

protected

bool PCLISocket::HandleSingleThreadForAll | ( |  | ) |

protected

bool PCLISocket::Listen | ( | WORD | port = `0` | ) |

Start listening socket.

PCLISocket::PDECLARE_NOTIFIER | ( | PThread | ,
|  | PCLISocket | ,
|  | ThreadMain |
| ) |  |

protected

virtual void PCLISocket::RemoveContext | ( | Context * | context | ) |

virtual

Remove the command line interpreter context.

The context thread is stopped, the channel closed and memory deleted.

virtual bool PCLISocket::Start | ( | bool | runInBackground = `true` | ) |

virtual

Start a command line interpreter.

This will start listening for incoming TCP connections and create/dispatch contexts to handle them.

Parameters

  runInBackground | Spawn a thread to read and interpret commands

Reimplemented from PCLI.

virtual void PCLISocket::Stop | ( |  | ) |

virtual

Stop and clean up command line interpreters.

All the running contexts threads will be stopped, closing the channels and memory cleaned up.

The listening socket is also closed and the listener dispatch thread shut down.

Reimplemented from PCLI.

## Member Data Documentation

ContextMap_t PCLISocket::m_contextBySocket

protected

PTCPSocket PCLISocket::m_listenSocket

protected

Referenced by GetPort().

bool PCLISocket::m_singleThreadForAll

protected

PThread* PCLISocket::m_thread

protected

The documentation for this class was generated from the following file:

- cli.h