Do not automatically remove watches for service names
[framework/connectivity/connman.git] / gdbus / gdbus.h
1 /*
2  *
3  *  D-Bus helper library
4  *
5  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifndef __GDBUS_H
25 #define __GDBUS_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <dbus/dbus.h>
32 #include <glib.h>
33
34 typedef void (* GDBusWatchFunction) (DBusConnection *connection,
35                                                         void *user_data);
36
37 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
38                                         DBusMessage *message, void *user_data);
39
40 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
41                                                         DBusError *error);
42
43 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
44                                                         DBusError *error);
45
46 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
47                                                         DBusError *error);
48
49 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
50                                 GDBusWatchFunction function,
51                                 void *user_data, DBusFreeFunction destroy);
52
53 typedef void (* GDBusDestroyFunction) (void *user_data);
54
55 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
56                                         DBusMessage *message, void *user_data);
57
58 typedef enum {
59         G_DBUS_METHOD_FLAG_DEPRECATED = (1 << 0),
60         G_DBUS_METHOD_FLAG_NOREPLY    = (1 << 1),
61         G_DBUS_METHOD_FLAG_ASYNC      = (1 << 2),
62 } GDBusMethodFlags;
63
64 typedef enum {
65         G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
66 } GDBusSignalFlags;
67
68 typedef enum {
69         G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
70 } GDBusPropertyFlags;
71
72 typedef struct {
73         const char *name;
74         const char *signature;
75         const char *reply;
76         GDBusMethodFunction function;
77         GDBusMethodFlags flags;
78 } GDBusMethodTable;
79
80 typedef struct {
81         const char *name;
82         const char *signature;
83         GDBusSignalFlags flags;
84 } GDBusSignalTable;
85
86 typedef struct {
87         const char *name;
88         const char *type;
89         GDBusPropertyFlags flags;
90 } GDBusPropertyTable;
91
92 gboolean g_dbus_register_interface(DBusConnection *connection,
93                                         const char *path, const char *name,
94                                         const GDBusMethodTable *methods,
95                                         const GDBusSignalTable *signals,
96                                         const GDBusPropertyTable *properties,
97                                         void *user_data,
98                                         GDBusDestroyFunction destroy);
99 gboolean g_dbus_unregister_interface(DBusConnection *connection,
100                                         const char *path, const char *name);
101
102 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
103                                                 const char *format, ...)
104                                         __attribute__((format(printf, 3, 4)));
105 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
106                                         const char *format, va_list args);
107 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
108 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
109                                                 int type, va_list args);
110
111 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
112 gboolean g_dbus_send_reply(DBusConnection *connection,
113                                 DBusMessage *message, int type, ...);
114 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
115                                 DBusMessage *message, int type, va_list args);
116
117 gboolean g_dbus_emit_signal(DBusConnection *connection,
118                                 const char *path, const char *interface,
119                                 const char *name, int type, ...);
120 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
121                                 const char *path, const char *interface,
122                                 const char *name, int type, va_list args);
123
124 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
125                                 GDBusWatchFunction connect,
126                                 GDBusWatchFunction disconnect,
127                                 void *user_data, GDBusDestroyFunction destroy);
128 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
129                                 GDBusWatchFunction function,
130                                 void *user_data, GDBusDestroyFunction destroy);
131 guint g_dbus_add_signal_watch(DBusConnection *connection,
132                                 const char *sender, const char *path,
133                                 const char *interface, const char *member,
134                                 GDBusSignalFunction function, void *user_data,
135                                 GDBusDestroyFunction destroy);
136 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
137 void g_dbus_remove_all_watches(DBusConnection *connection);
138
139 #ifdef __cplusplus
140 }
141 #endif
142
143 #endif /* __GDBUS_H */