Merge lp:~ted/ubuntu-app-launch/instance-compare into lp:ubuntu-app-launch

Proposed by Ted Gould
Status: Merged
Approved by: Ted Gould
Approved revision: 317
Merged at revision: 314
Proposed branch: lp:~ted/ubuntu-app-launch/instance-compare
Merge into: lp:ubuntu-app-launch
Prerequisite: lp:~ted/ubuntu-app-launch/registry-cleanup
Diff against target: 417 lines (+153/-22)
13 files modified
libubuntu-app-launch/application-impl-legacy.h (+1/-1)
libubuntu-app-launch/application-impl-libertine.h (+1/-1)
libubuntu-app-launch/application-impl-snap.cpp (+1/-1)
libubuntu-app-launch/application-impl-snap.h (+1/-1)
libubuntu-app-launch/application.cpp (+26/-0)
libubuntu-app-launch/application.h (+7/-1)
libubuntu-app-launch/helper-impl.h (+20/-4)
libubuntu-app-launch/helper.cpp (+53/-10)
libubuntu-app-launch/helper.h (+7/-1)
libubuntu-app-launch/jobs-base.h (+6/-1)
libubuntu-app-launch/type-tagger.h (+8/-0)
tests/libual-cpp-test.cc (+21/-0)
tests/registry-mock.h (+1/-1)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/instance-compare
Reviewer Review Type Date Requested Status
Pete Woods (community) Approve
unity-api-1-bot continuous-integration Needs Fixing
Review via email: mp+321598@code.launchpad.net

This proposal supersedes a proposal from 2017-03-30.

Commit message

Provide equality operators for Application and Application::Instance objects.

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

FAILED: Continuous integration, rev:310
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/286/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1896/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1903
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1685/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1685
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1685/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1685/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1685
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1685/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1685/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1685
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1685/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/286/rebuild

review: Needs Fixing (continuous-integration)
315. By Ted Gould

Reenable ABI check

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:312
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/287/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1898/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1905
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1687
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1687/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1687
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1687/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1687/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1687
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1687/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1687
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1687/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1687
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1687/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/287/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
316. By Ted Gould

App equality test

317. By Ted Gould

Merge registry cleanup changes

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntu-app-launch/application-impl-legacy.h'
2--- libubuntu-app-launch/application-impl-legacy.h 2017-04-04 05:40:51 +0000
3+++ libubuntu-app-launch/application-impl-legacy.h 2017-04-04 05:40:51 +0000
4@@ -50,7 +50,7 @@
5 public:
6 Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry::Impl>& registry);
7
8- AppID appId() override
9+ AppID appId() const override
10 {
11 return {AppID::Package::from_raw({}), _appname, AppID::Version::from_raw({})};
12 }
13
14=== modified file 'libubuntu-app-launch/application-impl-libertine.h'
15--- libubuntu-app-launch/application-impl-libertine.h 2017-04-04 05:40:51 +0000
16+++ libubuntu-app-launch/application-impl-libertine.h 2017-04-04 05:40:51 +0000
17@@ -54,7 +54,7 @@
18 const AppID::AppName& appname,
19 const std::shared_ptr<Registry::Impl>& registry);
20
21- AppID appId() override
22+ AppID appId() const override
23 {
24 return {_container, _appname, AppID::Version::from_raw("0.0")};
25 }
26
27=== modified file 'libubuntu-app-launch/application-impl-snap.cpp'
28--- libubuntu-app-launch/application-impl-snap.cpp 2017-04-04 05:40:51 +0000
29+++ libubuntu-app-launch/application-impl-snap.cpp 2017-04-04 05:40:51 +0000
30@@ -219,7 +219,7 @@
31 }
32
33 /** Returns the stored AppID */
34-AppID Snap::appId()
35+AppID Snap::appId() const
36 {
37 return appid_;
38 }
39
40=== modified file 'libubuntu-app-launch/application-impl-snap.h'
41--- libubuntu-app-launch/application-impl-snap.h 2017-04-04 05:40:51 +0000
42+++ libubuntu-app-launch/application-impl-snap.h 2017-04-04 05:40:51 +0000
43@@ -55,7 +55,7 @@
44
45 static std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry::Impl>& registry);
46
47- AppID appId() override;
48+ AppID appId() const override;
49
50 std::shared_ptr<Info> info() override;
51
52
53=== modified file 'libubuntu-app-launch/application.cpp'
54--- libubuntu-app-launch/application.cpp 2017-04-04 05:40:51 +0000
55+++ libubuntu-app-launch/application.cpp 2017-04-04 05:40:51 +0000
56@@ -363,5 +363,31 @@
57 return static_cast<oom::Score>(value);
58 }
59
60+bool Application::operator==(const Application& b) const
61+{
62+ return appId() == b.appId();
63+}
64+
65+bool Application::operator!=(const Application& b) const
66+{
67+ return appId() != b.appId();
68+}
69+
70+bool Application::Instance::operator==(const Application::Instance& b) const
71+{
72+ auto ja = dynamic_cast<const jobs::instance::Base*>(this);
73+ auto jb = dynamic_cast<const jobs::instance::Base*>(&b);
74+
75+ return ja->getAppId() == jb->getAppId() && ja->getInstanceId() == jb->getInstanceId();
76+}
77+
78+bool Application::Instance::operator!=(const Application::Instance& b) const
79+{
80+ auto ja = dynamic_cast<const jobs::instance::Base*>(this);
81+ auto jb = dynamic_cast<const jobs::instance::Base*>(&b);
82+
83+ return ja->getAppId() != jb->getAppId() || ja->getInstanceId() != jb->getInstanceId();
84+}
85+
86 } // namespace app_launch
87 } // namespace ubuntu
88
89=== modified file 'libubuntu-app-launch/application.h'
90--- libubuntu-app-launch/application.h 2017-02-15 15:09:51 +0000
91+++ libubuntu-app-launch/application.h 2017-04-04 05:40:51 +0000
92@@ -66,7 +66,7 @@
93
94 /* System level info */
95 /** Get the Application ID of this Application */
96- virtual AppID appId() = 0;
97+ virtual AppID appId() const = 0;
98
99 /** \brief Information and metadata about the application for programs that
100 are displaying the application to users
101@@ -255,6 +255,9 @@
102 virtual void stop() = 0;
103 /** Signal the shell to focus the Application::Instance */
104 virtual void focus() = 0;
105+
106+ bool operator==(const Instance& b) const;
107+ bool operator!=(const Instance& b) const;
108 };
109
110 /** A quick check to see if this application has any running instances */
111@@ -279,6 +282,9 @@
112 \param pid The pid to find the instance of
113 */
114 virtual std::shared_ptr<Instance> findInstance(const pid_t& pid) = 0;
115+
116+ bool operator==(const Application& b) const;
117+ bool operator!=(const Application& b) const;
118 };
119
120 } // namespace app_launch
121
122=== modified file 'libubuntu-app-launch/helper-impl.h'
123--- libubuntu-app-launch/helper-impl.h 2017-04-04 05:40:51 +0000
124+++ libubuntu-app-launch/helper-impl.h 2017-04-04 05:40:51 +0000
125@@ -39,17 +39,28 @@
126 {
127 public:
128 std::shared_ptr<jobs::instance::Base> impl;
129+ Helper::Type type_;
130
131- BaseInstance(const std::shared_ptr<jobs::instance::Base>& inst);
132- BaseInstance(const std::shared_ptr<Application::Instance>& inst);
133+ BaseInstance(const Helper::Type& type, const std::shared_ptr<jobs::instance::Base>& inst);
134+ BaseInstance(const Helper::Type& type, const std::shared_ptr<Application::Instance>& inst);
135
136 bool isRunning() override;
137 void stop() override;
138
139- const std::string& getInstanceId()
140+ const std::string& getInstanceId() const
141 {
142 return impl->getInstanceId();
143 }
144+
145+ const AppID& getAppId() const
146+ {
147+ return impl->getAppId();
148+ }
149+
150+ const Helper::Type& getType() const
151+ {
152+ return type_;
153+ }
154 };
155
156 class Base : public Helper
157@@ -57,7 +68,7 @@
158 public:
159 Base(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry::Impl>& registry);
160
161- AppID appId() override;
162+ AppID appId() const override;
163
164 bool hasInstances() override;
165 std::vector<std::shared_ptr<Helper::Instance>> instances() override;
166@@ -67,6 +78,11 @@
167
168 std::shared_ptr<Helper::Instance> existingInstance(const std::string& instanceid);
169
170+ const Helper::Type& getType() const
171+ {
172+ return _type;
173+ }
174+
175 private:
176 Helper::Type _type;
177 AppID _appid;
178
179=== modified file 'libubuntu-app-launch/helper.cpp'
180--- libubuntu-app-launch/helper.cpp 2017-04-04 05:40:51 +0000
181+++ libubuntu-app-launch/helper.cpp 2017-04-04 05:40:51 +0000
182@@ -49,13 +49,15 @@
183 * Instance
184 **********************/
185
186-BaseInstance::BaseInstance(const std::shared_ptr<jobs::instance::Base>& inst)
187+BaseInstance::BaseInstance(const Helper::Type& type, const std::shared_ptr<jobs::instance::Base>& inst)
188 : impl{inst}
189+ , type_(type)
190 {
191 }
192
193-BaseInstance::BaseInstance(const std::shared_ptr<Application::Instance>& inst)
194+BaseInstance::BaseInstance(const Helper::Type& type, const std::shared_ptr<Application::Instance>& inst)
195 : impl{std::dynamic_pointer_cast<jobs::instance::Base>(inst)}
196+ , type_(type)
197 {
198 }
199
200@@ -80,7 +82,7 @@
201 {
202 }
203
204-AppID Base::appId()
205+AppID Base::appId() const
206 {
207 return _appid;
208 }
209@@ -95,8 +97,9 @@
210 auto insts = registry_->jobs()->instances(_appid, _type.value());
211 std::vector<std::shared_ptr<Helper::Instance>> wrapped{insts.size()};
212
213- std::transform(insts.begin(), insts.end(), wrapped.begin(),
214- [](std::shared_ptr<jobs::instance::Base>& inst) { return std::make_shared<BaseInstance>(inst); });
215+ std::transform(insts.begin(), insts.end(), wrapped.begin(), [this](std::shared_ptr<jobs::instance::Base>& inst) {
216+ return std::make_shared<BaseInstance>(_type, inst);
217+ });
218
219 return wrapped;
220 }
221@@ -106,7 +109,7 @@
222 {
223 auto appinst = registry_->jobs()->existing(_appid, _type.value(), instanceid, {});
224
225- return std::make_shared<BaseInstance>(appinst);
226+ return std::make_shared<BaseInstance>(_type, appinst);
227 }
228
229 std::string genInstanceId()
230@@ -212,8 +215,10 @@
231 auto defaultenv = defaultEnv();
232 std::function<std::list<std::pair<std::string, std::string>>()> envfunc = [defaultenv]() { return defaultenv; };
233
234- return std::make_shared<BaseInstance>(registry_->jobs()->launch(
235- _appid, _type.value(), genInstanceId(), appURL(urls), jobs::manager::launchMode::STANDARD, envfunc));
236+ return std::make_shared<BaseInstance>(
237+ _type,
238+ registry_->jobs()->launch(_appid, _type.value(), genInstanceId(), appURL(urls),
239+ jobs::manager::launchMode::STANDARD, envfunc));
240 }
241
242 class MirFDProxy
243@@ -403,8 +408,10 @@
244 seconds. And then it'll be dropped. */
245 proxy->setTimeout(registry_->thread.timeout(std::chrono::seconds{2}, [proxy]() { g_debug("Mir Proxy Timeout"); }));
246
247- return std::make_shared<BaseInstance>(registry_->jobs()->launch(
248- _appid, _type.value(), genInstanceId(), appURL(urls), jobs::manager::launchMode::STANDARD, envfunc));
249+ return std::make_shared<BaseInstance>(
250+ _type,
251+ registry_->jobs()->launch(_appid, _type.value(), genInstanceId(), appURL(urls),
252+ jobs::manager::launchMode::STANDARD, envfunc));
253 }
254
255 } // namespace helper_impl
256@@ -418,6 +425,42 @@
257 return registry->impl->createHelper(type, appid, registry->impl);
258 }
259
260+bool Helper::operator==(const Helper& b) const
261+{
262+ auto ja = dynamic_cast<const helper_impls::Base*>(this);
263+ auto jb = dynamic_cast<const helper_impls::Base*>(&b);
264+
265+ return ja->appId() == jb->appId() && ja->getType() == jb->getType();
266+}
267+
268+bool Helper::operator!=(const Helper& b) const
269+{
270+ auto ja = dynamic_cast<const helper_impls::Base*>(this);
271+ auto jb = dynamic_cast<const helper_impls::Base*>(&b);
272+
273+ return ja->appId() != jb->appId() || ja->getType() != jb->getType();
274+}
275+
276+bool Helper::Instance::operator==(const Helper::Instance& b) const
277+{
278+ auto ja = dynamic_cast<const helper_impls::BaseInstance*>(this);
279+ auto jb = dynamic_cast<const helper_impls::BaseInstance*>(&b);
280+
281+ return ja->getAppId() == jb->getAppId() && /* AppID */
282+ ja->getType() == jb->getType() && /* Type */
283+ ja->getInstanceId() == jb->getInstanceId(); /* Instance ID */
284+}
285+
286+bool Helper::Instance::operator!=(const Helper::Instance& b) const
287+{
288+ auto ja = dynamic_cast<const helper_impls::BaseInstance*>(this);
289+ auto jb = dynamic_cast<const helper_impls::BaseInstance*>(&b);
290+
291+ return ja->getAppId() != jb->getAppId() || /* AppID */
292+ ja->getType() != jb->getType() || /* Type */
293+ ja->getInstanceId() != jb->getInstanceId(); /* Instance ID */
294+}
295+
296 /* Hardcore socket stuff */
297 #include <sys/socket.h>
298 #include <sys/types.h>
299
300=== modified file 'libubuntu-app-launch/helper.h'
301--- libubuntu-app-launch/helper.h 2017-02-23 15:19:30 +0000
302+++ libubuntu-app-launch/helper.h 2017-04-04 05:40:51 +0000
303@@ -86,7 +86,7 @@
304 static std::shared_ptr<Helper> create(Type type, AppID appid, std::shared_ptr<Registry> registry);
305
306 /** Get the AppID for this helper */
307- virtual AppID appId() = 0;
308+ virtual AppID appId() const = 0;
309
310 /** Running instance of a a Helper */
311 class Instance
312@@ -101,6 +101,9 @@
313
314 /** Stop a running helper */
315 virtual void stop() = 0;
316+
317+ bool operator==(const Instance& b) const;
318+ bool operator!=(const Instance& b) const;
319 };
320
321 /** Check to see if there are any instances of this untrusted helper */
322@@ -128,6 +131,9 @@
323 \param exec The exec line to use for the helper with the AppID given
324 */
325 static void setExec(std::vector<std::string> exec);
326+
327+ bool operator==(const Helper& b) const;
328+ bool operator!=(const Helper& b) const;
329 };
330
331 } // namespace app_launch
332
333=== modified file 'libubuntu-app-launch/jobs-base.h'
334--- libubuntu-app-launch/jobs-base.h 2017-04-04 05:40:51 +0000
335+++ libubuntu-app-launch/jobs-base.h 2017-04-04 05:40:51 +0000
336@@ -54,11 +54,16 @@
337 void resume() override;
338 void focus() override;
339
340- const std::string& getInstanceId()
341+ const std::string& getInstanceId() const
342 {
343 return instance_;
344 }
345
346+ const AppID& getAppId() const
347+ {
348+ return appId_;
349+ }
350+
351 /* OOM Functions */
352 void setOomAdjustment(const oom::Score score) override;
353 const oom::Score getOomAdjustment() override;
354
355=== modified file 'libubuntu-app-launch/type-tagger.h'
356--- libubuntu-app-launch/type-tagger.h 2017-03-01 03:31:27 +0000
357+++ libubuntu-app-launch/type-tagger.h 2017-04-04 05:40:51 +0000
358@@ -40,6 +40,14 @@
359 {
360 return _value == b;
361 }
362+ bool operator!=(const TypeTagger<Tag, T>& b) const
363+ {
364+ return _value != b._value;
365+ }
366+ bool operator!=(const T& b) const
367+ {
368+ return _value != b;
369+ }
370 ~TypeTagger()
371 {
372 }
373
374=== modified file 'tests/libual-cpp-test.cc'
375--- tests/libual-cpp-test.cc 2017-04-04 05:40:51 +0000
376+++ tests/libual-cpp-test.cc 2017-04-04 05:40:51 +0000
377@@ -598,6 +598,27 @@
378 EXPECT_EQ("unity8-package_foo_x123", (std::string)apps.back()->appId());
379 }
380
381+TEST_F(LibUAL, Equality)
382+{
383+ auto appid = ubuntu::app_launch::AppID::find(registry, "single");
384+
385+ auto black = std::make_shared<MockApp>(appid, registry->impl);
386+ auto white = std::make_shared<MockApp>(appid, registry->impl);
387+
388+ /* The outside isn't equal */
389+ EXPECT_NE(black, white);
390+
391+ /* The inside is */
392+ EXPECT_EQ(*black, *white);
393+
394+ auto multiappid = ubuntu::app_launch::AppID::find(registry, "multiple");
395+
396+ auto cat = std::make_shared<MockApp>(appid, registry->impl);
397+ auto dog = std::make_shared<MockApp>(multiappid, registry->impl);
398+
399+ EXPECT_NE(*cat, *dog);
400+}
401+
402 TEST_F(LibUAL, StartingResponses)
403 {
404 /* Get Bus */
405
406=== modified file 'tests/registry-mock.h'
407--- tests/registry-mock.h 2017-04-04 05:40:51 +0000
408+++ tests/registry-mock.h 2017-04-04 05:40:51 +0000
409@@ -70,7 +70,7 @@
410 {
411 }
412
413- ubuntu::app_launch::AppID appId() override
414+ ubuntu::app_launch::AppID appId() const override
415 {
416 return appid_;
417 }

Subscribers

People subscribed via source and target branches