Remove obsolete file.
[connman] / src / detect.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <glib.h>
27
28 #include "connman.h"
29
30 static GSList *device_list = NULL;
31
32 static struct connman_device *find_device(int index)
33 {
34         GSList *list;
35
36         for (list = device_list; list; list = list->next) {
37                 struct connman_device *device = list->data;
38
39                 if (connman_device_get_index(device) == index)
40                         return device;
41         }
42
43         return NULL;
44 }
45
46 static void detect_newlink(unsigned short type, int index,
47                                         unsigned flags, unsigned change)
48 {
49         struct connman_device *device;
50
51         DBG("type %d index %d", type, index);
52
53         device = find_device(index);
54         if (device != NULL)
55                 return;
56
57         device = connman_inet_create_device(index);
58         if (device == NULL)
59                 return;
60
61         if (connman_device_register(device) < 0) {
62                 connman_device_unref(device);
63                 return;
64         }
65
66         device_list = g_slist_append(device_list, device);
67 }
68
69 static void detect_dellink(unsigned short type, int index,
70                                         unsigned flags, unsigned change)
71 {
72         struct connman_device *device;
73
74         DBG("type %d index %d", type, index);
75
76         device = find_device(index);
77         if (device == NULL)
78                 return;
79
80         device_list = g_slist_remove(device_list, device);
81
82         connman_device_unregister(device);
83         connman_device_unref(device);
84 }
85
86 static struct connman_rtnl detect_rtnl = {
87         .name           = "detect",
88         .priority       = CONNMAN_RTNL_PRIORITY_LOW,
89         .newlink        = detect_newlink,
90         .dellink        = detect_dellink,
91 };
92
93 int __connman_detect_init(void)
94 {
95         int err;
96
97         DBG("");
98
99         err = connman_rtnl_register(&detect_rtnl);
100         if (err < 0)
101                 return err;
102
103         connman_rtnl_send_getlink();
104
105         return 0;
106 }
107
108 void __connman_detect_cleanup(void)
109 {
110         GSList *list;
111
112         DBG("");
113
114         connman_rtnl_unregister(&detect_rtnl);
115
116         for (list = device_list; list; list = list->next) {
117                 struct connman_device *device = list->data;
118
119                 connman_device_unregister(device);
120                 connman_device_unref(device);
121         }
122
123         g_slist_free(device_list);
124         device_list = NULL;
125 }