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>
33 #include <senf/Utils/Logger/SenfLog.hh>
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 typedef boost::intrusive_ptr<Server> ptr;
53 static void add(ptr server);
54 static void remove(ptr server);
56 static ServerManager & instance();
58 typedef std::set<ptr> Servers;
61 friend class senf::console::Server;
64 /** \brief Internal: Nonblocking boost::iostreams::sink
66 The sink discards data if the output socket would.
68 \fixme Don't throw exceptions ... set stream error indicator (if at all)
70 class NonblockingSocketSink
71 : public boost::iostreams::sink
74 NonblockingSocketSink(Client & client);
75 std::streamsize write(const char * s, std::streamsize n);
77 Client & client() const;
83 typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
85 typedef senf::ServerSocketHandle<
86 senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy,
87 senf::BSDAddressingPolicy>::policy > ServerHandle;
89 /** \brief Internal: Generic client interface
91 The ClientReader encapsulates the interaction of a single network client with the user: It
92 manages prompt display and reading an interactive command.
97 SENF_LOG_CLASS_AREA();
99 typedef ServerHandle::ClientHandle ClientHandle;
101 virtual ~ClientReader() = 0;
103 // Called by subclasses to get information from the Client
105 Client & client() const;
106 std::string promptString() const;
107 ClientHandle handle() const;
108 std::ostream & stream() const;
110 // Called by subclasses to perform actions in the Client
113 std::string::size_type handleInput(std::string const & input, bool incremental=false) const;
115 // Called by the Client
117 void disablePrompt();
119 void write(std::string const & data);
120 unsigned width() const;
123 ClientReader(Client & client);
126 virtual void v_disablePrompt() = 0;
127 virtual void v_enablePrompt() = 0;
128 virtual void v_write(std::string const & data) = 0;
129 virtual unsigned v_width() const = 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_write(std::string const & data);
149 virtual unsigned v_width() const;
151 void clientData(senf::ReadHelper<ClientHandle>::ptr helper);
159 /** \brief Internal: Primitive ClientReader implementation
161 This implementation uses the cooked telnet mode to read lines from the console. It does not
162 support explicit line editing or any other advanced features.
164 class NoninteractiveClientReader
165 : public ClientReader
168 NoninteractiveClientReader(Client & client);
171 virtual void v_disablePrompt();
172 virtual void v_enablePrompt();
173 virtual void v_write(std::string const & data);
174 virtual unsigned v_width() const;
176 void newData(int event);
178 scheduler::FdEvent readevent_;
184 //-/////////////////////////////////////////////////////////////////////////////////////////////////
191 // comment-column: 40
192 // c-file-style: "senf"
193 // indent-tabs-mode: nil
194 // ispell-local-dictionary: "american"
195 // compile-command: "scons -u test"