Add destruct callback to element structure
[connman] / include / device.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_DEVICE_H
23 #define __CONNMAN_DEVICE_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <connman/element.h>
30
31 /**
32  * SECTION:device
33  * @title: Device driver premitives
34  * @short_description: Functions for registering device drivers
35  */
36
37 enum connman_device_type {
38         CONNMAN_DEVICE_TYPE_UNKNOWN   = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN,
39         CONNMAN_DEVICE_TYPE_FAKE      = CONNMAN_ELEMENT_SUBTYPE_FAKE,
40         CONNMAN_DEVICE_TYPE_ETHERNET  = CONNMAN_ELEMENT_SUBTYPE_ETHERNET,
41         CONNMAN_DEVICE_TYPE_WIFI      = CONNMAN_ELEMENT_SUBTYPE_WIFI,
42         CONNMAN_DEVICE_TYPE_WIMAX     = CONNMAN_ELEMENT_SUBTYPE_WIMAX,
43         CONNMAN_DEVICE_TYPE_MODEM     = CONNMAN_ELEMENT_SUBTYPE_MODEM,
44         CONNMAN_DEVICE_TYPE_BLUETOOTH = CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH,
45         CONNMAN_DEVICE_TYPE_VENDOR    = 42,
46 };
47
48 enum connman_device_capabilities {
49         CONNMAN_DEVICE_CAPABILITY_SCANNING = (1 << 0),
50 };
51
52 enum connman_device_policy {
53         CONNMAN_DEVICE_POLICY_UNKNOWN = 0,
54         CONNMAN_DEVICE_POLICY_IGNORE  = 1,
55         CONNMAN_DEVICE_POLICY_AUTO    = 2,
56         CONNMAN_DEVICE_POLICY_OFF     = 3,
57 };
58
59 enum connman_device_state {
60         CONNMAN_DEVICE_STATE_UNKNOWN = 0,
61         CONNMAN_DEVICE_STATE_OFF     = 1,
62 };
63
64 struct connman_device_driver;
65
66 struct connman_device {
67         struct connman_element *element;
68         enum connman_device_type type;
69         unsigned long capabilities;
70         enum connman_device_policy policy;
71         enum connman_device_state state;
72         gboolean powered;
73         gboolean scanning;
74
75         struct connman_device_driver *driver;
76         void *driver_data;
77
78         GSList *networks;
79 };
80
81 extern int connman_device_set_powered(struct connman_device *device,
82                                                         gboolean powered);
83 extern int connman_device_set_scanning(struct connman_device *device,
84                                                         gboolean scanning);
85
86 static inline void *connman_device_get_data(struct connman_device *device)
87 {
88         return device->driver_data;
89 }
90
91 static inline void connman_device_set_data(struct connman_device *device,
92                                                                 void *data)
93 {
94         device->driver_data = data;
95 }
96
97 struct connman_device_driver {
98         const char *name;
99         enum connman_device_type type;
100         int priority;
101         int (*probe) (struct connman_device *device);
102         void (*remove) (struct connman_device *device);
103         int (*enable) (struct connman_device *device);
104         int (*disable) (struct connman_device *device);
105         int (*scan) (struct connman_device *device);
106 };
107
108 extern int connman_device_driver_register(struct connman_device_driver *driver);
109 extern void connman_device_driver_unregister(struct connman_device_driver *driver);
110
111 #ifdef __cplusplus
112 }
113 #endif
114
115 #endif /* __CONNMAN_DEVICE_H */