Skip to content

Commit

Permalink
Regression fixes after 1.3.6 open rewrote
Browse files Browse the repository at this point in the history
  • Loading branch information
mmertama committed Apr 3, 2024
1 parent 13bd141 commit 1ff4f15
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gempyrelib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#cmake_minimum_required (VERSION 3.18)


project (gempyre VERSION 1.3.6 LANGUAGES CXX C)
project (gempyre VERSION 1.3.7 LANGUAGES CXX C)
# Must use GNUInstallDirs to install libraries into correct
# locations on all platforms.
include(GNUInstallDirs)
Expand Down
2 changes: 1 addition & 1 deletion gempyrelib/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,6 @@ void Ui::flush() {
}

bool Ui::ui_available() const {
return m_ui->is_connected() && m_ui->is_running();
return m_ui->is_ui_available();
}

30 changes: 18 additions & 12 deletions gempyrelib/src/gempyre_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,15 @@ GempyreInternal& Ui::ref() {
//do nothing
} else if(type == "ui_ready") {
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "UI ready request");

const auto open_function = take_open();
add_request([open_function, this]() {
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "call onOpen");
open_function();
//set_hold(false);
if(open_function) {
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "calling onOpen");
open_function();
} else {
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "missing onOpen");
}
shoot_requests();
return true;
});
Expand Down Expand Up @@ -516,15 +520,15 @@ void GempyreInternal::eventLoop(bool is_main) {
}


if(has_requests() && *this != State::RUNNING) {
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "skip requestqueue", state_str());
}

if(!has_open() && !is_hold())
shoot_requests();
if( has_requests() &&
*this == State::RUNNING &&
!has_open() &&
!is_hold()) {
shoot_requests();
}

if(has_requests()) {
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "unfinished business", state_str(), is_connected());
GempyreUtils::log(GempyreUtils::LogLevel::Debug, "unfinished business", state_str(), is_running());
}

//if there are responses they must be handled
Expand Down Expand Up @@ -552,8 +556,10 @@ void GempyreInternal::eventLoop(bool is_main) {
}

void GempyreInternal::shoot_requests() {
GempyreUtils::log(GempyreUtils::LogLevel::Debug,
"shoot_requests", has_requests(), "running", *this == State::RUNNING, "available", is_ui_available());
//shoot pending requests
while(has_requests() && *this == State::RUNNING && is_connected()) {
while(has_requests() && *this == State::RUNNING && is_ui_available()) {
GempyreUtils::log(GempyreUtils::LogLevel::Debug_Trace, "do request");
auto topRequest = take_request();
if(!topRequest) // since "flush" can be called in another thread this can happen :-o
Expand Down Expand Up @@ -606,7 +612,7 @@ void GempyreInternal::consume_events() {
"has open:", has_open(),
"State:", state_str(),
"Connected", is_connected());
continue;
//continue;
}
const auto element = m_elements.find(it.element);
if(element != m_elements.end()) {
Expand Down
6 changes: 5 additions & 1 deletion gempyrelib/src/gempyre_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class GempyreInternal {
return has_server() && m_server->isRunning();
}

bool is_ui_available() const {
return is_connected() && is_running() && m_server->isUiReady();
}


void add_handler(const std::string& id, const std::string& name, const Element::SubscribeFunction& handler) {
HandlerFunction hf = [handler](const Event& event) {
Expand Down Expand Up @@ -405,7 +409,7 @@ class GempyreInternal {

std::function<void()> take_open() {
GEM_DEBUG("Take open");
const auto fptr = std::move(m_onOpen);
const auto fptr = m_onOpen;
m_onOpen = nullptr;
return fptr;
}
Expand Down
1 change: 1 addition & 0 deletions gempyrelib/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Server {
virtual bool isJoinable() const = 0;
virtual bool isRunning() const = 0;
virtual bool isConnected() const = 0;
virtual bool isUiReady() const = 0;

int queryId() const {return ++m_queryId;}
unsigned int port() const {return m_port;}
Expand Down
6 changes: 5 additions & 1 deletion gempyrelib/src/uwebsockets/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ bool Uws_Server::retryStart() {
}

bool Uws_Server::isConnected() const {
return !m_broadcaster->empty() /*&& m_uiready*/; // why was this -
return !m_broadcaster->empty();
}

bool Uws_Server::isUiReady() const {
return m_uiready;
}

bool Uws_Server::beginBatch() {
Expand Down
1 change: 1 addition & 0 deletions gempyrelib/src/uwebsockets/uws_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Uws_Server : public Server {
// joinable does not mean it is running, and not running does not mean it soon wont :-)

bool isConnected() const override;
bool isUiReady() const override;
bool retryStart() override;
void close(bool wait = false) override;
bool send(Server::TargetSocket target, Server::Value&& value) override;
Expand Down

0 comments on commit 1ff4f15

Please sign in to comment.