4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief testServer implementation */
33 #include <senf/Utils/Console.hh>
34 #include <senf/Scheduler/Scheduler.hh>
36 namespace kw = senf::console::kw;
37 namespace fty = senf::console::factory;
39 void echo(std::ostream & output, senf::console::ParseCommandInfo const & command)
41 typedef senf::console::ParseCommandInfo::TokensRange::iterator iterator;
42 iterator i (command.tokens().begin());
43 iterator i_end (command.tokens().end());
44 for (; i != i_end; ++i) {
45 output << i->value() << ' ';
52 senf::console::ScopedDirectory<TestObject> dir;
57 dir.add("vat", fty::Command(&TestObject::vat, this)
58 .arg("vat", "VAT in %", kw::default_value = 19)
59 .arg("amount", "Amount including VAT")
60 .doc("Returns the amount of {vat}-% VAT included in {amount}") );
63 double vat (int vat, double amount)
65 return amount * vat/(100.0+vat);
71 senf::scheduler::terminate();
72 throw senf::console::Executor::ExitException();
75 void enableLogging(std::ostream & os)
77 senf::console::Client::get(os).route<senf::log::NOTICE>();
80 int main(int, char **)
82 ::signal(SIGPIPE, SIG_IGN);
83 senf::log::ConsoleTarget::instance().route< senf::log::VERBOSE >();
86 .doc("This is the console test application");
89 .add("console",fty::Directory()
90 .doc("Console settings"));
92 senf::console::DirectoryNode & serverDir (
94 .add("server",fty::Directory()
95 .doc("server commands")));
97 senf::console::ScopedDirectory<> testDir;
100 .doc("Test functions");
102 senf::console::root()["console"]
103 .add("showlog", fty::Command(&enableLogging)
104 .doc("Enable display of log messages on the current console"));
106 senf::console::root().add("sl", fty::Link(senf::console::root()["console"]("showlog")));
109 .add("shutdown", fty::Command(&shutdownServer)
110 .doc("Terminate server application"));
113 .add("echo", fty::Command(&echo)
114 .doc("Example of a function utilizing manual argument parsing"));
118 .add("extra", test.dir)
119 .doc("Example of an instance directory");
121 senf::console::root().add("ex", fty::Link(test.dir));
123 senf::console::Server::start( senf::INet4SocketAddress(23232u) )
126 senf::scheduler::process();
134 // comment-column: 40
135 // c-file-style: "senf"
136 // indent-tabs-mode: nil
137 // ispell-local-dictionary: "american"
138 // compile-command: "scons -U testServer"