Skip to content

Commit

Permalink
fix: add DBus connection and service registration checks
Browse files Browse the repository at this point in the history
Improved error handling and logging for failed DBus operations.
  • Loading branch information
dxnu committed Dec 10, 2024
1 parent 5be713c commit 3763685
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
deepin-anything (7.0.3) unstable; urgency=medium
deepin-anything (7.0.4) unstable; urgency=medium

* Major update with a complete refactor and version upgrade.
* Fixed high CPU usage issues.
Expand Down
2 changes: 2 additions & 0 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project(
# Find the dependencies
find_package(Qt5 CONFIG REQUIRED Core DBus)
find_package(PkgConfig REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
pkg_check_modules(GNL REQUIRED libnl-3.0 libnl-genl-3.0)
pkg_check_modules(MOUNT REQUIRED mount IMPORTED_TARGET)
pkg_check_modules(LUCENE REQUIRED liblucene++)
Expand Down Expand Up @@ -62,6 +63,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
${LUCENE_CONTRIB_LIBRARIES}
${GNL_LIBRARIES}
${MOUNT_LIBRARIES}
${Boost_LIBRARIES}
Qt5::DBus
pthread
stdc++fs
Expand Down
10 changes: 10 additions & 0 deletions src/server/src/core/base_event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ base_event_handler::base_event_handler(std::string index_dir, QObject *parent)
timer_(std::thread(&base_event_handler::timer_worker, this, 1000)) {
new IAnythingAdaptor(this);
QDBusConnection dbus = QDBusConnection::systemBus();
if (!dbus.isConnected()) {
qWarning() << "Failed to connect to system bus:" << dbus.lastError().message();
exit(1);
}
QString service_name = "my.test.SAnything";
QString object_name = "/my/test/OAnything";
if (!dbus.interface()->isServiceRegistered(service_name)) {
dbus.registerService(service_name);
dbus.registerObject(object_name, this);
}

if (!dbus.registerService(service_name)) {
qWarning() << "Failed to register service:" << service_name
<< dbus.lastError().message();
exit(1);
}
}

base_event_handler::~base_event_handler() {
Expand Down

0 comments on commit 3763685

Please sign in to comment.