From ecd24280498e7e942104727d6547d357fb704a2a Mon Sep 17 00:00:00 2001 From: pdurante Date: Fri, 31 Aug 2007 03:15:39 +0000 Subject: [PATCH] * Async method calls makeup (Ben Martin) git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@12449 30a43799-04e7-0310-8b2b-ea0d24f86d0e --- include/dbus-c++/pendingcall.h | 11 +++++--- src/pendingcall.cpp | 50 ++++++++++++++++++++++++++++------ src/pendingcall_p.h | 3 +- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/include/dbus-c++/pendingcall.h b/include/dbus-c++/pendingcall.h index 4b9abc6..d7c64b8 100644 --- a/include/dbus-c++/pendingcall.h +++ b/include/dbus-c++/pendingcall.h @@ -31,6 +31,7 @@ #include "api.h" #include "util.h" +#include "message.h" namespace DBus { @@ -44,8 +45,12 @@ public: PendingCall( Private* ); + PendingCall( const PendingCall& ); + virtual ~PendingCall(); + PendingCall& operator = ( const PendingCall& ); + bool completed(); void cancel(); @@ -56,11 +61,9 @@ public: void* data(); - Slot slot; + Slot& slot(); -private: - - DXXAPILOCAL PendingCall( const PendingCall& ); + Message steal_reply(); private: diff --git a/src/pendingcall.cpp b/src/pendingcall.cpp index bdbcdd9..4696983 100644 --- a/src/pendingcall.cpp +++ b/src/pendingcall.cpp @@ -28,6 +28,7 @@ #include "internalerror.h" #include "pendingcall_p.h" +#include "message_p.h" using namespace DBus; @@ -40,13 +41,6 @@ PendingCall::Private::Private( DBusPendingCall* dpc ) } } -void PendingCall::Private::notify_stub( DBusPendingCall* dpc, void* data ) -{ - PendingCall* pc = static_cast(data); - - pc->slot(*pc); -} - PendingCall::Private::~Private() { if(dataslot != -1) @@ -55,10 +49,18 @@ PendingCall::Private::~Private() } } +void PendingCall::Private::notify_stub( DBusPendingCall* dpc, void* data ) +{ + PendingCall::Private* pvt = static_cast(data); + + PendingCall pc(pvt); + pvt->slot(pc); +} + PendingCall::PendingCall( PendingCall::Private* p ) : _pvt(p) { - if(!dbus_pending_call_set_notify(_pvt->call, Private::notify_stub, this, NULL)) + if(!dbus_pending_call_set_notify(_pvt->call, Private::notify_stub, p, NULL)) { throw ErrorNoMemory("Unable to initialize pending call"); } @@ -75,6 +77,17 @@ PendingCall::~PendingCall() dbus_pending_call_unref(_pvt->call); } +PendingCall& PendingCall::operator = ( const PendingCall& c ) +{ + if(&c != this) + { + dbus_pending_call_unref(_pvt->call); + _pvt = c._pvt; + dbus_pending_call_ref(_pvt->call); + } + return *this; +} + bool PendingCall::completed() { return dbus_pending_call_get_completed(_pvt->call); @@ -103,3 +116,24 @@ void* PendingCall::data() return dbus_pending_call_get_data(_pvt->call, _pvt->dataslot); } +Slot& PendingCall::slot() +{ + return _pvt->slot; +} + +Message PendingCall::steal_reply() +{ + DBusMessage* dmsg = dbus_pending_call_steal_reply(_pvt->call); + if(!dmsg) + { + dbus_bool_t callComplete = dbus_pending_call_get_completed(_pvt->call); + + if(callComplete) + throw ErrorNoReply("No reply available"); + else + throw ErrorNoReply("Call not complete"); + } + + return Message( new Message::Private(dmsg) ); +} + diff --git a/src/pendingcall_p.h b/src/pendingcall_p.h index 6f132db..0c5e7bc 100644 --- a/src/pendingcall_p.h +++ b/src/pendingcall_p.h @@ -40,7 +40,8 @@ struct DXXAPILOCAL PendingCall::Private { DBusPendingCall* call; int dataslot; - + Slot slot; + Private( DBusPendingCall* ); ~Private();