aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2016-03-21 19:33:35 -0500
committerCharles Kerr <charles.kerr@canonical.com>2016-03-21 19:33:35 -0500
commit70209f30bc6907ad545e33dc6e7de78cf63b9e9a (patch)
tree37371d95bcf65dc1a2de7e1b5c334904a87b745a
parentecf802d7c939fcc73838d19de546294bc1c89e33 (diff)
downloadayatana-indicator-display-70209f30bc6907ad545e33dc6e7de78cf63b9e9a.tar.gz
ayatana-indicator-display-70209f30bc6907ad545e33dc6e7de78cf63b9e9a.tar.bz2
ayatana-indicator-display-70209f30bc6907ad545e33dc6e7de78cf63b9e9a.zip
get greeter's IsActive property working
-rw-r--r--src/dbus-names.h11
-rw-r--r--src/greeter.cpp80
-rw-r--r--src/main.cpp3
3 files changed, 73 insertions, 21 deletions
diff --git a/src/dbus-names.h b/src/dbus-names.h
index 3127b9f..b31098a 100644
--- a/src/dbus-names.h
+++ b/src/dbus-names.h
@@ -45,5 +45,16 @@ namespace DBusNames
static constexpr char const * PATH = "/";
static constexpr char const * INTERFACE = "com.canonical.UnityGreeter";
}
+
+ namespace Properties
+ {
+ static constexpr char const * INTERFACE = "org.freedesktop.DBus.Properties";
+
+ namespace PropertiesChanged
+ {
+ static constexpr char const* NAME = "PropertiesChanged";
+ static constexpr char const* ARGS_VARIANT_TYPE = "(sa{sv}as)";
+ }
+ }
}
diff --git a/src/greeter.cpp b/src/greeter.cpp
index 351b870..cffa376 100644
--- a/src/greeter.cpp
+++ b/src/greeter.cpp
@@ -68,37 +68,69 @@ private:
{
m_bus = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(bus)));
+ g_dbus_connection_call(m_bus,
+ DBusNames::UnityGreeter::NAME,
+ DBusNames::UnityGreeter::PATH,
+ DBusNames::Properties::INTERFACE,
+ "Get",
+ g_variant_new("(ss)", DBusNames::UnityGreeter::INTERFACE, "IsActive"),
+ G_VARIANT_TYPE("(v)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ m_cancellable,
+ on_get_is_active_ready,
+ this);
+
m_subscription_id = g_dbus_connection_signal_subscribe(m_bus,
DBusNames::UnityGreeter::NAME,
- "org.freedesktop.DBus.Properties",
- "PropertiesChanged",
+ DBusNames::Properties::INTERFACE,
+ DBusNames::Properties::PropertiesChanged::NAME,
DBusNames::UnityGreeter::PATH,
- nullptr,
+ DBusNames::UnityGreeter::INTERFACE,
G_DBUS_SIGNAL_FLAGS_NONE,
- on_properties_changed_signal_static,
+ on_properties_changed_signal,
this,
nullptr);
}
- static void on_properties_changed_signal_static(GDBusConnection* /*connection*/,
- const gchar* sender_name,
- const gchar* object_path,
- const gchar* interface_name,
- const gchar* signal_name,
- GVariant* parameters,
- gpointer gself)
+ static void on_get_is_active_ready(GObject* source, GAsyncResult* res, gpointer gself)
{
- g_return_if_fail(!g_strcmp0(sender_name, DBusNames::UnityGreeter::NAME));
- g_return_if_fail(!g_strcmp0(object_path, DBusNames::UnityGreeter::PATH));
- g_return_if_fail(!g_strcmp0(interface_name, "org.freedesktop.DBus.Properties"));
- g_return_if_fail(!g_strcmp0(signal_name, "PropertiesChanged"));
-
- static_cast<Impl*>(gself)->on_properties_changed_signal(parameters);
+ GError* error {};
+ auto v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);
+ if (error != nullptr) {
+ if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning("UsbSnap: Error getting session bus: %s", error->message);
+ g_clear_error(&error);
+ } else {
+ GVariant* is_active {};
+ g_variant_get_child(v, 0, "v", &is_active_v);
+ static_cast<Impl*>(gself)->m_is_active.set(g_variant_get_boolean(is_active);
+ g_clear_pointer(&is_active, g_variant_unref);
+ }
+ g_clear_pointer(&v, g_variant_unref);
}
- void on_properties_changed_signal(GVariant* parameters)
+ static void on_properties_changed_signal(GDBusConnection* /*connection*/,
+ const gchar* /*sender_name*/,
+ const gchar* object_path,
+ const gchar* interface_name,
+ const gchar* signal_name,
+ GVariant* parameters,
+ gpointer gself)
{
- g_message("%s %s", G_STRLOC, g_variant_print(parameters, true));
+ g_return_if_fail(!g_strcmp0(object_path, DBusNames::UnityGreeter::PATH));
+ g_return_if_fail(!g_strcmp0(interface_name, DBusNames::Properties::INTERFACE));
+ g_return_if_fail(!g_strcmp0(signal_name, DBusNames::Properties::PropertiesChanged::NAME));
+ g_return_if_fail(g_variant_is_of_type(parameters, G_VARIANT_TYPE(DBusNames::Properties::PropertiesChanged::ARGS_VARIANT_TYPE)));
+
+ auto v = g_variant_get_child_value (parameters, 1);
+ gboolean is_active {};
+ if (g_variant_lookup(v, "IsActive", "b", &is_active))
+ {
+ g_debug("%s is_active changed to %d", G_STRLOC, int(is_active));
+ static_cast<Impl*>(gself)->m_is_active.set(is_active);
+ }
+ g_clear_pointer(&v, g_variant_unref);
}
core::Property<bool> m_is_active;
@@ -115,9 +147,15 @@ Greeter::Greeter() =default;
Greeter::~Greeter() =default;
-UnityGreeter::~UnityGreeter() =default;
-
UnityGreeter::UnityGreeter():
impl{new Impl{}}
{
}
+
+UnityGreeter::~UnityGreeter() =default;
+
+core::Property<bool>&
+UnityGreeter::is_active()
+{
+ return impl->is_active();
+}
diff --git a/src/main.cpp b/src/main.cpp
index 27e6bcc..6c111f1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,6 +19,8 @@
#include <src/exporter.h>
#include <src/rotation-lock.h>
+
+#include <src/greeter.h>
#include <src/usb-manager.h>
#include <src/usb-monitor.h>
@@ -61,6 +63,7 @@ main(int /*argc*/, char** /*argv*/)
static constexpr char const * ADB_SOCKET_PATH {"/dev/socket/adbd"};
static constexpr char const * PUBLIC_KEYS_FILENAME {"/data/misc/adb/adb_keys"};
auto usb_monitor = std::make_shared<GUDevUsbMonitor>();
+ auto greeter = std::make_shared<UnityGreeter>();
UsbManager usb_manager {ADB_SOCKET_PATH, PUBLIC_KEYS_FILENAME, usb_monitor};
// let's go!