Coverage Report

Created: 2025-07-23 08:13

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