File: dbus.h

package info (click to toggle)
seed 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,900 kB
  • sloc: ansic: 24,336; sh: 11,196; makefile: 773; xml: 187; python: 173
file content (216 lines) | stat: -rw-r--r-- 10,354 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* Copyright 2008 litl, LLC. All Rights Reserved. */

#ifndef __BIG_UTIL_DBUS_H__
#define __BIG_UTIL_DBUS_H__

#include <glib-object.h>
#include <dbus/dbus.h>

G_BEGIN_DECLS

/* Convenience macro */

#define BIG_DBUS_NAME_FROM_TYPE(type) ((type) == DBUS_BUS_SESSION ? "session" : "system")

/* Error names */
#define BIG_DBUS_ERROR_STREAM_RECEIVER_CLOSED "com.litl.Error.Stream.ReceiverClosed"

/*
 * Monitor whether we are connected / not-connected to the bus
 */

typedef void (* BigDBusConnectionOpenedFunc)   (DBusConnection *connection,
                                                void           *data);
typedef void (* BigDBusConnectionClosedFunc)   (DBusConnection *connection,
                                                void           *data);

typedef struct {
    DBusBusType which_bus;
    BigDBusConnectionOpenedFunc opened;
    BigDBusConnectionClosedFunc closed;
} BigDBusConnectFuncs;

void big_dbus_add_connect_funcs             (const BigDBusConnectFuncs *funcs,
                                             void                      *data);
void big_dbus_remove_connect_funcs          (const BigDBusConnectFuncs *funcs,
                                             void                      *data);
void big_dbus_add_connect_funcs_sync_notify (const BigDBusConnectFuncs *funcs,
                                             void                      *data);


void big_dbus_add_bus_weakref    (DBusBusType      bus_type,
                                  DBusConnection **connection_p);
void big_dbus_remove_bus_weakref (DBusBusType      bus_type,
                                  DBusConnection **connection_p);

void big_dbus_try_connecting_now (DBusBusType which_bus);

/*
 * Own a bus name
 *
 */

typedef enum {
    BIG_DBUS_NAME_SINGLE_INSTANCE,
    BIG_DBUS_NAME_MANY_INSTANCES
} BigDBusNameType;

typedef void (* BigDBusNameAcquiredFunc) (DBusConnection *connection,
                                          const char     *name,
                                          void           *data);
typedef void (* BigDBusNameLostFunc)     (DBusConnection *connection,
                                          const char     *name,
                                          void           *data);

typedef struct {
    const char *name;
    BigDBusNameType type;
    BigDBusNameAcquiredFunc acquired;
    BigDBusNameLostFunc lost;
} BigDBusNameOwnerFuncs;

guint        big_dbus_acquire_name       (DBusBusType                  bus_type,
                                          const BigDBusNameOwnerFuncs *funcs,
                                          void                        *data);
void         big_dbus_release_name       (DBusBusType                  bus_type,
                                          const BigDBusNameOwnerFuncs *funcs,
                                          void                        *data);
void         big_dbus_release_name_by_id (DBusBusType                  bus_type,
                                          guint                        id);

/*
 * Keep track of someone else's bus name
 *
 */

typedef enum {
    BIG_DBUS_NAME_START_IF_NOT_FOUND = 0x1
} BigDBusWatchNameFlags;

typedef void (* BigDBusNameAppearedFunc) (DBusConnection *connection,
                                          const char     *name,
                                          const char     *new_owner_unique_name,
                                          void           *data);
typedef void (* BigDBusNameVanishedFunc) (DBusConnection *connection,
                                          const char     *name,
                                          const char     *old_owner_unique_name,
                                          void           *data);

typedef struct {
    BigDBusNameAppearedFunc appeared;
    BigDBusNameVanishedFunc vanished;
} BigDBusWatchNameFuncs;

void        big_dbus_watch_name             (DBusBusType                  bus_type,
                                             const char                  *name,
                                             BigDBusWatchNameFlags        flags,
                                             const BigDBusWatchNameFuncs *funcs,
                                             void                        *data);
void        big_dbus_unwatch_name           (DBusBusType                  bus_type,
                                             const char                  *name,
                                             const BigDBusWatchNameFuncs *funcs,
                                             void                        *data);
const char* big_dbus_get_watched_name_owner (DBusBusType                  bus_type,
                                             const char                  *name);


typedef void (* BigDBusSignalHandler) (DBusConnection *connection,
                                       DBusMessage    *message,
                                       void           *data);
int big_dbus_watch_signal          (DBusBusType           bus_type,
                                    const char           *sender,
                                    const char           *path,
                                    const char           *iface,
                                    const char           *name,
                                    BigDBusSignalHandler  handler,
                                    void                 *data,
                                    GDestroyNotify        data_dnotify);
void big_dbus_unwatch_signal       (DBusBusType           bus_type,
                                    const char           *sender,
                                    const char           *path,
                                    const char           *iface,
                                    const char           *name,
                                    BigDBusSignalHandler  handler,
                                    void                 *data);
void big_dbus_unwatch_signal_by_id (DBusBusType           bus_type,
                                    int                   id);

/* A "json method" is a D-Bus method with signature
 *      DICT jsonMethodName(DICT)
 * with the idea that it both takes and returns
 * a JavaScript-style dictionary. This makes
 * our JavaScript-to-dbus bindings really simple,
 * and avoids a lot of futzing with dbus IDL.
 *
 * Of course it's completely annoying for someone
 * using D-Bus in a "normal" way but the idea is just
 * to use this to communicate within our own app
 * that happens to consist of multiple processes
 * and have bits written in JS.
 */
typedef void (* BigDBusJsonSyncMethodFunc)  (DBusConnection  *connection,
                                             DBusMessage     *message,
                                             DBusMessageIter *in_iter,
                                             DBusMessageIter *out_iter,
                                             void            *data,
                                             DBusError       *error);

typedef void (* BigDBusJsonAsyncMethodFunc) (DBusConnection  *connection,
                                             DBusMessage     *message,
                                             DBusMessageIter *in_iter,
                                             void            *data);

typedef struct {
    const char *name;
    /* one of these two but not both should be non-NULL */
    BigDBusJsonSyncMethodFunc sync_func;
    BigDBusJsonAsyncMethodFunc async_func;
} BigDBusJsonMethod;

void big_dbus_register_json       (DBusConnection          *connection,
                                   const char              *iface_name,
                                   const BigDBusJsonMethod *methods,
                                   int                      n_methods);
void big_dbus_unregister_json     (DBusConnection          *connection,
                                   const char              *iface_name);
void big_dbus_register_g_object   (DBusConnection          *connection,
                                   const char              *path,
                                   GObject                 *gobj,
                                   const char              *iface_name);
void big_dbus_unregister_g_object (DBusConnection          *connection,
                                   const char              *path);

void big_dbus_append_json_entry              (DBusMessageIter  *dict_iter,
                                              const char       *key,
                                              int               dbus_type,
                                              void             *basic_value_p);
void big_dbus_append_json_entry_STRING       (DBusMessageIter  *dict_iter,
                                              const char       *key,
                                              const char       *value);
void big_dbus_append_json_entry_INT32        (DBusMessageIter  *dict_iter,
                                              const char       *key,
                                              dbus_int32_t      value);
void big_dbus_append_json_entry_DOUBLE       (DBusMessageIter  *dict_iter,
                                              const char       *key,
                                              double            value);
void big_dbus_append_json_entry_BOOLEAN      (DBusMessageIter  *dict_iter,
                                              const char       *key,
                                              dbus_bool_t       value);
void big_dbus_append_json_entry_EMPTY_ARRAY  (DBusMessageIter  *dict_iter,
                                              const char       *key);
void big_dbus_append_json_entry_STRING_ARRAY (DBusMessageIter  *dict_iter,
                                              const char       *key,
                                              const char      **value);

gboolean big_dbus_message_iter_get_gsize  (DBusMessageIter  *iter,
                                           gsize            *value_p);
gboolean big_dbus_message_iter_get_gssize (DBusMessageIter  *iter,
                                           gssize           *value_p);

void big_dbus_start_service(DBusConnection *connection,
                            const char     *name);

G_END_DECLS

#endif  /* __BIG_UTIL_DBUS_H__ */