Console; Support non-function-pointer parsed commands via boost::function
[senf.git] / Console / Server.ih
index 8355450..eb6ab72 100644 (file)
 #define IH_Server_ 1
 
 // Custom includes
-#include <set>
-#include <boost/utility.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-#include "../Utils/intrusive_refcount.hh"
-#include "../Socket/Protocols/INet/TCPSocketHandle.hh"
-#include "../Socket/ServerSocketHandle.hh"
-#include "../Scheduler/Scheduler.hh"
-#include "../Scheduler/ReadHelper.hh"
+#include <boost/iostreams/concepts.hpp>
+#include <boost/iostreams/stream.hpp>
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
@@ -43,72 +36,28 @@ namespace senf {
 namespace console {
 namespace detail {
 
-    class Client;
+    /** \brief Internal: Nonblocking boost::iostreams::sink
 
-    /** \brief
-      */
-    class Server
-        : boost::noncopyable
-    {
-        SENF_LOG_CLASS_AREA();
-        SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE );
-    public:
-        ///////////////////////////////////////////////////////////////////////////
-        // Types
-
-        typedef senf::ServerSocketHandle<
-            senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy, 
-                                    senf::UnspecifiedAddressingPolicy>::policy > ServerHandle;
-
-        ~Server();
-
-        static void start(ServerHandle handle);
-
-    protected:
-
-    private:
-        Server(ServerHandle handle);
-
-        void newClient(Scheduler::EventId event);
-        void removeClient(Client & client);
-        
-        ServerHandle handle_;
-        
-        typedef std::set< boost::intrusive_ptr<Client> > Clients;
-        Clients clients_;
-        
-        static boost::scoped_ptr<Server> instance_;
-        
-        friend class Client;
-    };
-    
-    /** \brief
+        The sink discards data if the output socket would.
      */
-    class Client
-        : public senf::intrusive_refcount
+    class NonblockingSocketSink 
+        : public boost::iostreams::sink
     {
-        SENF_LOG_CLASS_AREA();
-        SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE );
     public:
-        typedef Server::ServerHandle::ClientSocketHandle ClientHandle;
-
-        ~Client();
+        typedef ClientSocketHandle< 
+            MakeSocketPolicy<StreamFramingPolicy,
+                             WriteablePolicy,
+                             ConnectedCommunicationPolicy>::policy > Handle;
 
-        void stopClient();
-
-    protected:
+        NonblockingSocketSink(Handle handle);
+        std::streamsize write(const char * s, std::streamsize n);
         
     private:
-        Client(ClientHandle handle);
-
-        void clientData(ReadHelper<ClientHandle>::ptr helper);
-        
-        ClientHandle handle_;
-        std::string tail_;
-
-        friend class Server;
+        Handle handle_;
     };
 
+    typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
+
 }}}
 
 ///////////////////////////////ih.e////////////////////////////////////////