X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FExecutor.hh;h=81dafd9468b3e77e79ee630b98fec9dd75ced674;hb=748363b235c4651b3992cc291a95dc2e18e45724;hp=08da10f150741f331f77056c342b6b0e14efe808;hpb=d620e7ff9b68377ea20ca266c23cc3f05781868c;p=senf.git diff --git a/Console/Executor.hh b/Console/Executor.hh index 08da10f..81dafd9 100644 --- a/Console/Executor.hh +++ b/Console/Executor.hh @@ -27,8 +27,10 @@ #define HH_Executor_ 1 // Custom includes +#include #include "Parse.hh" #include "../Utils/Logger/SenfLog.hh" +#include "Node.hh" //#include "Executor.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -36,35 +38,76 @@ namespace senf { namespace console { - /** \brief + /** \brief 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. */ class Executor + : boost::noncopyable { SENF_LOG_CLASS_AREA(); - SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE ); + SENF_LOG_DEFAULT_LEVEL( senf::log::VERBOSE ); public: /////////////////////////////////////////////////////////////////////////// // Types - typedef boost::iterator_range< ParseCommandInfo::argument_iterator> Arguments; - - struct ExitException {}; // NOT derived from std::exception ! + /// Thrown by built-in 'exit' command + struct ExitException {}; /////////////////////////////////////////////////////////////////////////// + //\/name Structors and default members + ///\{ - bool operator()(ParseCommandInfo const & command, std::ostream & output); - + Executor(); + + ///\} + /////////////////////////////////////////////////////////////////////////// + + void execute(std::ostream & output, ParseCommandInfo const & command); + ///< Execute command + /**< Output will be written to \a output. + Same as operator()(). */ + + void operator()(std::ostream & output, ParseCommandInfo const & command); + ///< Execute command + /**< Output will be written to \a output. + Same as execute(). */ + DirectoryNode & cwd() const; ///< Current working directory + protected: private: + GenericNode & traverseNode(ParseCommandInfo::argument_value_type const & path); + DirectoryNode & traverseDirectory(ParseCommandInfo::argument_value_type const & path); + CommandNode & traverseCommand(ParseCommandInfo::CommandPathRange const & path); + + struct InvalidPathException {}; + struct InvalidDirectoryException {}; + struct InvalidCommandException {}; + DirectoryNode::weak_ptr cwd_; + DirectoryNode::weak_ptr oldCwd_; + typedef std::vector DirStack; + DirStack dirstack_; }; }} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Executor.cci" +#include "Executor.cci" //#include "Executor.ct" //#include "Executor.cti" #endif