1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-glib.h GLib integration
3  *
4  * Copyright (C) 2002, 2003  CodeFactory AB
5  * Copyright (C) 2003, 2004 Red Hat, Inc.
6  *
7  * SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
8  *
9  * Licensed under the Academic Free License version 2.1
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  *
25  */
26 #ifndef DBUS_GLIB_H
27 #define DBUS_GLIB_H
28 
29 #include <glib-object.h>
30 #include <dbus/dbus-shared.h>
31 
32 G_BEGIN_DECLS
33 
34 #define DBUS_INSIDE_DBUS_GLIB_H 1
35 
36 
37 /*
38  * Convert to DBusConnection with dbus_g_connection_get_connection() in dbus-glib-lowlevel.h
39  */
40 typedef struct _DBusGConnection DBusGConnection;
41 /*
42  * Convert to DBusMessage with dbus_g_message_get_message() in dbus-glib-lowlevel.h
43  */
44 typedef struct _DBusGMessage DBusGMessage;
45 
46 
47 #define DBUS_TYPE_G_CONNECTION   (dbus_g_connection_get_g_type ())
48 #define DBUS_TYPE_G_MESSAGE      (dbus_g_message_get_g_type ())
49 GType dbus_g_connection_get_g_type   (void) G_GNUC_CONST;
50 GType dbus_g_message_get_g_type      (void) G_GNUC_CONST;
51 
52 
53 DBusGConnection*  dbus_g_connection_ref          (DBusGConnection        *connection);
54 void              dbus_g_connection_unref        (DBusGConnection        *connection);
55 DBusGMessage*     dbus_g_message_ref             (DBusGMessage           *message);
56 void              dbus_g_message_unref           (DBusGMessage           *message);
57 
58 void              dbus_g_connection_flush        (DBusGConnection        *connection);
59 
60 GQuark dbus_g_error_quark (void);
61 #define DBUS_GERROR dbus_g_error_quark ()
62 
63 typedef enum
64 {
65 DBUS_GERROR_FAILED,
66 DBUS_GERROR_NO_MEMORY,
67 DBUS_GERROR_SERVICE_UNKNOWN,
68 DBUS_GERROR_NAME_HAS_NO_OWNER,
69 DBUS_GERROR_NO_REPLY,
70 DBUS_GERROR_IO_ERROR,
71 DBUS_GERROR_BAD_ADDRESS,
72 DBUS_GERROR_NOT_SUPPORTED,
73 DBUS_GERROR_LIMITS_EXCEEDED,
74 DBUS_GERROR_ACCESS_DENIED,
75 DBUS_GERROR_AUTH_FAILED,
76 DBUS_GERROR_NO_SERVER,
77 DBUS_GERROR_TIMEOUT,
78 DBUS_GERROR_NO_NETWORK,
79 DBUS_GERROR_ADDRESS_IN_USE,
80 DBUS_GERROR_DISCONNECTED,
81 DBUS_GERROR_INVALID_ARGS,
82 DBUS_GERROR_FILE_NOT_FOUND,
83 DBUS_GERROR_FILE_EXISTS,
84 DBUS_GERROR_UNKNOWN_METHOD,
85 DBUS_GERROR_TIMED_OUT,
86 DBUS_GERROR_MATCH_RULE_NOT_FOUND,
87 DBUS_GERROR_MATCH_RULE_INVALID,
88 DBUS_GERROR_SPAWN_EXEC_FAILED,
89 DBUS_GERROR_SPAWN_FORK_FAILED,
90 DBUS_GERROR_SPAWN_CHILD_EXITED,
91 DBUS_GERROR_SPAWN_CHILD_SIGNALED,
92 DBUS_GERROR_SPAWN_FAILED,
93 DBUS_GERROR_UNIX_PROCESS_ID_UNKNOWN,
94 DBUS_GERROR_INVALID_SIGNATURE,
95 DBUS_GERROR_INVALID_FILE_CONTENT,
96 DBUS_GERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN,
97 DBUS_GERROR_REMOTE_EXCEPTION
98 } DBusGError;
99 
100 gboolean         dbus_g_error_has_name    (GError      *error,
101 					   const char  *name);
102 const char *     dbus_g_error_get_name    (GError      *error);
103 
104 void             dbus_g_thread_init (void);
105 
106 DBusGConnection* dbus_g_connection_open (const gchar  *address,
107                                          GError      **error);
108 DBusGConnection* dbus_g_connection_open_private (const gchar  *address,
109                                                  GMainContext *context,
110                                                  GError      **error);
111 DBusGConnection* dbus_g_bus_get         (DBusBusType   type,
112                                          GError      **error);
113 DBusGConnection* dbus_g_bus_get_private (DBusBusType   type,
114                                          GMainContext *context,
115                                          GError      **error);
116 
117 
118 typedef struct _DBusGObjectInfo DBusGObjectInfo;
119 typedef struct _DBusGMethodInfo DBusGMethodInfo;
120 
121 /**
122  * DBusGMethodInfo:
123  * @function: C method to invoke
124  * @marshaller: Marshaller to invoke method
125  * @data_offset: Offset into the introspection data
126  *
127  * Object typically generated by #dbus-binding-tool that
128  * stores a mapping from introspection data to a
129  * function pointer for a C method to be invoked.
130  */
131 struct _DBusGMethodInfo
132 {
133   GCallback                 function;
134   GClosureMarshal           marshaller;
135   int                       data_offset;
136 };
137 
138 /**
139  * DBusGObjectInfo:
140  * @format_version: Allows us to change the rest of this struct
141  *   by adding DBusGObjectInfo2, DBusGObjectInfo3, etc.
142  * @method_infos:  Array of method pointers
143  * @n_method_infos: Length of the infos array
144  * @data: Introspection data
145  * @exported_signals: Exported signals
146  * @exported_properties: Exported properties
147  *
148  * Introspection data for a #GObject, normally autogenerated by
149  * a tool such as #dbus-binding-tool.
150  */
151 struct _DBusGObjectInfo
152 {
153   int   format_version;
154 
155   const DBusGMethodInfo *method_infos;
156   int   n_method_infos;
157   const char *data;
158   const char *exported_signals;
159   const char *exported_properties;
160 };
161 
162 void       dbus_glib_global_set_disable_legacy_property_access (void);
163 
164 void       dbus_g_object_type_install_info     (GType                 object_type,
165                                                 const DBusGObjectInfo *info);
166 
167 void       dbus_g_object_type_register_shadow_property (GType         iface_type,
168                                                         const char    *dbus_prop_name,
169                                                         const char    *shadow_prop_name);
170 
171 void       dbus_g_error_domain_register        (GQuark                domain,
172 						const char *          default_iface,
173 						GType                 code_enum);
174 
175 void       dbus_g_connection_register_g_object (DBusGConnection       *connection,
176 						const char            *at_path,
177 						GObject               *object);
178 void       dbus_g_connection_unregister_g_object (DBusGConnection *connection,
179                                                   GObject *object);
180 GObject *  dbus_g_connection_lookup_g_object   (DBusGConnection       *connection,
181 						const char            *at_path);
182 
183 #ifdef DBUS_COMPILATION
184 #include "dbus/dbus-gtype-specialized.h"
185 #else
186 #include <dbus/dbus-gtype-specialized.h>
187 #endif
188 
189 /* definitions for some basic array types */
190 #define DBUS_TYPE_G_BOOLEAN_ARRAY  (dbus_g_type_get_collection ("GArray", G_TYPE_BOOLEAN))
191 #define DBUS_TYPE_G_UCHAR_ARRAY    (dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR))
192 #define DBUS_TYPE_G_UINT_ARRAY     (dbus_g_type_get_collection ("GArray", G_TYPE_UINT))
193 #define DBUS_TYPE_G_INT_ARRAY      (dbus_g_type_get_collection ("GArray", G_TYPE_INT))
194 #define DBUS_TYPE_G_UINT64_ARRAY   (dbus_g_type_get_collection ("GArray", G_TYPE_UINT64))
195 #define DBUS_TYPE_G_INT64_ARRAY    (dbus_g_type_get_collection ("GArray", G_TYPE_INT64))
196 #define DBUS_TYPE_G_OBJECT_ARRAY   (dbus_g_type_get_collection ("GPtrArray", G_TYPE_OBJECT))
197 
198 #define DBUS_TYPE_G_STRING_STRING_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
199 
200 typedef gchar DBusGObjectPath;
201 GType        dbus_g_object_path_get_g_type         (void) G_GNUC_CONST;
202 #define DBUS_TYPE_G_OBJECT_PATH (dbus_g_object_path_get_g_type ())
203 
204 typedef gchar DBusGSignature;
205 GType        dbus_g_signature_get_g_type           (void) G_GNUC_CONST;
206 #define DBUS_TYPE_G_SIGNATURE (dbus_g_signature_get_g_type ())
207 
208 void         dbus_g_object_register_marshaller      (GClosureMarshal  marshaller,
209 						     GType            rettype,
210 						     ...);
211 void         dbus_g_object_register_marshaller_array(GClosureMarshal  marshaller,
212 						     GType            rettype,
213 						     guint            n_types,
214 						     const GType*     types);
215 
216 typedef struct _DBusGProxy       DBusGProxy;
217 typedef struct _DBusGProxyClass  DBusGProxyClass;
218 
219 #define DBUS_TYPE_G_PROXY              (dbus_g_proxy_get_type ())
220 #define DBUS_G_PROXY(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), DBUS_TYPE_G_PROXY, DBusGProxy))
221 #define DBUS_G_PROXY_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_TYPE_G_PROXY, DBusGProxyClass))
222 #define DBUS_IS_G_PROXY(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), DBUS_TYPE_G_PROXY))
223 #define DBUS_IS_G_PROXY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_TYPE_G_PROXY))
224 #define DBUS_G_PROXY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_TYPE_G_PROXY, DBusGProxyClass))
225 
226 struct _DBusGProxy
227 {
228   /*< private >*/
229   GObject parent;
230 };
231 
232 struct _DBusGProxyClass
233 {
234   /*< private >*/
235   GObjectClass parent_class;  /**< Parent class */
236 };
237 
238 typedef struct _DBusGProxyCall DBusGProxyCall;
239 typedef void (* DBusGProxyCallNotify) (DBusGProxy       *proxy,
240 				       DBusGProxyCall   *call_id,
241 				       void             *user_data);
242 
243 GType             dbus_g_proxy_get_type              (void) G_GNUC_CONST;
244 DBusGProxy*       dbus_g_proxy_new_for_name          (DBusGConnection   *connection,
245                                                       const char        *name,
246                                                       const char        *path,
247                                                       const char        *iface);
248 DBusGProxy*       dbus_g_proxy_new_for_name_owner    (DBusGConnection   *connection,
249                                                       const char        *name,
250                                                       const char        *path,
251                                                       const char        *iface,
252                                                       GError           **error);
253 DBusGProxy*       dbus_g_proxy_new_from_proxy        (DBusGProxy        *proxy,
254                                                       const char        *iface,
255                                                       const char        *path);
256 DBusGProxy*       dbus_g_proxy_new_for_peer          (DBusGConnection   *connection,
257                                                       const char        *path,
258                                                       const char        *iface);
259 
260 void              dbus_g_proxy_set_interface         (DBusGProxy        *proxy,
261 						      const char        *interface_name);
262 void              dbus_g_proxy_add_signal            (DBusGProxy        *proxy,
263 						      const char        *signal_name,
264 						      GType              first_type,
265 						      ...);
266 
267 void              dbus_g_proxy_connect_signal        (DBusGProxy        *proxy,
268                                                       const char        *signal_name,
269                                                       GCallback          handler,
270                                                       void              *data,
271                                                       GClosureNotify     free_data_func);
272 void              dbus_g_proxy_disconnect_signal     (DBusGProxy        *proxy,
273                                                       const char        *signal_name,
274                                                       GCallback          handler,
275                                                       void              *data);
276 
277 gboolean          dbus_g_proxy_call                  (DBusGProxy        *proxy,
278 						      const char        *method,
279 						      GError           **error,
280 						      GType              first_arg_type,
281 						      ...);
282 
283 gboolean          dbus_g_proxy_call_with_timeout     (DBusGProxy        *proxy,
284 				                      const char       *method,
285 	                   			      int timeout,
286                    				      GError           **error,
287                    				      GType              first_arg_type,
288 				                      ...);
289 
290 void              dbus_g_proxy_call_no_reply         (DBusGProxy        *proxy,
291                                                       const char        *method,
292                                                       GType              first_arg_type,
293                                                       ...);
294 
295 DBusGProxyCall *  dbus_g_proxy_begin_call            (DBusGProxy        *proxy,
296                                                       const char        *method,
297 						      DBusGProxyCallNotify notify,
298 						      gpointer           user_data,
299 						      GDestroyNotify     destroy,
300                                                       GType              first_arg_type,
301                                                       ...);
302 DBusGProxyCall * dbus_g_proxy_begin_call_with_timeout (DBusGProxy        *proxy,
303 		                                       const char       *method,
304 		                                       DBusGProxyCallNotify notify,
305                                                        gpointer       user_data,
306                                                        GDestroyNotify   destroy,
307                                                        int timeout,
308                                                        GType             first_arg_type,
309 				                       ...);
310 
311 void              dbus_g_proxy_set_default_timeout   (DBusGProxy        *proxy,
312                                                       int                timeout);
313 
314 gboolean          dbus_g_proxy_end_call              (DBusGProxy        *proxy,
315                                                       DBusGProxyCall    *call,
316                                                       GError           **error,
317                                                       GType              first_arg_type,
318                                                       ...);
319 void              dbus_g_proxy_cancel_call           (DBusGProxy        *proxy,
320                                                       DBusGProxyCall    *call);
321 
322 const char*       dbus_g_proxy_get_path              (DBusGProxy        *proxy);
323 
324 const char*       dbus_g_proxy_get_bus_name          (DBusGProxy        *proxy);
325 
326 const char*       dbus_g_proxy_get_interface         (DBusGProxy        *proxy);
327 
328 typedef struct _DBusGMethodInvocation DBusGMethodInvocation;
329 
330 void              dbus_g_method_return               (DBusGMethodInvocation *context, ...);
331 
332 void              dbus_g_method_return_error         (DBusGMethodInvocation *context, const GError *error);
333 
334 DBusGConnection * dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context);
335 
336 /* Probably possible to replace this with a closure */
337 typedef struct {
338   GCallback cb;
339   gpointer userdata;
340 } DBusGAsyncData;
341 
342 #undef DBUS_INSIDE_DBUS_GLIB_H
343 
344 #include <dbus/dbus-gvalue-parse-variant.h>
345 
346 G_END_DECLS
347 
348 #endif /* DBUS_GLIB_H */
349