Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Executor.hh

Go to the documentation of this file.
00001 // $Id: Executor.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Scheduler_Console_Executor_
00027 #define HH_SENF_Scheduler_Console_Executor_ 1
00028 
00029 // Custom includes
00030 #include <boost/utility.hpp>
00031 #include "Parse.hh"
00032 #include <senf/Utils/Logger/SenfLog.hh>
00033 #include "Node.hh"
00034 
00035 //#include "Executor.mpp"
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 namespace senf {
00039 namespace console {
00040 
00057     class Executor
00058         : boost::noncopyable
00059     {
00060         SENF_LOG_CLASS_AREA();
00061         SENF_LOG_DEFAULT_LEVEL( senf::log::VERBOSE );
00062     public:
00063         //-////////////////////////////////////////////////////////////////////////
00064         // Types
00065 
00067         struct ExitException {};
00068 
00070         typedef boost::function<void (DirectoryNode &,std::string const &)> SecurityPolicy;
00071 
00073         struct IgnoreCommandException {};
00074 
00075         typedef void result_type;
00076 
00077         //-////////////////////////////////////////////////////////////////////////
00078         //\/name Structors and default members
00079         //\{
00080 
00081         Executor();
00082 
00083         //\}
00084         //-////////////////////////////////////////////////////////////////////////
00085 
00086         void execute(std::ostream & output, ParseCommandInfo const & command);
00088 
00091         void operator()(std::ostream & output, ParseCommandInfo const & command);
00093 
00095         GenericNode & getNode(ParseCommandInfo const & command);
00096         DirectoryNode & cwd() const;    
00097         void cwd(DirectoryNode & dir);  
00098         std::string cwdPath() const;    
00099         bool skipping() const;          
00100 
00101         bool autocd() const;            
00102 
00106         Executor & autocd(bool v);      
00107 
00109         bool autocomplete() const;      
00110 
00115         Executor & autocomplete(bool v); 
00116 
00119         DirectoryNode & chroot() const; 
00120 
00124         Executor & chroot(DirectoryNode & node); 
00125 
00130         Executor & policy(SecurityPolicy policy = SecurityPolicy()); 
00131 
00134     protected:
00135 
00136     private:
00137         typedef std::vector<DirectoryNode::weak_ptr> Path;
00138 
00139         void exec(std::ostream & output, ParseCommandInfo const & command);
00140 
00141         void cd(ParseCommandInfo::TokensRange dir);
00142         void ls(std::ostream & output, ParseCommandInfo::TokensRange dir);
00143         void ll(std::ostream & output, ParseCommandInfo::TokensRange dir);
00144         void lr(std::ostream & output, ParseCommandInfo::TokensRange dir);
00145         void pushd(ParseCommandInfo::TokensRange dir);
00146         void popd();
00147         void exit();
00148         void help(std::ostream & output, ParseCommandInfo::TokensRange path);
00149 
00150         GenericNode & traverseNode(ParseCommandInfo::TokensRange const & path);
00151         void traverseDirectory(ParseCommandInfo::TokensRange const & path,
00152                                Path & dir);
00153         std::string complete(DirectoryNode & dir, std::string const & name);
00154 
00155         struct InvalidPathException {
00156             std::string path;
00157             InvalidPathException() : path() {}
00158             InvalidPathException(std::string path_) : path(path_) {}
00159 
00160         };
00161         struct InvalidDirectoryException {
00162             std::string path;
00163             InvalidDirectoryException() : path() {}
00164             InvalidDirectoryException(std::string path_) : path(path_) {}
00165         };
00166         struct InvalidCommandException {};
00167 
00168         DirectoryNode::ptr root_;
00169         SecurityPolicy policy_;
00170         mutable Path cwd_;
00171         Path oldCwd_;
00172 
00173         typedef std::vector<Path> DirStack;
00174         DirStack dirstack_;
00175 
00176         bool autocd_;
00177         bool autocomplete_;
00178     };
00179 
00180     void senf_console_format_value(DirectoryNode::ptr value, std::ostream & os);
00181 
00182 }}
00183 
00184 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00185 #include "Executor.cci"
00186 //#include "Executor.ct"
00187 //#include "Executor.cti"
00188 #endif
00189 
00190 
00191 // Local Variables:
00192 // mode: c++
00193 // fill-column: 100
00194 // comment-column: 40
00195 // c-file-style: "senf"
00196 // indent-tabs-mode: nil
00197 // ispell-local-dictionary: "american"
00198 // compile-command: "scons -u test"
00199 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research