![Dbus를 사용하여 Linux에서 시스템 깨우기 이벤트 감지](https://linux55.com/image/226802/Dbus%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20Linux%EC%97%90%EC%84%9C%20%EC%8B%9C%EC%8A%A4%ED%85%9C%20%EA%B9%A8%EC%9A%B0%EA%B8%B0%20%EC%9D%B4%EB%B2%A4%ED%8A%B8%20%EA%B0%90%EC%A7%80.png)
애플리케이션이 절전 모드에서 깨어나자마자 애플리케이션에서 특정 작업을 수행하고 싶습니다. 이를 위해 내 애플리케이션에서 깨우기 이벤트를 감지하고 싶습니다. 내 cpp 프로그램에서 절전 이벤트를 감지하려면 다음 코드를 사용하고 있습니다. 온라인에서 아무것도 찾을 수 없기 때문에 사용할 DBus 신호와 같은 cpp에서 깨우기 이벤트를 감지하는 방법을 누군가 도와줄 수 있습니까?
#include <dbus/dbus.h>
static DBusHandlerResult handleSleepSignal (DBusConnection * connection, DBusMessage * message, void * user_data)
{
std::cout << "System is going to sleep." << std::endl;
return DBUS_HANDLER_RESULT_HANDLED;
}
int main ()
{
DBusError err;
dbus_error_init( & err);
// Connect to the session bus
DBusConnection * connection = dbus_bus_get(DBUS_BUS_SESSION, & err);
// Add a match rule to listen for signals indicating events
const char * match_rule = "type='signal',interface='org.freedesktop.login1.Manager',member='PrepareForSleep'";
dbus_bus_add_match(connection, match_rule, & err);
// Specify the callback function to handle sleep signal
dbus_connection_add_filter(connection, handleSleepSignal, nullptr, nullptr);
// Enter the main event loop
while (true) {
dbus_connection_read_write_dispatch(connection, -1);
}
// Cleanup
dbus_connection_unref(connection);
return 0;
}