~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/libs/dbus-c++/src/object.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
using namespace DBus;
41
41
 
42
42
Object::Object (Connection &conn, const Path &path, const char *service)
43
 
        : _conn (conn), _path (path), _service (service ? service : "")
44
 
{
 
43
        : _conn (conn), _path (path), _service (service ? service : "") {
45
44
}
46
45
 
47
 
Object::~Object()
48
 
{
 
46
Object::~Object() {
49
47
}
50
48
 
51
49
struct ObjectAdaptor::Private {
59
57
    NULL, NULL, NULL, NULL
60
58
};
61
59
 
62
 
void ObjectAdaptor::Private::unregister_function_stub (DBusConnection *conn, void *data)
63
 
{
 
60
void ObjectAdaptor::Private::unregister_function_stub (DBusConnection *conn, void *data) {
64
61
    //TODO: what do we have to do here ?
65
62
}
66
63
 
67
 
DBusHandlerResult ObjectAdaptor::Private::message_function_stub (DBusConnection *, DBusMessage *dmsg, void *data)
68
 
{
 
64
DBusHandlerResult ObjectAdaptor::Private::message_function_stub (DBusConnection *, DBusMessage *dmsg, void *data) {
69
65
    ObjectAdaptor *o = static_cast<ObjectAdaptor *> (data);
70
66
 
71
67
    if (o) {
89
85
typedef std::map<Path, ObjectAdaptor *> ObjectAdaptorTable;
90
86
static ObjectAdaptorTable _adaptor_table;
91
87
 
92
 
ObjectAdaptor *ObjectAdaptor::from_path (const Path &path)
93
 
{
 
88
ObjectAdaptor *ObjectAdaptor::from_path (const Path &path) {
94
89
    ObjectAdaptorTable::iterator ati = _adaptor_table.find (path);
95
90
 
96
91
    if (ati != _adaptor_table.end())
99
94
    return NULL;
100
95
}
101
96
 
102
 
ObjectAdaptorPList ObjectAdaptor::from_path_prefix (const std::string &prefix)
103
 
{
 
97
ObjectAdaptorPList ObjectAdaptor::from_path_prefix (const std::string &prefix) {
104
98
    ObjectAdaptorPList ali;
105
99
 
106
100
    ObjectAdaptorTable::iterator ati = _adaptor_table.begin();
117
111
    return ali;
118
112
}
119
113
 
120
 
ObjectPathList ObjectAdaptor::child_nodes_from_prefix (const std::string &prefix)
121
 
{
 
114
ObjectPathList ObjectAdaptor::child_nodes_from_prefix (const std::string &prefix) {
122
115
    ObjectPathList ali;
123
116
 
124
117
    ObjectAdaptorTable::iterator ati = _adaptor_table.begin();
143
136
}
144
137
 
145
138
ObjectAdaptor::ObjectAdaptor (Connection &conn, const Path &path)
146
 
        : Object (conn, path, conn.unique_name())
147
 
{
 
139
        : Object (conn, path, conn.unique_name()) {
148
140
    register_obj();
149
141
}
150
142
 
151
 
ObjectAdaptor::~ObjectAdaptor()
152
 
{
 
143
ObjectAdaptor::~ObjectAdaptor() {
153
144
    unregister_obj();
154
145
}
155
146
 
156
 
void ObjectAdaptor::register_obj()
157
 
{
 
147
void ObjectAdaptor::register_obj() {
158
148
    debug_log ("registering local object %s", path().c_str());
159
149
 
160
150
    if (!dbus_connection_register_object_path (conn()._pvt->conn, path().c_str(), &_vtable, this)) {
164
154
    _adaptor_table[path() ] = this;
165
155
}
166
156
 
167
 
void ObjectAdaptor::unregister_obj()
168
 
{
 
157
void ObjectAdaptor::unregister_obj() {
169
158
    _adaptor_table.erase (path());
170
159
 
171
160
    debug_log ("unregistering local object %s", path().c_str());
173
162
    dbus_connection_unregister_object_path (conn()._pvt->conn, path().c_str());
174
163
}
175
164
 
176
 
void ObjectAdaptor::_emit_signal (SignalMessage &sig)
177
 
{
 
165
void ObjectAdaptor::_emit_signal (SignalMessage &sig) {
178
166
    sig.path (path().c_str());
179
167
 
180
168
    conn().send (sig);
184
172
    const Tag *tag;
185
173
};
186
174
 
187
 
bool ObjectAdaptor::handle_message (const Message &msg)
188
 
{
 
175
bool ObjectAdaptor::handle_message (const Message &msg) {
189
176
    switch (msg.type()) {
190
177
 
191
178
        case DBUS_MESSAGE_TYPE_METHOD_CALL: {
221
208
    }
222
209
}
223
210
 
224
 
void ObjectAdaptor::return_later (const Tag *tag)
225
 
{
 
211
void ObjectAdaptor::return_later (const Tag *tag) {
226
212
    ReturnLaterError rle = { tag };
227
213
    throw rle;
228
214
}
229
215
 
230
 
void ObjectAdaptor::return_now (Continuation *ret)
231
 
{
 
216
void ObjectAdaptor::return_now (Continuation *ret) {
232
217
    ret->_conn.send (ret->_return);
233
218
 
234
219
    ContinuationMap::iterator di = _continuations.find (ret->_tag);
238
223
    _continuations.erase (di);
239
224
}
240
225
 
241
 
void ObjectAdaptor::return_error (Continuation *ret, const Error error)
242
 
{
 
226
void ObjectAdaptor::return_error (Continuation *ret, const Error error) {
243
227
    ret->_conn.send (ErrorMessage (ret->_call, error.name(), error.message()));
244
228
 
245
229
    ContinuationMap::iterator di = _continuations.find (ret->_tag);
249
233
    _continuations.erase (di);
250
234
}
251
235
 
252
 
ObjectAdaptor::Continuation *ObjectAdaptor::find_continuation (const Tag *tag)
253
 
{
 
236
ObjectAdaptor::Continuation *ObjectAdaptor::find_continuation (const Tag *tag) {
254
237
    ContinuationMap::iterator di = _continuations.find (tag);
255
238
 
256
239
    return di != _continuations.end() ? di->second : NULL;
257
240
}
258
241
 
259
242
ObjectAdaptor::Continuation::Continuation (Connection &conn, const CallMessage &call, const Tag *tag)
260
 
        : _conn (conn), _call (call), _return (_call), _tag (tag)
261
 
{
 
243
        : _conn (conn), _call (call), _return (_call), _tag (tag) {
262
244
    _writer = _return.writer(); //todo: verify
263
245
}
264
246
 
266
248
*/
267
249
 
268
250
ObjectProxy::ObjectProxy (Connection &conn, const Path &path, const char *service)
269
 
        : Object (conn, path, service)
270
 
{
 
251
        : Object (conn, path, service) {
271
252
    register_obj();
272
253
}
273
254
 
274
 
ObjectProxy::~ObjectProxy()
275
 
{
 
255
ObjectProxy::~ObjectProxy() {
276
256
    unregister_obj();
277
257
}
278
258
 
279
 
void ObjectProxy::register_obj()
280
 
{
 
259
void ObjectProxy::register_obj() {
281
260
    debug_log ("registering remote object %s", path().c_str());
282
261
 
283
262
    _filtered = new Callback<ObjectProxy, bool, const Message &> (this, &ObjectProxy::handle_message);
293
272
    }
294
273
}
295
274
 
296
 
void ObjectProxy::unregister_obj()
297
 
{
 
275
void ObjectProxy::unregister_obj() {
298
276
    debug_log ("unregistering remote object %s", path().c_str());
299
277
 
300
278
    InterfaceProxyTable::const_iterator ii = _interfaces.begin();
308
286
    conn().remove_filter (_filtered);
309
287
}
310
288
 
311
 
Message ObjectProxy::_invoke_method (CallMessage &call)
312
 
{
 
289
Message ObjectProxy::_invoke_method (CallMessage &call) {
313
290
    if (call.path() == NULL)
314
291
        call.path (path().c_str());
315
292
 
319
296
    return conn().send_blocking (call);
320
297
}
321
298
 
322
 
bool ObjectProxy::_invoke_method_noreply (CallMessage &call)
323
 
{
 
299
bool ObjectProxy::_invoke_method_noreply (CallMessage &call) {
324
300
    if (call.path() == NULL)
325
301
        call.path (path().c_str());
326
302
 
330
306
    return conn().send (call);
331
307
}
332
308
 
333
 
bool ObjectProxy::handle_message (const Message &msg)
334
 
{
 
309
bool ObjectProxy::handle_message (const Message &msg) {
335
310
    switch (msg.type()) {
336
311
 
337
312
        case DBUS_MESSAGE_TYPE_SIGNAL: {