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

[sensorfw-core] Do not timeout while reading data #7

Merged
merged 1 commit into from
Feb 15, 2025
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
27 changes: 15 additions & 12 deletions sensorfw-core/sensorfw_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ repowerd::Sensorfw::~Sensorfw()
stop();
release_sensor();
m_socket->dropConnection();
read_loop.join();
}

const char* repowerd::Sensorfw::plugin_string() const
Expand Down Expand Up @@ -125,6 +126,17 @@ bool repowerd::Sensorfw::load_plugin()
return the_result;
}

void repowerd::Sensorfw::run_socket_reader()
{
read_loop = std::thread([this](){
while (m_socket->isConnected()) {
if (m_socket->socket()->waitForReadyRead(-1)) {
data_recived_impl();
}
}
});
}

void repowerd::Sensorfw::request_sensor()
{
int constexpr timeout_default = 100;
Expand Down Expand Up @@ -191,15 +203,9 @@ void repowerd::Sensorfw::start()
return;

m_running = true;
read_loop = std::thread([this](){
log->log(log_tag, "Eventloop started");
while (m_running) {
if (m_socket->socket()->waitForReadyRead(10))
data_recived_impl();
}
m_running = false;
log->log(log_tag, "Eventloop stopped");
});

if (!read_loop.joinable())
run_socket_reader();

int constexpr timeout_default = 100;
auto const result = g_dbus_connection_call_sync(
Expand Down Expand Up @@ -250,9 +256,6 @@ void repowerd::Sensorfw::stop()
} else {
g_variant_unref(result);
}

read_loop.join();
read_loop = std::thread();
}

void repowerd::Sensorfw::set_interval(int interval) {
Expand Down
1 change: 1 addition & 0 deletions sensorfw-core/sensorfw_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Sensorfw {
void request_sensor();
bool release_sensor();
bool load_plugin();
void run_socket_reader();

const char* plugin_string() const;
const char* plugin_interface() const;
Expand Down