~phablet-team/ofono/ofono-bug-updates

« back to all changes in this revision

Viewing changes to drivers/hfpmodem/devinfo.c

  • Committer: Denis Kenzior
  • Author(s): Lucas De Marchi
  • Date: 2011-03-18 23:31:14 UTC
  • Revision ID: git-v1:888e07863b24026413bac8f449de377c879e1044
message: add cancelled state

Based on patch from Yang Gu <gyagp0@gmail.com>

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) 2011  BMW Car IT GmbH. All rights reserved.
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
 
#include <string.h>
28
 
 
29
 
#include <glib.h>
30
 
#include <gatchat.h>
31
 
#include <gatresult.h>
32
 
 
33
 
#include <ofono/log.h>
34
 
#include <ofono/modem.h>
35
 
#include <ofono/devinfo.h>
36
 
 
37
 
#include "hfpmodem.h"
38
 
 
39
 
struct devinfo_data {
40
 
        char *device_address;
41
 
        guint register_source;
42
 
};
43
 
 
44
 
static void hfp_query_serial(struct ofono_devinfo *info,
45
 
                                ofono_devinfo_query_cb_t cb,
46
 
                                void *data)
47
 
{
48
 
        struct devinfo_data *dev = ofono_devinfo_get_data(info);
49
 
        CALLBACK_WITH_SUCCESS(cb, dev->device_address, data);
50
 
}
51
 
 
52
 
static gboolean hfp_devinfo_register(gpointer user_data)
53
 
{
54
 
        struct ofono_devinfo *info = user_data;
55
 
        struct devinfo_data *dd = ofono_devinfo_get_data(info);
56
 
 
57
 
        dd->register_source = 0;
58
 
 
59
 
        ofono_devinfo_register(info);
60
 
 
61
 
        return FALSE;
62
 
}
63
 
 
64
 
static int hfp_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
65
 
                                void *user)
66
 
{
67
 
        const char *device_address = user;
68
 
        struct devinfo_data *dd;
69
 
 
70
 
        dd = g_new0(struct devinfo_data, 1);
71
 
        dd->device_address = g_strdup(device_address);
72
 
 
73
 
        ofono_devinfo_set_data(info, dd);
74
 
 
75
 
        dd->register_source = g_idle_add(hfp_devinfo_register, info);
76
 
        return 0;
77
 
}
78
 
 
79
 
static void hfp_devinfo_remove(struct ofono_devinfo *info)
80
 
{
81
 
        struct devinfo_data *dd = ofono_devinfo_get_data(info);
82
 
 
83
 
        ofono_devinfo_set_data(info, NULL);
84
 
        if (dd == NULL)
85
 
                return;
86
 
 
87
 
        if (dd->register_source != 0)
88
 
                g_source_remove(dd->register_source);
89
 
 
90
 
        g_free(dd->device_address);
91
 
        g_free(dd);
92
 
}
93
 
 
94
 
static struct ofono_devinfo_driver driver = {
95
 
        .name                   = "hfpmodem",
96
 
        .probe                  = hfp_devinfo_probe,
97
 
        .remove                 = hfp_devinfo_remove,
98
 
        .query_serial           = hfp_query_serial
99
 
};
100
 
 
101
 
void hfp_devinfo_init(void)
102
 
{
103
 
        ofono_devinfo_driver_register(&driver);
104
 
}
105
 
 
106
 
void hfp_devinfo_exit(void)
107
 
{
108
 
        ofono_devinfo_driver_unregister(&driver);
109
 
}