mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Use an XML blob for gapplication interface info
This is both more readable and more efficient. Double win !
This commit is contained in:
parent
4ce5a11daf
commit
8013401f6e
@ -35,112 +35,65 @@
|
||||
#include "gdbusmethodinvocation.h"
|
||||
|
||||
/* DBus Interface definition {{{1 */
|
||||
static const GDBusArgInfo platform_data_arg = { -1, (gchar *) "platform_data", (gchar *) "a{sv}" };
|
||||
|
||||
static const GDBusArgInfo open_uris_arg = { -1, (gchar *) "uris", (gchar *) "as" };
|
||||
static const GDBusArgInfo open_hint_arg = { -1, (gchar *) "hint", (gchar *) "s" };
|
||||
static GDBusInterfaceInfo *
|
||||
get_interface (const gchar *name)
|
||||
{
|
||||
static GDBusInterfaceInfo *org_gtk_Application;
|
||||
static GDBusInterfaceInfo *org_gtk_private_CommandLine;
|
||||
|
||||
static const GDBusArgInfo invoke_action_name_arg = { -1, (gchar *) "name", (gchar *) "s" };
|
||||
static const GDBusArgInfo invoke_action_args_arg = { -1, (gchar *) "args", (gchar *) "v" };
|
||||
if (org_gtk_Application == NULL)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GDBusNodeInfo *info;
|
||||
|
||||
static const GDBusArgInfo cmdline_path_arg = { -1, (gchar *) "path", (gchar *) "o" };
|
||||
static const GDBusArgInfo cmdline_arguments_arg = { -1, (gchar *) "arguments", (gchar *) "aay" };
|
||||
static const GDBusArgInfo cmdline_exit_status_arg = { -1, (gchar *) "exit_status", (gchar *) "i" };
|
||||
info = g_dbus_node_info_new_for_xml (
|
||||
"<node>"
|
||||
" <interface name='org.gtk.Application'>"
|
||||
" <method name='Activate'>"
|
||||
" <arg type='a{sv}' name='platform_data' direction='in'/>"
|
||||
" </method>"
|
||||
" <method name='Open'>"
|
||||
" <arg type='as' name='uris' direction='in'/>"
|
||||
" <arg type='s' name='hint' direction='in'/>"
|
||||
" <arg type='a{sv}' name='platform_data' direction='in'/>"
|
||||
" </method>"
|
||||
" <method name='CommandLine'>"
|
||||
" <arg type='o' name='path' direction='in'/>"
|
||||
" <arg type='aay' name='arguments' direction='in'/>"
|
||||
" <arg type='a{sv}' name='platform_data' direction='in'/>"
|
||||
" <arg type='i' name='exit_status' direction='out'/>"
|
||||
" </method>"
|
||||
" </interface>"
|
||||
" <interface name='org.gtk.private.CommandLine'>"
|
||||
" <method name='Print'>"
|
||||
" <arg type='s' name='message' direction='in'/>"
|
||||
" </method>"
|
||||
" <method name='PrintError'>"
|
||||
" <arg type='s' name='message' direction='in'/>"
|
||||
" </method>"
|
||||
" </interface>"
|
||||
"</node>", &error);
|
||||
|
||||
static const GDBusArgInfo *activate_in[] = { &platform_data_arg, NULL };
|
||||
static const GDBusArgInfo *activate_out[] = { NULL };
|
||||
if (info == NULL)
|
||||
g_error ("%s\n", error->message);
|
||||
|
||||
static const GDBusArgInfo *open_in[] = { &open_uris_arg, &open_hint_arg, &platform_data_arg, NULL };
|
||||
static const GDBusArgInfo *open_out[] = { NULL };
|
||||
org_gtk_Application = g_dbus_node_info_lookup_interface (info, "org.gtk.Application");
|
||||
g_assert (org_gtk_Application != NULL);
|
||||
g_dbus_interface_info_ref (org_gtk_Application);
|
||||
|
||||
static const GDBusArgInfo *cmdline_in[] = { &cmdline_path_arg, &cmdline_arguments_arg, &platform_data_arg, NULL };
|
||||
static const GDBusArgInfo *cmdline_out[] = { &cmdline_exit_status_arg, NULL };
|
||||
org_gtk_private_CommandLine = g_dbus_node_info_lookup_interface (info, "org.gtk.private.CommandLine");
|
||||
g_assert (org_gtk_private_CommandLine != NULL);
|
||||
g_dbus_interface_info_ref (org_gtk_private_CommandLine);
|
||||
|
||||
static const GDBusMethodInfo activate_method = {
|
||||
-1, (gchar *) "Activate",
|
||||
(GDBusArgInfo **) activate_in,
|
||||
(GDBusArgInfo **) activate_out
|
||||
};
|
||||
g_dbus_node_info_unref (info);
|
||||
}
|
||||
|
||||
static const GDBusMethodInfo open_method = {
|
||||
-1, (gchar *) "Open",
|
||||
(GDBusArgInfo **) open_in,
|
||||
(GDBusArgInfo **) open_out
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo command_line_method = {
|
||||
-1, (gchar *) "CommandLine",
|
||||
(GDBusArgInfo **) cmdline_in,
|
||||
(GDBusArgInfo **) cmdline_out
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo *application_methods[] = {
|
||||
&activate_method, &open_method, &command_line_method, NULL
|
||||
};
|
||||
|
||||
const GDBusInterfaceInfo org_gtk_Application = {
|
||||
-1, (gchar *) "org.gtk.Application",
|
||||
(GDBusMethodInfo **) application_methods
|
||||
};
|
||||
|
||||
static const GDBusArgInfo list_arg = { -1, (gchar *) "list", (gchar *) "a(savbav)" };
|
||||
static const GDBusArgInfo *describe_all_out[] = { &list_arg, NULL };
|
||||
|
||||
static const GDBusArgInfo action_name_arg = { -1, (gchar *) "action_name", (gchar *) "s" };
|
||||
static const GDBusArgInfo value_arg = { -1, (gchar *) "value", (gchar *) "v" };
|
||||
static const GDBusArgInfo *set_action_state_in[] = { &action_name_arg, &value_arg, &platform_data_arg, NULL };
|
||||
|
||||
static const GDBusArgInfo parameter_arg = { -1, (gchar *) "parameter", (gchar *) "av" };
|
||||
static const GDBusArgInfo *activate_action_in[] = { &action_name_arg, ¶meter_arg, &platform_data_arg, NULL };
|
||||
|
||||
static const GDBusMethodInfo describe_all_method = {
|
||||
-1, (gchar *) "DescribeAll", NULL,
|
||||
(GDBusArgInfo **) describe_all_out
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo set_action_state_method = {
|
||||
-1, (gchar *) "SetState",
|
||||
(GDBusArgInfo **) set_action_state_in
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo activate_action_method = {
|
||||
-1, (gchar *) "Activate",
|
||||
(GDBusArgInfo **) activate_action_in
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo *actions_methods[] = {
|
||||
&describe_all_method, &set_action_state_method, &activate_action_method, NULL
|
||||
};
|
||||
|
||||
const GDBusInterfaceInfo org_gtk_Actions = {
|
||||
-1, (gchar *) "org.gtk.Actions",
|
||||
(GDBusMethodInfo **) actions_methods
|
||||
};
|
||||
|
||||
static const GDBusArgInfo message_arg = { -1, (gchar *) "message", (gchar *) "s" };
|
||||
static const GDBusArgInfo *print_in[] = { &message_arg, NULL };
|
||||
static const GDBusArgInfo *print_out[] = { NULL };
|
||||
|
||||
static const GDBusMethodInfo stdout_method = {
|
||||
-1, (gchar *) "Print",
|
||||
(GDBusArgInfo **) print_in,
|
||||
(GDBusArgInfo **) print_out
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo stderr_method = {
|
||||
-1, (gchar *) "PrintError",
|
||||
(GDBusArgInfo **) print_in,
|
||||
(GDBusArgInfo **) print_out
|
||||
};
|
||||
|
||||
static const GDBusMethodInfo *cmdline_methods[] = {
|
||||
&stdout_method, &stderr_method, NULL
|
||||
};
|
||||
|
||||
const GDBusInterfaceInfo org_gtk_private_Cmdline = {
|
||||
-1, (gchar *) "org.gtk.private.CommandLine",
|
||||
(GDBusMethodInfo **) cmdline_methods
|
||||
};
|
||||
if (strcmp (name, "org.gtk.Application") == 0)
|
||||
return org_gtk_Application;
|
||||
else
|
||||
return org_gtk_private_CommandLine;
|
||||
}
|
||||
|
||||
/* GApplication implementation {{{1 */
|
||||
struct _GApplicationImpl
|
||||
@ -614,8 +567,7 @@ g_application_impl_register (GApplication *application,
|
||||
impl->object_id =
|
||||
g_dbus_connection_register_object (impl->session_bus,
|
||||
impl->object_path,
|
||||
(GDBusInterfaceInfo *)
|
||||
&org_gtk_Application,
|
||||
get_interface ("org.gtk.Application"),
|
||||
&vtable, impl, NULL, error);
|
||||
|
||||
if (impl->object_id == 0)
|
||||
@ -892,8 +844,7 @@ g_application_impl_command_line (GApplicationImpl *impl,
|
||||
|
||||
object_id = g_dbus_connection_register_object (impl->session_bus,
|
||||
object_path,
|
||||
(GDBusInterfaceInfo *)
|
||||
&org_gtk_private_Cmdline,
|
||||
get_interface ("org.gtk.private.CommandLine"),
|
||||
&vtable, &data, NULL, NULL);
|
||||
/* In theory we should try other paths... */
|
||||
g_assert (object_id != 0);
|
||||
|
Loading…
Reference in New Issue
Block a user