try {
switch(command.builtin()) {
case ParseCommandInfo::NoBuiltin :
+ traverseToCommand(command.commandPath())(output, command.arguments());
break;
-
+
case ParseCommandInfo::BuiltinCD :
if ( command.arguments() ) {
if (command.arguments().begin()->size() == 1
catch (InvalidDirectoryException &) {
output << "invalid directory" << std::endl;
}
+ catch (InvalidCommandException &) {
+ output << "invalid command" << std::endl;
+ }
return true;
}
prefix_ senf::console::DirectoryNode &
-senf::console::Executor::traverseTo(ParseCommandInfo::argument_value_type const & path)
+senf::console::Executor::traverseTo (ParseCommandInfo::argument_value_type const & path)
{
try {
return dynamic_cast<DirectoryNode&>(
throw InvalidDirectoryException();
}
}
+
+prefix_ senf::console::CommandNode &
+senf::console::Executor::traverseToCommand(ParseCommandInfo::CommandPathRange const & path)
+{
+ try {
+ return dynamic_cast<CommandNode &>( cwd().traverse(path) );
+ }
+ catch (std::bad_cast &) {
+ throw InvalidCommandException();
+ }
+ catch (UnknownNodeNameException &) {
+ throw InvalidCommandException();
+ }
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
private:
DirectoryNode & traverseTo(ParseCommandInfo::argument_value_type const & path);
+ CommandNode & traverseToCommand(ParseCommandInfo::CommandPathRange const & path);
struct InvalidDirectoryException {};
+ struct InvalidCommandException {};
DirectoryNode::weak_ptr cwd_;
DirectoryNode::weak_ptr oldCwd_;
#include <boost/utility.hpp>
#include <boost/range/iterator_range.hpp>
#include "../Utils/Exception.hh"
+#include "Parse.hh"
//#include "Node.mpp"
///////////////////////////////hh.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
+ virtual void operator()(std::ostream & output,
+ ParseCommandInfo::ArgumentsRange const & arguments) = 0;
+
ptr thisptr();
cptr thisptr() const;
// THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER stopClient RETURNS
stopClient();
return;
- }
+ }
+ catch (std::exception & ex) {
+ out_ << ex.what() << std::endl;
+ }
+ catch (...) {
+ out_ << "unidentified error (unknown exception thrown)" << std::endl;
+ }
showPrompt();
ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"),
// Custom includes
#include <iostream>
#include "Server.hh"
+#include "Node.hh"
#include "../Scheduler/Scheduler.hh"
#include "../Utils/Logger/SenfLog.hh"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
+namespace {
+ struct MyCommand : public senf::console::CommandNode
+ {
+ MyCommand(std::string name) : senf::console::CommandNode(name) {}
+ void operator()(std::ostream & output,
+ senf::console::ParseCommandInfo::ArgumentsRange const & arguments) {
+ senf::console::ParseCommandInfo::argument_iterator i (arguments.begin());
+ senf::console::ParseCommandInfo::argument_iterator i_end (arguments.end());
+ for (; i != i_end; ++i) {
+ senf::console::ParseCommandInfo::token_iterator j (i->begin());
+ senf::console::ParseCommandInfo::token_iterator j_end (i->end());
+ for (; j != j_end; ++j)
+ output << j->value() << ' ';
+ }
+ output << "\n";
+ }
+ };
+}
+
int main(int, char const **)
{
senf::log::ConsoleTarget::instance().route< senf::SenfLog, senf::log::NOTICE >();
senf::console::root().mkdir("network").mkdir("eth0");
senf::console::root().mkdir("server");
+ senf::console::root()["network"].add(
+ std::auto_ptr<senf::console::GenericNode>(new MyCommand("route")));
+
senf::console::Server::start( senf::INet4SocketAddress("127.0.0.1:23232") )
.name("testServer");