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 */
26 #ifndef IH_SENF_Scheduler_Console_Server_
27 #define IH_SENF_Scheduler_Console_Server_ 1
30 #include <boost/iostreams/concepts.hpp>
31 #include <boost/iostreams/stream.hpp>
34 ///////////////////////////////ih.p////////////////////////////////////////
47 typedef boost::intrusive_ptr<Server> ptr;
52 static void add(ptr server);
53 static void remove(ptr server);
55 static ServerManager & instance();
57 typedef std::set<ptr> Servers;
60 friend class senf::console::Server;
63 /** \brief Internal: Nonblocking boost::iostreams::sink
65 The sink discards data if the output socket would.
67 \fixme Don't throw exceptions ... set stream error indicator (if at all)
69 class NonblockingSocketSink
70 : public boost::iostreams::sink
73 typedef ClientSocketHandle<
74 senf::MakeSocketPolicy<StreamFramingPolicy,
76 ConnectedCommunicationPolicy>::policy > Handle;
78 NonblockingSocketSink(Client & client);
79 std::streamsize write(const char * s, std::streamsize n);
81 Client & client() const;
87 typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
89 typedef senf::ServerSocketHandle<
90 senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy,
91 senf::UnspecifiedAddressingPolicy>::policy > ServerHandle;
93 /** \brief Internal: Generic client interface
95 The ClientReader encapsulates the interaction of a single network client with the user: It
96 manages prompt display and reading an interactive command.
101 typedef ServerHandle::ClientHandle ClientHandle;
103 virtual ~ClientReader() = 0;
105 // Called by subclasses to get information from the Client
107 Client & client() const;
108 std::string promptString() const;
109 ClientHandle handle() const;
110 std::ostream & stream() const;
112 // Called by subclasses to perform actions in the Client
115 std::string::size_type handleInput(std::string const & input, bool incremental=false) const;
117 // Called by the Client
119 void disablePrompt();
121 void translate(std::string & data);
124 ClientReader(Client & client);
127 virtual void v_disablePrompt() = 0;
128 virtual void v_enablePrompt() = 0;
129 virtual void v_translate(std::string & data) = 0;
134 /** \brief Internal: Primitive ClientReader implementation
136 This implementation uses the cooked telnet mode to read lines from the console. It does not
137 support explicit line editing or any other advanced features.
139 class DumbClientReader
140 : public ClientReader
143 DumbClientReader(Client & client);
146 virtual void v_disablePrompt();
147 virtual void v_enablePrompt();
148 virtual void v_translate(std::string & data);
150 void clientData(senf::ReadHelper<ClientHandle>::ptr helper);
158 /** \brief Internal: Primitive ClientReader implementation
160 This implementation uses the cooked telnet mode to read lines from the console. It does not
161 support explicit line editing or any other advanced features.
163 class NoninteractiveClientReader
164 : public ClientReader
167 NoninteractiveClientReader(Client & client);
170 virtual void v_disablePrompt();
171 virtual void v_enablePrompt();
172 virtual void v_translate(std::string & data);
174 void newData(int event);
176 scheduler::FdEvent readevent_;
182 ///////////////////////////////ih.e////////////////////////////////////////
189 // comment-column: 40
190 // c-file-style: "senf"
191 // indent-tabs-mode: nil
192 // ispell-local-dictionary: "american"
193 // compile-command: "scons -u test"