23 #include "interface.h" 24 #include "goby/common/exception.h" 25 #include "goby/common/logger.h" 27 goby::util::LineBasedInterface::LineBasedInterface(
const std::string& delimiter)
28 : work_(io_service_), active_(false)
30 goby::glog.set_lock_action(goby::common::logger_lock::lock);
32 if (delimiter.empty())
33 throw Exception(
"Line based comms started with null string as delimiter!");
35 delimiter_ = delimiter;
36 io_launcher_.reset(
new IOLauncher(io_service_));
39 void goby::util::LineBasedInterface::start()
45 io_service_.post(boost::bind(&LineBasedInterface::do_start,
this));
48 void goby::util::LineBasedInterface::clear()
50 boost::mutex::scoped_lock lock(in_mutex_);
63 boost::mutex::scoped_lock lock(in_mutex_);
67 msg->CopyFrom(in_.back());
72 msg->CopyFrom(in_.front());
89 boost::mutex::scoped_lock lock(in_mutex_);
93 (*s) = in_.back().data();
98 (*s) = in_.front().data();
109 io_service_.post(boost::bind(&LineBasedInterface::do_write,
this, msg));
113 void goby::util::LineBasedInterface::close()
115 io_service_.post(boost::bind(&LineBasedInterface::do_close,
this, boost::system::error_code()));
118 void goby::util::LineBasedInterface::sleep(
int sec) { io_service_.post(boost::bind(::sleep, sec)); }
bool readline(std::string *s, AccessOrder order=OLDEST_FIRST)
returns string line (including delimiter)
common::FlexOstream glog
Access the Goby logger through this object.