5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
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.
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.
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
28 struct connman_network {
29 struct connman_element element;
30 enum connman_network_type type;
33 struct connman_network_driver *driver;
37 static void network_destruct(struct connman_element *element)
39 struct connman_network *network = element->network;
41 DBG("element %p name %s", element, element->name);
43 g_free(network->identifier);
47 * connman_network_create:
48 * @identifier: network identifier (for example an unqiue name)
50 * Allocate a new network and assign the #identifier to it.
52 * Returns: a newly-allocated #connman_network structure
54 struct connman_network *connman_network_create(const char *identifier,
55 enum connman_network_type type)
57 struct connman_network *network;
59 DBG("identifier %s type %d", identifier, type);
61 network = g_try_new0(struct connman_network, 1);
65 DBG("network %p", network);
67 network->element.refcount = 1;
69 network->element.name = g_strdup(identifier);
70 network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
71 network->element.index = -1;
73 network->element.network = network;
74 network->element.destruct = network_destruct;
77 network->identifier = g_strdup(identifier);
83 * connman_network_ref:
84 * @network: network structure
86 * Increase reference counter of network
88 struct connman_network *connman_network_ref(struct connman_network *network)
90 if (connman_element_ref(&network->element) == NULL)
97 * connman_network_unref:
98 * @network: network structure
100 * Decrease reference counter of network
102 void connman_network_unref(struct connman_network *network)
104 connman_element_unref(&network->element);
108 * connman_network_get_identifier:
109 * @network: network structure
111 * Get identifier of network
113 const char *connman_network_get_identifier(struct connman_network *network)
115 return network->identifier;
119 * connman_network_get_data:
120 * @network: network structure
122 * Get private network data pointer
124 void *connman_network_get_data(struct connman_network *network)
126 return network->driver_data;
130 * connman_network_set_data:
131 * @network: network structure
132 * @data: data pointer
134 * Set private network data pointer
136 void connman_network_set_data(struct connman_network *network, void *data)
138 network->driver_data = data;
141 static int network_probe(struct connman_element *element)
146 static void network_remove(struct connman_element *element)
150 static struct connman_driver network_driver = {
152 .type = CONNMAN_ELEMENT_TYPE_NETWORK,
153 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
154 .probe = network_probe,
155 .remove = network_remove,
158 int __connman_network_init(void)
162 return connman_driver_register(&network_driver);
165 void __connman_network_cleanup(void)
169 connman_driver_unregister(&network_driver);