#include "Server.ih"
// Custom includes
+#include <errno.h>
#include <iostream>
#include <boost/algorithm/string/trim.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include "../../Utils/senfassert.hh"
#include "../../Utils/membind.hh"
#include "../../Utils/Logger/SenfLog.hh"
-#include "Readline.hh"
+#include "LineEditor.hh"
+#include "ScopedDirectory.hh"
+#include "Sysdir.hh"
+#include "ParsedCommand.hh"
//#include "Server.mpp"
#define prefix_
try {
if (client_.handle().writeable()) {
std::string data (s, n);
- client_.translate(data);
- client_.handle().write( data );
+ client_.write(data);
}
}
catch (SystemException & ex) {
: handle_ (handle),
event_ ("senf::console::Server", senf::membind(&Server::newClient, this),
handle_, scheduler::FdEvent::EV_READ),
- root_ (senf::console::root().thisptr()), mode_ (Automatic)
+ root_ (senf::console::root().thisptr()), mode_ (Automatic),
+ name_ (::program_invocation_short_name)
{}
prefix_ void senf::console::Server::newClient(int event)
prefix_ void senf::console::detail::DumbClientReader::showPrompt()
{
std::string prompt (promptString());
+ prompt += " ";
stream() << std::flush;
handle().write(prompt);
showPrompt();
}
-prefix_ void senf::console::detail::DumbClientReader::v_translate(std::string & data)
-{}
+prefix_ void senf::console::detail::DumbClientReader::v_write(std::string const & data)
+{
+ handle().write(data);
+}
///////////////////////////////////////////////////////////////////////////
// senf::console::detail::NoninteractiveClientReader
prefix_ void senf::console::detail::NoninteractiveClientReader::v_enablePrompt()
{}
-prefix_ void senf::console::detail::NoninteractiveClientReader::v_translate(std::string & data)
-{}
+prefix_ void senf::console::detail::NoninteractiveClientReader::v_write(std::string const & data)
+{
+ handle().write(data);
+}
prefix_ void
senf::console::detail::NoninteractiveClientReader::newData(int event)
readevent_.disable();
timer_.disable();
mode_ = Server::Interactive;
- reader_.reset(new detail::SafeReadlineClientReader (*this));
+ reader_.reset(new detail::LineEditorSwitcher (*this));
executor_.autocd(true).autocomplete(true);
}
reader_.reset(new detail::NoninteractiveClientReader(*this));
}
-prefix_ void senf::console::Client::translate(std::string & data)
-{
- reader_->translate(data);
-}
-
prefix_ std::string::size_type senf::console::Client::handleInput(std::string data,
bool incremental)
{
_1 ));
}
catch (Executor::ExitException &) {
- // This generates an EOF condition on the Handle. This EOF condition is expected
- // to be handled gracefully by the ClientReader. We cannot call stop() here, since we
- // are called from the client reader callback and that will continue executing even if we
- // call stop here ...
+ // This generates an EOF condition on the Handle. This EOF condition is expected to be
+ // handled gracefully by the ClientReader. We cannot call stop() here, since we are called
+ // from the client reader callback and that will continue executing after stop() has been
+ // called. stop() however will delete *this instance ... BANG ...
handle_.facet<senf::TCPSocketProtocol>().shutdown(senf::TCPSocketProtocol::ShutRD);
}
catch (std::exception & ex) {
- stream() << ex.what() << std::endl;
+ std::string msg (ex.what());
+ std::string::size_type i (msg.find("-- \n"));
+ if (i != std::string::npos) {
+ backtrace_ = msg.substr(0,i);
+ msg = msg.substr(i+4);
+ } else
+ backtrace_.clear();
+ stream() << msg << std::endl;
}
catch (...) {
stream() << "unidentified error (unknown exception thrown)" << std::endl;
return os << *client;
}
+///////////////////////////////////////////////////////////////////////////
+// senf::console::Client::SysBacktrace
+
+prefix_ senf::console::Client::SysBacktrace::SysBacktrace()
+{
+ sysdir().node().add("backtrace", &SysBacktrace::backtrace)
+ .doc("Display the backtrace of the last error / exception in this console");
+}
+
+prefix_ void senf::console::Client::SysBacktrace::backtrace(std::ostream & os)
+{
+ Client & client (Client::get(os));
+ if (client.backtrace().empty())
+ os << "(no backtrace)";
+ else
+ os << client.backtrace();
+}
+
+senf::console::Client::SysBacktrace senf::console::Client::SysBacktrace::instance_;
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "Server.mpp"