Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk cleanup dispatcher #494

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/gtk/utils_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ bool Dispatcher::Init(std::function<void()> callback) {
gpointer user_data) -> gboolean {
auto self = reinterpret_cast<Dispatcher*>(user_data);
if (condition & G_IO_ERR || condition & G_IO_HUP) {
VLOG(2) << "Dispatcher: " << self << " pipe hup";
self->Destroy();
LOG(WARNING) << "Dispatcher: " << self << " pipe hup";
return G_SOURCE_REMOVE;
}
return self->ReadCallback();
Expand All @@ -409,7 +408,7 @@ bool Dispatcher::Init(std::function<void()> callback) {
g_source_unref(source_);

callback_ = callback;
VLOG(2) << "Dispatcher: " << this << " Inited";
LOG(INFO) << "Dispatcher: " << this << " Inited";
return true;
}

Expand All @@ -418,6 +417,7 @@ bool Dispatcher::Destroy() {
return true;
g_source_destroy(source_);
source_ = nullptr;
callback_ = nullptr;
bool failure_on_close = ::close(fds_[0]) != 0;
failure_on_close |= ::close(fds_[1]) != 0;
if (failure_on_close) {
Expand All @@ -426,7 +426,7 @@ bool Dispatcher::Destroy() {
}
fds_[0] = -1;
fds_[1] = -1;
VLOG(2) << "Dispatcher: " << this << " Destroyed";
LOG(INFO) << "Dispatcher: " << this << " Destroyed";
return true;
}

Expand Down Expand Up @@ -470,6 +470,9 @@ bool Dispatcher::ReadCallback() {
size -= ret;
}

if (!callback_) {
return G_SOURCE_REMOVE;
}
callback_();

return G_SOURCE_CONTINUE;
Expand Down
8 changes: 4 additions & 4 deletions src/gtk/yass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void YASSApp::OnStart(bool quiet) {
state_ = STARTING;
SaveConfig();

std::function<void(asio::error_code)> callback;
absl::AnyInvocable<void(asio::error_code)> callback;
if (!quiet) {
callback = [this](asio::error_code ec) {
bool successed = false;
Expand All @@ -222,13 +222,13 @@ void YASSApp::OnStart(bool quiet) {
dispatcher_.Emit();
};
}
worker_.Start(callback);
worker_.Start(std::move(callback));
}

void YASSApp::OnStop(bool quiet) {
state_ = STOPPING;

std::function<void()> callback;
absl::AnyInvocable<void()> callback;
if (!quiet) {
callback = [this]() {
{
Expand All @@ -239,7 +239,7 @@ void YASSApp::OnStop(bool quiet) {
dispatcher_.Emit();
};
}
worker_.Stop(callback);
worker_.Stop(std::move(callback));
}

void YASSApp::OnStarted() {
Expand Down
8 changes: 4 additions & 4 deletions src/gtk4/yass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void YASSApp::OnStart(bool quiet) {
state_ = STARTING;
SaveConfig();

std::function<void(asio::error_code)> callback;
absl::AnyInvocable<void(asio::error_code)> callback;
if (!quiet) {
callback = [this](asio::error_code ec) {
bool successed = false;
Expand All @@ -298,13 +298,13 @@ void YASSApp::OnStart(bool quiet) {
dispatcher_.Emit();
};
}
worker_.Start(callback);
worker_.Start(std::move(callback));
}

void YASSApp::OnStop(bool quiet) {
state_ = STOPPING;

std::function<void()> callback;
absl::AnyInvocable<void()> callback;
if (!quiet) {
callback = [this]() {
{
Expand All @@ -315,7 +315,7 @@ void YASSApp::OnStop(bool quiet) {
dispatcher_.Emit();
};
}
worker_.Stop(callback);
worker_.Stop(std::move(callback));
}

void YASSApp::OnStarted() {
Expand Down
8 changes: 4 additions & 4 deletions src/mac/YassAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (void)OnStart:(BOOL)quiet {
state_ = STARTING;
[self SaveConfig];

std::function<void(asio::error_code)> callback;
absl::AnyInvocable<void(asio::error_code)> callback;
if (!quiet) {
callback = [=](asio::error_code ec) {
bool successed = false;
Expand All @@ -111,21 +111,21 @@ - (void)OnStart:(BOOL)quiet {
});
};
}
worker_.Start(callback);
worker_.Start(std::move(callback));
}

- (void)OnStop:(BOOL)quiet {
state_ = STOPPING;

std::function<void()> callback;
absl::AnyInvocable<void()> callback;
if (!quiet) {
callback = [=]() {
dispatch_async(dispatch_get_main_queue(), ^{
[self OnStopped];
});
};
}
worker_.Stop(callback);
worker_.Stop(std::move(callback));
}

- (void)OnStarted {
Expand Down
8 changes: 4 additions & 4 deletions src/win32/yass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void CYassApp::OnStart(bool quiet) {
state_ = STARTING;
SaveConfig();

std::function<void(asio::error_code)> callback;
absl::AnyInvocable<void(asio::error_code)> callback;
if (!quiet) {
callback = [main_thread_id](asio::error_code ec) {
bool successed = false;
Expand All @@ -320,13 +320,13 @@ void CYassApp::OnStart(bool quiet) {
}
};
}
worker_.Start(callback);
worker_.Start(std::move(callback));
}

void CYassApp::OnStop(bool quiet) {
DWORD main_thread_id = GetCurrentThreadId();
state_ = STOPPING;
std::function<void()> callback;
absl::AnyInvocable<void()> callback;
if (!quiet) {
callback = [main_thread_id]() {
bool ret;
Expand All @@ -336,7 +336,7 @@ void CYassApp::OnStop(bool quiet) {
}
};
}
worker_.Stop(callback);
worker_.Stop(std::move(callback));
}

// https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types?redirectedfrom=MSDN
Expand Down
Loading