CUPowerSyscall::CUPowerSyscall() { CLog::Log(LOGINFO, "Selected UPower as PowerSyscall"); m_lowBattery = false; //! @todo do not use dbus_connection_pop_message() that requires the use of a //! private connection if (m_connection.Connect(DBUS_BUS_SYSTEM, true)) { dbus_connection_set_exit_on_disconnect(m_connection, false); CDBusError error; dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.UPower'", error); dbus_connection_flush(m_connection); if (error) { error.Log("UPower: Failed to attach to signal"); m_connection.Destroy(); } } m_CanPowerdown = false; m_CanReboot = false; UpdateCapabilities(); EnumeratePowerSources(); }
bool CDBusUtil::TryMethodCall(DBusBusType bus, const char* destination, const char* object, const char* interface, const char* method) { CDBusMessage message(destination, object, interface, method); CDBusError error; message.Send(bus, error); if (error) { error.Log(LOGDEBUG, std::string("DBus method call to ") + interface + "." + method + " at " + object + " of " + destination + " failed"); } return !error; }
bool CDBusConnection::Connect(DBusBusType bus, bool openPrivate) { CDBusError error; Connect(bus, error, openPrivate); if (error) { error.Log(LOGWARNING, "DBus connection failed"); return false; } return true; }
CLogindUPowerSyscall::CLogindUPowerSyscall() { m_delayLockFd = -1; m_lowBattery = false; CLog::Log(LOGINFO, "Selected Logind/UPower as PowerSyscall"); // Check if we have UPower. If not, we avoid any battery related operations. CDBusMessage message("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "EnumerateDevices"); m_hasUPower = message.SendSystem() != NULL; if (!m_hasUPower) CLog::Log(LOGINFO, "LogindUPowerSyscall - UPower not found, battery information will not be available"); m_canPowerdown = LogindCheckCapability("CanPowerOff"); m_canReboot = LogindCheckCapability("CanReboot"); m_canHibernate = LogindCheckCapability("CanHibernate"); m_canSuspend = LogindCheckCapability("CanSuspend"); InhibitDelayLock(); m_batteryLevel = 0; if (m_hasUPower) UpdateBatteryLevel(); if (!m_connection.Connect(DBUS_BUS_SYSTEM, true)) { return; } CDBusError error; dbus_connection_set_exit_on_disconnect(m_connection, false); dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.login1.Manager',member='PrepareForSleep'", error); if (!error && m_hasUPower) dbus_bus_add_match(m_connection, "type='signal',interface='org.freedesktop.UPower',member='DeviceChanged'", error); dbus_connection_flush(m_connection); if (error) { error.Log("UPowerSyscall: Failed to attach to signal"); m_connection.Destroy(); } }
CUDisks2Provider::CUDisks2Provider() { if (!m_connection.Connect(DBUS_BUS_SYSTEM, true)) { return; } dbus_connection_set_exit_on_disconnect(m_connection, static_cast<dbus_bool_t>(false)); CDBusError error; dbus_bus_add_match(m_connection, UDISKS2_MATCH_RULE, error); dbus_connection_flush(m_connection); if (error) { error.Log("UDisks2: Failed to attach to signal"); m_connection.Destroy(); } }