Coverage Report

Created: 2025-06-13 06:55

/src/glib/gio/gactiongroupexporter.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2010 Codethink Limited
3
 * Copyright © 2011 Canonical Limited
4
 *
5
 * SPDX-License-Identifier: LGPL-2.1-or-later
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General
18
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * Authors: Ryan Lortie <desrt@desrt.ca>
21
 */
22
23
#include "config.h"
24
25
#include "gactiongroupexporter.h"
26
27
#include "gdbusmethodinvocation.h"
28
#include "gremoteactiongroup.h"
29
#include "gdbusintrospection.h"
30
#include "gdbusconnection.h"
31
#include "gactiongroup.h"
32
#include "gdbuserror.h"
33
34
/**
35
 * SECTION:gactiongroupexporter
36
 * @title: GActionGroup exporter
37
 * @include: gio/gio.h
38
 * @short_description: Export GActionGroups on D-Bus
39
 * @see_also: #GActionGroup, #GDBusActionGroup
40
 *
41
 * These functions support exporting a #GActionGroup on D-Bus.
42
 * The D-Bus interface that is used is a private implementation
43
 * detail.
44
 *
45
 * To access an exported #GActionGroup remotely, use
46
 * g_dbus_action_group_get() to obtain a #GDBusActionGroup.
47
 */
48
49
static GVariant *
50
g_action_group_describe_action (GActionGroup *action_group,
51
                                const gchar  *name)
52
0
{
53
0
  const GVariantType *type;
54
0
  GVariantBuilder builder;
55
0
  gboolean enabled;
56
0
  GVariant *state;
57
58
0
  g_variant_builder_init (&builder, G_VARIANT_TYPE ("(bgav)"));
59
60
0
  enabled = g_action_group_get_action_enabled (action_group, name);
61
0
  g_variant_builder_add (&builder, "b", enabled);
62
63
0
  if ((type = g_action_group_get_action_parameter_type (action_group, name)))
64
0
    {
65
0
      gchar *str = g_variant_type_dup_string (type);
66
0
      g_variant_builder_add (&builder, "g", str);
67
0
      g_free (str);
68
0
    }
69
0
  else
70
0
    g_variant_builder_add (&builder, "g", "");
71
72
0
  g_variant_builder_open (&builder, G_VARIANT_TYPE ("av"));
73
0
  if ((state = g_action_group_get_action_state (action_group, name)))
74
0
    {
75
0
      g_variant_builder_add (&builder, "v", state);
76
0
      g_variant_unref (state);
77
0
    }
78
0
  g_variant_builder_close (&builder);
79
80
0
  return g_variant_builder_end (&builder);
81
0
}
82
83
/* Using XML saves us dozens of relocations vs. using the introspection
84
 * structure types.  We only need to burn cycles and memory if we
85
 * actually use the exporter -- not in every single app using GIO.
86
 *
87
 * It's also a lot easier to read. :)
88
 *
89
 * For documentation of this interface, see
90
 * https://wiki.gnome.org/Projects/GLib/GApplication/DBusAPI
91
 */
92
const char org_gtk_Actions_xml[] =
93
  "<node>"
94
  "  <interface name='org.gtk.Actions'>"
95
  "    <method name='List'>"
96
  "      <arg type='as' name='list' direction='out'/>"
97
  "    </method>"
98
  "    <method name='Describe'>"
99
  "      <arg type='s' name='action_name' direction='in'/>"
100
  "      <arg type='(bgav)' name='description' direction='out'/>"
101
  "    </method>"
102
  "    <method name='DescribeAll'>"
103
  "      <arg type='a{s(bgav)}' name='descriptions' direction='out'/>"
104
  "    </method>"
105
  "    <method name='Activate'>"
106
  "      <arg type='s' name='action_name' direction='in'/>"
107
  "      <arg type='av' name='parameter' direction='in'/>"
108
  "      <arg type='a{sv}' name='platform_data' direction='in'/>"
109
  "    </method>"
110
  "    <method name='SetState'>"
111
  "      <arg type='s' name='action_name' direction='in'/>"
112
  "      <arg type='v' name='value' direction='in'/>"
113
  "      <arg type='a{sv}' name='platform_data' direction='in'/>"
114
  "    </method>"
115
  "    <signal name='Changed'>"
116
  "      <arg type='as' name='removals'/>"
117
  "      <arg type='a{sb}' name='enable_changes'/>"
118
  "      <arg type='a{sv}' name='state_changes'/>"
119
  "      <arg type='a{s(bgav)}' name='additions'/>"
120
  "    </signal>"
121
  "  </interface>"
122
  "</node>";
123
124
static GDBusInterfaceInfo *org_gtk_Actions;
125
126
typedef struct
127
{
128
  GActionGroup    *action_group;
129
  GDBusConnection *connection;
130
  GMainContext    *context;
131
  gchar           *object_path;
132
  GHashTable      *pending_changes;
133
  GSource         *pending_source;
134
} GActionGroupExporter;
135
136
0
#define ACTION_ADDED_EVENT             (1u<<0)
137
0
#define ACTION_REMOVED_EVENT           (1u<<1)
138
0
#define ACTION_STATE_CHANGED_EVENT     (1u<<2)
139
0
#define ACTION_ENABLED_CHANGED_EVENT   (1u<<3)
140
141
static gboolean
142
g_action_group_exporter_dispatch_events (gpointer user_data)
143
0
{
144
0
  GActionGroupExporter *exporter = user_data;
145
0
  GVariantBuilder removes;
146
0
  GVariantBuilder enabled_changes;
147
0
  GVariantBuilder state_changes;
148
0
  GVariantBuilder adds;
149
0
  GHashTableIter iter;
150
0
  gpointer value;
151
0
  gpointer key;
152
153
0
  g_variant_builder_init (&removes, G_VARIANT_TYPE_STRING_ARRAY);
154
0
  g_variant_builder_init (&enabled_changes, G_VARIANT_TYPE ("a{sb}"));
155
0
  g_variant_builder_init (&state_changes, G_VARIANT_TYPE ("a{sv}"));
156
0
  g_variant_builder_init (&adds, G_VARIANT_TYPE ("a{s(bgav)}"));
157
158
0
  g_hash_table_iter_init (&iter, exporter->pending_changes);
159
0
  while (g_hash_table_iter_next (&iter, &key, &value))
160
0
    {
161
0
      guint events = GPOINTER_TO_INT (value);
162
0
      const gchar *name = key;
163
164
      /* Adds and removes are incompatible with enabled or state
165
       * changes, but we must report at least one event.
166
       */
167
0
      g_assert (((events & (ACTION_ENABLED_CHANGED_EVENT | ACTION_STATE_CHANGED_EVENT)) == 0) !=
168
0
                ((events & (ACTION_REMOVED_EVENT | ACTION_ADDED_EVENT)) == 0));
169
170
0
      if (events & ACTION_REMOVED_EVENT)
171
0
        g_variant_builder_add (&removes, "s", name);
172
173
0
      if (events & ACTION_ENABLED_CHANGED_EVENT)
174
0
        {
175
0
          gboolean enabled;
176
177
0
          enabled = g_action_group_get_action_enabled (exporter->action_group, name);
178
0
          g_variant_builder_add (&enabled_changes, "{sb}", name, enabled);
179
0
        }
180
181
0
      if (events & ACTION_STATE_CHANGED_EVENT)
182
0
        {
183
0
          GVariant *state;
184
185
0
          state = g_action_group_get_action_state (exporter->action_group, name);
186
0
          g_variant_builder_add (&state_changes, "{sv}", name, state);
187
0
          g_variant_unref (state);
188
0
        }
189
190
0
      if (events & ACTION_ADDED_EVENT)
191
0
        {
192
0
          GVariant *description;
193
194
0
          description = g_action_group_describe_action (exporter->action_group, name);
195
0
          g_variant_builder_add (&adds, "{s@(bgav)}", name, description);
196
0
        }
197
0
    }
198
199
0
  g_hash_table_remove_all (exporter->pending_changes);
200
201
0
  g_dbus_connection_emit_signal (exporter->connection, NULL, exporter->object_path,
202
0
                                 "org.gtk.Actions", "Changed",
203
0
                                 g_variant_new ("(asa{sb}a{sv}a{s(bgav)})",
204
0
                                                &removes, &enabled_changes,
205
0
                                                &state_changes, &adds),
206
0
                                 NULL);
207
208
0
  exporter->pending_source = NULL;
209
210
0
  return FALSE;
211
0
}
212
213
static void
214
g_action_group_exporter_flush_queue (GActionGroupExporter *exporter)
215
0
{
216
0
  if (exporter->pending_source)
217
0
    {
218
0
      g_source_destroy (exporter->pending_source);
219
0
      g_action_group_exporter_dispatch_events (exporter);
220
0
      g_assert (exporter->pending_source == NULL);
221
0
    }
222
0
}
223
224
static guint
225
g_action_group_exporter_get_events (GActionGroupExporter *exporter,
226
                                    const gchar          *name)
227
0
{
228
0
  return (gsize) g_hash_table_lookup (exporter->pending_changes, name);
229
0
}
230
231
static void
232
g_action_group_exporter_set_events (GActionGroupExporter *exporter,
233
                                    const gchar          *name,
234
                                    guint                 events)
235
0
{
236
0
  gboolean have_events;
237
0
  gboolean is_queued;
238
239
0
  if (events != 0)
240
0
    g_hash_table_insert (exporter->pending_changes, g_strdup (name), GINT_TO_POINTER (events));
241
0
  else
242
0
    g_hash_table_remove (exporter->pending_changes, name);
243
244
0
  have_events = g_hash_table_size (exporter->pending_changes) > 0;
245
0
  is_queued = exporter->pending_source != NULL;
246
247
0
  if (have_events && !is_queued)
248
0
    {
249
0
      GSource *source;
250
251
0
      source = g_idle_source_new ();
252
0
      exporter->pending_source = source;
253
0
      g_source_set_callback (source, g_action_group_exporter_dispatch_events, exporter, NULL);
254
0
      g_source_set_static_name (source, "[gio] g_action_group_exporter_dispatch_events");
255
0
      g_source_attach (source, exporter->context);
256
0
      g_source_unref (source);
257
0
    }
258
259
0
  if (!have_events && is_queued)
260
0
    {
261
0
      g_source_destroy (exporter->pending_source);
262
0
      exporter->pending_source = NULL;
263
0
    }
264
0
}
265
266
static void
267
g_action_group_exporter_action_added (GActionGroup *action_group,
268
                                      const gchar  *action_name,
269
                                      gpointer      user_data)
270
0
{
271
0
  GActionGroupExporter *exporter = user_data;
272
0
  guint event_mask;
273
274
0
  event_mask = g_action_group_exporter_get_events (exporter, action_name);
275
276
  /* The action is new, so we should not have any pending
277
   * enabled-changed or state-changed signals for it.
278
   */
279
0
  g_assert (~event_mask & (ACTION_STATE_CHANGED_EVENT |
280
0
                           ACTION_ENABLED_CHANGED_EVENT));
281
282
0
  event_mask |= ACTION_ADDED_EVENT;
283
284
0
  g_action_group_exporter_set_events (exporter, action_name, event_mask);
285
0
}
286
287
static void
288
g_action_group_exporter_action_removed (GActionGroup *action_group,
289
                                        const gchar  *action_name,
290
                                        gpointer      user_data)
291
0
{
292
0
  GActionGroupExporter *exporter = user_data;
293
0
  guint event_mask;
294
295
0
  event_mask = g_action_group_exporter_get_events (exporter, action_name);
296
297
  /* If the add event for this is still queued then just cancel it since
298
   * it's gone now.
299
   *
300
   * If the event was freshly added, there should not have been any
301
   * enabled or state changed events.
302
   */
303
0
  if (event_mask & ACTION_ADDED_EVENT)
304
0
    {
305
0
      g_assert (~event_mask & ~(ACTION_STATE_CHANGED_EVENT | ACTION_ENABLED_CHANGED_EVENT));
306
0
      event_mask &= ~ACTION_ADDED_EVENT;
307
0
    }
308
309
  /* Otherwise, queue a remove event.  Drop any state or enabled changes
310
   * that were queued before the remove. */
311
0
  else
312
0
    {
313
0
      event_mask |= ACTION_REMOVED_EVENT;
314
0
      event_mask &= ~(ACTION_STATE_CHANGED_EVENT | ACTION_ENABLED_CHANGED_EVENT);
315
0
    }
316
317
0
  g_action_group_exporter_set_events (exporter, action_name, event_mask);
318
0
}
319
320
static void
321
g_action_group_exporter_action_state_changed (GActionGroup *action_group,
322
                                              const gchar  *action_name,
323
                                              GVariant     *value,
324
                                              gpointer      user_data)
325
0
{
326
0
  GActionGroupExporter *exporter = user_data;
327
0
  guint event_mask;
328
329
0
  event_mask = g_action_group_exporter_get_events (exporter, action_name);
330
331
  /* If it was removed, it must have been added back.  Otherwise, why
332
   * are we hearing about changes?
333
   */
334
0
  g_assert (~event_mask & ACTION_REMOVED_EVENT ||
335
0
            event_mask & ACTION_ADDED_EVENT);
336
337
  /* If it is freshly added, don't also bother with the state change
338
   * signal since the updated state will be sent as part of the pending
339
   * add message.
340
   */
341
0
  if (~event_mask & ACTION_ADDED_EVENT)
342
0
    event_mask |= ACTION_STATE_CHANGED_EVENT;
343
344
0
  g_action_group_exporter_set_events (exporter, action_name, event_mask);
345
0
}
346
347
static void
348
g_action_group_exporter_action_enabled_changed (GActionGroup *action_group,
349
                                                const gchar  *action_name,
350
                                                gboolean      enabled,
351
                                                gpointer      user_data)
352
0
{
353
0
  GActionGroupExporter *exporter = user_data;
354
0
  guint event_mask;
355
356
0
  event_mask = g_action_group_exporter_get_events (exporter, action_name);
357
358
  /* Reasoning as above. */
359
0
  g_assert (~event_mask & ACTION_REMOVED_EVENT ||
360
0
            event_mask & ACTION_ADDED_EVENT);
361
362
0
  if (~event_mask & ACTION_ADDED_EVENT)
363
0
    event_mask |= ACTION_ENABLED_CHANGED_EVENT;
364
365
0
  g_action_group_exporter_set_events (exporter, action_name, event_mask);
366
0
}
367
368
static void
369
org_gtk_Actions_method_call (GDBusConnection       *connection,
370
                             const gchar           *sender,
371
                             const gchar           *object_path,
372
                             const gchar           *interface_name,
373
                             const gchar           *method_name,
374
                             GVariant              *parameters,
375
                             GDBusMethodInvocation *invocation,
376
                             gpointer               user_data)
377
0
{
378
0
  GActionGroupExporter *exporter = user_data;
379
0
  GVariant *result = NULL;
380
381
0
  g_action_group_exporter_flush_queue (exporter);
382
383
0
  if (g_str_equal (method_name, "List"))
384
0
    {
385
0
      gchar **list;
386
387
0
      list = g_action_group_list_actions (exporter->action_group);
388
0
      result = g_variant_new ("(^as)", list);
389
0
      g_strfreev (list);
390
0
    }
391
392
0
  else if (g_str_equal (method_name, "Describe"))
393
0
    {
394
0
      const gchar *name;
395
0
      GVariant *desc;
396
397
0
      g_variant_get (parameters, "(&s)", &name);
398
399
0
      if (!g_action_group_has_action (exporter->action_group, name))
400
0
        {
401
0
          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
402
0
                                                 "The named action ('%s') does not exist.", name);
403
0
          return;
404
0
        }
405
406
0
      desc = g_action_group_describe_action (exporter->action_group, name);
407
0
      result = g_variant_new ("(@(bgav))", desc);
408
0
    }
409
410
0
  else if (g_str_equal (method_name, "DescribeAll"))
411
0
    {
412
0
      GVariantBuilder builder;
413
0
      gchar **list;
414
0
      gint i;
415
416
0
      list = g_action_group_list_actions (exporter->action_group);
417
0
      g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{s(bgav)}"));
418
0
      for (i = 0; list[i]; i++)
419
0
        {
420
0
          const gchar *name = list[i];
421
0
          GVariant *description;
422
423
0
          description = g_action_group_describe_action (exporter->action_group, name);
424
0
          g_variant_builder_add (&builder, "{s@(bgav)}", name, description);
425
0
        }
426
0
      result = g_variant_new ("(a{s(bgav)})", &builder);
427
0
      g_strfreev (list);
428
0
    }
429
430
0
  else if (g_str_equal (method_name, "Activate"))
431
0
    {
432
0
      GVariant *parameter = NULL;
433
0
      GVariant *platform_data;
434
0
      GVariantIter *iter;
435
0
      const gchar *name;
436
0
      const GVariantType *parameter_type = NULL;
437
438
0
      g_variant_get (parameters, "(&sav@a{sv})", &name, &iter, &platform_data);
439
0
      g_variant_iter_next (iter, "v", &parameter);
440
0
      g_variant_iter_free (iter);
441
442
      /* Check the action exists and the parameter type matches. */
443
0
      if (!g_action_group_query_action (exporter->action_group,
444
0
                                        name, NULL, &parameter_type,
445
0
                                        NULL, NULL, NULL))
446
0
        {
447
0
          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
448
0
                                                 "Unknown action ‘%s’", name);
449
0
          g_clear_pointer (&parameter, g_variant_unref);
450
0
          g_variant_unref (platform_data);
451
0
          return;
452
0
        }
453
454
0
      if (!((parameter_type == NULL && parameter == NULL) ||
455
0
            (parameter_type != NULL && parameter != NULL && g_variant_is_of_type (parameter, parameter_type))))
456
0
        {
457
0
          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
458
0
                                                 "Invalid parameter for action ‘%s’: expected type %s but got type %s",
459
0
                                                 name,
460
0
                                                 (parameter_type != NULL) ? (const gchar *) parameter_type : "()",
461
0
                                                 (parameter != NULL) ? g_variant_get_type_string (parameter) : "()");
462
0
          g_clear_pointer (&parameter, g_variant_unref);
463
0
          g_variant_unref (platform_data);
464
0
          return;
465
0
        }
466
467
0
      if (G_IS_REMOTE_ACTION_GROUP (exporter->action_group))
468
0
        g_remote_action_group_activate_action_full (G_REMOTE_ACTION_GROUP (exporter->action_group),
469
0
                                                    name, parameter, platform_data);
470
0
      else
471
0
        g_action_group_activate_action (exporter->action_group, name, parameter);
472
473
0
      if (parameter)
474
0
        g_variant_unref (parameter);
475
476
0
      g_variant_unref (platform_data);
477
0
    }
478
479
0
  else if (g_str_equal (method_name, "SetState"))
480
0
    {
481
0
      GVariant *platform_data;
482
0
      const gchar *name;
483
0
      GVariant *state;
484
0
      const GVariantType *state_type = NULL;
485
486
0
      g_variant_get (parameters, "(&sv@a{sv})", &name, &state, &platform_data);
487
488
      /* Check the action exists and the state type matches. */
489
0
      if (!g_action_group_query_action (exporter->action_group,
490
0
                                        name, NULL, NULL,
491
0
                                        &state_type, NULL, NULL))
492
0
        {
493
0
          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
494
0
                                                 "Unknown action ‘%s’", name);
495
0
          g_variant_unref (state);
496
0
          g_variant_unref (platform_data);
497
0
          return;
498
0
        }
499
500
0
      if (state_type == NULL)
501
0
        {
502
0
          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
503
0
                                                 "Cannot change state of action ‘%s’ as it is stateless", name);
504
0
          g_variant_unref (state);
505
0
          g_variant_unref (platform_data);
506
0
          return;
507
0
        }
508
509
0
      if (!g_variant_is_of_type (state, state_type))
510
0
        {
511
0
          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
512
0
                                                 "Invalid state for action ‘%s’: expected type %s but got type %s",
513
0
                                                 name,
514
0
                                                 (const gchar *) state_type,
515
0
                                                 g_variant_get_type_string (state));
516
0
          g_variant_unref (state);
517
0
          g_variant_unref (platform_data);
518
0
          return;
519
0
        }
520
521
0
      if (G_IS_REMOTE_ACTION_GROUP (exporter->action_group))
522
0
        g_remote_action_group_change_action_state_full (G_REMOTE_ACTION_GROUP (exporter->action_group),
523
0
                                                        name, state, platform_data);
524
0
      else
525
0
        g_action_group_change_action_state (exporter->action_group, name, state);
526
527
0
      g_variant_unref (platform_data);
528
0
      g_variant_unref (state);
529
0
    }
530
531
0
  else
532
0
    g_assert_not_reached ();
533
534
0
  g_dbus_method_invocation_return_value (invocation, result);
535
0
}
536
537
static void
538
g_action_group_exporter_free (gpointer user_data)
539
0
{
540
0
  GActionGroupExporter *exporter = user_data;
541
542
0
  g_signal_handlers_disconnect_by_func (exporter->action_group,
543
0
                                        g_action_group_exporter_action_added, exporter);
544
0
  g_signal_handlers_disconnect_by_func (exporter->action_group,
545
0
                                        g_action_group_exporter_action_enabled_changed, exporter);
546
0
  g_signal_handlers_disconnect_by_func (exporter->action_group,
547
0
                                        g_action_group_exporter_action_state_changed, exporter);
548
0
  g_signal_handlers_disconnect_by_func (exporter->action_group,
549
0
                                        g_action_group_exporter_action_removed, exporter);
550
551
0
  g_hash_table_unref (exporter->pending_changes);
552
0
  if (exporter->pending_source)
553
0
    g_source_destroy (exporter->pending_source);
554
555
0
  g_main_context_unref (exporter->context);
556
0
  g_object_unref (exporter->connection);
557
0
  g_object_unref (exporter->action_group);
558
0
  g_free (exporter->object_path);
559
560
0
  g_slice_free (GActionGroupExporter, exporter);
561
0
}
562
563
/**
564
 * g_dbus_connection_export_action_group:
565
 * @connection: a #GDBusConnection
566
 * @object_path: a D-Bus object path
567
 * @action_group: a #GActionGroup
568
 * @error: a pointer to a %NULL #GError, or %NULL
569
 *
570
 * Exports @action_group on @connection at @object_path.
571
 *
572
 * The implemented D-Bus API should be considered private.  It is
573
 * subject to change in the future.
574
 *
575
 * A given object path can only have one action group exported on it.
576
 * If this constraint is violated, the export will fail and 0 will be
577
 * returned (with @error set accordingly).
578
 *
579
 * You can unexport the action group using
580
 * g_dbus_connection_unexport_action_group() with the return value of
581
 * this function.
582
 *
583
 * The thread default main context is taken at the time of this call.
584
 * All incoming action activations and state change requests are
585
 * reported from this context.  Any changes on the action group that
586
 * cause it to emit signals must also come from this same context.
587
 * Since incoming action activations and state change requests are
588
 * rather likely to cause changes on the action group, this effectively
589
 * limits a given action group to being exported from only one main
590
 * context.
591
 *
592
 * Returns: the ID of the export (never zero), or 0 in case of failure
593
 *
594
 * Since: 2.32
595
 **/
596
guint
597
g_dbus_connection_export_action_group (GDBusConnection  *connection,
598
                                       const gchar      *object_path,
599
                                       GActionGroup     *action_group,
600
                                       GError          **error)
601
0
{
602
0
  const GDBusInterfaceVTable vtable = {
603
0
    org_gtk_Actions_method_call, NULL, NULL, { 0 }
604
0
  };
605
0
  GActionGroupExporter *exporter;
606
0
  guint id;
607
608
0
  if G_UNLIKELY (org_gtk_Actions == NULL)
609
0
    {
610
0
      GError *my_error = NULL;
611
0
      GDBusNodeInfo *info;
612
613
0
      info = g_dbus_node_info_new_for_xml (org_gtk_Actions_xml, &my_error);
614
0
      if G_UNLIKELY (info == NULL)
615
0
        g_error ("%s", my_error->message);
616
0
      org_gtk_Actions = g_dbus_node_info_lookup_interface (info, "org.gtk.Actions");
617
0
      g_assert (org_gtk_Actions != NULL);
618
0
      g_dbus_interface_info_ref (org_gtk_Actions);
619
0
      g_dbus_node_info_unref (info);
620
0
    }
621
622
0
  exporter = g_slice_new (GActionGroupExporter);
623
0
  id = g_dbus_connection_register_object (connection, object_path, org_gtk_Actions, &vtable,
624
0
                                          exporter, g_action_group_exporter_free, error);
625
626
0
  if (id == 0)
627
0
    {
628
0
      g_slice_free (GActionGroupExporter, exporter);
629
0
      return 0;
630
0
    }
631
632
0
  exporter->context = g_main_context_ref_thread_default ();
633
0
  exporter->pending_changes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
634
0
  exporter->pending_source = NULL;
635
0
  exporter->action_group = g_object_ref (action_group);
636
0
  exporter->connection = g_object_ref (connection);
637
0
  exporter->object_path = g_strdup (object_path);
638
639
0
  g_signal_connect (action_group, "action-added",
640
0
                    G_CALLBACK (g_action_group_exporter_action_added), exporter);
641
0
  g_signal_connect (action_group, "action-removed",
642
0
                    G_CALLBACK (g_action_group_exporter_action_removed), exporter);
643
0
  g_signal_connect (action_group, "action-state-changed",
644
0
                    G_CALLBACK (g_action_group_exporter_action_state_changed), exporter);
645
0
  g_signal_connect (action_group, "action-enabled-changed",
646
0
                    G_CALLBACK (g_action_group_exporter_action_enabled_changed), exporter);
647
648
0
  return id;
649
0
}
650
651
/**
652
 * g_dbus_connection_unexport_action_group:
653
 * @connection: a #GDBusConnection
654
 * @export_id: the ID from g_dbus_connection_export_action_group()
655
 *
656
 * Reverses the effect of a previous call to
657
 * g_dbus_connection_export_action_group().
658
 *
659
 * It is an error to call this function with an ID that wasn't returned
660
 * from g_dbus_connection_export_action_group() or to call it with the
661
 * same ID more than once.
662
 *
663
 * Since: 2.32
664
 **/
665
void
666
g_dbus_connection_unexport_action_group (GDBusConnection *connection,
667
                                         guint            export_id)
668
0
{
669
0
  g_dbus_connection_unregister_object (connection, export_id);
670
0
}