4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Server internal header */
31 #ifndef IH_SENF_Scheduler_Console_Server_
32 #define IH_SENF_Scheduler_Console_Server_ 1
35 #include <boost/iostreams/concepts.hpp>
36 #include <boost/iostreams/stream.hpp>
37 #include <senf/Scheduler/ReadHelper.hh>
38 #include <senf/Socket/Protocols/INet/TCPSocketHandle.hh>
39 #include <senf/Utils/Logger/SenfLog.hh>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
54 typedef boost::intrusive_ptr<Server> ptr;
59 static void add(ptr server);
60 static void remove(ptr server);
62 static ServerManager & instance();
64 typedef std::set<ptr> Servers;
67 friend class senf::console::Server;
70 /** \brief Internal: Nonblocking boost::iostreams::sink
72 The sink discards data if the output socket would.
74 \fixme Don't throw exceptions ... set stream error indicator (if at all)
76 class NonblockingSocketSink
77 : public boost::iostreams::sink
80 NonblockingSocketSink(Client & client);
81 std::streamsize write(const char * s, std::streamsize n);
83 Client & client() const;
89 typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
91 typedef senf::ServerSocketHandle<
92 senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy,
93 senf::BSDAddressingPolicy>::policy > ServerHandle;
95 /** \brief Internal: Generic client interface
97 The ClientReader encapsulates the interaction of a single network client with the user: It
98 manages prompt display and reading an interactive command.
103 SENF_LOG_CLASS_AREA();
105 typedef ServerHandle::ClientHandle ClientHandle;
107 virtual ~ClientReader() = 0;
109 // Called by subclasses to get information from the Client
111 Client & client() const;
112 std::string promptString() const;
113 ClientHandle handle() const;
114 std::ostream & stream() const;
116 // Called by subclasses to perform actions in the Client
119 std::string::size_type handleInput(std::string const & input, bool incremental=false) const;
121 // Called by the Client
123 void disablePrompt();
125 void write(std::string const & data);
126 unsigned width() const;
129 ClientReader(Client & client);
132 virtual void v_disablePrompt() = 0;
133 virtual void v_enablePrompt() = 0;
134 virtual void v_write(std::string const & data) = 0;
135 virtual unsigned v_width() const = 0;
140 /** \brief Internal: Primitive ClientReader implementation
142 This implementation uses the cooked telnet mode to read lines from the console. It does not
143 support explicit line editing or any other advanced features.
145 class DumbClientReader
146 : public ClientReader
149 DumbClientReader(Client & client);
152 virtual void v_disablePrompt();
153 virtual void v_enablePrompt();
154 virtual void v_write(std::string const & data);
155 virtual unsigned v_width() const;
157 void clientData(senf::ReadHelper<ClientHandle>::ptr helper);
165 /** \brief Internal: Primitive ClientReader implementation
167 This implementation uses the cooked telnet mode to read lines from the console. It does not
168 support explicit line editing or any other advanced features.
170 class NoninteractiveClientReader
171 : public ClientReader
174 NoninteractiveClientReader(Client & client);
177 virtual void v_disablePrompt();
178 virtual void v_enablePrompt();
179 virtual void v_write(std::string const & data);
180 virtual unsigned v_width() const;
182 void newData(int event);
184 scheduler::FdEvent readevent_;
190 //-/////////////////////////////////////////////////////////////////////////////////////////////////
197 // comment-column: 40
198 // c-file-style: "senf"
199 // indent-tabs-mode: nil
200 // ispell-local-dictionary: "american"
201 // compile-command: "scons -u test"