X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FServer.ih;h=6bbaf5a4d5c0e475bb8372a8fe01dc3193094ad5;hb=456ee576285b76aa46240f8001f426757810dcc1;hp=57e0f5c9e3dc68145a90221c151bd004b028ae93;hpb=2d5a1fd2cef2d84e16226a7336948f524fbb71c6;p=senf.git diff --git a/Console/Server.ih b/Console/Server.ih index 57e0f5c..6bbaf5a 100644 --- a/Console/Server.ih +++ b/Console/Server.ih @@ -34,8 +34,16 @@ namespace senf { namespace console { + + class Server; + class Client; + namespace detail { + /** \brief Internal: Nonblocking boost::iostreams::sink + + The sink discards data if the output socket would. + */ class NonblockingSocketSink : public boost::iostreams::sink { @@ -45,15 +53,86 @@ namespace detail { WriteablePolicy, ConnectedCommunicationPolicy>::policy > Handle; - NonblockingSocketSink(Handle handle); + NonblockingSocketSink(Client & client); std::streamsize write(const char * s, std::streamsize n); + + Client & client() const; private: - Handle handle_; + Client & client_; }; typedef boost::iostreams::stream NonblockingSocketOStream; + typedef senf::ServerSocketHandle< + senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy, + senf::UnspecifiedAddressingPolicy>::policy > ServerHandle; + + /** \brief Internal: Generic client interface + + The ClientReader encapsulates the interaction of a single network client with the user: It + manages prompt display and reading an interactive command. + */ + class ClientReader + { + public: + typedef ServerHandle::ClientSocketHandle ClientHandle; + + virtual ~ClientReader() = 0; + + // Called by subclasses to get information from the Client + + Client & client() const; + std::string promptString() const; + ClientHandle handle() const; + std::ostream & stream() const; + + // Called by subclasses to perform actions in the Client + + void stopClient(); + void handleInput(std::string const & input) const; + + // Called by the Client + + void disablePrompt(); + void enablePrompt(); + void translate(std::string & data); + + protected: + ClientReader(Client & client); + + private: + virtual void v_disablePrompt() = 0; + virtual void v_enablePrompt() = 0; + virtual void v_translate(std::string & data) = 0; + + Client & client_; + }; + + /** \brief Internal: Primitive ClientReader implementation + + This implementation uses the cooked telnet mode to read lines from the console. It does not + support explicit line editing or any other advanced features. + */ + class DumbClientReader + : public ClientReader + { + public: + DumbClientReader(Client & client); + + private: + virtual void v_disablePrompt(); + virtual void v_enablePrompt(); + virtual void v_translate(std::string & data); + + void clientData(senf::ReadHelper::ptr helper); + void showPrompt(); + + std::string tail_; + unsigned promptLen_; + bool promptActive_; + }; + }}} ///////////////////////////////ih.e////////////////////////////////////////