3 * D-Bus++ - C++ bindings for D-Bus
5 * Copyright (C) 2005-2009 Paolo Durante <shackan@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <dbus-c++/pendingcall.h>
30 #include <dbus/dbus.h>
32 #include "internalerror.h"
33 #include "pendingcall_p.h"
34 #include "message_p.h"
38 PendingCall::Private::Private(DBusPendingCall
*dpc
, ObjectProxy
*p
, const PendingCallSlot
&s
, void* data
)
39 : call(dpc
), proxy(p
), slot(s
), dataslot(-1)
41 if (!dbus_pending_call_allocate_data_slot(&dataslot
))
43 throw ErrorNoMemory("Unable to allocate data slot");
46 if (!dbus_pending_call_set_data(call
, dataslot
, data
, NULL
))
48 throw ErrorNoMemory("Unable to initialize data slot");
51 if (!dbus_pending_call_set_notify(call
, Private::notify_stub
, this, NULL
))
53 throw ErrorNoMemory("Unable to initialize pending call");
57 PendingCall::Private::~Private()
61 dbus_pending_call_free_data_slot(&dataslot
);
65 void PendingCall::Private::notify_stub(DBusPendingCall
*dpc
, void *data
)
67 PendingCall::Private
*pvt
= static_cast<PendingCall::Private
*>(data
);
69 pvt
->slot(*(pvt
->token
));
71 pvt
->proxy
->_pending
.erase(pvt
->token
);
74 PendingCall::PendingCall()
77 PendingCall::PendingCall(PendingCall::Private
*pvt
)
80 pvt
->token
= pvt
->proxy
->_pending
.insert(*this);
83 PendingCall::PendingCall(const PendingCall
&c
)
86 if (_pvt
.get()) dbus_pending_call_ref(_pvt
->call
);
89 PendingCall::~PendingCall()
91 if (_pvt
.get()) dbus_pending_call_unref(_pvt
->call
);
94 PendingCall
&PendingCall::operator = (const PendingCall
&c
)
98 if (_pvt
.get()) dbus_pending_call_unref(_pvt
->call
);
100 if (_pvt
.get()) dbus_pending_call_ref(_pvt
->call
);
105 bool PendingCall::operator == (const PendingCall
&c
) const
107 return _pvt
== c
._pvt
;
110 bool PendingCall::completed() const
112 return dbus_pending_call_get_completed(_pvt
->call
);
115 void PendingCall::cancel()
117 dbus_pending_call_cancel(_pvt
->call
);
118 _pvt
->proxy
->_pending
.erase(_pvt
->token
);
121 void PendingCall::block()
123 dbus_pending_call_block(_pvt
->call
);
126 void PendingCall::data(void *p
)
128 if (!dbus_pending_call_set_data(_pvt
->call
, _pvt
->dataslot
, p
, NULL
))
130 throw ErrorNoMemory("Unable to initialize data slot");
134 void *PendingCall::data() const
136 return dbus_pending_call_get_data(_pvt
->call
, _pvt
->dataslot
);
139 const PendingCallSlot
&PendingCall::slot() const