X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FtestServer.cc;h=70b8d34e58bbaf2097bfcd4203b9a28126c389c1;hb=da1843a0fc5dfaea09d7d7ab3adf2d30795e04c5;hp=b55ca1b16ce3b5fcbfd969ffd3120ce973a592b9;hpb=9ff18548815d10140e83fba6ed2d573fe556c346;p=senf.git diff --git a/Console/testServer.cc b/Console/testServer.cc index b55ca1b..70b8d34 100644 --- a/Console/testServer.cc +++ b/Console/testServer.cc @@ -21,61 +21,84 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief test non-inline non-template implementation */ - -//#include "test.hh" -//#include "test.ih" + \brief testServer implementation */ // Custom includes #include -#include "Server.hh" -#include "Node.hh" -#include "../Scheduler/Scheduler.hh" -#include "../Utils/Logger/SenfLog.hh" +#include +#include + +namespace kw = senf::console::kw; + +void echo(std::ostream & output, senf::console::ParseCommandInfo const & command) +{ + typedef senf::console::ParseCommandInfo::ArgumentsRange::iterator iterator; + iterator i (command.arguments().begin()); + iterator i_end (command.arguments().end()); + for (; i != i_end; ++i) { + iterator::value_type::iterator j (i->begin()); + iterator::value_type::iterator j_end (i->end()); + for (; j != j_end; ++j) + output << j->value() << ' '; + } + output << "\n"; +} -//#include "test.mpp" -#define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +struct TestObject +{ + senf::console::ScopedDirectory dir; -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"; + TestObject() + : dir(this) + { + dir.add("vat", &TestObject::vat) + .arg("vat", "VAT in %", kw::default_value = 19) + .arg("amount", "Amount including VAT") + .doc("Returns the amount of {vat}-% VAT included in {amount}"); } - }; + + double vat (int vat, double amount) + { + return amount * vat/(100.0+vat); + } +}; + +void shutdownServer() +{ + senf::Scheduler::instance().terminate(); + throw senf::console::Executor::ExitException(); } -int main(int, char const **) +int main(int, char **) { + ::signal(SIGPIPE, SIG_IGN); 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() + .doc("This is the console test application"); + senf::console::root() + .mkdir("test") + .doc("Network related settings"); + senf::console::root() + .mkdir("server"); + senf::console::root()["server"] + .add("shutdown", &shutdownServer) + .doc("Terminate server application"); + senf::console::root()["test"] + .add("echo", &echo) + .doc("Example of a function utilizing manual argument parsing"); - senf::console::root()["network"].add( - std::auto_ptr(new MyCommand("route"))); + TestObject test; + senf::console::root() + .add("testob", test.dir) + .doc("Example of an instance directory"); - senf::console::Server::start( senf::INet4SocketAddress("127.0.0.1:23232") ) + senf::console::Server::start( senf::INet4SocketAddress(23232) ) .name("testServer"); senf::Scheduler::instance().process(); } -///////////////////////////////cc.e//////////////////////////////////////// -#undef prefix_ -//#include "test.mpp" - // Local Variables: // mode: c++