[glib] GDBusActionGroup: add static platform registration
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GDBusActionGroup: add static platform registration
- Date: Fri, 16 Dec 2011 15:54:48 +0000 (UTC)
commit fcc9902e98a6a6568a1150441c8680fd4615d437
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Dec 14 13:31:27 2011 -0500
GDBusActionGroup: add static platform registration
We provide a mechanism by which a 'platform' (eg: Gtk) can register some
hook functions to be called to collect platform-data at the point of
sending an outgoing action activation request and also to inform the
platform of this data on incoming requests (before and after dispatching
the actual request).
This can be used for forwarding timestamp and startup-notification
information (as is presently done in GApplication) but the before/after
hook could also be used for acquiring/releasing the Gdk lock or other
similar things.
https://bugzilla.gnome.org/show_bug.cgi?id=665737
gio/gactiongroupexporter.c | 10 ++++++++++
gio/gdbusactiongroup.c | 32 ++++++++++++++++++++++++++++++--
gio/gdbusactiongroup.h | 14 +++++++++++---
gio/gio.symbols | 1 +
4 files changed, 52 insertions(+), 5 deletions(-)
---
diff --git a/gio/gactiongroupexporter.c b/gio/gactiongroupexporter.c
index a399fff..8f3fccb 100644
--- a/gio/gactiongroupexporter.c
+++ b/gio/gactiongroupexporter.c
@@ -27,10 +27,14 @@
#include "gdbusmethodinvocation.h"
#include "gdbusintrospection.h"
#include "gdbusconnection.h"
+#include "gdbusactiongroup.h"
#include "gactiongroup.h"
#include "gapplication.h"
#include "gdbuserror.h"
+extern GDBusActionGroupEmitHookFunc g_dbus_action_group_before_emit_hook;
+extern GDBusActionGroupEmitHookFunc g_dbus_action_group_after_emit_hook;
+
/**
* SECTION:gactiongroupexporter
* @title: GActionGroup exporter
@@ -449,6 +453,9 @@ g_action_group_exporter_pre_emit (GActionGroupExporter *exporter,
if (G_IS_APPLICATION (exporter->action_group))
G_APPLICATION_GET_CLASS (exporter->action_group)
->before_emit (G_APPLICATION (exporter->action_group), platform_data);
+
+ else if (g_dbus_action_group_before_emit_hook != NULL)
+ (* g_dbus_action_group_before_emit_hook) (exporter->action_group, platform_data);
}
static void
@@ -458,6 +465,9 @@ g_action_group_exporter_post_emit (GActionGroupExporter *exporter,
if (G_IS_APPLICATION (exporter->action_group))
G_APPLICATION_GET_CLASS (exporter->action_group)
->after_emit (G_APPLICATION (exporter->action_group), platform_data);
+
+ else if (g_dbus_action_group_after_emit_hook != NULL)
+ (* g_dbus_action_group_after_emit_hook) (exporter->action_group, platform_data);
}
static void
diff --git a/gio/gdbusactiongroup.c b/gio/gdbusactiongroup.c
index 7c7b38e..c3353c1 100644
--- a/gio/gdbusactiongroup.c
+++ b/gio/gdbusactiongroup.c
@@ -38,6 +38,10 @@
* that is exported over D-Bus with g_dbus_connection_export_action_group().
*/
+G_GNUC_INTERNAL GDBusActionGroupSendHookFunc g_dbus_action_group_send_hook;
+G_GNUC_INTERNAL GDBusActionGroupEmitHookFunc g_dbus_action_group_before_emit_hook;
+G_GNUC_INTERNAL GDBusActionGroupEmitHookFunc g_dbus_action_group_after_emit_hook;
+
struct _GDBusActionGroup
{
GObject parent_instance;
@@ -368,10 +372,15 @@ g_dbus_action_group_change_state (GActionGroup *g_group,
GVariant *value)
{
GDBusActionGroup *group = G_DBUS_ACTION_GROUP (g_group);
+ GVariantBuilder platform_data_builder;
+
+ g_variant_builder_init (&platform_data_builder, G_VARIANT_TYPE_VARDICT);
+ if (g_dbus_action_group_send_hook != NULL)
+ (* g_dbus_action_group_send_hook) (group, &platform_data_builder);
/* Don't bother with the checks. The other side will do it again. */
g_dbus_connection_call (group->connection, group->bus_name, group->object_path, "org.gtk.Actions", "SetState",
- g_variant_new ("(sva{sv})", action_name, value, NULL),
+ g_variant_new ("(sva{sv})", action_name, value, &platform_data_builder),
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
}
@@ -381,6 +390,7 @@ g_dbus_action_group_activate (GActionGroup *g_group,
GVariant *parameter)
{
GDBusActionGroup *group = G_DBUS_ACTION_GROUP (g_group);
+ GVariantBuilder platform_data_builder;
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
@@ -388,8 +398,12 @@ g_dbus_action_group_activate (GActionGroup *g_group,
if (parameter)
g_variant_builder_add (&builder, "v", parameter);
+ g_variant_builder_init (&platform_data_builder, G_VARIANT_TYPE_VARDICT);
+ if (g_dbus_action_group_send_hook != NULL)
+ (* g_dbus_action_group_send_hook) (group, &platform_data_builder);
+
g_dbus_connection_call (group->connection, group->bus_name, group->object_path, "org.gtk.Actions", "Activate",
- g_variant_new ("(sava{sv})", action_name, &builder, NULL),
+ g_variant_new ("(sava{sv})", action_name, &builder, &platform_data_builder),
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
}
@@ -507,3 +521,17 @@ g_dbus_action_group_sync (GDBusActionGroup *group,
return reply != NULL;
}
+
+void
+g_dbus_action_group_register_platform (GDBusActionGroupSendHookFunc send,
+ GDBusActionGroupEmitHookFunc before,
+ GDBusActionGroupEmitHookFunc after)
+{
+ g_return_if_fail (g_dbus_action_group_send_hook == NULL &&
+ g_dbus_action_group_before_emit_hook == NULL &&
+ g_dbus_action_group_after_emit_hook == NULL);
+
+ g_dbus_action_group_send_hook = send;
+ g_dbus_action_group_before_emit_hook = before;
+ g_dbus_action_group_after_emit_hook = after;
+}
diff --git a/gio/gdbusactiongroup.h b/gio/gdbusactiongroup.h
index 12a8edf..d5b9b1d 100644
--- a/gio/gdbusactiongroup.h
+++ b/gio/gdbusactiongroup.h
@@ -45,9 +45,17 @@ G_BEGIN_DECLS
GType g_dbus_action_group_get_type (void) G_GNUC_CONST;
-GDBusActionGroup * g_dbus_action_group_get (GDBusConnection *connection,
- const gchar *bus_name,
- const gchar *object_path);
+GDBusActionGroup * g_dbus_action_group_get (GDBusConnection *connection,
+ const gchar *bus_name,
+ const gchar *object_path);
+
+typedef void (* GDBusActionGroupSendHookFunc) (GDBusActionGroup *group,
+ GVariantBuilder *builder);
+typedef void (* GDBusActionGroupEmitHookFunc) (GActionGroup *group,
+ GVariant *platform_data);
+void g_dbus_action_group_register_platform (GDBusActionGroupSendHookFunc send_hook,
+ GDBusActionGroupEmitHookFunc before_hook,
+ GDBusActionGroupEmitHookFunc after_hook);
G_END_DECLS
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 8fed849..a2d9469 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1442,6 +1442,7 @@ g_simple_action_new_stateful
g_simple_action_set_enabled
g_simple_action_set_state
g_dbus_action_group_get_type
+g_dbus_action_group_register_platform
g_dbus_action_group_get
g_dbus_menu_model_get_type
g_dbus_menu_model_get
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]