~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to audio/telephony-dummy.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-10-07 12:10:29 UTC
  • Revision ID: james.westby@ubuntu.com-20081007121029-4gup4fmmh2vfo5nh
Tags: upstream-4.12
ImportĀ upstreamĀ versionĀ 4.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  BlueZ - Bluetooth protocol stack for Linux
 
4
 *
 
5
 *  Copyright (C) 2006-2007  Nokia Corporation
 
6
 *  Copyright (C) 2004-2008  Marcel Holtmann <marcel@holtmann.org>
 
7
 *
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
22
 *
 
23
 */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <config.h>
 
27
#endif
 
28
 
 
29
#include <stdlib.h>
 
30
#include <stdio.h>
 
31
#include <stdint.h>
 
32
#include <glib.h>
 
33
#include <dbus/dbus.h>
 
34
#include <gdbus.h>
 
35
 
 
36
#include "logging.h"
 
37
#include "telephony.h"
 
38
 
 
39
static char *subscriber_number = NULL;
 
40
static char *active_call_number = NULL;
 
41
static int active_call_status = 0;
 
42
static int active_call_dir = 0;
 
43
 
 
44
static gboolean events_enabled = FALSE;
 
45
 
 
46
/* Response and hold state
 
47
 * -1 = none
 
48
 *  0 = incoming call is put on hold in the AG
 
49
 *  1 = held incoming call is accepted in the AG
 
50
 *  2 = held incoming call is rejected in the AG
 
51
 */
 
52
static int response_and_hold = -1;
 
53
 
 
54
static struct indicator dummy_indicators[] =
 
55
{
 
56
        { "battchg",    "0-5",  5 },
 
57
        { "signal",     "0-5",  5 },
 
58
        { "service",    "0,1",  1 },
 
59
        { "call",       "0,1",  0 },
 
60
        { "callsetup",  "0-3",  0 },
 
61
        { "callheld",   "0-2",  0 },
 
62
        { "roam",       "0,1",  0 },
 
63
        { NULL }
 
64
};
 
65
 
 
66
void telephony_device_connected(void *telephony_device)
 
67
{
 
68
        debug("telephony-dummy: device %p connected", telephony_device);
 
69
}
 
70
 
 
71
void telephony_device_disconnected(void *telephony_device)
 
72
{
 
73
        debug("telephony-dummy: device %p disconnected", telephony_device);
 
74
        events_enabled = FALSE;
 
75
}
 
76
 
 
77
void telephony_event_reporting_req(void *telephony_device, int ind)
 
78
{
 
79
        events_enabled = ind == 1 ? TRUE : FALSE;
 
80
 
 
81
        telephony_event_reporting_rsp(telephony_device, CME_ERROR_NONE);
 
82
}
 
83
 
 
84
void telephony_response_and_hold_req(void *telephony_device, int rh)
 
85
{
 
86
        response_and_hold = rh;
 
87
 
 
88
        telephony_response_and_hold_ind(response_and_hold);
 
89
 
 
90
        telephony_response_and_hold_rsp(telephony_device, CME_ERROR_NONE);
 
91
}
 
92
 
 
93
void telephony_last_dialed_number_req(void *telephony_device)
 
94
{
 
95
        telephony_last_dialed_number_rsp(telephony_device, CME_ERROR_NONE);
 
96
 
 
97
        /* Notify outgoing call set-up successfully initiated */
 
98
        telephony_update_indicator(dummy_indicators, "callsetup",
 
99
                                        EV_CALLSETUP_OUTGOING);
 
100
        telephony_update_indicator(dummy_indicators, "callsetup",
 
101
                                        EV_CALLSETUP_ALERTING);
 
102
 
 
103
        active_call_status = CALL_STATUS_ALERTING;
 
104
        active_call_dir = CALL_DIR_OUTGOING;
 
105
}
 
106
 
 
107
void telephony_terminate_call_req(void *telephony_device)
 
108
{
 
109
        g_free(active_call_number);
 
110
        active_call_number = NULL;
 
111
 
 
112
        telephony_terminate_call_rsp(telephony_device, CME_ERROR_NONE);
 
113
 
 
114
        if (telephony_get_indicator(dummy_indicators, "callsetup") > 0)
 
115
                telephony_update_indicator(dummy_indicators, "callsetup",
 
116
                                                EV_CALLSETUP_INACTIVE);
 
117
        else
 
118
                telephony_update_indicator(dummy_indicators, "call",
 
119
                                                EV_CALL_INACTIVE);
 
120
}
 
121
 
 
122
void telephony_answer_call_req(void *telephony_device)
 
123
{
 
124
        telephony_answer_call_rsp(telephony_device, CME_ERROR_NONE);
 
125
 
 
126
        telephony_update_indicator(dummy_indicators, "call", EV_CALL_ACTIVE);
 
127
        telephony_update_indicator(dummy_indicators, "callsetup",
 
128
                                        EV_CALLSETUP_INACTIVE);
 
129
 
 
130
        active_call_status = CALL_STATUS_ACTIVE;
 
131
}
 
132
 
 
133
void telephony_dial_number_req(void *telephony_device, const char *number)
 
134
{
 
135
        g_free(active_call_number);
 
136
        active_call_number = g_strdup(number);
 
137
 
 
138
        telephony_dial_number_rsp(telephony_device, CME_ERROR_NONE);
 
139
 
 
140
        /* Notify outgoing call set-up successfully initiated */
 
141
        telephony_update_indicator(dummy_indicators, "callsetup",
 
142
                                        EV_CALLSETUP_OUTGOING);
 
143
        telephony_update_indicator(dummy_indicators, "callsetup",
 
144
                                        EV_CALLSETUP_ALERTING);
 
145
 
 
146
        active_call_status = CALL_STATUS_ALERTING;
 
147
        active_call_dir = CALL_DIR_OUTGOING;
 
148
}
 
149
 
 
150
void telephony_transmit_dtmf_req(void *telephony_device, char tone)
 
151
{
 
152
        debug("telephony-dummy: transmit dtmf: %c", tone);
 
153
        telephony_transmit_dtmf_rsp(telephony_device, CME_ERROR_NONE);
 
154
}
 
155
 
 
156
void telephony_subscriber_number_req(void *telephony_device)
 
157
{
 
158
        debug("telephony-dummy: subscriber number request");
 
159
        if (subscriber_number)
 
160
                telephony_subscriber_number_ind(subscriber_number, 0,
 
161
                                                SUBSCRIBER_SERVICE_VOICE);
 
162
        telephony_subscriber_number_rsp(telephony_device, CME_ERROR_NONE);
 
163
}
 
164
 
 
165
void telephony_list_current_calls_req(void *telephony_device)
 
166
{
 
167
        debug("telephony-dummy: list current calls request");
 
168
        if (active_call_number)
 
169
                telephony_list_current_call_ind(1, active_call_dir,
 
170
                                                active_call_status,
 
171
                                                CALL_MODE_VOICE,
 
172
                                                CALL_MULTIPARTY_NO,
 
173
                                                active_call_number,
 
174
                                                0);
 
175
        telephony_list_current_calls_rsp(telephony_device, CME_ERROR_NONE);
 
176
}
 
177
 
 
178
/* D-Bus method handlers */
 
179
static DBusMessage *outgoing_call(DBusConnection *conn, DBusMessage *msg,
 
180
                                        void *data)
 
181
{
 
182
        const char *number;
 
183
 
 
184
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
 
185
                                                DBUS_TYPE_INVALID))
 
186
                return NULL;
 
187
 
 
188
        debug("telephony-dummy: outgoing call to %s", number);
 
189
 
 
190
        g_free(active_call_number);
 
191
        active_call_number = g_strdup(number);
 
192
 
 
193
        telephony_update_indicator(dummy_indicators, "callsetup",
 
194
                                        EV_CALLSETUP_OUTGOING);
 
195
        telephony_update_indicator(dummy_indicators, "callsetup",
 
196
                                        EV_CALLSETUP_ALERTING);
 
197
 
 
198
        active_call_status = CALL_STATUS_ALERTING;
 
199
        active_call_dir = CALL_DIR_OUTGOING;
 
200
 
 
201
        return dbus_message_new_method_return(msg);
 
202
}
 
203
 
 
204
static DBusMessage *incoming_call(DBusConnection *conn, DBusMessage *msg,
 
205
                                        void *data)
 
206
{
 
207
        const char *number;
 
208
 
 
209
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
 
210
                                                DBUS_TYPE_INVALID))
 
211
                return NULL;
 
212
 
 
213
        debug("telephony-dummy: incoming call to %s", number);
 
214
 
 
215
        g_free(active_call_number);
 
216
        active_call_number = g_strdup(number);
 
217
 
 
218
        telephony_update_indicator(dummy_indicators, "callsetup",
 
219
                                        EV_CALLSETUP_INCOMING);
 
220
 
 
221
        active_call_status = CALL_STATUS_INCOMING;
 
222
        active_call_dir = CALL_DIR_INCOMING;
 
223
 
 
224
        telephony_incoming_call_ind(number, 0);
 
225
 
 
226
        return dbus_message_new_method_return(msg);
 
227
}
 
228
 
 
229
static DBusMessage *cancel_call(DBusConnection *conn, DBusMessage *msg,
 
230
                                        void *data)
 
231
{
 
232
        debug("telephony-dummy: cancel call");
 
233
 
 
234
        g_free(active_call_number);
 
235
        active_call_number = NULL;
 
236
 
 
237
        if (telephony_get_indicator(dummy_indicators, "callsetup") > 0) {
 
238
                telephony_update_indicator(dummy_indicators, "callsetup",
 
239
                                                EV_CALLSETUP_INACTIVE);
 
240
                telephony_calling_stopped_ind();
 
241
        }
 
242
 
 
243
        if (telephony_get_indicator(dummy_indicators, "call") > 0)
 
244
                telephony_update_indicator(dummy_indicators, "call",
 
245
                                                EV_CALL_INACTIVE);
 
246
 
 
247
        return dbus_message_new_method_return(msg);
 
248
}
 
249
 
 
250
static DBusMessage *signal_strength(DBusConnection *conn, DBusMessage *msg,
 
251
                                        void *data)
 
252
{
 
253
        dbus_uint32_t strength;
 
254
 
 
255
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &strength,
 
256
                                                DBUS_TYPE_INVALID))
 
257
                return NULL;
 
258
 
 
259
        if (strength > 5)
 
260
                return NULL;
 
261
 
 
262
        telephony_update_indicator(dummy_indicators, "signal", strength);
 
263
 
 
264
        debug("telephony-dummy: signal strength set to %u", strength);
 
265
 
 
266
        return dbus_message_new_method_return(msg);
 
267
}
 
268
 
 
269
static DBusMessage *battery_level(DBusConnection *conn, DBusMessage *msg,
 
270
                                        void *data)
 
271
{
 
272
        dbus_uint32_t level;
 
273
 
 
274
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &level,
 
275
                                                DBUS_TYPE_INVALID))
 
276
                return NULL;
 
277
 
 
278
        if (level > 5)
 
279
                return NULL;
 
280
 
 
281
        telephony_update_indicator(dummy_indicators, "battchg", level);
 
282
 
 
283
        debug("telephony-dummy: battery level set to %u", level);
 
284
 
 
285
        return dbus_message_new_method_return(msg);
 
286
}
 
287
 
 
288
static DBusMessage *roaming_status(DBusConnection *conn, DBusMessage *msg,
 
289
                                        void *data)
 
290
{
 
291
        dbus_bool_t roaming;
 
292
        int val;
 
293
 
 
294
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &roaming,
 
295
                                                DBUS_TYPE_INVALID))
 
296
                return NULL;
 
297
 
 
298
        val = roaming ? EV_ROAM_ACTIVE : EV_ROAM_INACTIVE;
 
299
 
 
300
        telephony_update_indicator(dummy_indicators, "roam", val);
 
301
 
 
302
        debug("telephony-dummy: roaming status set to %d", val);
 
303
 
 
304
        return dbus_message_new_method_return(msg);
 
305
}
 
306
 
 
307
static DBusMessage *registration_status(DBusConnection *conn, DBusMessage *msg,
 
308
                                        void *data)
 
309
{
 
310
        dbus_bool_t registration;
 
311
        int val;
 
312
 
 
313
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &registration,
 
314
                                                DBUS_TYPE_INVALID))
 
315
                return NULL;
 
316
 
 
317
        val = registration ? EV_SERVICE_PRESENT : EV_SERVICE_NONE;
 
318
 
 
319
        telephony_update_indicator(dummy_indicators, "service", val);
 
320
 
 
321
        debug("telephony-dummy: registration status set to %d", val);
 
322
 
 
323
        return dbus_message_new_method_return(msg);
 
324
}
 
325
 
 
326
static DBusMessage *set_subscriber_number(DBusConnection *conn,
 
327
                                                DBusMessage *msg,
 
328
                                                void *data)
 
329
{
 
330
        const char *number;
 
331
 
 
332
        if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
 
333
                                                DBUS_TYPE_INVALID))
 
334
                return NULL;
 
335
 
 
336
        g_free(subscriber_number);
 
337
        subscriber_number = g_strdup(number);
 
338
 
 
339
        debug("telephony-dummy: subscriber number set to %s", number);
 
340
 
 
341
        return dbus_message_new_method_return(msg);
 
342
}
 
343
 
 
344
static GDBusMethodTable dummy_methods[] = {
 
345
        { "OutgoingCall",       "s",    "",     outgoing_call           },
 
346
        { "IncomingCall",       "s",    "",     incoming_call           },
 
347
        { "CancelCall",         "",     "",     cancel_call             },
 
348
        { "SignalStrength",     "u",    "",     signal_strength         },
 
349
        { "BatteryLevel",       "u",    "",     battery_level           },
 
350
        { "RoamingStatus",      "b",    "",     roaming_status          },
 
351
        { "RegistrationStatus", "b",    "",     registration_status     },
 
352
        { "SetSubscriberNumber","s",    "",     set_subscriber_number   },
 
353
        { }
 
354
};
 
355
 
 
356
static DBusConnection *connection = NULL;
 
357
 
 
358
int telephony_init(void)
 
359
{
 
360
        uint32_t features = AG_FEATURE_REJECT_A_CALL |
 
361
                                AG_FEATURE_ENHANCED_CALL_STATUS |
 
362
                                AG_FEATURE_EXTENDED_ERROR_RESULT_CODES;
 
363
 
 
364
        connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
 
365
 
 
366
        g_dbus_register_interface(connection, "/org/bluez/test",
 
367
                                        "org.bluez.TelephonyTest",
 
368
                                        dummy_methods, NULL,
 
369
                                        NULL, NULL, NULL);
 
370
 
 
371
        telephony_ready_ind(features, dummy_indicators, response_and_hold);
 
372
 
 
373
        return 0;
 
374
}
 
375
 
 
376
void telephony_exit(void)
 
377
{
 
378
        dbus_connection_unref(connection);
 
379
        connection = NULL;
 
380
}