dbus: Do not include libdbus dbus/dbus.h into dbus_{old,new}.h
[libeap.git] / wpa_supplicant / dbus / dbus_new_helpers.h
1 /*
2  * WPA Supplicant / dbus-based control interface
3  * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4  * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Alternatively, this software may be distributed under the terms of BSD
11  * license.
12  *
13  * See README and COPYING for more details.
14  */
15
16 #ifndef WPA_DBUS_CTRL_H
17 #define WPA_DBUS_CTRL_H
18
19 #include <dbus/dbus.h>
20
21 typedef DBusMessage * (* WPADBusMethodHandler)(DBusMessage *message,
22                                                void *user_data);
23 typedef void (* WPADBusArgumentFreeFunction)(void *handler_arg);
24
25 typedef DBusMessage * (* WPADBusPropertyAccessor)(DBusMessage *message,
26                                                   const void *user_data);
27
28 struct wpa_dbus_object_desc {
29         DBusConnection *connection;
30
31         /* list of methods, properties and signals registered with object */
32         struct wpa_dbus_method_desc *methods;
33         struct wpa_dbus_signal_desc *signals;
34         struct wpa_dbus_property_desc *properties;
35
36         /* argument for method handlers and properties
37          * getter and setter functions */
38         void *user_data;
39         /* function used to free above argument */
40         WPADBusArgumentFreeFunction user_data_free_func;
41 };
42
43 enum dbus_prop_access { R, W, RW };
44
45 enum dbus_arg_direction { ARG_IN, ARG_OUT };
46
47 struct wpa_dbus_argument {
48         char *name;
49         char *type;
50         enum dbus_arg_direction dir;
51 };
52
53 #define END_ARGS { NULL, NULL, ARG_IN }
54
55 /**
56  * struct wpa_dbus_method_desc - DBus method description
57  */
58 struct wpa_dbus_method_desc {
59         /* pointer to next description in list */
60         struct wpa_dbus_method_desc *next;
61
62         /* method interface */
63         char *dbus_interface;
64         /* method name */
65         char *dbus_method;
66
67         /* method handling function */
68         WPADBusMethodHandler method_handler;
69
70         /* number of method arguments */
71         int args_num;
72         /* array of arguments */
73         struct wpa_dbus_argument args[];
74 };
75
76 /**
77  * struct wpa_dbus_signal_desc - DBus signal description
78  */
79 struct wpa_dbus_signal_desc {
80         /* pointer to next description in list */
81         struct wpa_dbus_signal_desc *next;
82
83         /* signal interface */
84         char *dbus_interface;
85         /* signal name */
86         char *dbus_signal;
87
88         /* number of signal arguments */
89         int args_num;
90         /* array of arguments */
91         struct wpa_dbus_argument args[0];
92 };
93
94 /**
95  * struct wpa_dbus_property_desc - DBus property description
96  */
97 struct wpa_dbus_property_desc {
98         /* pointer to next description in list */
99         struct wpa_dbus_property_desc *next;
100
101         /* property interface */
102         char *dbus_interface;
103         /* property name */
104         char *dbus_property;
105         /* property type signature in DBus type notation */
106         char *type;
107
108         /* property access permissions */
109         enum dbus_prop_access access;
110
111         /* property getter function */
112         WPADBusPropertyAccessor getter;
113         /* property setter function */
114         WPADBusPropertyAccessor setter;
115 };
116
117
118 #define WPAS_DBUS_OBJECT_PATH_MAX 150
119 #define WPAS_DBUS_INTERFACE_MAX 150
120 #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
121
122 #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
123 #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
124 #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
125 #define WPA_DBUS_PROPERTIES_GET "Get"
126 #define WPA_DBUS_PROPERTIES_SET "Set"
127 #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
128
129 void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
130
131 int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
132                              char *dbus_service,
133                              struct wpa_dbus_object_desc *obj_desc);
134
135 int wpa_dbus_register_object_per_iface(
136         struct wpas_dbus_priv *ctrl_iface,
137         const char *path, const char *ifname,
138         struct wpa_dbus_object_desc *obj_desc);
139
140 int wpa_dbus_unregister_object_per_iface(
141         struct wpas_dbus_priv *ctrl_iface,
142         const char *path);
143
144 int wpa_dbus_method_register(struct wpa_dbus_object_desc *obj_dsc,
145                              const char *dbus_interface,
146                              const char *dbus_method,
147                              WPADBusMethodHandler method_handler,
148                              const struct wpa_dbus_argument args[]);
149
150 int wpa_dbus_signal_register(struct wpa_dbus_object_desc *obj_dsc,
151                              const char *dbus_interface,
152                              const char *dbus_signal,
153                              const struct wpa_dbus_argument args[]);
154
155 int wpa_dbus_property_register(
156         struct wpa_dbus_object_desc *obj_dsc,
157         const char *dbus_interface, const char *dbus_property,
158         const char *type,
159         WPADBusPropertyAccessor getter,
160         WPADBusPropertyAccessor setter,
161         enum dbus_prop_access _access);
162
163 void wpa_dbus_signal_property_changed(struct wpas_dbus_priv *iface,
164                                       WPADBusPropertyAccessor property_getter,
165                                       void *getter_arg,
166                                       const char *path,
167                                       const char *interface_name,
168                                       const char *property_name);
169
170 void wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
171                                     const char *path, const char *interface,
172                                     DBusMessageIter *dict_iter);
173
174 DBusMessage * wpa_dbus_introspect(DBusMessage *message,
175                                   struct wpa_dbus_object_desc *obj_dsc);
176
177 #endif /* WPA_DBUS_CTRL_H */