Add copy of libgdbus helper for easier adoption
[framework/connectivity/connman.git] / gdbus / gdbus.h
1 /*
2  *
3  *  D-Bus helper library
4  *
5  *  Copyright (C) 2004-2008  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) (void *user_data);
35
36 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
37                                         DBusMessage *message, void *user_data);
38
39 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
40                                                         DBusError *error);
41
42 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
43                                                         DBusError *error);
44
45 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
46                                 GDBusWatchFunction function,
47                                 void *user_data, DBusFreeFunction destroy);
48
49 typedef void (* GDBusDestroyFunction) (void *user_data);
50
51 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
52                                         DBusMessage *message, void *user_data);
53
54 typedef enum {
55         G_DBUS_METHOD_FLAG_DEPRECATED = (1 << 0),
56         G_DBUS_METHOD_FLAG_NOREPLY    = (1 << 1),
57         G_DBUS_METHOD_FLAG_ASYNC      = (1 << 2),
58 } GDBusMethodFlags;
59
60 typedef enum {
61         G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
62 } GDBusSignalFlags;
63
64 typedef enum {
65         G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
66 } GDBusPropertyFlags;
67
68 typedef struct {
69         const char *name;
70         const char *signature;
71         const char *reply;
72         GDBusMethodFunction function;
73         GDBusMethodFlags flags;
74 } GDBusMethodTable;
75
76 typedef struct {
77         const char *name;
78         const char *signature;
79         GDBusSignalFlags flags;
80 } GDBusSignalTable;
81
82 typedef struct {
83         const char *name;
84         const char *type;
85         GDBusPropertyFlags flags;
86 } GDBusPropertyTable;
87
88 gboolean g_dbus_register_interface(DBusConnection *connection,
89                                         const char *path, const char *name,
90                                         GDBusMethodTable *methods,
91                                         GDBusSignalTable *signals,
92                                         GDBusPropertyTable *properties,
93                                         void *user_data,
94                                         GDBusDestroyFunction destroy);
95 gboolean g_dbus_unregister_interface(DBusConnection *connection,
96                                         const char *path, const char *name);
97
98 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
99                                                 const char *format, ...);
100 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
101                                         const char *format, va_list args);
102 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
103 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
104                                                 int type, va_list args);
105
106 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
107 gboolean g_dbus_send_reply(DBusConnection *connection,
108                                 DBusMessage *message, int type, ...);
109 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
110                                 DBusMessage *message, int type, va_list args);
111
112 gboolean g_dbus_emit_signal(DBusConnection *connection,
113                                 const char *path, const char *interface,
114                                 const char *name, int type, ...);
115 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
116                                 const char *path, const char *interface,
117                                 const char *name, int type, va_list args);
118
119 guint g_dbus_add_disconnect_watch(DBusConnection *connection,
120                                 const char *name,
121                                 GDBusWatchFunction function,
122                                 void *user_data, GDBusDestroyFunction destroy);
123 guint g_dbus_add_signal_watch(DBusConnection *connection,
124                                 const char *rule, GDBusSignalFunction function,
125                                 void *user_data, GDBusDestroyFunction destroy);
126 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
127 void g_dbus_remove_all_watches(DBusConnection *connection);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif /* __GDBUS_H */