lots of work on determinism in the linux driver.
This commit is contained in:
@@ -33,7 +33,6 @@ Channel::Channel(DrivenEngine *de, int chid, int port, const std::string &target
|
||||
port_ = port;
|
||||
closed_ = false;
|
||||
target_ = target;
|
||||
readline_enabled_ = false;
|
||||
readline_lastc_ = 0;
|
||||
desired_prompt_ = "";
|
||||
stop_driver_ = stop;
|
||||
@@ -112,37 +111,25 @@ void Channel::feed_readline(int nbytes, const char *bytes) {
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::peek_outgoing(int *nbytes, const char **bytes) {
|
||||
if (readline_enabled_) {
|
||||
void Channel::peek_outgoing(int *nbytes, const char **bytes) const {
|
||||
*nbytes = sb_drvout_->fill();
|
||||
*bytes = sb_drvout_->data();
|
||||
}
|
||||
|
||||
void Channel::pump_readline() {
|
||||
if (sb_drvout_ != sb_out_) {
|
||||
if (!sb_out_->empty()) {
|
||||
erase_command();
|
||||
sb_out_->transfer_into(sb_drvout_.get());
|
||||
}
|
||||
echo_command();
|
||||
}
|
||||
*nbytes = sb_drvout_->fill();
|
||||
*bytes = sb_drvout_->data();
|
||||
}
|
||||
|
||||
void Channel::sent_outgoing(int nbytes) {
|
||||
sb_drvout_->read_bytes(nbytes);
|
||||
}
|
||||
|
||||
void Channel::set_readline(bool e) {
|
||||
if (e != readline_enabled_) {
|
||||
readline_enabled_ = e;
|
||||
if (readline_enabled_) {
|
||||
sb_drvout_ = std::make_shared<StreamBuffer>();
|
||||
} else {
|
||||
sb_out_->transfer_into(sb_drvout_.get());
|
||||
sb_out_->clear();
|
||||
sb_drvout_->transfer_into(sb_out_.get());
|
||||
sb_drvout_ = sb_out_;
|
||||
}
|
||||
desired_command_ = "";
|
||||
}
|
||||
}
|
||||
|
||||
int DrivenEngine::find_unused_chid() {
|
||||
// Note: channel ID zero is special, it is never reused.
|
||||
for (int i = 0; i < MAX_CHAN; i++) {
|
||||
@@ -244,7 +231,7 @@ void DrivenEngine::drv_sent_outgoing(int chid, int nbytes) {
|
||||
void DrivenEngine::drv_recv_incoming(int chid, int nbytes, const char *bytes) {
|
||||
if (nbytes > 0) {
|
||||
Channel *ch = get_chid(chid);
|
||||
if (ch->readline_enabled_) {
|
||||
if (ch->sb_drvout_ != ch->sb_out_) {
|
||||
ch->feed_readline(nbytes, bytes);
|
||||
} else {
|
||||
ch->sb_in_->write_bytes(bytes, nbytes);
|
||||
@@ -271,25 +258,22 @@ void DrivenEngine::drv_clear_lua_source() {
|
||||
rescan_lua_source_ = false;
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_add_lua_source(const char *fn, const char *data) {
|
||||
void DrivenEngine::drv_add_lua_source(std::string_view fn, std::string_view data) {
|
||||
if (lua_source_ == nullptr) {
|
||||
lua_source_.reset(new util::LuaSourceVec);
|
||||
}
|
||||
lua_source_->emplace_back(std::string(fn), std::string(data));
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_set_lua_source(util::LuaSourcePtr src) {
|
||||
lua_source_ = std::move(src);
|
||||
rescan_lua_source_ = false;
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_invoke_event_init(int argc, char *argv[]) {
|
||||
event_init(argc, argv);
|
||||
stdio_channel_->pump_readline();
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_invoke_event_update(double clock) {
|
||||
clock_ = clock;
|
||||
event_update();
|
||||
stdio_channel_->pump_readline();
|
||||
}
|
||||
|
||||
bool DrivenEngine::drv_get_rescan_lua_source() const {
|
||||
@@ -303,7 +287,7 @@ bool DrivenEngine::drv_get_stop_driver() const {
|
||||
DrivenEngine::DrivenEngine() {
|
||||
next_unused_chid_ = 1;
|
||||
stdio_channel_ = std::make_shared<Channel>(this, 0, 0, "", false);
|
||||
stdio_channel_->set_readline(true);
|
||||
stdio_channel_->sb_drvout_ = std::make_shared<StreamBuffer>();
|
||||
channels_[0] = stdio_channel_;
|
||||
rescan_lua_source_ = true;
|
||||
clock_ = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user