X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FtestServer.cc;h=1d0ed5893c562a1b2bce988f85df18d34b7c72c8;hb=e879290346fe5242d7df2d70ee552d264081492f;hp=8e9323a2ad6373d48d277a0a5b6db77b15c980ad;hpb=412cf8e222086fb5d89b15cb11556799e131f390;p=senf.git diff --git a/Console/testServer.cc b/Console/testServer.cc index 8e9323a..1d0ed58 100644 --- a/Console/testServer.cc +++ b/Console/testServer.cc @@ -21,34 +21,100 @@ // 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 "../Scheduler/Scheduler.hh" -#include "../Utils/Logger/SenfLog.hh" +#include +#include + +namespace kw = senf::console::kw; -//#include "test.mpp" -#define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +void echo(std::ostream & output, senf::console::ParseCommandInfo const & command) +{ + typedef senf::console::ParseCommandInfo::TokensRange::iterator iterator; + iterator i (command.tokens().begin()); + iterator i_end (command.tokens().end()); + for (; i != i_end; ++i) { + output << i->value() << ' '; + } + output << "\n"; +} -int main(int, char const **) +struct TestObject { - senf::log::ConsoleTarget::instance().route< senf::SenfLog, senf::log::NOTICE >(); + senf::console::ScopedDirectory dir; - senf::console::Server::start( senf::INet4SocketAddress("127.0.0.1:23232") ) - .name("testServer "); + 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}"); + } - senf::Scheduler::instance().process(); + double vat (int vat, double amount) + { + return amount * vat/(100.0+vat); + } +}; + +void shutdownServer() +{ + senf::Scheduler::instance().terminate(); + throw senf::console::Executor::ExitException(); +} + +void enableLogging(std::ostream & os) +{ + senf::console::Client::get(os).route(); } -///////////////////////////////cc.e//////////////////////////////////////// -#undef prefix_ -//#include "test.mpp" +int main(int, char **) +{ + ::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("console") + .doc("Console settings"); + + senf::console::DirectoryNode & serverDir ( + senf::console::root() + .mkdir("server") + .doc("server commands") ); + + senf::console::ScopedDirectory<> testDir; + senf::console::root() + .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"); + + testDir + .add("echo", &echo) + .doc("Example of a function utilizing manual argument parsing"); + + TestObject test; + testDir + .add("extra", test.dir) + .doc("Example of an instance directory"); + + senf::console::Server::start( senf::INet4SocketAddress(23232u) ) + .name("testServer"); + + senf::Scheduler::instance().process(); +} // Local Variables: