02067e69e0956655388975b4a38c00855e9cbe5b
[connman] / src / network.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.h"
27
28 struct connman_network {
29         struct connman_element element;
30         enum connman_network_type type;
31
32         struct connman_network_driver *driver;
33         void *driver_data;
34 };
35
36 static void network_destruct(struct connman_element *element)
37 {
38         DBG("element %p name %s", element, element->name);
39 }
40
41 /**
42  * connman_network_create:
43  * @identifier: network identifier (for example an unqiue name)
44  *
45  * Allocate a new network and assign the #identifier to it.
46  *
47  * Returns: a newly-allocated #connman_network structure
48  */
49 struct connman_network *connman_network_create(const char *identifier,
50                                                 enum connman_network_type type)
51 {
52         struct connman_network *network;
53
54         DBG("identifier %s type %d", identifier, type);
55
56         network = g_try_new0(struct connman_network, 1);
57         if (network == NULL)
58                 return NULL;
59
60         DBG("network %p", network);
61
62         network->element.refcount = 1;
63
64         network->element.name = g_strdup(identifier);
65         network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
66         network->element.index = -1;
67
68         network->element.network = network;
69         network->element.destruct = network_destruct;
70
71         network->type = type;
72
73         return network;
74 }
75
76 /**
77  * connman_network_ref:
78  * @network: network structure
79  *
80  * Increase reference counter of  network
81  */
82 struct connman_network *connman_network_ref(struct connman_network *network)
83 {
84         if (connman_element_ref(&network->element) == NULL)
85                 return NULL;
86
87         return network;
88 }
89
90 /**
91  * connman_network_unref:
92  * @network: network structure
93  *
94  * Decrease reference counter of network
95  */
96 void connman_network_unref(struct connman_network *network)
97 {
98         connman_element_unref(&network->element);
99 }
100
101 static int network_probe(struct connman_element *element)
102 {
103         return 0;
104 }
105
106 static void network_remove(struct connman_element *element)
107 {
108 }
109
110 static struct connman_driver network_driver = {
111         .name           = "network",
112         .type           = CONNMAN_ELEMENT_TYPE_NETWORK,
113         .priority       = CONNMAN_DRIVER_PRIORITY_LOW,
114         .probe          = network_probe,
115         .remove         = network_remove,
116 };
117
118 int __connman_network_init(void)
119 {
120         DBG("");
121
122         return connman_driver_register(&network_driver);
123 }
124
125 void __connman_network_cleanup(void)
126 {
127         DBG("");
128
129         connman_driver_unregister(&network_driver);
130 }