From 5d753a34dcb898d1572f527a95b7ec9b58be1803 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 13 Sep 2014 13:12:04 -0500 Subject: hide Clock's implementation details into an Impl class. --- include/datetime/clock.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 1d488d1..0b2a543 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -55,12 +55,9 @@ protected: void maybe_emit (const DateTime& a, const DateTime& b); private: - static void on_system_bus_ready(GObject*, GAsyncResult*, gpointer); - static void on_prepare_for_sleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); - - GCancellable * m_cancellable = nullptr; - GDBusConnection * m_system_bus = nullptr; - unsigned int m_sleep_subscription_id = 0; + class Impl; + friend class Impl; + std::unique_ptr m_impl; // we've got raw pointers and GSignal tags in here, so disable copying Clock(const Clock&) =delete; -- cgit v1.2.3 From 187b660a2a80f4aabf0b87c3fae02cb0841dd2e0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 13 Sep 2014 13:39:19 -0500 Subject: update the time string when a powerd.Wakeup signal is seen. --- include/datetime/dbus-shared.h | 5 +++ src/clock.cpp | 79 +++++++++++++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index db10c1d..c09caa2 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -24,4 +24,9 @@ #define BUS_DATETIME_NAME "com.canonical.indicator.datetime" #define BUS_DATETIME_PATH "/com/canonical/indicator/datetime" +#define BUS_POWERD_NAME "com.canonical.powerd" +#define BUS_POWERD_PATH "/com/canonical/powerd" +#define BUS_POWERD_INTERFACE "com.canonical.powerd" + + #endif /* _INDICATOR_DATETIME_DBUS_SHARED_H_ */ diff --git a/src/clock.cpp b/src/clock.cpp index 748174b..6831732 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -49,6 +50,14 @@ public: on_login1_vanished, this, nullptr); m_watched_names.insert(tag); + + tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM, + BUS_POWERD_NAME, + G_BUS_NAME_WATCHER_FLAGS_NONE, + on_powerd_appeared, + on_powerd_vanished, + this, nullptr); + m_watched_names.insert(tag); } @@ -60,19 +69,18 @@ public: private: - void remember_subscription(const std::string& name, - GDBusConnection* bus, - guint tag) + void remember_subscription(const std::string & name, + GDBusConnection * bus, + guint tag) { - auto subscription = std::shared_ptr( - G_DBUS_CONNECTION(g_object_ref(bus)), - [tag](GDBusConnection* bus){ - g_dbus_connection_signal_unsubscribe(bus, tag); - g_object_unref(G_OBJECT(bus)); - } - ); - - m_subscriptions[name].push_back(subscription); + g_object_ref(bus); + + auto deleter = [tag](GDBusConnection* bus){ + g_dbus_connection_signal_unsubscribe(bus, tag); + g_object_unref(G_OBJECT(bus)); + }; + + m_subscriptions[name].push_back(std::shared_ptr(bus, deleter)); } /** @@ -115,6 +123,53 @@ private: GVariant* /*parameters*/, gpointer gself) { + g_debug("firing clock.minute_changed() due to PrepareForSleep"); + static_cast(gself)->m_owner.minute_changed(); + } + + /** + *** DBus Chatter: com.canonical.powerd + *** + *** Fire Clock::minute_changed() signal when powerd says the system's + *** has awoken from sleep -- the old timestamp is likely out-of-date + **/ + + static void on_powerd_appeared(GDBusConnection * bus, + const gchar * name, + const gchar * name_owner, + gpointer gself) + { + auto tag = g_dbus_connection_signal_subscribe(bus, + name_owner, + BUS_POWERD_INTERFACE, + "Wakeup", // signal name + BUS_POWERD_PATH, + nullptr, // arg0 + G_DBUS_SIGNAL_FLAGS_NONE, + on_wakeup, + gself, // user_data + nullptr); // user_data closure + + + static_cast(gself)->remember_subscription(name, bus, tag); + } + + static void on_powerd_vanished(GDBusConnection * /*bus*/, + const gchar * name, + gpointer gself) + { + static_cast(gself)->m_subscriptions[name].clear(); + } + + static void on_wakeup(GDBusConnection* /*connection*/, + const gchar* /*sender_name*/, + const gchar* /*object_path*/, + const gchar* /*interface_name*/, + const gchar* /*signal_name*/, + GVariant* /*parameters*/, + gpointer gself) + { + g_debug("firing clock.minute_changed() due to powerd.Wakeup"); static_cast(gself)->m_owner.minute_changed(); } -- cgit v1.2.3