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;
|
||||
}
|
||||
|
||||
void DrivenEngine::rescan_lua_source(bool b) {
|
||||
rescan_lua_source_ = b;
|
||||
}
|
||||
|
||||
void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) {
|
||||
visible_world_ = w;
|
||||
visible_actor_id_ = id;
|
||||
@@ -192,6 +188,7 @@ DrivenEngine::DrivenEngine() {
|
||||
channels_[0] = stdio_channel_;
|
||||
rescan_lua_source_ = false;
|
||||
clock_ = 0.0;
|
||||
have_prints_ = false;
|
||||
stop_driver_ = false;
|
||||
}
|
||||
|
||||
@@ -381,6 +378,10 @@ double DrivenEngine::drv_get_clock() const {
|
||||
return clock_;
|
||||
}
|
||||
|
||||
bool DrivenEngine::drv_get_have_prints() const {
|
||||
return have_prints_;
|
||||
}
|
||||
|
||||
bool DrivenEngine::drv_get_rescan_lua_source() const {
|
||||
return rescan_lua_source_;
|
||||
}
|
||||
@@ -536,6 +537,10 @@ static double drv_get_clock(EngineWrapper *w) {
|
||||
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) {
|
||||
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_console_prompt = drv_get_console_prompt;
|
||||
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_stop_driver = drv_get_stop_driver;
|
||||
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,
|
||||
// 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.
|
||||
//
|
||||
@@ -274,6 +279,7 @@ public:
|
||||
bool drv_get_outgoing_empty(uint32_t chid) const;
|
||||
void drv_get_console_prompt(uint32_t *len, const char **data) const;
|
||||
double drv_get_clock() const;
|
||||
bool drv_get_have_prints() const;
|
||||
bool drv_get_rescan_lua_source() const;
|
||||
bool drv_get_stop_driver() const;
|
||||
int64_t drv_get_actor_id() const;
|
||||
@@ -310,6 +316,7 @@ private:
|
||||
StreamBuffer call_function_retpk_;
|
||||
bool rescan_lua_source_;
|
||||
double clock_;
|
||||
bool have_prints_;
|
||||
bool stop_driver_;
|
||||
eng::string console_prompt_;
|
||||
friend class Channel;
|
||||
|
||||
@@ -115,6 +115,11 @@ struct EngineWrapper {
|
||||
//
|
||||
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
|
||||
// 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
|
||||
|
||||
@@ -276,6 +276,7 @@ public:
|
||||
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), retpk)) {
|
||||
send_invocation(print_channeler_.invocation(actor_id_));
|
||||
}
|
||||
set_have_prints(false);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -313,6 +314,8 @@ public:
|
||||
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)) {
|
||||
master_->invoke(print_channeler_.invocation(admin_id_));
|
||||
}
|
||||
set_have_prints(false);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -354,6 +355,9 @@ public:
|
||||
}
|
||||
}
|
||||
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) {
|
||||
if (printbuffer == nullptr) return false;
|
||||
if (printbuffer->first_line() > line_) {
|
||||
|
||||
@@ -149,6 +149,9 @@ public:
|
||||
// Reset the print channeler.
|
||||
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.
|
||||
// Update the current line number. Return true if the printbuffer
|
||||
// contains any lines that have already been channeled.
|
||||
|
||||
Reference in New Issue
Block a user