Merge lp:~michihenning/storage-framework/api2 into lp:storage-framework/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 84
Merged at revision: 70
Proposed branch: lp:~michihenning/storage-framework/api2
Merge into: lp:storage-framework/devel
Diff against target: 340 lines (+66/-90)
10 files modified
include/unity/storage/qt/Account.h (+6/-8)
include/unity/storage/qt/Item.h (+12/-12)
include/unity/storage/qt/Runtime.h (+3/-6)
include/unity/storage/qt/internal/RuntimeImpl.h (+1/-5)
src/qt/Account.cpp (+7/-5)
src/qt/Item.cpp (+7/-5)
src/qt/Runtime.cpp (+1/-6)
src/qt/internal/AccountImpl.cpp (+1/-5)
src/qt/internal/ItemImpl.cpp (+27/-7)
src/qt/internal/RuntimeImpl.cpp (+1/-31)
To merge this branch: bzr merge lp:~michihenning/storage-framework/api2
Reviewer Review Type Date Requested Status
James Henstridge Approve
unity-api-1-bot continuous-integration Approve
Review via email: mp+306447@code.launchpad.net

Commit message

First batch of fixes from code review:
Removed CONSTANT from Q_PROPERTY definitions of Item and Account.
Moved qHash() into correct namespace.
Adjusted hash() and qHash() of Item to also combine with the account hash.
Adjusted operator==() and operator<() of Item to compare equal or less than only if the accounts also compare equal or less than.
make_test_account() trailing arguments are now defaulted, so we don't need an overload.
Chained the RuntimeImpl constructors.

Description of the change

First batch of fixes from code review:
Removed CONSTANT from Q_PROPERTY definitions of Item and Account.
Moved qHash() into correct namespace.
Adjusted hash() and qHash() of Item to also combine with the account hash.
Adjusted operator==() and operator<() of Item to compare equal or less than only if the accounts also compare equal or less than.
make_test_account() trailing arguments are now defaulted, so we don't need an overload.
Chained the RuntimeImpl constructors.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:84
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/126/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/729
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/735
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/543/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/126/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/unity/storage/qt/Account.h'
2--- include/unity/storage/qt/Account.h 2016-09-20 04:53:49 +0000
3+++ include/unity/storage/qt/Account.h 2016-09-22 12:00:14 +0000
4@@ -42,10 +42,10 @@
5 class Q_DECL_EXPORT Account final
6 {
7 Q_GADGET
8- Q_PROPERTY(bool READ isValid CONSTANT FINAL)
9- Q_PROPERTY(QString READ owner CONSTANT FINAL)
10- Q_PROPERTY(QString READ ownerId CONSTANT FINAL)
11- Q_PROPERTY(QString READ description CONSTANT FINAL)
12+ Q_PROPERTY(bool READ isValid FINAL)
13+ Q_PROPERTY(QString READ owner FINAL)
14+ Q_PROPERTY(QString READ ownerId FINAL)
15+ Q_PROPERTY(QString READ description FINAL)
16
17 public:
18 Account();
19@@ -81,6 +81,8 @@
20 friend class internal::ItemImpl;
21 };
22
23+uint Q_DECL_EXPORT qHash(Account const& acc);
24+
25 } // namespace qt
26 } // namespace storage
27 } // namespace unity
28@@ -97,7 +99,3 @@
29 };
30
31 } // namespace std
32-
33-// Note: qHash(Account) does *not* return the same hash value is std::hash<Account> because
34-// std:hash() returns size_t (typically 64 bits), but qHash() returns uint (typically 32 bits).
35-uint Q_DECL_EXPORT qHash(unity::storage::qt::Account const& acc);
36
37=== modified file 'include/unity/storage/qt/Item.h'
38--- include/unity/storage/qt/Item.h 2016-09-21 01:02:46 +0000
39+++ include/unity/storage/qt/Item.h 2016-09-22 12:00:14 +0000
40@@ -53,14 +53,14 @@
41 class Q_DECL_EXPORT Item final
42 {
43 Q_GADGET
44- Q_PROPERTY(QString itemId READ itemId CONSTANT FINAL)
45- Q_PROPERTY(QString name READ name CONSTANT FINAL)
46- Q_PROPERTY(unity::storage::qt::Account account READ account CONSTANT FINAL)
47- Q_PROPERTY(QString etag READ etag CONSTANT FINAL)
48- Q_PROPERTY(unity::storage::qt::Item::Type type READ type CONSTANT FINAL)
49- Q_PROPERTY(QVariantMap metadata READ metadata CONSTANT FINAL)
50- Q_PROPERTY(QDateTime lastModifiedTime READ lastModifiedTime CONSTANT FINAL)
51- Q_PROPERTY(QVector<QString> parentIds READ parentIds CONSTANT FINAL)
52+ Q_PROPERTY(QString itemId READ itemId FINAL)
53+ Q_PROPERTY(QString name READ name FINAL)
54+ Q_PROPERTY(unity::storage::qt::Account account READ account FINAL)
55+ Q_PROPERTY(QString etag READ etag FINAL)
56+ Q_PROPERTY(unity::storage::qt::Item::Type type READ type FINAL)
57+ Q_PROPERTY(QVariantMap metadata READ metadata FINAL)
58+ Q_PROPERTY(QDateTime lastModifiedTime READ lastModifiedTime FINAL)
59+ Q_PROPERTY(QVector<QString> parentIds READ parentIds FINAL)
60
61 public:
62 Item();
63@@ -116,6 +116,10 @@
64 friend class internal::ItemImpl;
65 };
66
67+// Note: qHash(Item) does *not* return the same hash value is std::hash<Item> because
68+// std:hash() returns size_t (typically 64 bits), but qHash() returns uint (typically 32 bits).
69+uint Q_DECL_EXPORT qHash(unity::storage::qt::Item const& i);
70+
71 } // namespace qt
72 } // namespace storage
73 } // namespace unity
74@@ -136,7 +140,3 @@
75 };
76
77 } // namespace std
78-
79-// Note: qHash(Item) does *not* return the same hash value is std::hash<Item> because
80-// std:hash() returns size_t (typically 64 bits), but qHash() returns uint (typically 32 bits).
81-uint Q_DECL_EXPORT qHash(unity::storage::qt::Item const& i);
82
83=== modified file 'include/unity/storage/qt/Runtime.h'
84--- include/unity/storage/qt/Runtime.h 2016-09-21 00:29:49 +0000
85+++ include/unity/storage/qt/Runtime.h 2016-09-22 12:00:14 +0000
86@@ -62,14 +62,11 @@
87 StorageError shutdown();
88 Q_INVOKABLE AccountsJob* accounts() const;
89
90- // TODO: Get rid of two-argument version and default trailing params.
91- // TODO: can be const methods.
92- Account make_test_account(QString const& bus_name, QString const& object_path);
93 Account make_test_account(QString const& bus_name,
94 QString const& object_path,
95- QString const& owner_id,
96- QString const& owner,
97- QString const& description);
98+ QString const& owner_id = "",
99+ QString const& owner = "",
100+ QString const& description = "") const;
101
102 private:
103 std::shared_ptr<internal::RuntimeImpl> p_;
104
105=== modified file 'include/unity/storage/qt/internal/RuntimeImpl.h'
106--- include/unity/storage/qt/internal/RuntimeImpl.h 2016-09-21 00:29:49 +0000
107+++ include/unity/storage/qt/internal/RuntimeImpl.h 2016-09-22 12:00:14 +0000
108@@ -21,11 +21,10 @@
109 #include <unity/storage/qt/Account.h>
110 #include <unity/storage/qt/StorageError.h>
111
112-#include <OnlineAccounts/Manager>
113-
114 #pragma GCC diagnostic push
115 #pragma GCC diagnostic ignored "-Wcast-align"
116 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
117+#include <OnlineAccounts/Manager>
118 #include <QDBusConnection>
119 #pragma GCC diagnostic pop
120
121@@ -62,9 +61,6 @@
122 std::shared_ptr<OnlineAccounts::Manager> accounts_manager() const;
123
124 Account make_test_account(QString const& bus_name,
125- QString const& object_path);
126-
127- Account make_test_account(QString const& bus_name,
128 QString const& object_path,
129 QString const& owner_id,
130 QString const& owner,
131
132=== modified file 'src/qt/Account.cpp'
133--- src/qt/Account.cpp 2016-09-20 02:24:36 +0000
134+++ src/qt/Account.cpp 2016-09-22 12:00:14 +0000
135@@ -138,11 +138,13 @@
136 return p_->hash();
137 }
138
139+// Due to potentially different size of size_t and uint, hash() and qhash() may not return the same value.
140+
141+uint qHash(Account const& acc)
142+{
143+ return acc.hash();
144+}
145+
146 } // namespace qt
147 } // namespace storage
148 } // namespace unity
149-
150-uint qHash(unity::storage::qt::Account const& acc)
151-{
152- return acc.hash();
153-}
154
155=== modified file 'src/qt/Item.cpp'
156--- src/qt/Item.cpp 2016-09-20 02:24:36 +0000
157+++ src/qt/Item.cpp 2016-09-22 12:00:14 +0000
158@@ -220,11 +220,13 @@
159 return p_->hash();
160 }
161
162+// Due to potentially different size of size_t and uint, hash() and qhash() may not return the same value.
163+
164+uint qHash(Item const& i)
165+{
166+ return i.hash();
167+}
168+
169 } // namespace qt
170 } // namespace storage
171 } // namespace unity
172-
173-uint qHash(unity::storage::qt::Item const& i)
174-{
175- return i.hash();
176-}
177
178=== modified file 'src/qt/Runtime.cpp'
179--- src/qt/Runtime.cpp 2016-09-16 06:25:08 +0000
180+++ src/qt/Runtime.cpp 2016-09-22 12:00:14 +0000
181@@ -68,16 +68,11 @@
182 return p_->accounts();
183 }
184
185-Account Runtime::make_test_account(QString const& bus_name, QString const& object_path)
186-{
187- return p_->make_test_account(bus_name, object_path);
188-}
189-
190 Account Runtime::make_test_account(QString const& bus_name,
191 QString const& object_path,
192 QString const& owner_id,
193 QString const& owner,
194- QString const& description)
195+ QString const& description) const
196 {
197 return p_->make_test_account(bus_name, object_path, owner_id, owner, description);
198 }
199
200=== modified file 'src/qt/internal/AccountImpl.cpp'
201--- src/qt/internal/AccountImpl.cpp 2016-09-20 04:53:49 +0000
202+++ src/qt/internal/AccountImpl.cpp 2016-09-22 12:00:14 +0000
203@@ -169,11 +169,7 @@
204 {
205 return false;
206 }
207- if (description_ < other.description_)
208- {
209- return true;
210- }
211- return false;
212+ return description_ < other.description_;
213 }
214
215 bool AccountImpl::operator<=(AccountImpl const& other) const
216
217=== modified file 'src/qt/internal/ItemImpl.cpp'
218--- src/qt/internal/ItemImpl.cpp 2016-09-20 02:24:36 +0000
219+++ src/qt/internal/ItemImpl.cpp 2016-09-22 12:00:14 +0000
220@@ -25,6 +25,8 @@
221 #include <unity/storage/qt/internal/RuntimeImpl.h>
222 #include <unity/storage/qt/internal/validate.h>
223
224+#include <boost/functional/hash.hpp>
225+
226 #include <cassert>
227
228 using namespace std;
229@@ -176,7 +178,9 @@
230 {
231 if (is_valid_)
232 {
233- return other.is_valid_ && md_.item_id == other.md_.item_id;
234+ return other.is_valid_
235+ && *account_ == *other.account_
236+ && md_.item_id == other.md_.item_id;
237 }
238 return !other.is_valid_;
239 }
240@@ -188,11 +192,24 @@
241
242 bool ItemImpl::operator<(ItemImpl const& other) const
243 {
244- if (is_valid_)
245- {
246- return other.is_valid_ && md_.item_id < other.md_.item_id;
247- }
248- return other.is_valid_;
249+ if (!is_valid_)
250+ {
251+ return other.is_valid_;
252+ }
253+ if (is_valid_ && !other.is_valid_)
254+ {
255+ return false;
256+ }
257+ assert(is_valid_ && other.is_valid_);
258+ if (*account_ < *other.account_)
259+ {
260+ return true;
261+ }
262+ if (*account_ > *other.account_)
263+ {
264+ return false;
265+ }
266+ return md_.item_id < other.md_.item_id;
267 }
268
269 bool ItemImpl::operator<=(ItemImpl const& other) const
270@@ -216,7 +233,10 @@
271 {
272 return 0;
273 }
274- return qHash(md_.item_id);
275+ size_t hash = 0;
276+ boost::hash_combine(hash, account_->hash());
277+ boost::hash_combine(hash, qHash(md_.item_id));
278+ return hash;
279 }
280
281 Item ItemImpl::make_item(QString const& method,
282
283=== modified file 'src/qt/internal/RuntimeImpl.cpp'
284--- src/qt/internal/RuntimeImpl.cpp 2016-09-21 00:53:09 +0000
285+++ src/qt/internal/RuntimeImpl.cpp 2016-09-22 12:00:14 +0000
286@@ -57,24 +57,9 @@
287
288 }
289
290-// TODO: chain the two constructors.
291 RuntimeImpl::RuntimeImpl()
292- : is_valid_(true)
293- , conn_(QDBusConnection::sessionBus())
294- , accounts_manager_(new OnlineAccounts::Manager("", conn_))
295+ : RuntimeImpl(QDBusConnection::sessionBus())
296 {
297- register_meta_types();
298-
299-#if 0
300- if (!conn_.isConnected())
301- {
302- // LCOV_EXCL_START
303- is_valid_ = false;
304- QString msg = "Runtime(): cannot connect to session bus: " + conn_.lastError().message();
305- error_ = StorageErrorImpl::local_comms_error(msg);
306- // LCOV_EXCL_STOP
307- }
308-#endif
309 }
310
311 RuntimeImpl::RuntimeImpl(QDBusConnection const& bus)
312@@ -83,15 +68,6 @@
313 , accounts_manager_(new OnlineAccounts::Manager("", conn_))
314 {
315 register_meta_types();
316-
317-#if 0
318- if (!conn_.isConnected())
319- {
320- is_valid_ = false;
321- QString msg = "Runtime(): DBus connection is not connected";
322- error_ = StorageErrorImpl::local_comms_error(msg);
323- }
324-#endif
325 }
326
327 RuntimeImpl::~RuntimeImpl()
328@@ -143,12 +119,6 @@
329 }
330
331 Account RuntimeImpl::make_test_account(QString const& bus_name,
332- QString const& object_path)
333-{
334- return make_test_account(bus_name, object_path, "", "", "");
335-}
336-
337-Account RuntimeImpl::make_test_account(QString const& bus_name,
338 QString const& object_path,
339 QString const& owner_id,
340 QString const& owner,

Subscribers

People subscribed via source and target branches

to all changes: