Merge lp:~alecu/unity-scope-click/simplify-bridge-take2 into lp:unity-scope-click/devel

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 214
Merged at revision: 220
Proposed branch: lp:~alecu/unity-scope-click/simplify-bridge-take2
Merge into: lp:unity-scope-click/devel
Prerequisite: lp:~dobey/unity-scope-click/pkg-refactor
Diff against target: 415 lines (+23/-193)
7 files modified
scope/click/download-manager.cpp (+1/-1)
scope/click/preview.cpp (+4/-4)
scope/click/qtbridge.cpp (+7/-28)
scope/click/qtbridge.h (+4/-132)
scope/click/query.cpp (+4/-4)
scope/click/query.h (+1/-12)
scope/tests/test_query.cpp (+2/-12)
To merge this branch: bzr merge lp:~alecu/unity-scope-click/simplify-bridge-take2
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
dobey (community) Approve
Thomas Voß Pending
Review via email: mp+217235@code.launchpad.net

This proposal supersedes a proposal from 2014-04-16.

Commit message

Remove unused code in the qtbridge

Description of the change

This branch gets rid of HeapAllocatedObject and Environment, since they have no unit tests and are no longer being used.

To post a comment you must log in.
Revision history for this message
dobey (dobey) wrote : Posted in a previous version of this proposal

Noice!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
213. By Alejandro J. Cura

merged with lp:unity-scope-click/devel

214. By Alejandro J. Cura

Add fix for new usage of enter_with_task

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/click/download-manager.cpp'
2--- scope/click/download-manager.cpp 2014-03-22 00:08:31 +0000
3+++ scope/click/download-manager.cpp 2014-04-25 18:38:37 +0000
4@@ -335,7 +335,7 @@
5 void click::Downloader::startDownload(std::string url, std::string package_name,
6 const std::function<void (std::pair<std::string, click::InstallError >)>& callback)
7 {
8- qt::core::world::enter_with_task([this, callback, url, package_name] (qt::core::world::Environment& /*env*/)
9+ qt::core::world::enter_with_task([this, callback, url, package_name] ()
10 {
11 auto& dm = downloadManagerInstance(networkAccessManager);
12
13
14=== modified file 'scope/click/preview.cpp'
15--- scope/click/preview.cpp 2014-04-24 17:11:54 +0000
16+++ scope/click/preview.cpp 2014-04-25 18:38:37 +0000
17@@ -99,7 +99,7 @@
18 // I think this should not be required when we switch the click::Index over
19 // to using the Qt bridge. With that, the qt dependency becomes an implementation detail
20 // and code using it does not need to worry about threading/event loop topics.
21- qt::core::world::enter_with_task([this, details_callback, reviews_callback, app_name](qt::core::world::Environment&)
22+ qt::core::world::enter_with_task([this, details_callback, reviews_callback, app_name]()
23 {
24 index_operation = index->get_details(app_name, [this, app_name, details_callback, reviews_callback](PackageDetails details, click::Index::Error error){
25 if(error == click::Index::Error::NoError) {
26@@ -346,7 +346,7 @@
27 std::future<bool> manifest_future = manifest_promise.get_future();
28 std::string app_name = result["name"].get_string();
29 if (!app_name.empty()) {
30- qt::core::world::enter_with_task([&](qt::core::world::Environment& /*env*/) {
31+ qt::core::world::enter_with_task([&]() {
32 click::Interface().get_manifest_for_app(app_name,
33 [&](Manifest manifest, ManifestError error) {
34 qDebug() << "Got manifest for:" << app_name.c_str();
35@@ -415,7 +415,7 @@
36 // this can happen if the app was just installed and we have its http uri from the Result.
37 if (!app_url.startsWith("application:///")) {
38 const std::string name = result["name"].get_string();
39- auto ft = qt::core::world::enter_with_task([this, name, callback] (qt::core::world::Environment& /*env*/)
40+ auto ft = qt::core::world::enter_with_task([this, name, callback] ()
41 {
42 click::Interface().get_dotdesktop_filename(name,
43 [callback] (std::string val, click::ManifestError error) {
44@@ -577,7 +577,7 @@
45 package.title = result.title();
46 package.name = result["name"].get_string();
47 package.version = result["version"].get_string();
48- qt::core::world::enter_with_task([this, package] (qt::core::world::Environment& /*env*/)
49+ qt::core::world::enter_with_task([this, package] ()
50 {
51 click::PackageManager manager;
52 manager.uninstall(package, [&](int code, std::string stderr_content) {
53
54=== modified file 'scope/click/qtbridge.cpp'
55--- scope/click/qtbridge.cpp 2014-02-07 11:14:48 +0000
56+++ scope/click/qtbridge.cpp 2014-04-25 18:38:37 +0000
57@@ -39,10 +39,6 @@
58 {
59 namespace world
60 {
61-Environment::Environment(QObject *parent) : QObject(parent)
62-{
63-}
64-
65 namespace detail
66 {
67 QEvent::Type qt_core_world_task_event_type()
68@@ -51,28 +47,20 @@
69 return event_type;
70 }
71
72-class Environment : public qt::core::world::Environment
73-{
74-public:
75- Environment(QObject* parent) : qt::core::world::Environment(parent)
76- {
77- }
78-};
79-
80 class TaskEvent : public QEvent
81 {
82 public:
83- TaskEvent(const std::function<void(qt::core::world::Environment&)>& task)
84+ TaskEvent(const std::function<void()>& task)
85 : QEvent(qt_core_world_task_event_type()),
86 task(task)
87 {
88 }
89
90- void run(qt::core::world::Environment& env)
91+ void run()
92 {
93 try
94 {
95- task(env);
96+ task();
97 promise.set_value();
98 } catch(...)
99 {
100@@ -86,7 +74,7 @@
101 }
102
103 private:
104- std::function<void(qt::core::world::Environment&)> task;
105+ std::function<void()> task;
106 std::promise<void> promise;
107 };
108
109@@ -125,12 +113,6 @@
110 return instance;
111 }
112
113-qt::core::world::Environment* environment()
114-{
115- static detail::Environment* env = new detail::Environment(coreApplicationInstance());
116- return env;
117-}
118-
119 bool TaskHandler::event(QEvent *e)
120 {
121 if (e->type() != qt_core_world_task_event_type())
122@@ -139,7 +121,7 @@
123 auto te = dynamic_cast<TaskEvent*>(e);
124 if (te)
125 {
126- te->run(*environment());
127+ te->run();
128 return true;
129 }
130
131@@ -160,9 +142,6 @@
132 detail::task_handler()->moveToThread(
133 detail::coreApplicationInstance()->thread());
134
135- detail::environment()->moveToThread(
136- detail::coreApplicationInstance()->thread());
137-
138 // Signal to other worlds that we are good to go.
139 ready();
140
141@@ -174,14 +153,14 @@
142
143 void destroy()
144 {
145- enter_with_task([](qt::core::world::Environment&)
146+ enter_with_task([]()
147 {
148 // We make sure that all tasks have completed before quitting the app.
149 QEventLoopLocker locker;
150 }).wait_for(std::chrono::seconds{1});
151 }
152
153-std::future<void> enter_with_task(const std::function<void(qt::core::world::Environment&)>& task)
154+std::future<void> enter_with_task(const std::function<void()>& task)
155 {
156 QCoreApplication* instance = QCoreApplication::instance();
157
158
159=== modified file 'scope/click/qtbridge.h'
160--- scope/click/qtbridge.h 2014-02-24 12:41:57 +0000
161+++ scope/click/qtbridge.h 2014-04-25 18:38:37 +0000
162@@ -32,134 +32,6 @@
163 {
164 namespace world
165 {
166-// Forward declaration to allow for friend declaration in HeapAllocatedObject.
167-class Environment;
168-}
169-}
170-
171-/**
172- * @brief Models an object allocated on the heap in qt world, but pulled over
173- * to this world to be passed on to tasks. Please note that compilation will
174- * abort if QObject is not a base of T.
175- *
176- * One other important thing to note: The destrucotor will throw a std::runtime_error
177- * if a HeapAllocatedObject has not been free'd in Qt world and does _not_ have a parent
178- * assigned. In that case, the object would be leaked.
179- *
180- */
181-template<typename T>
182-class HeapAllocatedObject
183-{
184-public:
185- static_assert(
186- std::is_base_of<QObject, T>::value,
187- "HeapAllocatedObject<T> is only required to transport QObject"
188- " subclasses over the world boundary.");
189-
190- /** Constructs an empty, invalid instance. */
191- HeapAllocatedObject() = default;
192-
193- /** HeapAllocatedObjects, i.e., their shared state, can be copied. */
194- HeapAllocatedObject(const HeapAllocatedObject<T>& rhs) = default;
195-
196- /** HeapAllocatedObjects, i.e., their shared state can be assigned. */
197- HeapAllocatedObject& operator=(const HeapAllocatedObject<T>& rhs) = default;
198-
199- /** HeapAllocatedObjects, i.e., their shared state can be compared for equality. */
200- inline bool operator==(const HeapAllocatedObject<T>& rhs) const
201- {
202- return state == rhs.state || state->instance == rhs.state->instance;
203- }
204-
205- /** Check if this object contains a valid instance. */
206- inline operator bool() const
207- {
208- return state && (state->instance != nullptr);
209- }
210-
211-private:
212- friend class qt::core::world::Environment;
213-
214- struct Private
215- {
216- Private(T* instance) : instance(instance)
217- {
218- }
219-
220- ~Private()
221- {
222- if (instance != nullptr && instance->parent() == nullptr)
223- {
224- std::cerr << "HeapAllocatedObject::Private::~Private: Giving up ownership "
225- "on a QObject instance without a parent: "
226- << std::string(qPrintable(instance->metaObject()->className()))
227- << std::endl;
228- ::abort();
229- }
230- }
231-
232- T* instance{nullptr};
233- };
234-
235- HeapAllocatedObject(T* instance) : state(std::make_shared<Private>(instance))
236- {
237- }
238-
239- std::shared_ptr<Private> state;
240-};
241-
242-namespace core
243-{
244-namespace world
245-{
246-/**
247- * @brief The Environment class models the environment in the Qt world
248- * that tasks operate under.
249- */
250-class Environment : public QObject
251-{
252- Q_OBJECT
253-
254-public:
255- /**
256- * @brief Allocates subclasses of a QObject in the Qt world to make sure
257- * thread assumptions are satisfied.
258- *
259- * @tparam Args Construction argument types to be passed to the class's c'tor.
260- * @param args Construction arguments to be passed to the class's c'tor.
261- */
262- template<typename T, typename... Args>
263- qt::HeapAllocatedObject<T> allocate(Args... args)
264- {
265- return qt::HeapAllocatedObject<T>{new T(args...)};
266- }
267-
268- /**
269- * @brief Frees a previously allocated object in the Qt world.
270- * @param object The object to be freed.
271- */
272- template<typename T>
273- void free(const qt::HeapAllocatedObject<T>& object)
274- {
275- delete object.state->instance;
276- object.state->instance = nullptr;
277- }
278-
279- /**
280- * @brief Provides access to the instance contained in the object handle.
281- * @param object The object containing the instance to be accessed.
282- * @return A pointer to an instance of T, or nullptr.
283- */
284- template<typename T>
285- T* resolve(const HeapAllocatedObject<T>& object)
286- {
287- return object.state->instance;
288- }
289-
290-protected:
291- Environment(QObject* parent);
292-};
293-
294 /**
295 * @brief Sets up the Qt core world and executes its event loop. Blocks until destroy() is called.
296 * @param argc Number of arguments in argv.
297@@ -179,7 +51,7 @@
298 * @param task The task to be executed in the Qt core world.
299 * @return A std::future that can be waited for to synchronize to the world's internal event loop.
300 */
301-std::future<void> enter_with_task(const std::function<void(Environment&)>& task);
302+std::future<void> enter_with_task(const std::function<void()>& task);
303
304
305 /**
306@@ -188,16 +60,16 @@
307 * @return A std::future that can be waited for to get hold of the result of the task.
308 */
309 template<typename T>
310-inline std::future<T> enter_with_task_and_expect_result(const std::function<T(Environment&)>& task)
311+inline std::future<T> enter_with_task_and_expect_result(const std::function<T()>& task)
312 {
313 std::shared_ptr<std::promise<T>> promise = std::make_shared<std::promise<T>>();
314 std::future<T> future = promise->get_future();
315
316- auto t = [promise, task](Environment& env)
317+ auto t = [promise, task]()
318 {
319 try
320 {
321- promise->set_value(task(env));
322+ promise->set_value(task());
323 } catch(...)
324 {
325 promise->set_exception(std::current_exception());
326
327=== modified file 'scope/click/query.cpp'
328--- scope/click/query.cpp 2014-04-16 20:26:26 +0000
329+++ scope/click/query.cpp 2014-04-25 18:38:37 +0000
330@@ -169,10 +169,10 @@
331 return searchReply->register_category(id, title, icon, renderer_template);
332 }
333
334-void click::Query::run_under_qt(const std::function<void (qt::core::world::Environment &)> &task)
335+void click::Query::run_under_qt(const std::function<void ()> &task)
336 {
337- qt::core::world::enter_with_task([task](qt::core::world::Environment& env) {
338- task(env);
339+ qt::core::world::enter_with_task([task]() {
340+ task();
341 });
342 }
343
344@@ -188,7 +188,7 @@
345 return;
346 }
347
348- run_under_qt([=](qt::core::world::Environment& /*env*/)
349+ run_under_qt([=]()
350 {
351 qDebug() << "starting search of" << QString::fromStdString(impl->query);
352
353
354=== modified file 'scope/click/query.h'
355--- scope/click/query.h 2014-04-12 19:19:36 +0000
356+++ scope/click/query.h 2014-04-25 18:38:37 +0000
357@@ -38,17 +38,6 @@
358 #include <QSharedPointer>
359 #include <set>
360
361-namespace qt
362-{
363-namespace core
364-{
365-namespace world
366-{
367-class Environment;
368-}
369-}
370-}
371-
372 namespace click
373 {
374
375@@ -98,7 +87,7 @@
376 std::string const& title,
377 std::string const& icon,
378 scopes::CategoryRenderer const& renderer_template);
379- virtual void run_under_qt(const std::function<void(qt::core::world::Environment&)>& task);
380+ virtual void run_under_qt(const std::function<void()> &task);
381
382 private:
383 struct Private;
384
385=== modified file 'scope/tests/test_query.cpp'
386--- scope/tests/test_query.cpp 2014-04-14 20:48:43 +0000
387+++ scope/tests/test_query.cpp 2014-04-25 18:38:37 +0000
388@@ -76,15 +76,6 @@
389 std::function<void(click::PackageList)>));
390 };
391
392-class MockEnvironment : public qt::core::world::Environment
393-{
394-public:
395- MockEnvironment(QObject* parent) : qt::core::world::Environment(parent)
396- {
397- }
398-};
399-
400-
401 class MockQueryBase : public click::Query {
402 public:
403 MockQueryBase(const std::string query, click::Index& index,
404@@ -93,10 +84,9 @@
405
406 }
407
408- void run_under_qt(const std::function<void (qt::core::world::Environment &)> &task) {
409+ void run_under_qt(const std::function<void()> &task) {
410 // when testing, do not actually run under qt
411- MockEnvironment env(nullptr);
412- task(env);
413+ task();
414 }
415 };
416

Subscribers

People subscribed via source and target branches

to all changes: