1 | /* |
2 | * This file is part of Soprano Project. |
3 | * |
4 | * Copyright (C) 2008-2009 Sebastian Trueg <trueg@kde.org> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef _SOPRANO_ASYNC_RESULT_H_ |
23 | #define _SOPRANO_ASYNC_RESULT_H_ |
24 | |
25 | #include <QtCore/QObject> |
26 | #include <QtCore/QVariant> |
27 | |
28 | #include "error.h" |
29 | #include "soprano_export.h" |
30 | |
31 | |
32 | namespace Soprano { |
33 | |
34 | class StatementIterator; |
35 | class Node; |
36 | class NodeIterator; |
37 | class QueryResultIterator; |
38 | |
39 | namespace Util { |
40 | |
41 | class AsyncModel; |
42 | |
43 | /** |
44 | * \class AsyncResult asyncmodel.h Soprano/Util/AsyncResult |
45 | * |
46 | * \brief A delayed result as returned by AsyncModel. |
47 | * |
48 | * \author Sebastian Trueg <trueg@kde.org> |
49 | * |
50 | * \since 2.1 |
51 | */ |
52 | class SOPRANO_EXPORT AsyncResult : public QObject, public Error::ErrorCache |
53 | { |
54 | Q_OBJECT |
55 | |
56 | Q_SIGNALS: |
57 | /** |
58 | * Emitted once the async operation is completed |
59 | * and the result can be read. |
60 | * |
61 | * The result will delete itself. |
62 | */ |
63 | void resultReady( Soprano::Util::AsyncResult* ); |
64 | |
65 | public: |
66 | /** |
67 | * Constructor method to ensure binary compatibility. |
68 | * |
69 | * \since 2.2 |
70 | */ |
71 | static AsyncResult* createResult(); |
72 | |
73 | ~AsyncResult(); |
74 | |
75 | /** |
76 | * The result of the async operation. Its type is dependent |
77 | * on the operation (for example Error::ErrorCode for |
78 | * AsyncModel::addStatementAsync or StatementIterator for |
79 | * AsyncModel::listStatementsAsync). Types may need to be |
80 | * registered with Q_DECLARE_METATYPE. |
81 | * |
82 | * Use Error::ErrorCache::lastError() to check |
83 | * for error details. |
84 | * |
85 | * This value is not ready before resultReady() |
86 | * has been emitted. <b>Do only use this in a slot connected to |
87 | * resultReady.</b> |
88 | * |
89 | * \sa errorCode, statementIterator, nodeIterator, queryResultIterator, node |
90 | */ |
91 | QVariant value() const { return m_result; } |
92 | |
93 | /** |
94 | * Convenience method which converts value() into |
95 | * a Error::ErrorCode as returned for the following AsyncModel methods: |
96 | * \li AsyncModel::addStatementAsync |
97 | * \li AsyncModel::removeStatementAsync |
98 | * \li AsyncModel::removeAllStatementsAsync |
99 | * |
100 | * \sa value() |
101 | * |
102 | * \since 2.2 |
103 | */ |
104 | Error::ErrorCode errorCode() const; |
105 | |
106 | /** |
107 | * Convenience method which converts value() into |
108 | * a StatementIterator as returned AsyncModel::listStatementsAsync. |
109 | * |
110 | * \sa value() |
111 | * |
112 | * \since 2.2 |
113 | */ |
114 | StatementIterator statementIterator() const; |
115 | |
116 | /** |
117 | * Convenience method which converts value() into |
118 | * a StatementIterator as returned AsyncModel::listContextsAsync. |
119 | * |
120 | * \sa value() |
121 | * |
122 | * \since 2.2 |
123 | */ |
124 | NodeIterator nodeIterator() const; |
125 | |
126 | /** |
127 | * Convenience method which converts value() into |
128 | * a StatementIterator as returned AsyncModel::executeQueryAsync. |
129 | * |
130 | * \sa value() |
131 | * |
132 | * \since 2.2 |
133 | */ |
134 | QueryResultIterator queryResultIterator() const; |
135 | |
136 | /** |
137 | * Convenience method which converts value() into |
138 | * a StatementIterator as returned AsyncModel::createBlankNodeAsync. |
139 | * |
140 | * \sa value() |
141 | * |
142 | * \since 2.2 |
143 | */ |
144 | Node node() const; |
145 | |
146 | /** |
147 | * Sets the final result and emits the resultReady signal. This method |
148 | * should never be called by clients. |
149 | */ |
150 | void setResult( const QVariant& result, const Error::Error& error ); |
151 | |
152 | private Q_SLOTS: |
153 | void slotResultReady(); |
154 | |
155 | private: |
156 | AsyncResult(); |
157 | |
158 | QVariant m_result; |
159 | |
160 | friend class AsyncModel; |
161 | }; |
162 | } |
163 | } |
164 | |
165 | #endif |
166 | |