Using CHANNEL_PRINTS to transfer printbuffers to stdout is now working.
This commit is contained in:
@@ -168,10 +168,6 @@ void DrivenEngine::set_console_prompt(const eng::string &prompt) {
|
|||||||
console_prompt_ = prompt;
|
console_prompt_ = prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrivenEngine::rescan_lua_source(bool b) {
|
|
||||||
rescan_lua_source_ = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) {
|
void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) {
|
||||||
visible_world_ = w;
|
visible_world_ = w;
|
||||||
visible_actor_id_ = id;
|
visible_actor_id_ = id;
|
||||||
@@ -192,6 +188,7 @@ DrivenEngine::DrivenEngine() {
|
|||||||
channels_[0] = stdio_channel_;
|
channels_[0] = stdio_channel_;
|
||||||
rescan_lua_source_ = false;
|
rescan_lua_source_ = false;
|
||||||
clock_ = 0.0;
|
clock_ = 0.0;
|
||||||
|
have_prints_ = false;
|
||||||
stop_driver_ = false;
|
stop_driver_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,6 +378,10 @@ double DrivenEngine::drv_get_clock() const {
|
|||||||
return clock_;
|
return clock_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DrivenEngine::drv_get_have_prints() const {
|
||||||
|
return have_prints_;
|
||||||
|
}
|
||||||
|
|
||||||
bool DrivenEngine::drv_get_rescan_lua_source() const {
|
bool DrivenEngine::drv_get_rescan_lua_source() const {
|
||||||
return rescan_lua_source_;
|
return rescan_lua_source_;
|
||||||
}
|
}
|
||||||
@@ -536,6 +537,10 @@ static double drv_get_clock(EngineWrapper *w) {
|
|||||||
return w->engine->drv_get_clock();
|
return w->engine->drv_get_clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool drv_get_have_prints(EngineWrapper *w) {
|
||||||
|
return w->engine->drv_get_have_prints();
|
||||||
|
}
|
||||||
|
|
||||||
static bool drv_get_rescan_lua_source(EngineWrapper *w) {
|
static bool drv_get_rescan_lua_source(EngineWrapper *w) {
|
||||||
return w->engine->drv_get_rescan_lua_source();
|
return w->engine->drv_get_rescan_lua_source();
|
||||||
}
|
}
|
||||||
@@ -913,6 +918,7 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
|
|||||||
w->get_outgoing_empty = drv_get_outgoing_empty;
|
w->get_outgoing_empty = drv_get_outgoing_empty;
|
||||||
w->get_console_prompt = drv_get_console_prompt;
|
w->get_console_prompt = drv_get_console_prompt;
|
||||||
w->get_clock = drv_get_clock;
|
w->get_clock = drv_get_clock;
|
||||||
|
w->get_have_prints = drv_get_have_prints;
|
||||||
w->get_rescan_lua_source = drv_get_rescan_lua_source;
|
w->get_rescan_lua_source = drv_get_rescan_lua_source;
|
||||||
w->get_stop_driver = drv_get_stop_driver;
|
w->get_stop_driver = drv_get_stop_driver;
|
||||||
w->get_actor_id = drv_get_actor_id;
|
w->get_actor_id = drv_get_actor_id;
|
||||||
|
|||||||
@@ -218,7 +218,12 @@ public:
|
|||||||
// DRIVER: this merely sets a flag, which the driver will notice later,
|
// DRIVER: this merely sets a flag, which the driver will notice later,
|
||||||
// causing the driver to update the lua source.
|
// causing the driver to update the lua source.
|
||||||
//
|
//
|
||||||
void rescan_lua_source(bool b);
|
void rescan_lua_source(bool b) { rescan_lua_source_ = b; }
|
||||||
|
|
||||||
|
// Set the flag to indicate that you have something you want to
|
||||||
|
// print. This will trigger the driver to access CHANNEL_PRINTS.
|
||||||
|
//
|
||||||
|
void set_have_prints(bool b) { have_prints_ = b; }
|
||||||
|
|
||||||
// Set the world pointer and the actor ID.
|
// Set the world pointer and the actor ID.
|
||||||
//
|
//
|
||||||
@@ -274,6 +279,7 @@ public:
|
|||||||
bool drv_get_outgoing_empty(uint32_t chid) const;
|
bool drv_get_outgoing_empty(uint32_t chid) const;
|
||||||
void drv_get_console_prompt(uint32_t *len, const char **data) const;
|
void drv_get_console_prompt(uint32_t *len, const char **data) const;
|
||||||
double drv_get_clock() const;
|
double drv_get_clock() const;
|
||||||
|
bool drv_get_have_prints() const;
|
||||||
bool drv_get_rescan_lua_source() const;
|
bool drv_get_rescan_lua_source() const;
|
||||||
bool drv_get_stop_driver() const;
|
bool drv_get_stop_driver() const;
|
||||||
int64_t drv_get_actor_id() const;
|
int64_t drv_get_actor_id() const;
|
||||||
@@ -310,6 +316,7 @@ private:
|
|||||||
StreamBuffer call_function_retpk_;
|
StreamBuffer call_function_retpk_;
|
||||||
bool rescan_lua_source_;
|
bool rescan_lua_source_;
|
||||||
double clock_;
|
double clock_;
|
||||||
|
bool have_prints_;
|
||||||
bool stop_driver_;
|
bool stop_driver_;
|
||||||
eng::string console_prompt_;
|
eng::string console_prompt_;
|
||||||
friend class Channel;
|
friend class Channel;
|
||||||
|
|||||||
@@ -115,6 +115,11 @@ struct EngineWrapper {
|
|||||||
//
|
//
|
||||||
double (*get_clock)(EngineWrapper *w);
|
double (*get_clock)(EngineWrapper *w);
|
||||||
|
|
||||||
|
// Check the 'have prints' flag. If true, then the engine
|
||||||
|
// wants the driver to use CHANNEL_PRINTS to obtain prints.
|
||||||
|
//
|
||||||
|
bool (*get_have_prints)(EngineWrapper *w);
|
||||||
|
|
||||||
// Check the 'rescan_lua_source' flag. If this flag is set, it means
|
// Check the 'rescan_lua_source' flag. If this flag is set, it means
|
||||||
// that the engine wants the driver to rescan the lua source code.
|
// that the engine wants the driver to rescan the lua source code.
|
||||||
// When the driver sees this flag, it should rescan the source and call
|
// When the driver sees this flag, it should rescan the source and call
|
||||||
|
|||||||
@@ -276,6 +276,7 @@ public:
|
|||||||
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), retpk)) {
|
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), retpk)) {
|
||||||
send_invocation(print_channeler_.invocation(actor_id_));
|
send_invocation(print_channeler_.invocation(actor_id_));
|
||||||
}
|
}
|
||||||
|
set_have_prints(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -313,6 +314,8 @@ public:
|
|||||||
world_to_asynchronous();
|
world_to_asynchronous();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_have_prints(print_channeler_.have_prints(world_->get_printbuffer(actor_id_)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ public:
|
|||||||
if (print_channeler_.channel(master_->get_printbuffer(admin_id_), retpk)) {
|
if (print_channeler_.channel(master_->get_printbuffer(admin_id_), retpk)) {
|
||||||
master_->invoke(print_channeler_.invocation(admin_id_));
|
master_->invoke(print_channeler_.invocation(admin_id_));
|
||||||
}
|
}
|
||||||
|
set_have_prints(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -354,6 +355,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
util::remove_marked_items(http_server_channels_);
|
util::remove_marked_items(http_server_channels_);
|
||||||
|
|
||||||
|
// Notify the driver if there are any prints.
|
||||||
|
set_have_prints(print_channeler_.have_prints(master_->get_printbuffer(admin_id_)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -179,6 +179,13 @@ void PrintBuffer::patch(StreamBuffer *sb, DebugCollector *dbc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PrintChanneler::have_prints(const PrintBuffer *printbuffer) const
|
||||||
|
{
|
||||||
|
return ((printbuffer != nullptr) &&
|
||||||
|
(printbuffer->first_line() < printbuffer->first_unchecked()) &&
|
||||||
|
(line_ < printbuffer->first_unchecked()));
|
||||||
|
}
|
||||||
|
|
||||||
bool PrintChanneler::channel(const PrintBuffer *printbuffer, StreamBuffer *sb) {
|
bool PrintChanneler::channel(const PrintBuffer *printbuffer, StreamBuffer *sb) {
|
||||||
if (printbuffer == nullptr) return false;
|
if (printbuffer == nullptr) return false;
|
||||||
if (printbuffer->first_line() > line_) {
|
if (printbuffer->first_line() > line_) {
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ public:
|
|||||||
// Reset the print channeler.
|
// Reset the print channeler.
|
||||||
void reset() { line_ = 0; }
|
void reset() { line_ = 0; }
|
||||||
|
|
||||||
|
// Check if there's anything to channel.
|
||||||
|
bool have_prints(const PrintBuffer *pb) const;
|
||||||
|
|
||||||
// Copy any new lines from the printbuffer to the stream buffer.
|
// Copy any new lines from the printbuffer to the stream buffer.
|
||||||
// Update the current line number. Return true if the printbuffer
|
// Update the current line number. Return true if the printbuffer
|
||||||
// contains any lines that have already been channeled.
|
// contains any lines that have already been channeled.
|
||||||
|
|||||||
@@ -197,18 +197,18 @@ class Driver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void handle_console_output() {
|
void handle_console_output() {
|
||||||
while (true) {
|
if (engw.get_have_prints(&engw)) {
|
||||||
uint32_t ndata; const char *data;
|
uint32_t ndata;
|
||||||
engw.get_outgoing(&engw, 0, &ndata, &data);
|
const char *data;
|
||||||
if (ndata == 0) break;
|
engw.play_access(&engw, AccessKind::CHANNEL_PRINTS, 0, 0, "", &ndata, &data);
|
||||||
if (ndata > DRV_SHORTSTRING_SIZE) ndata = DRV_SHORTSTRING_SIZE;
|
if (ndata > 0) {
|
||||||
std::string_view src(data, ndata);
|
if (ndata > DRV_SHORTSTRING_SIZE) ndata = DRV_SHORTSTRING_SIZE;
|
||||||
int consumed;
|
std::string_view src(data, ndata);
|
||||||
std::u32string cps = drvutil::utf8_to_utf32(src, &consumed);
|
int consumed;
|
||||||
readline_device_.print(cps);
|
std::u32string cps = drvutil::utf8_to_utf32(src, &consumed);
|
||||||
engw.play_sent_outgoing(&engw, 0, consumed);
|
readline_device_.print(cps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,8 +660,8 @@ class Driver {
|
|||||||
handle_new_outgoing_sockets();
|
handle_new_outgoing_sockets();
|
||||||
handle_socket_input_output();
|
handle_socket_input_output();
|
||||||
handle_console_input();
|
handle_console_input();
|
||||||
handle_console_output();
|
|
||||||
engw.play_update(&engw, drvutil::get_monotonic_clock());
|
engw.play_update(&engw, drvutil::get_monotonic_clock());
|
||||||
|
handle_console_output();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user