Add element subtype for generic network devices
[platform/upstream/connman.git] / include / element.h
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 #ifndef __CONNMAN_ELEMENT_H
23 #define __CONNMAN_ELEMENT_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <errno.h>
30 #include <glib.h>
31
32 #include <connman/property.h>
33
34 /**
35  * SECTION:element
36  * @title: Element premitives
37  * @short_description: Functions for handling elements
38  */
39
40 enum connman_element_state {
41         CONNMAN_ELEMENT_STATE_UNKNOWN   = 0,
42         CONNMAN_ELEMENT_STATE_CONNECT   = 1,
43         CONNMAN_ELEMENT_STATE_CONNECTED = 2,
44         CONNMAN_ELEMENT_STATE_CLOSED    = 3,
45 };
46
47 enum connman_element_type {
48         CONNMAN_ELEMENT_TYPE_UNKNOWN    = 0,
49         CONNMAN_ELEMENT_TYPE_ROOT       = 1,
50         CONNMAN_ELEMENT_TYPE_DEVICE     = 2,
51         CONNMAN_ELEMENT_TYPE_NETWORK    = 3,
52         CONNMAN_ELEMENT_TYPE_IPV4       = 4,
53         CONNMAN_ELEMENT_TYPE_IPV6       = 5,
54         CONNMAN_ELEMENT_TYPE_DHCP       = 6,
55         CONNMAN_ELEMENT_TYPE_BOOTP      = 7,
56         CONNMAN_ELEMENT_TYPE_ZEROCONF   = 8,
57         CONNMAN_ELEMENT_TYPE_RESOLVER   = 9,
58
59         CONNMAN_ELEMENT_TYPE_INTERNET   = 42,
60 };
61
62 enum connman_element_subtype {
63         CONNMAN_ELEMENT_SUBTYPE_UNKNOWN   = 0,
64         CONNMAN_ELEMENT_SUBTYPE_NETWORK   = 1,
65         CONNMAN_ELEMENT_SUBTYPE_ETHERNET  = 2,
66         CONNMAN_ELEMENT_SUBTYPE_WIFI      = 3,
67         CONNMAN_ELEMENT_SUBTYPE_WIMAX     = 4,
68         CONNMAN_ELEMENT_SUBTYPE_MODEM     = 5,
69         CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH = 6,
70 };
71
72 struct connman_driver;
73
74 struct connman_element {
75         gint refcount;
76         GStaticMutex mutex;
77         gint index;
78         gchar *name;
79         gchar *path;
80         enum connman_element_type type;
81         enum connman_element_subtype subtype;
82         enum connman_element_state state;
83         gboolean enabled;
84         guint16 priority;
85
86         struct connman_element *parent;
87
88         struct connman_driver *driver;
89         void *driver_data;
90
91         GSList *properties;
92
93         struct {
94                 gchar *identifier;
95         } network;
96
97         struct {
98                 gchar *address;
99                 gchar *netmask;
100                 gchar *gateway;
101                 gchar *network;
102                 gchar *broadcast;
103                 gchar *nameserver;
104         } ipv4;
105 };
106
107 #define connman_element_lock(element)    g_static_mutex_lock(&(element)->mutex)
108 #define connman_element_unlock(element)  g_static_mutex_unlock(&(element)->mutex)
109
110 extern struct connman_element *connman_element_create(const char *name);
111 extern struct connman_element *connman_element_ref(struct connman_element *element);
112 extern void connman_element_unref(struct connman_element *element);
113
114 extern int connman_element_add_static_property(struct connman_element *element,
115                                 const char *name, int type, const void *value);
116 extern int connman_element_define_properties(struct connman_element *element, ...);
117 extern int connman_element_create_property(struct connman_element *element,
118                                                 const char *name, int type);
119 extern int connman_element_set_property(struct connman_element *element,
120                                 enum connman_property_id id, const void *value);
121 extern int connman_element_get_value(struct connman_element *element,
122                                 enum connman_property_id id, void *value);
123
124 extern int connman_element_register(struct connman_element *element,
125                                         struct connman_element *parent);
126 extern void connman_element_unregister(struct connman_element *element);
127 extern void connman_element_unregister_children(struct connman_element *element);
128 extern void connman_element_update(struct connman_element *element);
129
130 static inline void *connman_element_get_data(struct connman_element *element)
131 {
132         return element->driver_data;
133 }
134
135 static inline void connman_element_set_data(struct connman_element *element,
136                                                                 void *data)
137 {
138         element->driver_data = data;
139 }
140
141 #ifdef __cplusplus
142 }
143 #endif
144
145 #endif /* __CONNMAN_ELEMENT_H */