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