dbus: Define priv argument for object rather than for method
[mech_eap.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
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 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
56
57 #ifndef SIGPOLL
58 #ifdef SIGIO
59 /*
60  * If we do not have SIGPOLL, try to use SIGIO instead. This is needed for
61  * FreeBSD.
62  */
63 #define SIGPOLL SIGIO
64 #endif
65 #endif
66
67 #define WPAS_DBUS_OBJECT_PATH_MAX 150
68 #define WPAS_DBUS_INTERFACE_MAX 150
69 #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
70
71 #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
72 #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
73 #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
74 #define WPA_DBUS_PROPERTIES_GET "Get"
75 #define WPA_DBUS_PROPERTIES_SET "Set"
76 #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
77
78 void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
79
80 int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
81                              char *dbus_service,
82                              struct wpa_dbus_object_desc *obj_desc);
83
84 int wpa_dbus_register_object_per_iface(
85         struct wpas_dbus_priv *ctrl_iface,
86         const char *path, const char *ifname,
87         struct wpa_dbus_object_desc *obj_desc);
88
89 int wpa_dbus_unregister_object_per_iface(
90         struct wpas_dbus_priv *ctrl_iface,
91         const char *path);
92
93 int wpa_dbus_method_register(struct wpa_dbus_object_desc *obj_dsc,
94                              const char *dbus_interface,
95                              const char *dbus_method,
96                              WPADBusMethodHandler method_handler,
97                              const struct wpa_dbus_argument args[]);
98
99 int wpa_dbus_signal_register(struct wpa_dbus_object_desc *obj_dsc,
100                              const char *dbus_interface,
101                              const char *dbus_signal,
102                              const struct wpa_dbus_argument args[]);
103
104 int wpa_dbus_property_register(
105         struct wpa_dbus_object_desc *obj_dsc,
106         const char *dbus_interface, const char *dbus_property,
107         const char *type,
108         WPADBusPropertyAccessor getter,
109         WPADBusPropertyAccessor setter,
110         enum dbus_prop_access _access);
111
112 void wpa_dbus_signal_property_changed(struct wpas_dbus_priv *iface,
113                                       WPADBusPropertyAccessor property_getter,
114                                       void *getter_arg,
115                                       const char *path,
116                                       const char *interface_name,
117                                       const char *property_name);
118
119
120 #else /* CONFIG_CTRL_IFACE_DBUS_NEW */
121
122 static inline void wpa_dbus_signal_property_changed(
123         struct wpas_dbus_priv *iface,
124         WPADBusPropertyAccessor property_getter, void *getter_arg,
125         const char *path, const char *interface_name,
126         const char *property_name)
127 {
128 }
129
130 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
131
132 #endif /* WPA_DBUS_CTRL_H */