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 class NonblockingSocketSink
67 : public boost::iostreams::sink
70 typedef ClientSocketHandle<
71 MakeSocketPolicy<StreamFramingPolicy,
73 ConnectedCommunicationPolicy>::policy > Handle;
75 NonblockingSocketSink(Client & client);
76 std::streamsize write(const char * s, std::streamsize n);
78 Client & client() const;
84 typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
86 typedef senf::ServerSocketHandle<
87 senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy,
88 senf::UnspecifiedAddressingPolicy>::policy > ServerHandle;
90 /** \brief Internal: Generic client interface
92 The ClientReader encapsulates the interaction of a single network client with the user: It
93 manages prompt display and reading an interactive command.
98 typedef ServerHandle::ClientSocketHandle ClientHandle;
100 virtual ~ClientReader() = 0;
102 // Called by subclasses to get information from the Client
104 Client & client() const;
105 std::string promptString() const;
106 ClientHandle handle() const;
107 std::ostream & stream() const;
109 // Called by subclasses to perform actions in the Client
112 std::string::size_type handleInput(std::string const & input, bool incremental=false) const;
114 // Called by the Client
116 void disablePrompt();
118 void translate(std::string & data);
121 ClientReader(Client & client);
124 virtual void v_disablePrompt() = 0;
125 virtual void v_enablePrompt() = 0;
126 virtual void v_translate(std::string & data) = 0;
131 /** \brief Internal: Primitive ClientReader implementation
133 This implementation uses the cooked telnet mode to read lines from the console. It does not
134 support explicit line editing or any other advanced features.
136 class DumbClientReader
137 : public ClientReader
140 DumbClientReader(Client & client);
143 virtual void v_disablePrompt();
144 virtual void v_enablePrompt();
145 virtual void v_translate(std::string & data);
147 void clientData(senf::ReadHelper<ClientHandle>::ptr helper);
155 /** \brief Internal: Primitive ClientReader implementation
157 This implementation uses the cooked telnet mode to read lines from the console. It does not
158 support explicit line editing or any other advanced features.
160 class NoninteractiveClientReader
161 : public ClientReader
164 NoninteractiveClientReader(Client & client);
167 virtual void v_disablePrompt();
168 virtual void v_enablePrompt();
169 virtual void v_translate(std::string & data);
171 void newData(senf::Scheduler::EventId event);
173 SchedulerBinding binding_;
179 ///////////////////////////////ih.e////////////////////////////////////////
186 // comment-column: 40
187 // c-file-style: "senf"
188 // indent-tabs-mode: nil
189 // ispell-local-dictionary: "american"
190 // compile-command: "scons -u test"