~awe/phablet-extras/ofono-lp1188404

« back to all changes in this revision

Viewing changes to drivers/rilmodem/call-volume.c

  • Committer: Tarmac
  • Author(s): Tony Espy
  • Date: 2013-04-11 01:00:53 UTC
  • mfrom: (27.1.8 ofono-raring)
  • Revision ID: tarmac-20130411010053-u5x1792w0e3r62l4
Re-based ofono/RILD code on new upstream version ofono-1.12-0ubuntu2b1 from Raring.
.

Approved by Ricardo Salveti, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
 
6
 *  Copyright (C) 2012 Canonical Ltd.
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License version 2 as
 
10
 *  published by the Free Software Foundation.
 
11
 *
 
12
 *  This program 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
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 *
 
21
 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#include <config.h>
 
25
#endif
 
26
 
 
27
#define _GNU_SOURCE
 
28
#include <string.h>
 
29
#include <stdio.h>
 
30
#include <errno.h>
 
31
 
 
32
#include <glib.h>
 
33
 
 
34
#include <ofono/log.h>
 
35
#include <ofono/modem.h>
 
36
#include <ofono/call-volume.h>
 
37
 
 
38
#include "gril.h"
 
39
#include "grilutil.h"
 
40
 
 
41
#include "common.h"
 
42
 
 
43
#include "rilmodem.h"
 
44
#include "parcel.h"
 
45
 
 
46
struct cv_data {
 
47
        GRil *ril;
 
48
        unsigned int vendor;
 
49
};
 
50
 
 
51
static void volume_mute_cb(struct ril_msg *message, gpointer user_data)
 
52
{
 
53
        struct cb_data *cbd = user_data;
 
54
        ofono_call_volume_cb_t cb = cbd->cb;
 
55
        struct ofono_error error;
 
56
 
 
57
        DBG("");
 
58
 
 
59
        if (message->error == RIL_E_SUCCESS) {
 
60
                decode_ril_error(&error, "OK");
 
61
        } else {
 
62
                ofono_error("Could not set the ril mute state");
 
63
                decode_ril_error(&error, "FAIL");
 
64
        }
 
65
 
 
66
        cb(&error, cbd->data);
 
67
}
 
68
 
 
69
static void ril_call_volume_mute(struct ofono_call_volume *cv, int muted,
 
70
                                ofono_call_volume_cb_t cb, void *data)
 
71
{
 
72
        struct cv_data *cvd = ofono_call_volume_get_data(cv);
 
73
        struct cb_data *cbd = cb_data_new(cb, data);
 
74
        struct parcel rilp;
 
75
 
 
76
        DBG("");
 
77
 
 
78
        parcel_init(&rilp);
 
79
        parcel_w_int32(&rilp, 1);
 
80
        parcel_w_int32(&rilp, muted);
 
81
        g_ril_send(cvd->ril, RIL_REQUEST_SET_MUTE, rilp.data,
 
82
                        rilp.size, volume_mute_cb, cbd, g_free);
 
83
        parcel_free(&rilp);
 
84
 
 
85
        return;
 
86
}
 
87
 
 
88
static void probe_mute_cb(struct ril_msg *message, gpointer user_data)
 
89
{
 
90
        struct ofono_call_volume *cv = user_data;
 
91
        struct parcel rilp;
 
92
        int muted;
 
93
 
 
94
        DBG("");
 
95
 
 
96
        if (message->error != RIL_E_SUCCESS) {
 
97
                ofono_error("Could not retrive the ril mute state");
 
98
                return;
 
99
        }
 
100
 
 
101
        /* Set up Parcel struct for proper parsing */
 
102
        rilp.data = message->buf;
 
103
        rilp.size = message->buf_len;
 
104
        rilp.capacity = message->buf_len;
 
105
        rilp.offset = 0;
 
106
 
 
107
        muted = parcel_r_int32(&rilp);
 
108
        DBG("Initial ril muted state: %d", muted);
 
109
 
 
110
        ofono_call_volume_set_muted(cv, muted);
 
111
}
 
112
 
 
113
static void call_probe_mute(gpointer user_data)
 
114
{
 
115
        struct ofono_call_volume *cv = user_data;
 
116
        struct cv_data *cvd = ofono_call_volume_get_data(cv);
 
117
 
 
118
        DBG("Requesting mute from RIL");
 
119
 
 
120
        g_ril_send(cvd->ril, RIL_REQUEST_GET_MUTE, NULL, 0,
 
121
                                probe_mute_cb, cv, NULL);
 
122
 
 
123
        return;
 
124
}
 
125
 
 
126
static gboolean ril_delayed_register(gpointer user_data)
 
127
{
 
128
        struct ofono_call_volume *cv = user_data;
 
129
        DBG("");
 
130
        ofono_call_volume_register(cv);
 
131
 
 
132
        /* Probe the mute state */
 
133
        call_probe_mute(user_data);
 
134
 
 
135
        /* This makes the timeout a single-shot */
 
136
        return FALSE;
 
137
}
 
138
 
 
139
static int ril_call_volume_probe(struct ofono_call_volume *cv,
 
140
                                unsigned int vendor, void *data)
 
141
{
 
142
        GRil *ril = data;
 
143
        struct cv_data *cvd;
 
144
 
 
145
        DBG("");
 
146
 
 
147
        cvd = g_new0(struct cv_data, 1);
 
148
        if (cvd == NULL)
 
149
                return -ENOMEM;
 
150
 
 
151
        cvd->ril = g_ril_clone(ril);
 
152
        cvd->vendor = vendor;
 
153
 
 
154
        ofono_call_volume_set_data(cv, cvd);
 
155
 
 
156
        g_timeout_add_seconds(2, ril_delayed_register, cv);
 
157
 
 
158
        return 0;
 
159
}
 
160
 
 
161
static void ril_call_volume_remove(struct ofono_call_volume *cv)
 
162
{
 
163
        struct cv_data *cvd = ofono_call_volume_get_data(cv);
 
164
 
 
165
        ofono_call_volume_set_data(cv, NULL);
 
166
 
 
167
        g_ril_unref(cvd->ril);
 
168
        g_free(cvd);
 
169
}
 
170
 
 
171
static struct ofono_call_volume_driver driver = {
 
172
        .name = "rilmodem",
 
173
        .probe = ril_call_volume_probe,
 
174
        .remove = ril_call_volume_remove,
 
175
        .mute = ril_call_volume_mute,
 
176
};
 
177
 
 
178
void ril_call_volume_init(void)
 
179
{
 
180
        ofono_call_volume_driver_register(&driver);
 
181
}
 
182
 
 
183
void ril_call_volume_exit(void)
 
184
{
 
185
        ofono_call_volume_driver_unregister(&driver);
 
186
}