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.
24 \brief Server internal header */
30 #include <boost/iostreams/concepts.hpp>
31 #include <boost/iostreams/stream.hpp>
34 ///////////////////////////////ih.p////////////////////////////////////////
45 : public senf::singleton<ServerManager>
48 typedef boost::intrusive_ptr<Server> ptr;
53 static void add(ptr server);
54 static void remove(ptr server);
56 typedef std::set<ptr> Servers;
59 friend class senf::console::Server;
62 /** \brief Internal: Nonblocking boost::iostreams::sink
64 The sink discards data if the output socket would.
66 \fixme Don't throw exceptions ... set stream error indicator (if at all)
68 class NonblockingSocketSink
69 : public boost::iostreams::sink
72 typedef ClientSocketHandle<
73 MakeSocketPolicy<StreamFramingPolicy,
75 ConnectedCommunicationPolicy>::policy > Handle;
77 NonblockingSocketSink(Client & client);
78 std::streamsize write(const char * s, std::streamsize n);
80 Client & client() const;
86 typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
88 typedef senf::ServerSocketHandle<
89 senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy,
90 senf::UnspecifiedAddressingPolicy>::policy > ServerHandle;
92 /** \brief Internal: Generic client interface
94 The ClientReader encapsulates the interaction of a single network client with the user: It
95 manages prompt display and reading an interactive command.
100 typedef ServerHandle::ClientSocketHandle ClientHandle;
102 virtual ~ClientReader() = 0;
104 // Called by subclasses to get information from the Client
106 Client & client() const;
107 std::string promptString() const;
108 ClientHandle handle() const;
109 std::ostream & stream() const;
111 // Called by subclasses to perform actions in the Client
114 std::string::size_type handleInput(std::string const & input, bool incremental=false) const;
116 // Called by the Client
118 void disablePrompt();
120 void translate(std::string & data);
123 ClientReader(Client & client);
126 virtual void v_disablePrompt() = 0;
127 virtual void v_enablePrompt() = 0;
128 virtual void v_translate(std::string & data) = 0;
133 /** \brief Internal: Primitive ClientReader implementation
135 This implementation uses the cooked telnet mode to read lines from the console. It does not
136 support explicit line editing or any other advanced features.
138 class DumbClientReader
139 : public ClientReader
142 DumbClientReader(Client & client);
145 virtual void v_disablePrompt();
146 virtual void v_enablePrompt();
147 virtual void v_translate(std::string & data);
149 void clientData(senf::ReadHelper<ClientHandle>::ptr helper);
157 /** \brief Internal: Primitive ClientReader implementation
159 This implementation uses the cooked telnet mode to read lines from the console. It does not
160 support explicit line editing or any other advanced features.
162 class NoninteractiveClientReader
163 : public ClientReader
166 NoninteractiveClientReader(Client & client);
169 virtual void v_disablePrompt();
170 virtual void v_enablePrompt();
171 virtual void v_translate(std::string & data);
173 void newData(senf::Scheduler::EventId event);
175 SchedulerBinding binding_;
181 ///////////////////////////////ih.e////////////////////////////////////////
188 // comment-column: 40
189 // c-file-style: "senf"
190 // indent-tabs-mode: nil
191 // ispell-local-dictionary: "american"
192 // compile-command: "scons -u test"