ofono: Start refactoring plugin
[platform/upstream/connman.git] / plugins / ofono.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
6  *  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
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 <errno.h>
28 #include <stdlib.h>
29
30 #include <gdbus.h>
31 #include <string.h>
32
33 #define CONNMAN_API_SUBJECT_TO_CHANGE
34 #include <connman/plugin.h>
35 #include <connman/device.h>
36 #include <connman/network.h>
37 #include <connman/dbus.h>
38 #include <connman/log.h>
39
40 static DBusConnection *connection;
41
42 static int network_probe(struct connman_network *network)
43 {
44         DBG("network %p", network);
45
46         return 0;
47 }
48
49 static void network_remove(struct connman_network *network)
50 {
51         DBG("network %p", network);
52 }
53
54 static int network_connect(struct connman_network *network)
55 {
56         DBG("network %p", network);
57
58         return 0;
59 }
60
61 static int network_disconnect(struct connman_network *network)
62 {
63         DBG("network %p", network);
64
65         return 0;
66 }
67
68 static struct connman_network_driver network_driver = {
69         .name           = "network",
70         .type           = CONNMAN_NETWORK_TYPE_CELLULAR,
71         .probe          = network_probe,
72         .remove         = network_remove,
73         .connect        = network_connect,
74         .disconnect     = network_disconnect,
75 };
76
77 static int modem_probe(struct connman_device *device)
78 {
79         DBG("device %p", device);
80
81         return 0;
82 }
83
84 static void modem_remove(struct connman_device *device)
85 {
86         DBG("device %p", device);
87 }
88
89 static int modem_enable(struct connman_device *device)
90 {
91         DBG("device %p", device);
92
93         return 0;
94 }
95
96 static int modem_disable(struct connman_device *device)
97 {
98         DBG("device %p", device);
99
100         return 0;
101 }
102
103 static struct connman_device_driver modem_driver = {
104         .name           = "modem",
105         .type           = CONNMAN_DEVICE_TYPE_CELLULAR,
106         .probe          = modem_probe,
107         .remove         = modem_remove,
108         .enable         = modem_enable,
109         .disable        = modem_disable,
110 };
111
112 static int ofono_init(void)
113 {
114         int err;
115
116         DBG("");
117
118         connection = connman_dbus_get_connection();
119         if (connection == NULL)
120                 return -EIO;
121
122         err = connman_network_driver_register(&network_driver);
123         if (err < 0)
124                 goto remove;
125
126         err = connman_device_driver_register(&modem_driver);
127         if (err < 0) {
128                 connman_network_driver_unregister(&network_driver);
129                 goto remove;
130         }
131
132         return 0;
133
134 remove:
135         dbus_connection_unref(connection);
136
137         return err;
138 }
139
140 static void ofono_exit(void)
141 {
142         DBG("");
143
144         connman_device_driver_unregister(&modem_driver);
145         connman_network_driver_unregister(&network_driver);
146
147         dbus_connection_unref(connection);
148 }
149
150 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
151                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)