# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

pendingcall.cpp
Go to the documentation of this file.
1/*
2 *
3 * D-Bus++ - C++ bindings for D-Bus
4 *
5 * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6 *
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <dbus-c++/pendingcall.h>
29
30#include <dbus/dbus.h>
31
32#include "internalerror.h"
33#include "pendingcall_p.h"
34#include "message_p.h"
35
36 using namespace DBus;
37
38 PendingCall::Private::Private(DBusPendingCall *dpc)
39 : call(dpc), dataslot(-1)
40{
41 if (!dbus_pending_call_allocate_data_slot(&dataslot))
42 {
43 throw ErrorNoMemory("Unable to allocate data slot");
44 }
45}
46
47 PendingCall::Private::~Private()
48{
49 if (dataslot != -1)
50 {
51 dbus_pending_call_allocate_data_slot(&dataslot);
52 }
53}
54
55 void PendingCall::Private::notify_stub(DBusPendingCall *dpc, void *data)
56{
57 PendingCall::Private *pvt = static_cast<PendingCall::Private *>(data);
58
59 PendingCall pc(pvt);
60 pvt->slot(pc);
61}
62
63 PendingCall::PendingCall(PendingCall::Private *p)
64 : _pvt(p)
65{
66 if (!dbus_pending_call_set_notify(_pvt->call, Private::notify_stub, p, NULL))
67 {
68 throw ErrorNoMemory("Unable to initialize pending call");
69 }
70}
71
72 PendingCall::PendingCall(const PendingCall &c)
73 : _pvt(c._pvt)
74{
75 dbus_pending_call_ref(_pvt->call);
76}
77
78 PendingCall::~PendingCall()
79{
80 dbus_pending_call_unref(_pvt->call);
81}
82
83 PendingCall &PendingCall::operator = (const PendingCall &c)
84{
85 if (&c != this)
86 {
87 dbus_pending_call_unref(_pvt->call);
88 _pvt = c._pvt;
89 dbus_pending_call_ref(_pvt->call);
90 }
91 return *this;
92}
93
94 bool PendingCall::completed()
95{
96 return dbus_pending_call_get_completed(_pvt->call);
97}
98
99 void PendingCall::cancel()
100{
101 dbus_pending_call_cancel(_pvt->call);
102}
103
104 void PendingCall::block()
105{
106 dbus_pending_call_block(_pvt->call);
107}
108
109 void PendingCall::data(void *p)
110{
111 if (!dbus_pending_call_set_data(_pvt->call, _pvt->dataslot, p, NULL))
112 {
113 throw ErrorNoMemory("Unable to initialize data slot");
114 }
115}
116
117 void *PendingCall::data()
118{
119 return dbus_pending_call_get_data(_pvt->call, _pvt->dataslot);
120}
121
122 Slot<void, PendingCall &>& PendingCall::slot()
123{
124 return _pvt->slot;
125}
126
127 Message PendingCall::steal_reply()
128{
129 DBusMessage *dmsg = dbus_pending_call_steal_reply(_pvt->call);
130 if (!dmsg)
131 {
132 dbus_bool_t callComplete = dbus_pending_call_get_completed(_pvt->call);
133
134 if (callComplete)
135 throw ErrorNoReply("No reply available");
136 else
137 throw ErrorNoReply("Call not complete");
138 }
139
140 return Message(new Message::Private(dmsg));
141}
142
DBus::Message
Definition message.h:159
DBus::PendingCall::cancel
void cancel()
Cancels the pending call, such that any reply or error received will just be ignored.
Definition pendingcall.cpp:99
DBus::PendingCall::slot
Slot< void, PendingCall & > & slot()
Definition pendingcall.cpp:122
DBus::PendingCall::steal_reply
Message steal_reply()
Gets the reply.
Definition pendingcall.cpp:127
DBus::PendingCall::completed
bool completed()
Checks whether the pending call has received a reply yet, or not.
Definition pendingcall.cpp:94
DBus::PendingCall::PendingCall
PendingCall(Private *)
Definition pendingcall.cpp:63
DBus::PendingCall::data
void data(void *data)
Stores a pointer on a PendingCall, along with an optional function to be used for freeing the data wh...
Definition pendingcall.cpp:109
DBus::PendingCall::data
void * data()
Retrieves data previously set with dbus_pending_call_set_data().
Definition pendingcall.cpp:117
DBus::PendingCall::block
void block()
Block until the pending call is completed.
Definition pendingcall.cpp:104
DBus::PendingCall::operator=
PendingCall & operator=(const PendingCall &)
Definition pendingcall.cpp:83
DBus::PendingCall::~PendingCall
virtual ~PendingCall()
Definition pendingcall.cpp:78
DBus::PendingCall::_pvt
RefPtrI< Private > _pvt
Definition pendingcall.h:125
DBus::Slot
Definition util.h:226
internalerror.h
message_p.h
DBus
Definition connection_p.h:42
pendingcall.h
pendingcall_p.h
DBus::ErrorNoMemory
Definition error.h:82
DBus::ErrorNoReply
Definition error.h:103
DBus::Message::Private
Definition message_p.h:41
DBus::PendingCall::Private
Definition pendingcall_p.h:41
DBus::PendingCall::Private::~Private
~Private()
Definition pendingcall.cpp:47
DBus::PendingCall::Private::slot
Slot< void, PendingCall & > slot
Definition pendingcall_p.h:44
DBus::PendingCall::Private::notify_stub
static void notify_stub(DBusPendingCall *dpc, void *data)
Definition pendingcall.cpp:55
DBus::PendingCall::Private::Private
Private(DBusPendingCall *)
Definition pendingcall.cpp:38
DBus::PendingCall::Private::dataslot
int dataslot
Definition pendingcall_p.h:43
DBus::PendingCall::Private::call
DBusPendingCall * call
Definition pendingcall_p.h:42