2
* Copyright (C) 2010, 2011 Tuomo Penttinen, all rights reserved.
4
* Author: Tuomo Penttinen <tp@herqq.org>
6
* This file is part of Herqq UPnP (HUPnP) library.
8
* Herqq UPnP is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* Herqq UPnP 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
16
* GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
25
#include <HUpnpCore/HUpnp>
35
class HAsyncOpPrivate;
38
* \brief This abstract class is used as a base for identifying an asynchronous
39
* operation and detail information of it.
41
* Some HUPnP components provide an asynchronous interface for running possible
42
* long-standing operations. A most notable example of this is the client-side
43
* action invocation initiated with HClientAction::beginInvoke(). In cases
44
* like this, the class running the operation returns a derivative of this class,
45
* which is used to identify and describe the running operation.
49
* The component that runs an asynchronous operation provides an instance
50
* derived from this class when the operation is started. A copy of that instance is
51
* provided also when the component signals the operation is complete.
52
* The provided instance uniquely identifies the operation, carries information
53
* whether the operation eventually succeeded or not and it may contain an error
54
* description in case of an error.
60
* HClientActionOp op = someActionObject->beginInvoke();
63
* // The operation completes, after which you can:
66
* int retVal = op.returnValue();
67
* // retrieve a return value indicating whether the operation succeeded.
69
* QString errDescr = op.errorDescription();
70
* // retrieve an error description if the operation failed.
74
* \note HAsyncOp and any derivative class provided by HUPnP use \e explicit
75
* \e sharing, which basically means that every copy of an instance references
76
* the same underlying data and any change to that data is visible to all of the
79
* \headerfile hasyncop.h HAsyncOp
81
* \ingroup hupnp_devicemodel
83
* \remarks This class is not thread-safe.
87
class H_UPNP_CORE_EXPORT HAsyncOp
89
H_DECLARE_PRIVATE(HAsyncOp)
90
friend H_UPNP_CORE_EXPORT bool operator==(const HAsyncOp&, const HAsyncOp&);
94
HAsyncOpPrivate* h_ptr;
99
HAsyncOp(HAsyncOpPrivate&);
104
HAsyncOp(qint32 returnCode, const QString& errorDescription,
105
HAsyncOpPrivate& dd);
108
* Creates a new valid instance.
110
* Creates a new valid instance, i.e isNull() always returns \e false.
117
* Creates a new invalid instance.
119
* \param returnCode specifies the return code.
121
* \param errorDescription specifies a human-readable description of the error
124
HAsyncOp(qint32 returnCode, const QString& errorDescription);
127
* \brief Copy constructor.
129
* Creates a shallow copy of \a other increasing the reference count of
132
HAsyncOp(const HAsyncOp&);
135
* \brief Assignment operator.
137
* Switches this instance to refer to the contents of \a other increasing the
138
* reference count of \a other.
140
HAsyncOp& operator=(const HAsyncOp&);
145
* \brief Destroys the instance.
147
* Decreases the reference count or destroys the instance once the reference
148
* count drops to zero.
150
virtual ~HAsyncOp() = 0;
153
* \brief Returns a human readable error description.
155
* \return a human readable error description, if any.
157
* \sa setErrorDescription()
159
QString errorDescription() const;
162
* \brief Sets a human readable error description.
164
* \param arg specifies the human readable error description.
166
* \sa errorDescription()
168
void setErrorDescription(const QString& arg);
171
* \brief Returns the return value of the asynchronous operation.
173
* \sa setReturnValue()
175
int returnValue() const;
178
* \brief Sets the return value of the asynchronous operation.
180
* \param returnValue specifies the return value of the asynchronous operation.
184
void setReturnValue(int returnValue);
187
* \brief Returns an identifier of the asynchronous operation.
189
* \return an identifier of the asynchronous operation. The identifier
190
* is "unique" within the process where the library is loaded. More specifically,
191
* the ID is monotonically incremented and it is allowed to overflow.
193
unsigned int id() const;
196
* \brief Indicates whether the object identifies an asynchronous operation.
198
* \retval true in case the object does not identify an asynchronous operation.
199
* This is usually the case when an operation was not successfully started.
200
* \retval false in case the object identifies an asynchronous operation.
205
* \brief Indicates whether the object identifies an asynchronous operation.
207
* This is a convenience method and it is semantically equivalent with isNull().
209
* \retval true in case the object does not identify an asynchronous operation.
210
* This is usually the case when an operation was not successfully started.
211
* \retval false in case the object identifies an asynchronous operation.
213
inline bool operator!() const
219
* Aborts the execution of the operation.
221
* Aborts the execution of the operation.
224
* It is up to the implementation to decide whether to implement this. The
225
* default implementation does nothing.
227
virtual void abort();
233
#endif /* HASYNCOP_H_ */