summaryrefslogtreecommitdiff
path: root/telepathy-glib/base-call-content.c
blob: 87ceefd08d713d46f20f78c9ad6b8de8f15dd9c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
/*
 * base-call-content.c - Source for TpBaseCallContent
 * Copyright © 2009–2011 Collabora Ltd.
 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
 * @author Will Thompson <will.thompson@collabora.co.uk>
 * @author Xavier Claessens <xavier.claessens@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * SECTION:base-call-content
 * @title: TpBaseCallContent
 * @short_description: base class for #TpSvcCall1Content implementations
 * @see_also: #TpSvcCall1Content, #TpBaseCallChannel and #TpBaseCallStream
 *
 * This base class makes it easier to write #TpSvcCall1Content
 * implementations by implementing its properties, and some of its methods.
 *
 * Subclasses should fill in #TpBaseCallContentClass.get_interfaces,
 * and #TpBaseCallContentClass.deinit virtual function.
 *
 * Since: 0.17.5
 */

/**
 * TpBaseCallContent:
 *
 * A base class for call content implementations
 *
 * Since: 0.17.5
 */

/**
 * TpBaseCallContentClass:
 * @get_interfaces: extra interfaces provided by this content (this SHOULD NOT
 *  include %TP_IFACE_CALL_CONTENT itself). Implementation must first chainup on
 *  parent class implementation then add extra interfaces into the #GPtrArray.
 * @deinit: optional; virtual method called by #TpBaseCallChannel when removing
 *  the content
 * @start_tone: optional; virtual method called when user requested to send
 *  a DTMF tone. Note that this method is already implemented by
 *  #TpBaseMediaCallContent and so does not have to be overriden when using that
 *  subclass
 * @stop_tone: optional; virtual method called when user requested to stop
 *  sending currently being played DTMF tones. Note that this method is already
 *  implemented by #TpBaseMediaCallContent and so does not have to be overriden
 *  when using that subclass
 * @multiple_tones: optional; virtual method called when user requested to send
 *  multiple DTMF tones. Note that this method is already implemented by
 *  #TpBaseMediaCallContent and so does not have to be overriden when using that
 *  subclass
 *
 * The class structure for #TpBaseCallContent
 *
 * Since: 0.17.5
 */

/**
 * TpBaseCallContentGetInterfacesFunc:
 * @self: a #TpBaseCallContent
 *
 * Signature of an implementation of #TpBaseCallContentClass.get_interfaces.
 *
 * Returns: a #GPtrArray containing static strings.
 * Since: 0.17.5
 */

/**
 * TpBaseCallContentDeinitFunc:
 * @self: a #TpBaseCallContent
 *
 * Signature of an implementation of #TpBaseCallContentClass.deinit.
 *
 * Since: 0.17.5
 */

/**
 * TpBaseCallContentStartToneFunc:
 * @self: a #TpBaseCallContent
 * @event: a #TpDTMFEvent
 * @error: a #GError to fill
 *
 * Signature of an implementation of #TpBaseCallContentClass.start_tone.
 *
 * Returns: %TRUE on success, otherwise %FALSE and set @error
 * Since: 0.17.5
 */

/**
 * TpBaseCallContentStopToneFunc:
 * @self: a #TpBaseCallContent
 * @error: a #GError to fill
 *
 * Signature of an implementation of #TpBaseCallContentClass.stop_tone.
 *
 * Returns: %TRUE on success, otherwise %FALSE and set @error
 * Since: 0.17.5
 */

/**
 * TpBaseCallContentMultipleTonesFunc:
 * @self: a #TpBaseCallContent
 * @tones: a string representation of one or more DTMF events
 * @error: a #GError to fill
 *
 * Signature of an implementation of #TpBaseCallContentClass.multiple_tones.
 *
 * Returns: %TRUE on success, otherwise %FALSE and set @error
 * Since: 0.17.5
 */

#include "config.h"

#include "telepathy-glib/base-call-content.h"

#define DEBUG_FLAG TP_DEBUG_CALL

#include "telepathy-glib/base-call-channel.h"
#include "telepathy-glib/base-call-internal.h"
#include "telepathy-glib/base-connection.h"
#include "telepathy-glib/debug-internal.h"
#include "telepathy-glib/dbus.h"
#include "telepathy-glib/dbus-properties-mixin.h"
#include "telepathy-glib/gtypes.h"
#include "telepathy-glib/interfaces.h"
#include "telepathy-glib/svc-call.h"
#include "telepathy-glib/svc-generic.h"
#include "telepathy-glib/util.h"
#include "telepathy-glib/util-internal.h"
#include <telepathy-glib/value-array.h>

static void call_content_iface_init (gpointer g_iface, gpointer iface_data);
static void call_content_dtmf_iface_init (gpointer g_iface,
    gpointer iface_data);

G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TpBaseCallContent, tp_base_call_content,
    G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CALL1_CONTENT,
        call_content_iface_init)
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CALL1_CONTENT_INTERFACE_DTMF1,
        call_content_dtmf_iface_init)
    )

struct _TpBaseCallContentPrivate
{
  TpBaseConnection *conn;

  gchar *object_path;

  gchar *name;
  TpMediaStreamType media_type;
  TpHandle creator;
  TpCallContentDisposition disposition;

  /* GList or reffed TpBaseCallStream */
  GList *streams;

  /* Borrowed */
  TpBaseCallChannel *channel;

  gboolean deinit_has_run;
};

enum
{
  PROP_OBJECT_PATH = 1,
  PROP_CONNECTION,

  /* Call.Content Properties */
  PROP_INTERFACES,
  PROP_NAME,
  PROP_MEDIA_TYPE,
  PROP_CREATOR,
  PROP_DISPOSITION,
  PROP_STREAMS,

  /* Call.Content.Interface.DTMF properties */

  PROP_CURRENTLY_SENDING_TONES,
  PROP_DEFERRED_TONES,
};

static void
tp_base_call_content_init (TpBaseCallContent *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      TP_TYPE_BASE_CALL_CONTENT, TpBaseCallContentPrivate);
}

static void
tp_base_call_content_constructed (GObject *obj)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (obj);
  GDBusConnection *bus = tp_base_connection_get_dbus_connection (
      (TpBaseConnection *) self->priv->conn);

  if (G_OBJECT_CLASS (tp_base_call_content_parent_class)->constructed != NULL)
    G_OBJECT_CLASS (tp_base_call_content_parent_class)->constructed (obj);

  DEBUG ("Registering %s", self->priv->object_path);
  tp_dbus_connection_register_object (bus, self->priv->object_path, obj);
}

static void
tp_base_call_content_deinit_real (TpBaseCallContent *self)
{
  GDBusConnection *bus = tp_base_connection_get_dbus_connection (
      (TpBaseConnection *) self->priv->conn);

  tp_dbus_connection_unregister_object (bus, G_OBJECT (self));

  tp_clear_pointer (&self->priv->streams, _tp_object_list_free);
}

static GPtrArray *
tp_base_call_content_get_interfaces (TpBaseCallContent *self)
{
  return g_ptr_array_new ();
}

static void
tp_base_call_content_dispose (GObject *object)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (object);

  if (!self->priv->deinit_has_run)
    _tp_base_call_content_deinit (self);

  g_assert (self->priv->deinit_has_run);

  tp_clear_pointer (&self->priv->streams, _tp_object_list_free);
  g_object_notify (G_OBJECT (self), "streams");
  tp_clear_object (&self->priv->conn);

  if (G_OBJECT_CLASS (tp_base_call_content_parent_class)->dispose != NULL)
    G_OBJECT_CLASS (tp_base_call_content_parent_class)->dispose (object);
}

static void
tp_base_call_content_finalize (GObject *object)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (object);

  /* free any data held directly by the object here */
  g_free (self->priv->object_path);
  g_free (self->priv->name);

  G_OBJECT_CLASS (tp_base_call_content_parent_class)->finalize (object);
}

static void
tp_base_call_content_get_property (
    GObject *object,
    guint property_id,
    GValue *value,
    GParamSpec *pspec)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (object);
  TpBaseCallContentClass *klass = TP_BASE_CALL_CONTENT_GET_CLASS (self);

  switch (property_id)
    {
      case PROP_OBJECT_PATH:
        g_value_set_string (value, self->priv->object_path);
        break;
      case PROP_CONNECTION:
        g_value_set_object (value, self->priv->conn);
        break;
      case PROP_INTERFACES:
        {
          GPtrArray *interfaces = klass->get_interfaces (self);

          g_ptr_array_add (interfaces, NULL);
          g_value_set_boxed (value, interfaces->pdata);
          g_ptr_array_unref (interfaces);
          break;
        }
      case PROP_NAME:
        g_value_set_string (value, self->priv->name);
        break;
      case PROP_MEDIA_TYPE:
        g_value_set_uint (value, self->priv->media_type);
        break;
      case PROP_CREATOR:
        g_value_set_uint (value, self->priv->creator);
        break;
      case PROP_DISPOSITION:
        g_value_set_uint (value, self->priv->disposition);
        break;
      case PROP_STREAMS:
        {
          GPtrArray *arr = g_ptr_array_sized_new (2);
          GList *l;

          for (l = self->priv->streams; l != NULL; l = g_list_next (l))
            {
              TpBaseCallStream *s = TP_BASE_CALL_STREAM (l->data);
              g_ptr_array_add (arr,
                  g_strdup (tp_base_call_stream_get_object_path (s)));
            }

          g_value_take_boxed (value, arr);
          break;
        }
      case PROP_CURRENTLY_SENDING_TONES:
        g_value_set_boolean (value, FALSE);
        break;
      case PROP_DEFERRED_TONES:
        g_value_set_static_string (value, "");
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}

static void
tp_base_call_content_set_property (
    GObject *object,
    guint property_id,
    const GValue *value,
    GParamSpec *pspec)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (object);

  switch (property_id)
    {
      case PROP_OBJECT_PATH:
        self->priv->object_path = g_value_dup_string (value);
        g_assert (self->priv->object_path != NULL);
        break;
      case PROP_CONNECTION:
        self->priv->conn = g_value_dup_object (value);
        break;
      case PROP_NAME:
        self->priv->name = g_value_dup_string (value);
        break;
      case PROP_MEDIA_TYPE:
        self->priv->media_type = g_value_get_uint (value);
        break;
      case PROP_CREATOR:
        self->priv->creator = g_value_get_uint (value);
        break;
      case PROP_DISPOSITION:
        self->priv->disposition = g_value_get_uint (value);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}

static void
tp_base_call_content_class_init (TpBaseCallContentClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GParamSpec *param_spec;
  static TpDBusPropertiesMixinPropImpl content_props[] = {
    { "Interfaces", "interfaces", NULL },
    { "Name", "name", NULL },
    { "Type", "media-type", NULL },
    { "Disposition", "disposition", NULL },
    { "Streams", "streams", NULL },
    { NULL }
  };
  static TpDBusPropertiesMixinPropImpl content_dtmf_props[] = {
    { "CurrentlySendingTones", "currently-sending-tones", NULL },
    { "DeferredTones", "deferred-tones", NULL },
    { NULL }
  };

  g_type_class_add_private (klass, sizeof (TpBaseCallContentPrivate));

  object_class->constructed = tp_base_call_content_constructed;
  object_class->dispose = tp_base_call_content_dispose;
  object_class->finalize = tp_base_call_content_finalize;
  object_class->get_property = tp_base_call_content_get_property;
  object_class->set_property = tp_base_call_content_set_property;

  klass->deinit = tp_base_call_content_deinit_real;
  klass->get_interfaces = tp_base_call_content_get_interfaces;

  /**
   * TpBaseCallContent:object-path:
   *
   * The D-Bus object path used for this object on the bus.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_string ("object-path", "D-Bus object path",
      "The D-Bus object path used for this object on the bus.",
      NULL,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_OBJECT_PATH, param_spec);

  /**
   * TpBaseCallContent:connection:
   *
   * #TpBaseConnection object that owns this call content.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_object ("connection", "TpBaseConnection object",
      "Tp base connection object that owns this call content",
      TP_TYPE_BASE_CONNECTION,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);

  /**
   * TpBaseCallContent:interfaces:
   *
   * Additional interfaces implemented by this content.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
      "Additional interfaces implemented by this content",
      G_TYPE_STRV,
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);

  /**
   * TpBaseCallContent:name:
   *
   * The name of this content, if any.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_string ("name", "Name",
      "The name of this content, if any",
      "",
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_NAME, param_spec);

  /**
   * TpBaseCallContent:media-type:
   *
   * The #TpMediaStreamType of this content.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_uint ("media-type", "Media Type",
      "The media type of this content",
      0, G_MAXUINT, 0,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_MEDIA_TYPE, param_spec);

  /**
   * TpBaseCallContent:creator:
   *
   * The contact #TpHandle of the creator of this content.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_uint ("creator", "Creator",
      "The creator of this content",
      0, G_MAXUINT, 0,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_CREATOR, param_spec);

  /**
   * TpBaseCallContent:disposition:
   *
   * The #TpCallContentDisposition of this content.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_uint ("disposition", "Disposition",
      "The disposition of this content",
      0, G_MAXUINT, 0,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_DISPOSITION, param_spec);

  /**
   * TpBaseCallContent:streams:
   *
   * A #GPtrArray of this content streams' #TpBaseCallStream:object-path.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_boxed ("streams", "Stream",
      "The streams of this content",
      TP_ARRAY_TYPE_OBJECT_PATH_LIST,
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_STREAMS,
      param_spec);

  /**
   * TpBaseCallContent:currently-sending-tones:
   *
   * If this content is currently sending tones or not
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_boolean ("currently-sending-tones",
      "CurrentlySendingTones",
      "If the Content is currently sending tones or not",
      FALSE,
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_CURRENTLY_SENDING_TONES,
      param_spec);

  /**
   * TpBaseCallContent:deferred-tones:
   *
   * Tones that are waiting for the user action to play.
   *
   * Since: 0.17.5
   */
  param_spec = g_param_spec_string ("deferred-tones",
      "DeferredTones",
      "The tones requested in the initial channel request",
      NULL,
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_DEFERRED_TONES,
      param_spec);

  tp_dbus_properties_mixin_class_init (object_class, 0);
  tp_dbus_properties_mixin_implement_interface (object_class,
      TP_IFACE_QUARK_CALL1_CONTENT,
      tp_dbus_properties_mixin_getter_gobject_properties, NULL, content_props);
  tp_dbus_properties_mixin_implement_interface (object_class,
      TP_IFACE_QUARK_CALL1_CONTENT_INTERFACE_DTMF1,
      tp_dbus_properties_mixin_getter_gobject_properties, NULL,
      content_dtmf_props);
}

/**
 * tp_base_call_content_get_connection:
 * @self: a #TpBaseCallContent
 *
 * <!-- -->
 *
 * Returns: the value of #TpBaseCallContent:connection
 * Since: 0.17.5
 */
TpBaseConnection *
tp_base_call_content_get_connection (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self), NULL);

  return self->priv->conn;
}

/**
 * tp_base_call_content_get_object_path:
 * @self: a #TpBaseCallContent
 *
 * <!-- -->
 *
 * Returns: the value of #TpBaseCallContent:object-path
 * Since: 0.17.5
 */
const gchar *
tp_base_call_content_get_object_path (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self), NULL);

  return self->priv->object_path;
}

/**
 * tp_base_call_content_get_name:
 * @self: a #TpBaseCallContent
 *
 * <!-- -->
 *
 * Returns: the value of #TpBaseCallContent:name
 * Since: 0.17.5
 */
const gchar *
tp_base_call_content_get_name (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self), NULL);

  return self->priv->name;
}

/**
 * tp_base_call_content_get_media_type:
 * @self: a #TpBaseCallContent
 *
 * <!-- -->
 *
 * Returns: the value of #TpBaseCallContent:media-type
 * Since: 0.17.5
 */
TpMediaStreamType
tp_base_call_content_get_media_type (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self),
      TP_MEDIA_STREAM_TYPE_AUDIO);

  return self->priv->media_type;
}

/**
 * tp_base_call_content_get_disposition:
 * @self: a #TpBaseCallContent
 *
 * <!-- -->
 *
 * Returns: the value of #TpBaseCallContent:disposition
 * Since: 0.17.5
 */
TpCallContentDisposition
tp_base_call_content_get_disposition (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self),
      TP_CALL_CONTENT_DISPOSITION_NONE);

  return self->priv->disposition;
}

/**
 * tp_base_call_content_get_streams:
 * @self: a #TpBaseCallContent
 *
 * <!-- -->
 *
 * Returns: a #GList of #TpBaseCallStream of this content.
 * Since: 0.17.5
 */
GList *
tp_base_call_content_get_streams (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self), NULL);

  return self->priv->streams;
}

/**
 * tp_base_call_content_add_stream:
 * @self: a #TpBaseCallContent
 * @stream: a #TpBaseCallStream
 *
 * Add @stream to @self's #TpBaseCallContent:streams. Emitting StreamsAdded
 * DBus signal.
 *
 * Since: 0.17.5
 */
void
tp_base_call_content_add_stream (TpBaseCallContent *self,
    TpBaseCallStream *stream)
{
  GPtrArray *paths;

  g_return_if_fail (TP_IS_BASE_CALL_CONTENT (self));
  g_return_if_fail (TP_IS_BASE_CALL_STREAM (stream));
  g_return_if_fail (tp_base_call_stream_get_connection (stream) ==
      self->priv->conn);
  g_return_if_fail (self->priv->channel != NULL);
  g_return_if_fail (g_list_find (self->priv->streams, stream) == NULL);

  _tp_base_call_stream_set_content (stream, self);

  self->priv->streams = g_list_prepend (self->priv->streams,
      g_object_ref (stream));
  g_object_notify (G_OBJECT (self), "streams");

  paths = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);

  g_ptr_array_add (paths, g_strdup (
     tp_base_call_stream_get_object_path (
         TP_BASE_CALL_STREAM (stream))));
  tp_svc_call1_content_emit_streams_added (self, paths);
  g_ptr_array_unref (paths);
}

void
_tp_base_call_content_remove_stream_internal (TpBaseCallContent *self,
    TpBaseCallStream *stream,
    const GValueArray *reason_array)
{
  GList *l;
  GPtrArray *paths;

  l = g_list_find (self->priv->streams, stream);
  g_return_if_fail (l != NULL);

  self->priv->streams = g_list_delete_link (self->priv->streams, l);
  g_object_notify (G_OBJECT (self), "streams");

  paths = g_ptr_array_new ();
  g_ptr_array_add (paths, (gpointer)
      tp_base_call_stream_get_object_path (stream));

  tp_svc_call1_content_emit_streams_removed (self, paths, reason_array);

  g_ptr_array_unref (paths);
  g_object_unref (stream);
}

/**
 * tp_base_call_content_remove_stream:
 * @self: a #TpBaseCallContent
 * @stream: a #TpBaseCallStream
 * @actor_handle: the contact responsible for the change, or 0 if no contact was
 *  responsible.
 * @reason: the #TpCallStateChangeReason of the change
 * @dbus_reason: a specific reason for the change, which may be a D-Bus error in
 *  the Telepathy namespace, a D-Bus error in any other namespace (for
 *  implementation-specific errors), or the empty string to indicate that the
 *  state change was not an error.
 * @message: an optional debug message, to expediate debugging the potentially
 *  many processes involved in a call.
 *
 * Remove @stream from @self's #TpBaseCallContent:streams. Emitting
 * StreamsRemoved DBus signal.
 *
 * Since: 0.17.5
 */
void
tp_base_call_content_remove_stream (TpBaseCallContent *self,
    TpBaseCallStream *stream,
    TpHandle actor_handle,
    TpCallStateChangeReason reason,
    const gchar *dbus_reason,
    const gchar *message)
{
  GValueArray *reason_array;

  g_return_if_fail (TP_IS_BASE_CALL_CONTENT (self));
  g_return_if_fail (TP_IS_BASE_CALL_STREAM (stream));

  reason_array = _tp_base_call_state_reason_new (actor_handle, reason,
      dbus_reason, message);

  _tp_base_call_content_remove_stream_internal (self, stream, reason_array);

  tp_value_array_free (reason_array);
}

static void
tp_call_content_remove (TpSvcCall1Content *content,
    GDBusMethodInvocation *context)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (content);

  if (!tp_base_call_channel_has_mutable_contents (self->priv->channel))
    {
      GError error = { TP_ERROR, TP_ERROR_NOT_IMPLEMENTED,
          "Contents are not mutable" };
      g_dbus_method_invocation_return_gerror (context, &error);
      return;
    }

  tp_base_call_channel_remove_content (self->priv->channel, self,
      tp_base_channel_get_self_handle ((TpBaseChannel *) self->priv->channel),
      TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED, "",
      "User has removed the content");

  tp_svc_call1_content_return_from_remove (context);
}

static void
call_content_iface_init (gpointer g_iface, gpointer iface_data)
{
  TpSvcCall1ContentClass *klass =
    (TpSvcCall1ContentClass *) g_iface;

#define IMPLEMENT(x) tp_svc_call1_content_implement_##x (\
    klass, tp_call_content_##x)
  IMPLEMENT(remove);
#undef IMPLEMENT
}

/* These functions are used only internally */

void
_tp_base_call_content_set_channel (TpBaseCallContent *self,
    TpBaseCallChannel *channel)
{
  g_return_if_fail (TP_IS_BASE_CALL_CONTENT (self));
  g_return_if_fail (TP_IS_BASE_CALL_CHANNEL (channel));
  g_return_if_fail (self->priv->channel == NULL);

  self->priv->channel = channel;

  if (self->priv->disposition == TP_CALL_CONTENT_DISPOSITION_INITIAL)
    {
      TpBaseCallContentClass *klass = TP_BASE_CALL_CONTENT_GET_CLASS (self);
      const gchar *tones;

      tones =_tp_base_call_channel_get_initial_tones (channel);
      if (tones && tones[0] && klass->multiple_tones != NULL)
        {
          klass->multiple_tones (self, tones, NULL);
        }
    }

}

TpBaseCallChannel *
_tp_base_call_content_get_channel (TpBaseCallContent *self)
{
  g_return_val_if_fail (TP_IS_BASE_CALL_CONTENT (self), NULL);
  g_return_val_if_fail (self->priv->channel != NULL, NULL);

  return self->priv->channel;
}

void
_tp_base_call_content_deinit (TpBaseCallContent *self)
{
  TpBaseCallContentClass *klass;

  g_return_if_fail (TP_IS_BASE_CALL_CONTENT (self));

  g_assert (!self->priv->deinit_has_run);
  self->priv->deinit_has_run = TRUE;

  klass = TP_BASE_CALL_CONTENT_GET_CLASS (self);
  klass->deinit (self);
}

void
_tp_base_call_content_accepted (TpBaseCallContent *self,
    TpHandle actor_handle)
{
  GList *l;

  g_return_if_fail (TP_IS_BASE_CALL_CONTENT (self));

  if (self->priv->disposition != TP_CALL_CONTENT_DISPOSITION_INITIAL)
    return;

  for (l = self->priv->streams ; l != NULL; l = g_list_next (l))
    {
      TpBaseCallStream *s = TP_BASE_CALL_STREAM (l->data);

      if (tp_base_call_stream_get_local_sending_state (s) ==
          TP_SENDING_STATE_PENDING_SEND)
        tp_base_call_stream_update_local_sending_state (s,
            TP_SENDING_STATE_SENDING, actor_handle,
            TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED, "",
            "User accepted the Call");
    }
}

static void
tp_call_content_start_tone (TpSvcCall1ContentInterfaceDTMF1 *dtmf,
    guchar event,
    GDBusMethodInvocation *context)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (dtmf);
  TpBaseCallContentClass *klass = TP_BASE_CALL_CONTENT_GET_CLASS (self);
  GError *error = NULL;

  if (klass->start_tone == NULL)
    {
      GError err = {G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
                    "Method does not exist"};
      g_dbus_method_invocation_return_gerror (context, &err);
      return;
    }

  if (!klass->start_tone (self, event, &error))
    {
      g_dbus_method_invocation_return_gerror (context, error);
      g_clear_error (&error);
      return;
    }

  tp_svc_call1_content_interface_dtmf1_return_from_start_tone (context);
}

static void
tp_call_content_stop_tone (TpSvcCall1ContentInterfaceDTMF1 *dtmf,
   GDBusMethodInvocation *context)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (dtmf);
  TpBaseCallContentClass *klass = TP_BASE_CALL_CONTENT_GET_CLASS (self);
  GError *error = NULL;

  if (klass->stop_tone == NULL)
    {
      GError err = {G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
                    "Method does not exist"};
      g_dbus_method_invocation_return_gerror (context, &err);
      return;
    }

  if (!klass->stop_tone (self, &error))
    {
      g_dbus_method_invocation_return_gerror (context, error);
      g_clear_error (&error);
      return;
    }

  tp_svc_call1_content_interface_dtmf1_return_from_stop_tone (context);
}

static void
tp_call_content_multiple_tones (TpSvcCall1ContentInterfaceDTMF1 *dtmf,
    const gchar *tones,
    GDBusMethodInvocation *context)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (dtmf);
  TpBaseCallContentClass *klass = TP_BASE_CALL_CONTENT_GET_CLASS (self);
  GError *error = NULL;

  if (klass->multiple_tones == NULL)
    {
      GError err = {G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
                    "Method does not exist"};
      g_dbus_method_invocation_return_gerror (context, &err);
      return;
    }

  if (!klass->multiple_tones (self, tones, &error))
    {
      g_dbus_method_invocation_return_gerror (context, error);
      g_clear_error (&error);
      return;
    }

  tp_svc_call1_content_interface_dtmf1_return_from_multiple_tones (context);
}

static void
call_content_dtmf_iface_init (gpointer g_iface, gpointer iface_data)
{
  TpSvcCall1ContentInterfaceDTMF1Class *klass =
      (TpSvcCall1ContentInterfaceDTMF1Class *) g_iface;

#define IMPLEMENT(x) tp_svc_call1_content_interface_dtmf1_implement_##x (\
    klass, tp_call_content_##x)
  IMPLEMENT(start_tone);
  IMPLEMENT(stop_tone);
  IMPLEMENT(multiple_tones);
#undef IMPLEMENT
}