2004-05-31 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / glib / dbus-glib.h
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 Red Hat, Inc.
6  *
7  * Licensed under the Academic Free License version 2.0
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  */
24 #ifndef DBUS_GLIB_H
25 #define DBUS_GLIB_H
26
27 #include <dbus/dbus.h>
28 #include <glib-object.h>
29
30 G_BEGIN_DECLS
31
32 #define DBUS_INSIDE_DBUS_GLIB_H 1
33
34 GQuark dbus_g_error_quark (void);
35 #define DBUS_GERROR dbus_g_error_quark ()
36
37 #define DBUS_TYPE_CONNECTION (dbus_connection_get_g_type ())
38 #define DBUS_TYPE_MESSAGE    (dbus_message_get_g_type ())
39 GType dbus_connection_get_g_type (void) G_GNUC_CONST;
40 GType dbus_message_get_g_type    (void) G_GNUC_CONST;
41
42 typedef enum
43 {
44   /* FIXME map all the DBUS_ERROR to DBUS_GERROR, should
45    * probably be automated in some way, perhaps
46    * via lame perl script
47    */
48   DBUS_GERROR_FAILED
49 } DBusGError;
50
51 void dbus_set_g_error (GError   **gerror,
52                        DBusError *derror);
53
54 void            dbus_g_thread_init                (void);
55 void            dbus_connection_setup_with_g_main (DBusConnection  *connection,
56                                                    GMainContext    *context);
57 void            dbus_server_setup_with_g_main     (DBusServer      *server,
58                                                    GMainContext    *context);
59 DBusConnection* dbus_bus_get_with_g_main          (DBusBusType      type,
60                                                    GError         **error);
61
62 typedef struct DBusGObjectInfo DBusGObjectInfo;
63 typedef struct DBusGMethodInfo DBusGMethodInfo;
64
65 /**
66  * Object typically generated by dbus-glib-tool that
67  * stores a mapping from introspection data to a
68  * function pointer for a C method to be invoked.
69  */
70 struct DBusGMethodInfo
71 {
72   GCallback                 function;    /**< C method to invoke */
73   DBusHandleMessageFunction marshaller;  /**< Marshaller to go DBusMessage to C method */
74   int                       data_offset; /**< Offset into the introspection data */
75 };
76
77 /**
78  * Introspection data for a GObject, normally autogenerated by
79  * a tool such as dbus-glib-tool.
80  */
81 struct DBusGObjectInfo
82 {
83   int   format_version;         /**< Allows us to change the rest of this struct
84                                  *   by adding DBusGObjectInfo2, DBusGObjectInfo3, etc.
85                                  */
86   const DBusGMethodInfo *infos; /**< Array of method pointers */
87   const unsigned char *data;    /**< Introspection data */
88 };
89
90 void dbus_g_object_class_install_info  (GObjectClass          *object_class,
91                                         const DBusGObjectInfo *info);
92 void dbus_connection_register_g_object (DBusConnection        *connection,
93                                         const char            *at_path,
94                                         GObject               *object);
95
96
97 typedef struct DBusGProxy       DBusGProxy;
98 typedef struct DBusGProxyClass  DBusGProxyClass;
99
100 typedef void (* DBusGProxySignalHandler) (DBusGProxy  *proxy,
101                                           DBusMessage *signal,
102                                           void        *user_data);
103
104 #define DBUS_TYPE_GPROXY              (dbus_gproxy_get_type ())
105 #define DBUS_GPROXY(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), DBUS_TYPE_GPROXY, DBusGProxy))
106 #define DBUS_GPROXY_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_TYPE_GPROXY, DBusGProxyClass))
107 #define DBUS_IS_GPROXY(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), DBUS_TYPE_GPROXY))
108 #define DBUS_IS_GPROXY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_TYPE_GPROXY))
109 #define DBUS_GPROXY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_TYPE_GPROXY, DBusGProxyClass))
110
111
112 GType            dbus_gproxy_get_type              (void) G_GNUC_CONST;
113 DBusGProxy*      dbus_gproxy_new_for_service       (DBusConnection           *connection,
114                                                     const char               *service_name,
115                                                     const char               *path_name,
116                                                     const char               *interface_name);
117 DBusGProxy*      dbus_gproxy_new_for_service_owner (DBusConnection           *connection,
118                                                     const char               *service_name,
119                                                     const char               *path_name,
120                                                     const char               *interface_name,
121                                                     GError                  **error);
122 DBusGProxy*      dbus_gproxy_new_for_peer          (DBusConnection           *connection,
123                                                     const char               *path_name,
124                                                     const char               *interface_name);
125 void             dbus_gproxy_connect_signal        (DBusGProxy               *proxy,
126                                                     const char               *signal_name,
127                                                     DBusGProxySignalHandler   handler,
128                                                     void                     *data,
129                                                     GClosureNotify            free_data_func);
130 void             dbus_gproxy_disconnect_signal     (DBusGProxy               *proxy,
131                                                     const char               *signal_name,
132                                                     DBusGProxySignalHandler   handler,
133                                                     void                     *data);
134 DBusPendingCall* dbus_gproxy_begin_call            (DBusGProxy               *proxy,
135                                                     const char               *method,
136                                                     int                       first_arg_type,
137                                                     ...);
138 gboolean         dbus_gproxy_end_call              (DBusGProxy               *proxy,
139                                                     DBusPendingCall          *pending,
140                                                     GError                  **error,
141                                                     int                       first_arg_type,
142                                                     ...);
143 void             dbus_gproxy_call_no_reply         (DBusGProxy               *proxy,
144                                                     const char               *method,
145                                                     int                       first_arg_type,
146                                                     ...);
147 void             dbus_gproxy_send                  (DBusGProxy               *proxy,
148                                                     DBusMessage              *message,
149                                                     dbus_uint32_t            *client_serial);
150
151
152 #undef DBUS_INSIDE_DBUS_GLIB_H
153
154 G_END_DECLS
155
156 #endif /* DBUS_GLIB_H */
157
158
159