Console: Implement ObjectDirectory proxy
[senf.git] / Console / Server.cc
index 6cd21d9..4e37e68 100644 (file)
@@ -104,7 +104,7 @@ prefix_ void senf::console::Server::removeClient(Client & client)
 prefix_ senf::console::Client::Client(ClientHandle handle, std::string const & name)
     : handle_ (handle), name_ (name), out_(::dup(handle.fd()))
 {
-    out_ << name_ << "# " << std::flush;
+    showPrompt();
     ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"),
                                         senf::membind(&Client::clientData, this) );
 }
@@ -126,11 +126,6 @@ prefix_ void senf::console::Client::clientData(ReadHelper<ClientHandle>::ptr hel
         return;
     }
 
-#   warning fix Client::clientData implementation
-    // Remove the 'dup' needed here so we don't close the same fd twice (see Client constructor)
-    // Make output non-blocking
-    // Don't register a new ReadHelper every round
-
     std::string data (tail_ + helper->data());
     tail_ = helper->tail();
     boost::trim(data); // Gets rid of superfluous  \r or \n characters
@@ -143,13 +138,24 @@ prefix_ void senf::console::Client::clientData(ReadHelper<ClientHandle>::ptr hel
         // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER stopClient RETURNS
         stopClient();
         return;
-    }        
+    }
+    catch (std::exception & ex) {
+        out_ << ex.what() << std::endl;
+    }
+    catch (...) {
+        out_ << "unidentified error (unknown exception thrown)" << std::endl;
+    }
 
-    out_ << name_ << "# " << std::flush;
+    showPrompt();
     ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"),
                                         senf::membind(&Client::clientData, this) );
 }
 
+prefix_ void senf::console::Client::showPrompt()
+{
+    out_ << name_ << ":" << executor_.cwd().path() << "# " << std::flush;
+}
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "Server.mpp"