dbus: Share common initialization code for both old and new interface
[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                                                   void *user_data);
27
28 struct wpa_dbus_object_desc {
29         DBusConnection *connection;
30         struct wpa_dbus_method_desc *methods;
31         struct wpa_dbus_signal_desc *signals;
32         struct wpa_dbus_property_desc *properties;
33 };
34
35 enum dbus_prop_access { R, W, RW };
36
37 enum dbus_arg_direction { ARG_IN, ARG_OUT };
38
39 struct wpa_dbus_argument {
40         char *name;
41         char *type;
42         enum dbus_arg_direction dir;
43 };
44
45 #define END_ARGS { NULL, NULL, ARG_IN }
46
47 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
48
49 #ifndef SIGPOLL
50 #ifdef SIGIO
51 /*
52  * If we do not have SIGPOLL, try to use SIGIO instead. This is needed for
53  * FreeBSD.
54  */
55 #define SIGPOLL SIGIO
56 #endif
57 #endif
58
59 #define WPAS_DBUS_OBJECT_PATH_MAX 150
60 #define WPAS_DBUS_INTERFACE_MAX 150
61 #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
62
63 #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
64 #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
65 #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
66 #define WPA_DBUS_PROPERTIES_GET "Get"
67 #define WPA_DBUS_PROPERTIES_SET "Set"
68 #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
69
70 void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
71
72 int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
73                              char *dbus_service,
74                              struct wpa_dbus_object_desc *obj_desc);
75
76 int wpa_dbus_register_object_per_iface(
77         struct wpas_dbus_priv *ctrl_iface,
78         const char *path, const char *ifname,
79         struct wpa_dbus_object_desc *obj_desc);
80
81 int wpa_dbus_unregister_object_per_iface(
82         struct wpas_dbus_priv *ctrl_iface,
83         const char *path);
84
85 int wpa_dbus_method_register(struct wpa_dbus_object_desc *obj_dsc,
86                              const char *dbus_interface,
87                              const char *dbus_method,
88                              WPADBusMethodHandler method_handler,
89                              void *handler_argument,
90                              WPADBusArgumentFreeFunction argument_free_func,
91                              const struct wpa_dbus_argument args[]);
92
93 int wpa_dbus_signal_register(struct wpa_dbus_object_desc *obj_dsc,
94                              const char *dbus_interface,
95                              const char *dbus_signal,
96                              const struct wpa_dbus_argument args[]);
97
98 int wpa_dbus_property_register(
99         struct wpa_dbus_object_desc *obj_dsc,
100         const char *dbus_interface, const char *dbus_property,
101         const char *type,
102         WPADBusPropertyAccessor getter,
103         WPADBusPropertyAccessor setter,
104         void *user_data,
105         WPADBusArgumentFreeFunction user_data_free_func,
106         enum dbus_prop_access _access);
107
108 void wpa_dbus_signal_property_changed(struct wpas_dbus_priv *iface,
109                                       WPADBusPropertyAccessor property_getter,
110                                       void *getter_arg,
111                                       const char *path,
112                                       const char *interface_name,
113                                       const char *property_name);
114
115
116 #else /* CONFIG_CTRL_IFACE_DBUS_NEW */
117
118 static inline void wpa_dbus_signal_property_changed(
119         struct wpas_dbus_priv *iface,
120         WPADBusPropertyAccessor property_getter, void *getter_arg,
121         const char *path, const char *interface_name,
122         const char *property_name)
123 {
124 }
125
126 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
127
128 #endif /* WPA_DBUS_CTRL_H */