From 8502c81e2d46a89583d18253915103f29fa9e977 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Tue, 5 Jul 2016 16:42:21 -0300 Subject: Remove call to keepDisplayOn since that now is handled by Unity during Notifications --- src/awake.cpp | 107 ---------------------------------------------------------- 1 file changed, 107 deletions(-) (limited to 'src/awake.cpp') diff --git a/src/awake.cpp b/src/awake.cpp index dd41c35..dc49436 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -48,16 +48,9 @@ public: g_cancellable_cancel (m_cancellable); g_object_unref (m_cancellable); - if (m_display_on_timer) - { - g_source_remove (m_display_on_timer); - m_display_on_timer = 0; - } - if (m_system_bus != nullptr) { unforce_awake (); - remove_display_on_request (); g_object_unref (m_system_bus); } } @@ -101,20 +94,6 @@ private: on_force_awake_response, self); - // ask unity-system-compositor to turn on the screen - g_dbus_connection_call (system_bus, - BUS_SCREEN_NAME, - BUS_SCREEN_PATH, - BUS_SCREEN_INTERFACE, - "keepDisplayOn", - nullptr, - G_VARIANT_TYPE("(i)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_keep_display_on_response, - self); - g_object_unref (system_bus); } } @@ -152,54 +131,6 @@ private: } } - static void on_keep_display_on_response (GObject * connection, - GAsyncResult * res, - gpointer gself) - { - GError * error; - GVariant * args; - - error = nullptr; - args = g_dbus_connection_call_finish (G_DBUS_CONNECTION(connection), - res, - &error); - if (error != nullptr) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && - !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) - { - g_warning ("Unable to turn on the screen: %s", error->message); - } - - g_error_free (error); - } - else - { - auto self = static_cast(gself); - - self->m_display_on_cookie = NO_DISPLAY_ON_COOKIE; - g_variant_get (args, "(i)", &self->m_display_on_cookie); - g_debug ("m_display_on_cookie is now '%d'", self->m_display_on_cookie); - - self->m_display_on_timer = g_timeout_add_seconds (self->m_display_on_seconds, - on_display_on_timer, - gself); - - g_variant_unref (args); - } - } - - static gboolean on_display_on_timer (gpointer gself) - { - auto self = static_cast(gself); - - self->m_display_on_timer = 0; - self->remove_display_on_request(); - - return G_SOURCE_REMOVE; - } - - void unforce_awake () { g_return_if_fail (G_IS_DBUS_CONNECTION(m_system_bus)); @@ -223,48 +154,10 @@ private: } } - void remove_display_on_request () - { - g_return_if_fail (G_IS_DBUS_CONNECTION(m_system_bus)); - - if (m_display_on_cookie != NO_DISPLAY_ON_COOKIE) - { - g_dbus_connection_call (m_system_bus, - BUS_SCREEN_NAME, - BUS_SCREEN_PATH, - BUS_SCREEN_INTERFACE, - "removeDisplayOnRequest", - g_variant_new("(i)", m_display_on_cookie), - nullptr, - G_DBUS_CALL_FLAGS_NONE, - -1, - nullptr, - nullptr, - nullptr); - - m_display_on_cookie = NO_DISPLAY_ON_COOKIE; - } - } - const std::string m_app_name; GCancellable * m_cancellable = nullptr; GDBusConnection * m_system_bus = nullptr; char * m_awake_cookie = nullptr; - - /** - * As described by bug #1434637, alarms should have the display turn on, - * dim, and turn off "just like it would if you'd woken it up yourself". - * USC may be adding an intent-based bus API to handle this use case, - * e.g. turnDisplayOnTemporarily(intent), but there's no timeframe for it. - * - * Until that's avaialble, we can get close to Design's specs by - * requesting a display-on cookie and then releasing the cookie - * a moment later. */ - const guint m_display_on_seconds = 1; - guint m_display_on_timer = 0; - int32_t m_display_on_cookie = NO_DISPLAY_ON_COOKIE; - - static constexpr int32_t NO_DISPLAY_ON_COOKIE { std::numeric_limits::min() }; }; /*** -- cgit v1.2.3 From fd6d89d244509981c6b57d5fe87c84078204bde0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Oct 2016 12:07:05 -0500 Subject: in Awake, remove an unnecessary async call by passing the system bus into the constructor instead of fetching it asynchronously --- include/notifications/awake.h | 4 ++- src/awake.cpp | 66 +++++++++++++------------------------------ 2 files changed, 23 insertions(+), 47 deletions(-) (limited to 'src/awake.cpp') 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 +#include + 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(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}} { } -- cgit v1.2.3 From 192f5450b2725c259d471eaab0e066ec78932f57 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 4 Nov 2016 11:00:24 -0500 Subject: remove unnecessary test in Awake::Impl::~Impl() --- src/awake.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/awake.cpp') diff --git a/src/awake.cpp b/src/awake.cpp index 3bcd8ed..9ee337e 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -62,12 +62,8 @@ public: { g_cancellable_cancel (m_cancellable); g_object_unref (m_cancellable); - - if (m_system_bus != nullptr) - { - unforce_awake (); - g_object_unref (m_system_bus); - } + unforce_awake (); + g_clear_object (&m_system_bus); } private: @@ -99,7 +95,6 @@ private: g_clear_pointer (&self->m_awake_cookie, g_free); g_variant_get (args, "(s)", &self->m_awake_cookie); - g_debug ("m_awake_cookie is now '%s'", self->m_awake_cookie); g_variant_unref (args); } @@ -120,7 +115,7 @@ private: nullptr, G_DBUS_CALL_FLAGS_NONE, -1, - nullptr, + m_cancellable, nullptr, nullptr); -- cgit v1.2.3