1 /*
2  * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19 
20 #ifndef __LIBTRACKER_COMMON_DBUS_H__
21 #define __LIBTRACKER_COMMON_DBUS_H__
22 
23 #include <gio/gio.h>
24 
25 G_BEGIN_DECLS
26 
27 #if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
28 #error "only <libtracker-common/tracker-common.h> must be included directly."
29 #endif
30 
31 /* Allow bus type override by env var TRACKER_BUS_TYPE */
32 #define TRACKER_IPC_BUS           tracker_ipc_bus()
33 
34 #define TRACKER_DBUS_ERROR_DOMAIN "TrackerDBus"
35 #define TRACKER_DBUS_ERROR        tracker_dbus_error_quark()
36 
37 #define tracker_gdbus_async_return_if_fail(expr,invocation)	\
38 	G_STMT_START { \
39 		if G_LIKELY(expr) { } else { \
40 			GError *assert_error = NULL; \
41 	  \
42 			g_set_error (&assert_error, \
43 			             TRACKER_DBUS_ERROR, \
44 			             TRACKER_DBUS_ERROR_ASSERTION_FAILED, \
45 			             "Assertion `%s' failed", \
46 			             #expr); \
47 	  \
48 			g_dbus_method_invocation_return_gerror (invocation, assert_error); \
49 			g_clear_error (&assert_error); \
50 	  \
51 			return; \
52 		}; \
53 	} G_STMT_END
54 
55 typedef struct _TrackerDBusRequest TrackerDBusRequest;
56 
57 typedef enum {
58 	TRACKER_DBUS_EVENTS_TYPE_ADD,
59 	TRACKER_DBUS_EVENTS_TYPE_UPDATE,
60 	TRACKER_DBUS_EVENTS_TYPE_DELETE
61 } TrackerDBusEventsType;
62 
63 typedef enum {
64 	TRACKER_DBUS_ERROR_ASSERTION_FAILED,
65 	TRACKER_DBUS_ERROR_UNSUPPORTED,
66 	TRACKER_DBUS_ERROR_BROKEN_PIPE
67 } TrackerDBusError;
68 
69 
70 GBusType            tracker_ipc_bus                    (void);
71 
72 GQuark              tracker_dbus_error_quark           (void);
73 
74 /* Utils */
75 gchar **            tracker_dbus_slist_to_strv         (GSList                     *list);
76 
77 /* Requests */
78 TrackerDBusRequest *tracker_dbus_request_begin         (const gchar                *sender,
79                                                         const gchar                *format,
80                                                         ...);
81 void                tracker_dbus_request_end           (TrackerDBusRequest         *request,
82                                                         GError                     *error);
83 void                tracker_dbus_request_comment       (TrackerDBusRequest         *request,
84                                                         const gchar                *format,
85                                                         ...);
86 void                tracker_dbus_request_info          (TrackerDBusRequest         *request,
87                                                         const gchar                *format,
88                                                         ...);
89 void                tracker_dbus_request_debug         (TrackerDBusRequest         *request,
90                                                         const gchar                *format,
91                                                         ...);
92 
93 void                tracker_dbus_enable_client_lookup  (gboolean                    enable);
94 
95 gboolean            tracker_dbus_request_name (GDBusConnection  *connection,
96                                                const gchar      *name,
97                                                GError          **error);
98 
99 /* GDBus convenience API */
100 TrackerDBusRequest *tracker_g_dbus_request_begin       (GDBusMethodInvocation      *invocation,
101                                                         const gchar                *format,
102                                                         ...);
103 
104 G_END_DECLS
105 
106 #endif /* __LIBTRACKER_COMMON_DBUS_H__ */
107