// 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 <iostream>
-#include "Server.hh"
-#include "Node.hh"
-#include "../Scheduler/Scheduler.hh"
-#include "../Utils/Logger/SenfLog.hh"
-
-//#include "test.mpp"
-#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";
+#include <senf/Console.hh>
+#include <senf/Scheduler/Scheduler.hh>
+
+namespace kw = senf::console::kw;
+
+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";
+}
+
+struct TestObject
+{
+ senf::console::ScopedDirectory<TestObject> 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}");
}
- };
+
+ 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<senf::log::NOTICE>();
}
-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("console")
+ .doc("Console settings");
- senf::console::root().mkdir("network").mkdir("eth0");
- senf::console::root().mkdir("server");
+ senf::console::DirectoryNode & serverDir (
+ senf::console::root()
+ .mkdir("server")
+ .doc("server commands") );
- senf::console::root()["network"].add(
- std::auto_ptr<senf::console::GenericNode>(new MyCommand("route")));
+ senf::console::ScopedDirectory<> testDir;
+ senf::console::root()
+ .add("test", testDir)
+ .doc("Test functions");
- senf::console::Server::start( senf::INet4SocketAddress("127.0.0.1:23232") )
+ 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();
}
-///////////////////////////////cc.e////////////////////////////////////////
-#undef prefix_
-//#include "test.mpp"
-
\f
// Local Variables:
// mode: c++