// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief Server internal header */ #ifndef IH_SENF_Scheduler_Console_Server_ #define IH_SENF_Scheduler_Console_Server_ 1 // Custom includes #include #include #include #include #include //-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace console { class Server; class Client; namespace detail { class ServerManager { public: typedef boost::intrusive_ptr ptr; protected: private: static void add(ptr server); static void remove(ptr server); static ServerManager & instance(); typedef std::set Servers; Servers servers_; friend class senf::console::Server; }; /** \brief Internal: Nonblocking boost::iostreams::sink The sink discards data if the output socket would. \fixme Don't throw exceptions ... set stream error indicator (if at all) */ class NonblockingSocketSink : public boost::iostreams::sink { public: NonblockingSocketSink(Client & client); std::streamsize write(const char * s, std::streamsize n); Client & client() const; private: Client & client_; }; typedef boost::iostreams::stream NonblockingSocketOStream; typedef senf::ServerSocketHandle< senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy, senf::BSDAddressingPolicy>::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: SENF_LOG_CLASS_AREA(); typedef ServerHandle::ClientHandle 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(); std::string::size_type handleInput(std::string const & input, bool incremental=false) const; // Called by the Client void disablePrompt(); void enablePrompt(); void write(std::string const & data); unsigned width() const; protected: ClientReader(Client & client); private: virtual void v_disablePrompt() = 0; virtual void v_enablePrompt() = 0; virtual void v_write(std::string const & data) = 0; virtual unsigned v_width() const = 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_write(std::string const & data); virtual unsigned v_width() const; void clientData(senf::ReadHelper::ptr helper); void showPrompt(); std::string tail_; unsigned promptLen_; bool promptActive_; }; /** \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 NoninteractiveClientReader : public ClientReader { public: NoninteractiveClientReader(Client & client); private: virtual void v_disablePrompt(); virtual void v_enablePrompt(); virtual void v_write(std::string const & data); virtual unsigned v_width() const; void newData(int event); scheduler::FdEvent readevent_; std::string buffer_; }; }}} //-///////////////////////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: