4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /** \page console_testserver Test Server
25 \dontinclude testServer.cc
27 You can find this code in the \c testServer.cc source file.
33 Here we see the necessary include files. For console support only <tt>senf/Console.hh</tt> needs
34 to be included. This will pull in all necessary definitions.
36 We declare an alias for the senf::console::kw namespace which we will use further down for the
43 The first callback \c echo utilizes \link console_manualparse manual argument
44 parsing\endlink. You should always refer to the iterator types as shown here since this will be
45 safe from future changes.
47 The following \c struct \c TestObject is used to show how member functions and objects are used
52 Important is the definition of the <b>public</b> senf::console::ScopedDirectory member called \c
53 dir. This member can be used later to add the class to the node tree. Here we just register a
54 single function \c vat (with \link console_autoparse automatic argument parsing\endlink) and
55 set some command attributes.
59 The \c shutdownServer callback terminates the server.
63 This happens in two steps: First the \c terminate() call tells the scheduler to leave it's
64 main-loop after shutdownServer returns (which is ultimately called via the console server from
65 the scheduler). Throwing a senf::console::Executor::ExitException is like entering the \c exit
66 built-in command at the console.
68 The next callback accesses the client instance directly to manipulate the logging:
72 The senf::console::Client instance can be accessed using the senf::console::Client::get() helper
73 via the output stream. Since every Client is a senf::log::Target, we can route arbitrary log
74 messages to the console instance.
76 We now define \c main() which initializes the node tree and starts the console server
80 Here we just setup more verbose logging and set \c SIGPIPE signals to be ignored. \c SIGPIPE's
81 are a pain and really should be disabled.
85 This shows, how to set the top-level documentation and create a new subdirectory.
89 Here we create another new directory and save a reference so we can later access the node
90 directly. All the add commands return such a node reference of the correct type (this is a lie,
91 but it works like this anyways and it's an implementation detail that must not concern you
94 Instead of creating a new directory directly and later sotring a reference, it is better to use
95 \c senf::console::ScopedDirectory<> like this:
99 This will automatically remove the node from the tree when the \c senf::console::ScopedDirectory
100 instance is destroyed. It also protects against the problem of dangling references: When using a
101 plain reference, removing the directory from the tree will destroy the node. The reference
102 however will still reference the (now nonexistent) directory and any access via the reference
103 will crash the program.
105 The next statements add commands to the various directories declared so far
109 We now continue by creating an instance of our test class \c TestObject
113 We add that objects directory to the \c test dir. We now have created a directory structure like
127 We now start the server (giving it a nice descriptive name) and run the scheduler.
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -U doc"