* 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
This commit is contained in:
pdurante 2007-08-31 03:15:39 +00:00
parent b8c0b7c52c
commit ecd2428049
3 changed files with 51 additions and 13 deletions

View file

@ -31,6 +31,7 @@
#include "api.h" #include "api.h"
#include "util.h" #include "util.h"
#include "message.h"
namespace DBus { namespace DBus {
@ -44,8 +45,12 @@ public:
PendingCall( Private* ); PendingCall( Private* );
PendingCall( const PendingCall& );
virtual ~PendingCall(); virtual ~PendingCall();
PendingCall& operator = ( const PendingCall& );
bool completed(); bool completed();
void cancel(); void cancel();
@ -56,11 +61,9 @@ public:
void* data(); void* data();
Slot<void, PendingCall&> slot; Slot<void, PendingCall&>& slot();
private: Message steal_reply();
DXXAPILOCAL PendingCall( const PendingCall& );
private: private:

View file

@ -28,6 +28,7 @@
#include "internalerror.h" #include "internalerror.h"
#include "pendingcall_p.h" #include "pendingcall_p.h"
#include "message_p.h"
using namespace DBus; 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<PendingCall*>(data);
pc->slot(*pc);
}
PendingCall::Private::~Private() PendingCall::Private::~Private()
{ {
if(dataslot != -1) if(dataslot != -1)
@ -55,10 +49,18 @@ PendingCall::Private::~Private()
} }
} }
void PendingCall::Private::notify_stub( DBusPendingCall* dpc, void* data )
{
PendingCall::Private* pvt = static_cast<PendingCall::Private*>(data);
PendingCall pc(pvt);
pvt->slot(pc);
}
PendingCall::PendingCall( PendingCall::Private* p ) PendingCall::PendingCall( PendingCall::Private* p )
: _pvt(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"); throw ErrorNoMemory("Unable to initialize pending call");
} }
@ -75,6 +77,17 @@ PendingCall::~PendingCall()
dbus_pending_call_unref(_pvt->call); 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() bool PendingCall::completed()
{ {
return dbus_pending_call_get_completed(_pvt->call); 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); return dbus_pending_call_get_data(_pvt->call, _pvt->dataslot);
} }
Slot<void, PendingCall&>& 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) );
}

View file

@ -40,6 +40,7 @@ struct DXXAPILOCAL PendingCall::Private
{ {
DBusPendingCall* call; DBusPendingCall* call;
int dataslot; int dataslot;
Slot<void, PendingCall&> slot;
Private( DBusPendingCall* ); Private( DBusPendingCall* );