Execute config/console commands. More...
#include <senf/Utils/Console/Executor.hh>
Classes | |
struct | ExitException |
Thrown by built-in 'exit' command. More... | |
struct | IgnoreCommandException |
Thrown by the SecurityPolicy to silently ignore a command. More... | |
Public Types | |
typedef boost::function< void(DirectoryNode &, std::string const &)> | SecurityPolicy |
Executor policy function. More... | |
typedef void | result_type |
Public Member Functions | |
void | execute (std::ostream &output, ParseCommandInfo const &command) |
Execute command. More... | |
void | operator() (std::ostream &output, ParseCommandInfo const &command) |
Execute command. More... | |
GenericNode & | getNode (ParseCommandInfo const &command) |
DirectoryNode & | cwd () const |
Current working directory. More... | |
void | cwd (DirectoryNode &dir) |
Change current directory. More... | |
std::string | cwdPath () const |
Return pathname of current directory. More... | |
bool | skipping () const |
true , if currently skipping a directory group More... | |
bool | autocd () const |
Get current autocd status. More... | |
Executor & | autocd (bool v) |
Set autocd status. More... | |
bool | autocomplete () const |
Get current autocomplete status. More... | |
Executor & | autocomplete (bool v) |
Set autocomplete status. More... | |
DirectoryNode & | chroot () const |
Get root node. More... | |
Executor & | chroot (DirectoryNode &node) |
chroot into given directory More... | |
Executor & | policy (SecurityPolicy policy=SecurityPolicy()) |
Set security policy. More... | |
Executor () | |
Execute config/console commands.
The Executor interprets parsed config/console commands and executes them. It manages the current execution context (current directory, directory stack and so on).
The executor is normally called directly by the parser callback for each command.
Executing the built-in 'exit' command will throw Executor::ExitException. This exception (which is not derived from std::exception since it's not a real exception) must be handled by the caller.
All directories are managed using weak pointers. If any of the directories expires (current directory, directory stack, last directory) it will be replaced with the root directory. Directories expire when they are destructed or when they are detached from the config tree root node.
Definition at line 48 of file Executor.hh.
typedef void senf::console::Executor::result_type |
Definition at line 66 of file Executor.hh.
typedef boost::function<void (DirectoryNode &,std::string const &)> senf::console::Executor::SecurityPolicy |
Executor policy function.
Definition at line 61 of file Executor.hh.
senf::console::Executor::Executor | ( | ) |
bool senf::console::Executor::autocd | ( | ) | const |
Get current autocd status.
if autocd is enabled, specifying a directory name as command will cd to that directory. Disabled by default (but enabled automatically by the interactive console).
bool senf::console::Executor::autocomplete | ( | ) | const |
Get current autocomplete status.
if autocomplete is enabled, path components which can be uniquely completed will be completed automatically. Disabled by default (but enabled automatically by the interactive console).
Executor& senf::console::Executor::autocomplete | ( | bool | v | ) |
Set autocomplete status.
DirectoryNode& senf::console::Executor::chroot | ( | ) | const |
Get root node.
The root node defaults to senf::console::root(). If changed, all path references are relative to this node and objects outside that tree cannot be accessed.
Executor& senf::console::Executor::chroot | ( | DirectoryNode & | node | ) |
chroot into given directory
After this call, all path's are interpreted relative to node and only nodes in the tree rooted at node are accessible via the executor. This value defaults to senf::console::root().
senf::console::DirectoryNode & senf::console::Executor::cwd | ( | ) | const |
Current working directory.
Definition at line 49 of file Executor.cc.
void senf::console::Executor::cwd | ( | DirectoryNode & | dir | ) |
Change current directory.
std::string senf::console::Executor::cwdPath | ( | ) | const |
Return pathname of current directory.
Definition at line 58 of file Executor.cc.
void senf::console::Executor::execute | ( | std::ostream & | output, |
ParseCommandInfo const & | command | ||
) |
Execute command.
Output will be written to output. Same as operator()().
Definition at line 71 of file Executor.cc.
senf::console::GenericNode & senf::console::Executor::getNode | ( | ParseCommandInfo const & | command | ) |
Definition at line 169 of file Executor.cc.
void senf::console::Executor::operator() | ( | std::ostream & | output, |
ParseCommandInfo const & | command | ||
) |
Execute command.
Output will be written to output. Same as execute().
Executor& senf::console::Executor::policy | ( | SecurityPolicy | policy = SecurityPolicy() | ) |
Set security policy.
The security policy is called before traversing a node to validate that access.
bool senf::console::Executor::skipping | ( | ) | const |
true
, if currently skipping a directory group