Remove enable and disable element callbacks
[connman] / plugins / fake.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 #define CONNMAN_API_SUBJECT_TO_CHANGE
27 #include <connman/plugin.h>
28 #include <connman/driver.h>
29 #include <connman/element.h>
30 #include <connman/log.h>
31
32 static void create_network(struct connman_element *parent, const char *name)
33 {
34         struct connman_element *element;
35
36         element = connman_element_create(name);
37         element->type = CONNMAN_ELEMENT_TYPE_NETWORK;
38         element->subtype = CONNMAN_ELEMENT_SUBTYPE_FAKE;
39
40         connman_element_register(element, parent);
41         connman_element_unref(element);
42 }
43
44 static int fake_device_probe(struct connman_element *element)
45 {
46         DBG("");
47
48         return 0;
49 }
50
51 static void fake_device_remove(struct connman_element *element)
52 {
53         DBG("");
54 }
55
56 static int fake_device_update(struct connman_element *element)
57 {
58         DBG("");
59
60         create_network(element, "network_new");
61
62         return 0;
63 }
64
65 static int fake_device_enable(struct connman_element *element)
66 {
67         DBG("");
68
69         create_network(element, "network_one");
70         create_network(element, "network_two");
71
72         return 0;
73 }
74
75 static int fake_device_disable(struct connman_element *element)
76 {
77         DBG("");
78
79         connman_element_unregister_children(element);
80
81         return 0;
82 }
83
84 static struct connman_driver fake_device_driver = {
85         .name           = "fake-device",
86         .type           = CONNMAN_ELEMENT_TYPE_DEVICE,
87         .subtype        = CONNMAN_ELEMENT_SUBTYPE_FAKE,
88         .probe          = fake_device_probe,
89         .remove         = fake_device_remove,
90         .update         = fake_device_update,
91         .enable         = fake_device_enable,
92         .disable        = fake_device_disable,
93 };
94
95 static void create_device(const char *name)
96 {
97         struct connman_element *element;
98
99         element = connman_element_create(name);
100         element->type = CONNMAN_ELEMENT_TYPE_DEVICE;
101         element->subtype = CONNMAN_ELEMENT_SUBTYPE_FAKE;
102
103         //connman_element_define_properties(element,
104         //                              CONNMAN_PROPERTY_ID_IPV4_METHOD,
105         //                              CONNMAN_PROPERTY_ID_INVALID);
106
107         connman_element_register(element, NULL);
108         connman_element_unref(element);
109 }
110
111 static int fake_init(void)
112 {
113         create_device("fakeone");
114         create_device("faketwo");
115
116         return connman_driver_register(&fake_device_driver);
117 }
118
119 static void fake_exit(void)
120 {
121         connman_driver_unregister(&fake_device_driver);
122 }
123
124 CONNMAN_PLUGIN_DEFINE(fake, "Tesing plugin", VERSION, fake_init, fake_exit)