diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2016-10-06 12:07:05 -0500 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2021-08-29 14:37:39 +0200 |
commit | fd6d89d244509981c6b57d5fe87c84078204bde0 (patch) | |
tree | de52babc06068193147fbd618f026baa78efa2ce | |
parent | 231168012760d2161318bc31498e72ada7a82716 (diff) | |
download | ayatana-indicator-datetime-fd6d89d244509981c6b57d5fe87c84078204bde0.tar.gz ayatana-indicator-datetime-fd6d89d244509981c6b57d5fe87c84078204bde0.tar.bz2 ayatana-indicator-datetime-fd6d89d244509981c6b57d5fe87c84078204bde0.zip |
in Awake, remove an unnecessary async call by passing the system bus into the constructor instead of fetching it asynchronously
-rw-r--r-- | include/notifications/awake.h | 4 | ||||
-rw-r--r-- | src/awake.cpp | 66 |
2 files changed, 23 insertions, 47 deletions
diff --git a/include/notifications/awake.h b/include/notifications/awake.h index b441692..d0b46eb 100644 --- a/include/notifications/awake.h +++ b/include/notifications/awake.h @@ -22,6 +22,8 @@ #include <memory> +#include <gio/gio.h> + namespace ayatana { namespace indicator { namespace notifications { @@ -36,7 +38,7 @@ namespace notifications { class Awake { public: - explicit Awake(const std::string& app_name); + explicit Awake(GDBusConnection* system_bus, const std::string& app_name); ~Awake(); private: diff --git a/src/awake.cpp b/src/awake.cpp index dc49436..3bcd8ed 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -36,11 +36,26 @@ class Awake::Impl { public: - Impl(const std::string& app_name): + Impl(GDBusConnection* bus, const std::string& app_name): m_app_name(app_name), - m_cancellable(g_cancellable_new()) + m_cancellable(g_cancellable_new()), + m_system_bus{G_DBUS_CONNECTION(g_object_ref(bus))} { - g_bus_get(G_BUS_TYPE_SYSTEM, m_cancellable, on_system_bus_ready, this); + // ask repowerd to keep the system awake + static constexpr int32_t POWERD_SYS_STATE_ACTIVE = 1; + g_dbus_connection_call (m_system_bus, + BUS_POWERD_NAME, + BUS_POWERD_PATH, + BUS_POWERD_INTERFACE, + "requestSysState", + g_variant_new("(si)", m_app_name.c_str(), POWERD_SYS_STATE_ACTIVE), + G_VARIANT_TYPE("(s)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + m_cancellable, + on_force_awake_response, + this); + } ~Impl() @@ -57,47 +72,6 @@ public: private: - static void on_system_bus_ready (GObject *, - GAsyncResult *res, - gpointer gself) - { - GError * error; - GDBusConnection * system_bus; - - error = nullptr; - system_bus = g_bus_get_finish (res, &error); - if (error != nullptr) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("Unable to get bus: %s", error->message); - - g_error_free (error); - } - else if (system_bus != nullptr) - { - auto self = static_cast<Impl*>(gself); - - self->m_system_bus = G_DBUS_CONNECTION (g_object_ref (system_bus)); - - // ask powerd to keep the system awake - static constexpr int32_t POWERD_SYS_STATE_ACTIVE = 1; - g_dbus_connection_call (system_bus, - BUS_POWERD_NAME, - BUS_POWERD_PATH, - BUS_POWERD_INTERFACE, - "requestSysState", - g_variant_new("(si)", self->m_app_name.c_str(), POWERD_SYS_STATE_ACTIVE), - G_VARIANT_TYPE("(s)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_force_awake_response, - self); - - g_object_unref (system_bus); - } - } - static void on_force_awake_response (GObject * connection, GAsyncResult * res, gpointer gself) @@ -164,8 +138,8 @@ private: **** ***/ -Awake::Awake(const std::string& app_name): - impl(new Impl(app_name)) +Awake::Awake(GDBusConnection* system_bus, const std::string& app_name): + impl{new Impl{system_bus, app_name}} { } |