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
|
/*
* media-observer - Observe media channels
*
* Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/>
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
* notice and this notice are preserved.
*/
#include <glib.h>
#include <telepathy-glib/telepathy-glib.h>
#include <telepathy-glib/debug.h>
#include <telepathy-glib/simple-observer.h>
static void
chan_invalidated_cb (TpProxy *proxy,
guint domain,
gint code,
gchar *message,
gpointer user_data)
{
TpChannel *channel = TP_CHANNEL (proxy);
GHashTable *props;
props = tp_channel_borrow_immutable_properties (channel);
g_print ("Call with %s terminated\n",
tp_asv_get_string (props, TP_PROP_CHANNEL_TARGET_ID));
g_object_unref (channel);
}
static void
observe_channels_cb (TpSimpleObserver *self,
TpAccount *account,
TpConnection *connection,
GList *channels,
TpChannelDispatchOperation *dispatch_operation,
GList *requests,
TpObserveChannelsContext *context,
gpointer user_data)
{
GList *l;
gboolean recovering;
recovering = tp_observe_channels_context_is_recovering (context);
for (l = channels; l != NULL; l = g_list_next (l))
{
TpChannel *channel = l->data;
GHashTable *props;
gboolean requested;
if (tp_strdiff (tp_channel_get_channel_type (channel),
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))
continue;
props = tp_channel_borrow_immutable_properties (channel);
requested = tp_asv_get_boolean (props, TP_PROP_CHANNEL_REQUESTED, NULL);
g_print ("Observing %s %s call %s %s\n",
recovering? "existing": "new",
requested? "outgoing": "incoming",
requested? "to": "from",
tp_asv_get_string (props, TP_PROP_CHANNEL_TARGET_ID));
g_signal_connect (g_object_ref (channel), "invalidated",
G_CALLBACK (chan_invalidated_cb), NULL);
}
tp_observe_channels_context_accept (context);
}
int
main (int argc,
char **argv)
{
GMainLoop *mainloop;
TpAccountManager *manager;
GError *error = NULL;
TpBaseClient *observer;
g_type_init ();
tp_debug_set_flags (g_getenv ("EXAMPLE_DEBUG"));
manager = tp_account_manager_dup ();
observer = tp_simple_observer_new_with_am (manager, FALSE,
"ExampleMediaObserver", FALSE, observe_channels_cb, NULL, NULL);
tp_base_client_take_observer_filter (observer, tp_asv_new (
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
TP_HANDLE_TYPE_CONTACT,
NULL));
if (!tp_base_client_register (observer, &error))
{
g_warning ("Failed to register Observer: %s\n", error->message);
g_error_free (error);
goto out;
}
g_print ("Start observing\n");
mainloop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (mainloop);
if (mainloop != NULL)
g_main_loop_unref (mainloop);
out:
g_object_unref (manager);
g_object_unref (observer);
return 0;
}
|