X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FtestServer.cc;h=3ed6ba98144c9a637662e4f8290b7fce02554c31;hb=489be2bbd4d03259a17df14e4962a4524cd5b654;hp=8b3f3dad01fe91def6fe57e397721514f5793f46;hpb=c70f7413515b513656f850f51a3cc2ea9d776a37;p=senf.git diff --git a/Console/testServer.cc b/Console/testServer.cc index 8b3f3da..3ed6ba9 100644 --- a/Console/testServer.cc +++ b/Console/testServer.cc @@ -21,97 +21,104 @@ // 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 "ObjectDirectory.hh" -#include "../Scheduler/Scheduler.hh" -#include "../Utils/Logger/SenfLog.hh" - -//#include "test.mpp" -#define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// - -namespace { - - void fn(std::ostream & output, - senf::console::CommandNode::Arguments const & arguments) { - senf::console::CommandNode::Arguments::iterator i (arguments.begin()); - senf::console::CommandNode::Arguments::iterator i_end (arguments.end()); - for (; i != i_end; ++i) { - senf::console::CommandNode::Arguments::value_type::iterator j (i->begin()); - senf::console::CommandNode::Arguments::value_type::iterator j_end (i->end()); - for (; j != j_end; ++j) - output << j->value() << ' '; - } - output << "\n"; - } +#include +#include - struct TestObject - { - senf::console::ObjectDirectory dir; +namespace kw = senf::console::kw; - TestObject() : dir(this) { - dir.add("blub", &TestObject::blub) - .doc("Example of a member function"); +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"; +} + +struct TestObject +{ + senf::console::ScopedDirectory dir; + + 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}"); } - - void blub(std::ostream & output, senf::console::CommandNode::Arguments const & args) { - output << "blub\n"; + + double vat (int vat, double amount) + { + return amount * vat/(100.0+vat); } - }; +}; - void shutdownServer(std::ostream &, - senf::console::CommandNode::Arguments const &) - { - senf::Scheduler::instance().terminate(); - throw senf::console::Executor::ExitException(); - } +void shutdownServer() +{ + senf::Scheduler::instance().terminate(); + throw senf::console::Executor::ExitException(); +} +void enableLogging(std::ostream & os) +{ + senf::console::Client::get(os).route(); } -int main(int, char const **) +int main(int, char **) { - senf::log::ConsoleTarget::instance().route< senf::SenfLog, senf::log::NOTICE >(); + ::signal(SIGPIPE, SIG_IGN); + senf::log::ConsoleTarget::instance().route< senf::log::VERBOSE >(); senf::console::root() .doc("This is the console test application"); + senf::console::root() - .mkdir("network") - .doc("Network related settings"); - senf::console::root()["network"] - .mkdir("eth0") - .doc("Ethernet device eth0"); + .mkdir("console") + .doc("Console settings"); + + senf::console::DirectoryNode & serverDir ( + senf::console::root() + .mkdir("server") + .doc("server commands") ); + + senf::console::ScopedDirectory<> testDir; senf::console::root() - .mkdir("server"); - senf::console::root()["server"] + .add("test", testDir) + .doc("Test functions"); + + senf::console::root()["console"] + .add("showlog", &enableLogging) + .doc("Enable display of log messages on the current console"); + + serverDir .add("shutdown", &shutdownServer) .doc("Terminate server application"); - senf::console::root()["network"] - .add("route", &fn) - .doc("Example of a directly registered function"); + + testDir + .add("echo", &echo) + .doc("Example of a function utilizing manual argument parsing"); TestObject test; - senf::console::root() - .add("testob", test.dir) + testDir + .add("extra", 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(23232u) ) .name("testServer"); senf::Scheduler::instance().process(); } -///////////////////////////////cc.e//////////////////////////////////////// -#undef prefix_ -//#include "test.mpp" - // Local Variables: // mode: c++