* 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:
parent
b8c0b7c52c
commit
ecd2428049
3 changed files with 51 additions and 13 deletions
|
@ -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<void, PendingCall&> slot;
|
||||
Slot<void, PendingCall&>& slot();
|
||||
|
||||
private:
|
||||
|
||||
DXXAPILOCAL PendingCall( const PendingCall& );
|
||||
Message steal_reply();
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -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<PendingCall*>(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<PendingCall::Private*>(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<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) );
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ struct DXXAPILOCAL PendingCall::Private
|
|||
{
|
||||
DBusPendingCall* call;
|
||||
int dataslot;
|
||||
|
||||
Slot<void, PendingCall&> slot;
|
||||
|
||||
Private( DBusPendingCall* );
|
||||
|
||||
~Private();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue