Merge lp:~ted/ubuntu-app-launch/registry-cleanup into lp:ubuntu-app-launch
- registry-cleanup
- Merge into trunk.17.04
Status: | Merged |
---|---|
Approved by: | Charles Kerr |
Approved revision: | 328 |
Merged at revision: | 310 |
Proposed branch: | lp:~ted/ubuntu-app-launch/registry-cleanup |
Merge into: | lp:ubuntu-app-launch |
Diff against target: |
4035 lines (+920/-965) 40 files modified
libubuntu-app-launch/app-store-base.cpp (+8/-8) libubuntu-app-launch/app-store-base.h (+13/-15) libubuntu-app-launch/app-store-legacy.cpp (+14/-18) libubuntu-app-launch/app-store-legacy.h (+8/-15) libubuntu-app-launch/app-store-libertine.cpp (+13/-17) libubuntu-app-launch/app-store-libertine.h (+8/-15) libubuntu-app-launch/app-store-snap.cpp (+19/-23) libubuntu-app-launch/app-store-snap.h (+8/-15) libubuntu-app-launch/application-impl-base.cpp (+2/-2) libubuntu-app-launch/application-impl-base.h (+10/-10) libubuntu-app-launch/application-impl-legacy.cpp (+8/-8) libubuntu-app-launch/application-impl-legacy.h (+1/-1) libubuntu-app-launch/application-impl-libertine.cpp (+8/-8) libubuntu-app-launch/application-impl-libertine.h (+1/-1) libubuntu-app-launch/application-impl-snap.cpp (+13/-13) libubuntu-app-launch/application-impl-snap.h (+4/-4) libubuntu-app-launch/application-info-desktop.cpp (+3/-3) libubuntu-app-launch/application-info-desktop.h (+5/-3) libubuntu-app-launch/application.cpp (+45/-34) libubuntu-app-launch/helper-impl.h (+2/-2) libubuntu-app-launch/helper.cpp (+15/-17) libubuntu-app-launch/info-watcher-zg.cpp (+1/-1) libubuntu-app-launch/info-watcher-zg.h (+1/-1) libubuntu-app-launch/info-watcher.cpp (+16/-2) libubuntu-app-launch/info-watcher.h (+10/-1) libubuntu-app-launch/jobs-base.cpp (+98/-118) libubuntu-app-launch/jobs-base.h (+33/-26) libubuntu-app-launch/jobs-systemd.cpp (+312/-352) libubuntu-app-launch/jobs-systemd.h (+6/-2) libubuntu-app-launch/registry-impl.cpp (+34/-16) libubuntu-app-launch/registry-impl.h (+52/-22) libubuntu-app-launch/registry.cpp (+27/-49) libubuntu-app-launch/registry.h (+6/-4) tests/application-info-desktop.cpp (+2/-2) tests/info-watcher-zg.cpp (+2/-3) tests/jobs-base-test.cpp (+2/-2) tests/jobs-systemd.cpp (+26/-22) tests/libual-cpp-test.cc (+40/-49) tests/list-apps.cpp (+6/-6) tests/registry-mock.h (+38/-55) |
To merge this branch: | bzr merge lp:~ted/ubuntu-app-launch/registry-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
unity-api-1-bot | continuous-integration | Approve | |
Charles Kerr (community) | Approve | ||
James Henstridge | Abstain | ||
Review via email: mp+321240@code.launchpad.net |
Commit message
Cleanup registry references to make them consistent
Description of the change
Basically all this branch is doing is getting rid of the std::shared_
For anything that leaves the protection of the UAL API it keeps a reference to the Registry::Impl object and can use that to reference the internal structures. Everything else is just getting a Registry& to be able to find stuff again.
unity-api-1-bot (unity-api-1-bot) wrote : | # |
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:318
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
James Henstridge (jamesh) wrote : | # |
I don't really know this code base, but seeing a merge that converts a bunch of smart pointers into raw pointers (which is essentially what these reference variables are) raises some red flags.
Is there a guarantee that all instances of these classes will be destroyed before the associated Registry instance? If not, you're just replacing indeterminate cleanup of the registry object for dangling pointers.
Some alternatives that might do what you want include:
1. add a shutdown() method that will do the cleanup, and then in other classes check to see if the registry has been shut down before using it.
2. use std::weak_ptr, so these other classes won't keep the registry alive, but also won't leave a dangling reference.
It's a bit hard to say what would be appropriate without looking into it more.
Ted Gould (ted) wrote : | # |
Yes, generally that is the case. Here we're talking about all objects that are owned directly by the object that is the raw pointer. Their lifecycle is guaranteed to be shorter than it.
For objects that could have a longer lifecycle than the Registry object we're using the smart pointer on the implementation to keep track of the resources.
The problem the smartpointers were causing is that they make it so the initialization is funky. You don't have the smart pointer until after the objects is initialized, so objects that are created during its initialization could take the smart pointer as a parameter. So to resolve that we had lazy initialization of the objects which was basically spaghetti all over the codebase. And that is what caused the linked bug, a path that didn't lazy initialize all the subobjects that were needed.
- 319. By Ted Gould
-
Make it so that we don't set all the objects on init of Impl, just with setters and getters in the Registry object.
- 320. By Ted Gould
-
Switch the jobs over to smart pointers
- 321. By Ted Gould
-
Switch App Stores over to using smart poitners
- 322. By Ted Gould
-
Now that the Impl is ready at init we can get the bus then too
- 323. By Ted Gould
-
Adapt tests to changes
- 324. By Ted Gould
-
Clean up the handling of the ZG Watcher
- 325. By Ted Gould
-
Fix zgwatcher setup
- 326. By Ted Gould
-
Ensure the jobs-systemd tests have a legacy appstore to use
- 327. By Ted Gould
-
Change around the zgWatcher and realize the test is really just a placeholder
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:327
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
James Henstridge (jamesh) wrote : | # |
Having objects that aren't fully constructed by their constructor can make it difficult to reason about code, so it'd be good to avoid that if at all possible.
If all you need is for a class to be able to create a shared pointer of itself, then std::enable_
http://
There are a few caveats though:
1. You probably don't want to be using shared_from_this() from within the constructor if the constructor can throw an exception: then the object in the shared pointer will be destroyed.
2. You want to make sure the class is always instantiated into a shared pointer. Making the constructor private and offering a factory function to create a shared_ptr is one way to handle this.
Ted Gould (ted) wrote : | # |
Cool, I didn't know about that, and it would help in some situations. I was able to put the smart pointers back in most cases by using a two-stage init of the implementation object. Since it's only created once, and in private code, it's an easy one to do that with and actually solves all the issues in this (rather small) codebase.
Thanks for pushing me to fix it.
Charles Kerr (charlesk) wrote : | # |
This patch is a little confusing.
I don't think I understand the problem enough. It sounds like you're saying a second registry was created because of cyclical instantiation?
If that's the case, some of these changes seem arbitrary, e.g. keeping a registry_ pointer in the Base instead of passing it as an argument the subclasses' methods. if it's not done being created when passed as an argument, surely it's got less chance of being done in the subclass' constructors? And if that's not the rationale, why move it into the parent class?
There are also a handful of cases (commented inline) where arguments are passed in when the parent class already has the same pointer, so the inconsistency seems like it's signalling something about how the cyclical initialization's being repaired, but I have to admit I'm missing it.
Passing Registry::Impl pointers around outside of the Registry seems very strange as well. Maybe this is just cosmetic, i.e. if Impl has evolved into a public class and needs to renamed or moved.
Other comments inline.
Ted Gould (ted) wrote : | # |
Comments inline.
Generally the problem was that the initialization of most of the objects that the Registry was doing to do its work were initialized at basically random times. This lead to things like the bug that is attached.
The reason that this was is because they all wanted to have access the shared resources in the registry so they were waiting around for a std::shared_
So what the branch does is instead have those internal objects use std::shared_
Also, it removes a couple raw pointers and some other minor internal API cleanups.
Charles Kerr (charlesk) wrote : | # |
Thanks for the clarification.
Let's file the entire initialization sequence away in "things to simplify." I agree that could be out of scope for this fix; approving.
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:328
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'libubuntu-app-launch/app-store-base.cpp' |
2 | --- libubuntu-app-launch/app-store-base.cpp 2017-02-28 21:15:46 +0000 |
3 | +++ libubuntu-app-launch/app-store-base.cpp 2017-04-04 21:22:36 +0000 |
4 | @@ -29,8 +29,8 @@ |
5 | namespace app_store |
6 | { |
7 | |
8 | -Base::Base() |
9 | - : info_watcher::Base({}) |
10 | +Base::Base(const std::shared_ptr<Registry::Impl>& registry) |
11 | + : info_watcher::Base(registry) |
12 | { |
13 | } |
14 | |
15 | @@ -38,14 +38,14 @@ |
16 | { |
17 | } |
18 | |
19 | -std::list<std::shared_ptr<Base>> Base::allAppStores() |
20 | +std::list<std::shared_ptr<Base>> Base::allAppStores(const std::shared_ptr<Registry::Impl>& registry) |
21 | { |
22 | return { |
23 | - std::make_shared<Legacy>() /* Legacy */ |
24 | - , |
25 | - std::make_shared<Libertine>() /* Libertine */ |
26 | - , |
27 | - std::make_shared<Snap>() /* Snappy */ |
28 | + std::make_shared<Legacy>(registry) /* Legacy */ |
29 | + , |
30 | + std::make_shared<Libertine>(registry) /* Libertine */ |
31 | + , |
32 | + std::make_shared<Snap>(registry) /* Snappy */ |
33 | }; |
34 | } |
35 | |
36 | |
37 | === modified file 'libubuntu-app-launch/app-store-base.h' |
38 | --- libubuntu-app-launch/app-store-base.h 2017-02-24 20:39:24 +0000 |
39 | +++ libubuntu-app-launch/app-store-base.h 2017-04-04 21:22:36 +0000 |
40 | @@ -28,36 +28,34 @@ |
41 | { |
42 | namespace app_launch |
43 | { |
44 | +namespace app_impls |
45 | +{ |
46 | +class Base; |
47 | +} |
48 | namespace app_store |
49 | { |
50 | |
51 | class Base : public info_watcher::Base |
52 | { |
53 | public: |
54 | - Base(); |
55 | + Base(const std::shared_ptr<Registry::Impl>& registry); |
56 | virtual ~Base(); |
57 | |
58 | /* Discover tools */ |
59 | - virtual bool verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) = 0; |
60 | - virtual bool verifyAppname(const AppID::Package& package, |
61 | - const AppID::AppName& appname, |
62 | - const std::shared_ptr<Registry>& registry) = 0; |
63 | - virtual AppID::AppName findAppname(const AppID::Package& package, |
64 | - AppID::ApplicationWildcard card, |
65 | - const std::shared_ptr<Registry>& registry) = 0; |
66 | - virtual AppID::Version findVersion(const AppID::Package& package, |
67 | - const AppID::AppName& appname, |
68 | - const std::shared_ptr<Registry>& registry) = 0; |
69 | - virtual bool hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry) = 0; |
70 | + virtual bool verifyPackage(const AppID::Package& package) = 0; |
71 | + virtual bool verifyAppname(const AppID::Package& package, const AppID::AppName& appname) = 0; |
72 | + virtual AppID::AppName findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) = 0; |
73 | + virtual AppID::Version findVersion(const AppID::Package& package, const AppID::AppName& appname) = 0; |
74 | + virtual bool hasAppId(const AppID& appid) = 0; |
75 | |
76 | /* Possible apps */ |
77 | - virtual std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry>& registry) = 0; |
78 | + virtual std::list<std::shared_ptr<Application>> list() = 0; |
79 | |
80 | /* Application Creation */ |
81 | - virtual std::shared_ptr<app_impls::Base> create(const AppID& appid, const std::shared_ptr<Registry>& registry) = 0; |
82 | + virtual std::shared_ptr<app_impls::Base> create(const AppID& appid) = 0; |
83 | |
84 | /* Static get all */ |
85 | - static std::list<std::shared_ptr<Base>> allAppStores(); |
86 | + static std::list<std::shared_ptr<Base>> allAppStores(const std::shared_ptr<Registry::Impl>& registry); |
87 | }; |
88 | |
89 | } // namespace app_store |
90 | |
91 | === modified file 'libubuntu-app-launch/app-store-legacy.cpp' |
92 | --- libubuntu-app-launch/app-store-legacy.cpp 2017-03-20 10:13:50 +0000 |
93 | +++ libubuntu-app-launch/app-store-legacy.cpp 2017-04-04 21:22:36 +0000 |
94 | @@ -30,7 +30,8 @@ |
95 | namespace app_store |
96 | { |
97 | |
98 | -Legacy::Legacy() |
99 | +Legacy::Legacy(const std::shared_ptr<Registry::Impl>& registry) |
100 | + : Base(registry) |
101 | { |
102 | } |
103 | |
104 | @@ -44,7 +45,7 @@ |
105 | \param appid AppID to check |
106 | \param registry persistent connections to use |
107 | */ |
108 | -bool Legacy::hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry) |
109 | +bool Legacy::hasAppId(const AppID& appid) |
110 | { |
111 | try |
112 | { |
113 | @@ -53,7 +54,7 @@ |
114 | return false; |
115 | } |
116 | |
117 | - return verifyAppname(appid.package, appid.appname, registry); |
118 | + return verifyAppname(appid.package, appid.appname); |
119 | } |
120 | catch (std::runtime_error& e) |
121 | { |
122 | @@ -66,7 +67,7 @@ |
123 | \param package Container name |
124 | \param registry persistent connections to use |
125 | */ |
126 | -bool Legacy::verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) |
127 | +bool Legacy::verifyPackage(const AppID::Package& package) |
128 | { |
129 | return package.value().empty(); |
130 | } |
131 | @@ -78,11 +79,9 @@ |
132 | \param appname Application name to look for |
133 | \param registry persistent connections to use |
134 | */ |
135 | -bool Legacy::verifyAppname(const AppID::Package& package, |
136 | - const AppID::AppName& appname, |
137 | - const std::shared_ptr<Registry>& registry) |
138 | +bool Legacy::verifyAppname(const AppID::Package& package, const AppID::AppName& appname) |
139 | { |
140 | - if (!verifyPackage(package, registry)) |
141 | + if (!verifyPackage(package)) |
142 | { |
143 | throw std::runtime_error{"Invalid Legacy package: " + std::string(package)}; |
144 | } |
145 | @@ -118,9 +117,7 @@ |
146 | \param card Application search paths |
147 | \param registry persistent connections to use |
148 | */ |
149 | -AppID::AppName Legacy::findAppname(const AppID::Package& package, |
150 | - AppID::ApplicationWildcard card, |
151 | - const std::shared_ptr<Registry>& registry) |
152 | +AppID::AppName Legacy::findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) |
153 | { |
154 | throw std::runtime_error("Legacy apps can't be discovered by package"); |
155 | } |
156 | @@ -131,17 +128,16 @@ |
157 | \param appname Application name (unused) |
158 | \param registry persistent connections to use (unused) |
159 | */ |
160 | -AppID::Version Legacy::findVersion(const AppID::Package& package, |
161 | - const AppID::AppName& appname, |
162 | - const std::shared_ptr<Registry>& registry) |
163 | +AppID::Version Legacy::findVersion(const AppID::Package& package, const AppID::AppName& appname) |
164 | { |
165 | return AppID::Version::from_raw({}); |
166 | } |
167 | |
168 | static const std::regex desktop_remover("^(.*)\\.desktop$"); |
169 | |
170 | -std::list<std::shared_ptr<Application>> Legacy::list(const std::shared_ptr<Registry>& registry) |
171 | +std::list<std::shared_ptr<Application>> Legacy::list() |
172 | { |
173 | + auto reg = getReg(); |
174 | std::list<std::shared_ptr<Application>> list; |
175 | std::unique_ptr<GList, decltype(&g_list_free)> head(g_app_info_get_all(), |
176 | [](GList* l) { g_list_free_full(l, g_object_unref); }); |
177 | @@ -179,7 +175,7 @@ |
178 | |
179 | try |
180 | { |
181 | - auto app = std::make_shared<app_impls::Legacy>(AppID::AppName::from_raw(appname), registry); |
182 | + auto app = std::make_shared<app_impls::Legacy>(AppID::AppName::from_raw(appname), reg); |
183 | list.push_back(app); |
184 | } |
185 | catch (std::runtime_error& e) |
186 | @@ -191,9 +187,9 @@ |
187 | return list; |
188 | } |
189 | |
190 | -std::shared_ptr<app_impls::Base> Legacy::create(const AppID& appid, const std::shared_ptr<Registry>& registry) |
191 | +std::shared_ptr<app_impls::Base> Legacy::create(const AppID& appid) |
192 | { |
193 | - return std::make_shared<app_impls::Legacy>(appid.appname, registry); |
194 | + return std::make_shared<app_impls::Legacy>(appid.appname, getReg()); |
195 | } |
196 | |
197 | } // namespace app_store |
198 | |
199 | === modified file 'libubuntu-app-launch/app-store-legacy.h' |
200 | --- libubuntu-app-launch/app-store-legacy.h 2017-02-24 20:39:24 +0000 |
201 | +++ libubuntu-app-launch/app-store-legacy.h 2017-04-04 21:22:36 +0000 |
202 | @@ -31,28 +31,21 @@ |
203 | class Legacy : public Base |
204 | { |
205 | public: |
206 | - Legacy(); |
207 | + Legacy(const std::shared_ptr<Registry::Impl>& registry); |
208 | virtual ~Legacy(); |
209 | |
210 | /* Discover tools */ |
211 | - virtual bool verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) override; |
212 | - virtual bool verifyAppname(const AppID::Package& package, |
213 | - const AppID::AppName& appname, |
214 | - const std::shared_ptr<Registry>& registry) override; |
215 | - virtual AppID::AppName findAppname(const AppID::Package& package, |
216 | - AppID::ApplicationWildcard card, |
217 | - const std::shared_ptr<Registry>& registry) override; |
218 | - virtual AppID::Version findVersion(const AppID::Package& package, |
219 | - const AppID::AppName& appname, |
220 | - const std::shared_ptr<Registry>& registry) override; |
221 | - virtual bool hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry) override; |
222 | + virtual bool verifyPackage(const AppID::Package& package) override; |
223 | + virtual bool verifyAppname(const AppID::Package& package, const AppID::AppName& appname) override; |
224 | + virtual AppID::AppName findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) override; |
225 | + virtual AppID::Version findVersion(const AppID::Package& package, const AppID::AppName& appname) override; |
226 | + virtual bool hasAppId(const AppID& appid) override; |
227 | |
228 | /* Possible apps */ |
229 | - virtual std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry>& registry) override; |
230 | + virtual std::list<std::shared_ptr<Application>> list() override; |
231 | |
232 | /* Application Creation */ |
233 | - virtual std::shared_ptr<app_impls::Base> create(const AppID& appid, |
234 | - const std::shared_ptr<Registry>& registry) override; |
235 | + virtual std::shared_ptr<app_impls::Base> create(const AppID& appid) override; |
236 | }; |
237 | |
238 | } // namespace app_store |
239 | |
240 | === modified file 'libubuntu-app-launch/app-store-libertine.cpp' |
241 | --- libubuntu-app-launch/app-store-libertine.cpp 2017-03-20 10:13:50 +0000 |
242 | +++ libubuntu-app-launch/app-store-libertine.cpp 2017-04-04 21:22:36 +0000 |
243 | @@ -30,7 +30,8 @@ |
244 | namespace app_store |
245 | { |
246 | |
247 | -Libertine::Libertine() |
248 | +Libertine::Libertine(const std::shared_ptr<Registry::Impl>& registry) |
249 | + : Base(registry) |
250 | { |
251 | } |
252 | |
253 | @@ -44,7 +45,7 @@ |
254 | \param appid AppID to check |
255 | \param registry persistent connections to use |
256 | */ |
257 | -bool Libertine::hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry) |
258 | +bool Libertine::hasAppId(const AppID& appid) |
259 | { |
260 | try |
261 | { |
262 | @@ -53,7 +54,7 @@ |
263 | return false; |
264 | } |
265 | |
266 | - return verifyAppname(appid.package, appid.appname, registry); |
267 | + return verifyAppname(appid.package, appid.appname); |
268 | } |
269 | catch (std::runtime_error& e) |
270 | { |
271 | @@ -67,7 +68,7 @@ |
272 | \param package Container name |
273 | \param registry persistent connections to use |
274 | */ |
275 | -bool Libertine::verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) |
276 | +bool Libertine::verifyPackage(const AppID::Package& package) |
277 | { |
278 | auto containers = unique_gcharv(libertine_list_containers()); |
279 | |
280 | @@ -90,9 +91,7 @@ |
281 | \param appname Application name to look for |
282 | \param registry persistent connections to use |
283 | */ |
284 | -bool Libertine::verifyAppname(const AppID::Package& package, |
285 | - const AppID::AppName& appname, |
286 | - const std::shared_ptr<Registry>& registry) |
287 | +bool Libertine::verifyAppname(const AppID::Package& package, const AppID::AppName& appname) |
288 | { |
289 | auto apps = unique_gcharv(libertine_list_apps_for_container(package.value().c_str())); |
290 | |
291 | @@ -115,9 +114,7 @@ |
292 | \param card Application search paths |
293 | \param registry persistent connections to use |
294 | */ |
295 | -AppID::AppName Libertine::findAppname(const AppID::Package& package, |
296 | - AppID::ApplicationWildcard card, |
297 | - const std::shared_ptr<Registry>& registry) |
298 | +AppID::AppName Libertine::findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) |
299 | { |
300 | throw std::runtime_error("Legacy apps can't be discovered by package"); |
301 | } |
302 | @@ -128,17 +125,16 @@ |
303 | \param appname Application name (unused) |
304 | \param registry persistent connections to use (unused) |
305 | */ |
306 | -AppID::Version Libertine::findVersion(const AppID::Package& package, |
307 | - const AppID::AppName& appname, |
308 | - const std::shared_ptr<Registry>& registry) |
309 | +AppID::Version Libertine::findVersion(const AppID::Package& package, const AppID::AppName& appname) |
310 | { |
311 | return AppID::Version::from_raw("0.0"); |
312 | } |
313 | |
314 | -std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry) |
315 | +std::list<std::shared_ptr<Application>> Libertine::list() |
316 | { |
317 | std::list<std::shared_ptr<Application>> applist; |
318 | |
319 | + auto reg = getReg(); |
320 | auto containers = unique_gcharv(libertine_list_containers()); |
321 | |
322 | for (int i = 0; containers.get()[i] != nullptr; i++) |
323 | @@ -151,7 +147,7 @@ |
324 | try |
325 | { |
326 | auto appid = AppID::parse(apps.get()[j]); |
327 | - auto sapp = std::make_shared<app_impls::Libertine>(appid.package, appid.appname, registry); |
328 | + auto sapp = std::make_shared<app_impls::Libertine>(appid.package, appid.appname, reg); |
329 | applist.emplace_back(sapp); |
330 | } |
331 | catch (std::runtime_error& e) |
332 | @@ -164,9 +160,9 @@ |
333 | return applist; |
334 | } |
335 | |
336 | -std::shared_ptr<app_impls::Base> Libertine::create(const AppID& appid, const std::shared_ptr<Registry>& registry) |
337 | +std::shared_ptr<app_impls::Base> Libertine::create(const AppID& appid) |
338 | { |
339 | - return std::make_shared<app_impls::Libertine>(appid.package, appid.appname, registry); |
340 | + return std::make_shared<app_impls::Libertine>(appid.package, appid.appname, getReg()); |
341 | } |
342 | |
343 | } // namespace app_store |
344 | |
345 | === modified file 'libubuntu-app-launch/app-store-libertine.h' |
346 | --- libubuntu-app-launch/app-store-libertine.h 2017-02-24 20:39:24 +0000 |
347 | +++ libubuntu-app-launch/app-store-libertine.h 2017-04-04 21:22:36 +0000 |
348 | @@ -31,28 +31,21 @@ |
349 | class Libertine : public Base |
350 | { |
351 | public: |
352 | - Libertine(); |
353 | + Libertine(const std::shared_ptr<Registry::Impl>& registry); |
354 | virtual ~Libertine(); |
355 | |
356 | /* Discover tools */ |
357 | - virtual bool verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) override; |
358 | - virtual bool verifyAppname(const AppID::Package& package, |
359 | - const AppID::AppName& appname, |
360 | - const std::shared_ptr<Registry>& registry) override; |
361 | - virtual AppID::AppName findAppname(const AppID::Package& package, |
362 | - AppID::ApplicationWildcard card, |
363 | - const std::shared_ptr<Registry>& registry) override; |
364 | - virtual AppID::Version findVersion(const AppID::Package& package, |
365 | - const AppID::AppName& appname, |
366 | - const std::shared_ptr<Registry>& registry) override; |
367 | - virtual bool hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry) override; |
368 | + virtual bool verifyPackage(const AppID::Package& package) override; |
369 | + virtual bool verifyAppname(const AppID::Package& package, const AppID::AppName& appname) override; |
370 | + virtual AppID::AppName findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) override; |
371 | + virtual AppID::Version findVersion(const AppID::Package& package, const AppID::AppName& appname) override; |
372 | + virtual bool hasAppId(const AppID& appid) override; |
373 | |
374 | /* Possible apps */ |
375 | - virtual std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry>& registry) override; |
376 | + virtual std::list<std::shared_ptr<Application>> list() override; |
377 | |
378 | /* Application Creation */ |
379 | - virtual std::shared_ptr<app_impls::Base> create(const AppID& appid, |
380 | - const std::shared_ptr<Registry>& registry) override; |
381 | + virtual std::shared_ptr<app_impls::Base> create(const AppID& appid) override; |
382 | }; |
383 | |
384 | } // namespace app_store |
385 | |
386 | === modified file 'libubuntu-app-launch/app-store-snap.cpp' |
387 | --- libubuntu-app-launch/app-store-snap.cpp 2017-03-14 19:59:21 +0000 |
388 | +++ libubuntu-app-launch/app-store-snap.cpp 2017-04-04 21:22:36 +0000 |
389 | @@ -43,7 +43,8 @@ |
390 | /** Snappy has more restrictive appnames than everyone else */ |
391 | const std::regex appnameRegex{"^[a-zA-Z0-9](?:-?[a-zA-Z0-9])*$"}; |
392 | |
393 | -Snap::Snap() |
394 | +Snap::Snap(const std::shared_ptr<Registry::Impl>& registry) |
395 | + : Base(registry) |
396 | { |
397 | } |
398 | |
399 | @@ -59,7 +60,7 @@ |
400 | \param appid Application ID of the snap |
401 | \param registry Registry to use for persistent connections |
402 | */ |
403 | -bool Snap::hasAppId(const AppID& appId, const std::shared_ptr<Registry>& registry) |
404 | +bool Snap::hasAppId(const AppID& appId) |
405 | { |
406 | if (appId.package.value().empty() || appId.version.value().empty()) |
407 | { |
408 | @@ -71,7 +72,7 @@ |
409 | return false; |
410 | } |
411 | |
412 | - auto pkginfo = registry->impl->snapdInfo.pkgInfo(appId.package); |
413 | + auto pkginfo = getReg()->snapdInfo.pkgInfo(appId.package); |
414 | return app_impls::Snap::checkPkgInfo(pkginfo, appId); |
415 | } |
416 | |
417 | @@ -80,11 +81,11 @@ |
418 | \param package Package name |
419 | \param registry Registry to use for persistent connections |
420 | */ |
421 | -bool Snap::verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) |
422 | +bool Snap::verifyPackage(const AppID::Package& package) |
423 | { |
424 | try |
425 | { |
426 | - auto pkgInfo = registry->impl->snapdInfo.pkgInfo(package); |
427 | + auto pkgInfo = getReg()->snapdInfo.pkgInfo(package); |
428 | return pkgInfo != nullptr; |
429 | } |
430 | catch (std::runtime_error& e) |
431 | @@ -99,16 +100,14 @@ |
432 | \param appname Command name |
433 | \param registry Registry to use for persistent connections |
434 | */ |
435 | -bool Snap::verifyAppname(const AppID::Package& package, |
436 | - const AppID::AppName& appname, |
437 | - const std::shared_ptr<Registry>& registry) |
438 | +bool Snap::verifyAppname(const AppID::Package& package, const AppID::AppName& appname) |
439 | { |
440 | if (!std::regex_match(appname.value(), appnameRegex)) |
441 | { |
442 | return false; |
443 | } |
444 | |
445 | - auto pkgInfo = registry->impl->snapdInfo.pkgInfo(package); |
446 | + auto pkgInfo = getReg()->snapdInfo.pkgInfo(package); |
447 | |
448 | if (!pkgInfo) |
449 | { |
450 | @@ -125,11 +124,9 @@ |
451 | \param card Wildcard to use for finding the appname |
452 | \param registry Registry to use for persistent connections |
453 | */ |
454 | -AppID::AppName Snap::findAppname(const AppID::Package& package, |
455 | - AppID::ApplicationWildcard card, |
456 | - const std::shared_ptr<Registry>& registry) |
457 | +AppID::AppName Snap::findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) |
458 | { |
459 | - auto pkgInfo = registry->impl->snapdInfo.pkgInfo(package); |
460 | + auto pkgInfo = getReg()->snapdInfo.pkgInfo(package); |
461 | |
462 | if (!pkgInfo) |
463 | { |
464 | @@ -165,11 +162,9 @@ |
465 | \param appname Not used for snaps |
466 | \param registry Registry to use for persistent connections |
467 | */ |
468 | -AppID::Version Snap::findVersion(const AppID::Package& package, |
469 | - const AppID::AppName& appname, |
470 | - const std::shared_ptr<Registry>& registry) |
471 | +AppID::Version Snap::findVersion(const AppID::Package& package, const AppID::AppName& appname) |
472 | { |
473 | - auto pkgInfo = registry->impl->snapdInfo.pkgInfo(package); |
474 | + auto pkgInfo = getReg()->snapdInfo.pkgInfo(package); |
475 | if (pkgInfo) |
476 | { |
477 | return AppID::Version::from_raw(pkgInfo->revision); |
478 | @@ -194,11 +189,12 @@ |
479 | |
480 | \param registry Registry to use for persistent connections |
481 | */ |
482 | -std::list<std::shared_ptr<Application>> Snap::list(const std::shared_ptr<Registry>& registry) |
483 | +std::list<std::shared_ptr<Application>> Snap::list() |
484 | { |
485 | std::set<std::shared_ptr<Application>, appcompare> apps; |
486 | + auto reg = getReg(); |
487 | |
488 | - auto lifecycleApps = registry->impl->snapdInfo.appsForInterface(LIFECYCLE_INTERFACE); |
489 | + auto lifecycleApps = reg->snapdInfo.appsForInterface(LIFECYCLE_INTERFACE); |
490 | |
491 | auto lifecycleForApp = [&](const AppID& appID) { |
492 | auto iterator = lifecycleApps.find(appID); |
493 | @@ -213,12 +209,12 @@ |
494 | }; |
495 | |
496 | auto addAppsForInterface = [&](const std::string& interface, app_info::Desktop::XMirEnable xMirEnable) { |
497 | - for (const auto& id : registry->impl->snapdInfo.appsForInterface(interface)) |
498 | + for (const auto& id : reg->snapdInfo.appsForInterface(interface)) |
499 | { |
500 | auto interfaceInfo = std::make_tuple(xMirEnable, lifecycleForApp(id)); |
501 | try |
502 | { |
503 | - auto app = std::make_shared<app_impls::Snap>(id, registry, interfaceInfo); |
504 | + auto app = std::make_shared<app_impls::Snap>(id, reg, interfaceInfo); |
505 | apps.emplace(app); |
506 | } |
507 | catch (std::runtime_error& e) |
508 | @@ -239,9 +235,9 @@ |
509 | return std::list<std::shared_ptr<Application>>(apps.begin(), apps.end()); |
510 | } |
511 | |
512 | -std::shared_ptr<app_impls::Base> Snap::create(const AppID& appid, const std::shared_ptr<Registry>& registry) |
513 | +std::shared_ptr<app_impls::Base> Snap::create(const AppID& appid) |
514 | { |
515 | - return std::make_shared<app_impls::Snap>(appid, registry); |
516 | + return std::make_shared<app_impls::Snap>(appid, getReg()); |
517 | } |
518 | |
519 | } // namespace app_store |
520 | |
521 | === modified file 'libubuntu-app-launch/app-store-snap.h' |
522 | --- libubuntu-app-launch/app-store-snap.h 2017-02-24 20:39:24 +0000 |
523 | +++ libubuntu-app-launch/app-store-snap.h 2017-04-04 21:22:36 +0000 |
524 | @@ -31,28 +31,21 @@ |
525 | class Snap : public Base |
526 | { |
527 | public: |
528 | - Snap(); |
529 | + Snap(const std::shared_ptr<Registry::Impl>& registry); |
530 | virtual ~Snap(); |
531 | |
532 | /* Discover tools */ |
533 | - virtual bool verifyPackage(const AppID::Package& package, const std::shared_ptr<Registry>& registry) override; |
534 | - virtual bool verifyAppname(const AppID::Package& package, |
535 | - const AppID::AppName& appname, |
536 | - const std::shared_ptr<Registry>& registry) override; |
537 | - virtual AppID::AppName findAppname(const AppID::Package& package, |
538 | - AppID::ApplicationWildcard card, |
539 | - const std::shared_ptr<Registry>& registry) override; |
540 | - virtual AppID::Version findVersion(const AppID::Package& package, |
541 | - const AppID::AppName& appname, |
542 | - const std::shared_ptr<Registry>& registry) override; |
543 | - virtual bool hasAppId(const AppID& appid, const std::shared_ptr<Registry>& registry) override; |
544 | + virtual bool verifyPackage(const AppID::Package& package) override; |
545 | + virtual bool verifyAppname(const AppID::Package& package, const AppID::AppName& appname) override; |
546 | + virtual AppID::AppName findAppname(const AppID::Package& package, AppID::ApplicationWildcard card) override; |
547 | + virtual AppID::Version findVersion(const AppID::Package& package, const AppID::AppName& appname) override; |
548 | + virtual bool hasAppId(const AppID& appid) override; |
549 | |
550 | /* Possible apps */ |
551 | - virtual std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry>& registry) override; |
552 | + virtual std::list<std::shared_ptr<Application>> list() override; |
553 | |
554 | /* Application Creation */ |
555 | - virtual std::shared_ptr<app_impls::Base> create(const AppID& appid, |
556 | - const std::shared_ptr<Registry>& registry) override; |
557 | + virtual std::shared_ptr<app_impls::Base> create(const AppID& appid) override; |
558 | }; |
559 | |
560 | } // namespace app_store |
561 | |
562 | === modified file 'libubuntu-app-launch/application-impl-base.cpp' |
563 | --- libubuntu-app-launch/application-impl-base.cpp 2017-03-20 10:13:50 +0000 |
564 | +++ libubuntu-app-launch/application-impl-base.cpp 2017-04-04 21:22:36 +0000 |
565 | @@ -40,8 +40,8 @@ |
566 | namespace app_impls |
567 | { |
568 | |
569 | -Base::Base(const std::shared_ptr<Registry>& registry) |
570 | - : _registry(registry) |
571 | +Base::Base(const std::shared_ptr<Registry::Impl>& registry) |
572 | + : registry_(registry) |
573 | { |
574 | g_debug("Application construction: %p", static_cast<void*>(this)); |
575 | } |
576 | |
577 | === modified file 'libubuntu-app-launch/application-impl-base.h' |
578 | --- libubuntu-app-launch/application-impl-base.h 2017-02-23 21:18:30 +0000 |
579 | +++ libubuntu-app-launch/application-impl-base.h 2017-04-04 21:22:36 +0000 |
580 | @@ -17,21 +17,21 @@ |
581 | * Ted Gould <ted.gould@canonical.com> |
582 | */ |
583 | |
584 | +#pragma once |
585 | + |
586 | #include "application-info-desktop.h" |
587 | #include "application.h" |
588 | -#include "info-watcher.h" |
589 | - |
590 | -extern "C" { |
591 | -#include "ubuntu-app-launch.h" |
592 | -#include <gio/gio.h> |
593 | -} |
594 | - |
595 | -#pragma once |
596 | +#include "registry-impl.h" |
597 | +#include "registry.h" |
598 | |
599 | namespace ubuntu |
600 | { |
601 | namespace app_launch |
602 | { |
603 | +namespace app_info |
604 | +{ |
605 | +class Desktop; |
606 | +} |
607 | namespace app_impls |
608 | { |
609 | |
610 | @@ -41,7 +41,7 @@ |
611 | class Base : public ubuntu::app_launch::Application |
612 | { |
613 | public: |
614 | - Base(const std::shared_ptr<Registry>& registry); |
615 | + Base(const std::shared_ptr<Registry::Impl>& registry); |
616 | virtual ~Base(); |
617 | |
618 | bool hasInstances() override; |
619 | @@ -52,7 +52,7 @@ |
620 | |
621 | protected: |
622 | /** Pointer to the registry so we can ask it for things */ |
623 | - std::shared_ptr<Registry> _registry; |
624 | + std::shared_ptr<Registry::Impl> registry_; |
625 | |
626 | static std::list<std::pair<std::string, std::string>> confinedEnv(const std::string& package, |
627 | const std::string& pkgdir); |
628 | |
629 | === modified file 'libubuntu-app-launch/application-impl-legacy.cpp' |
630 | --- libubuntu-app-launch/application-impl-legacy.cpp 2017-03-20 10:13:50 +0000 |
631 | +++ libubuntu-app-launch/application-impl-legacy.cpp 2017-04-04 21:22:36 +0000 |
632 | @@ -52,7 +52,7 @@ |
633 | } |
634 | } |
635 | |
636 | -Legacy::Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry) |
637 | +Legacy::Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry::Impl>& registry) |
638 | : Base(registry) |
639 | , _appname(appname) |
640 | { |
641 | @@ -73,7 +73,7 @@ |
642 | flags |= app_info::DesktopFlags::XMIR_DEFAULT; |
643 | } |
644 | |
645 | - appinfo_ = std::make_shared<app_info::Desktop>(appId(), _keyfile, _basedir, rootDir, flags, _registry); |
646 | + appinfo_ = std::make_shared<app_info::Desktop>(appId(), _keyfile, _basedir, rootDir, flags, registry_); |
647 | |
648 | if (!_keyfile) |
649 | { |
650 | @@ -135,7 +135,7 @@ |
651 | |
652 | std::vector<std::shared_ptr<Application::Instance>> Legacy::instances() |
653 | { |
654 | - auto vbase = _registry->impl->jobs->instances(appId(), "application-legacy"); |
655 | + auto vbase = registry_->jobs()->instances(appId(), "application-legacy"); |
656 | return std::vector<std::shared_ptr<Application::Instance>>(vbase.begin(), vbase.end()); |
657 | } |
658 | |
659 | @@ -222,8 +222,8 @@ |
660 | std::function<std::list<std::pair<std::string, std::string>>(void)> envfunc = [this, instance]() { |
661 | return launchEnv(instance); |
662 | }; |
663 | - return _registry->impl->jobs->launch(appId(), "application-legacy", instance, urls, |
664 | - jobs::manager::launchMode::STANDARD, envfunc); |
665 | + return registry_->jobs()->launch(appId(), "application-legacy", instance, urls, jobs::manager::launchMode::STANDARD, |
666 | + envfunc); |
667 | } |
668 | |
669 | /** Create an UpstartInstance for this AppID using the UpstartInstance launch |
670 | @@ -237,13 +237,13 @@ |
671 | std::function<std::list<std::pair<std::string, std::string>>(void)> envfunc = [this, instance]() { |
672 | return launchEnv(instance); |
673 | }; |
674 | - return _registry->impl->jobs->launch(appId(), "application-legacy", instance, urls, jobs::manager::launchMode::TEST, |
675 | - envfunc); |
676 | + return registry_->jobs()->launch(appId(), "application-legacy", instance, urls, jobs::manager::launchMode::TEST, |
677 | + envfunc); |
678 | } |
679 | |
680 | std::shared_ptr<Application::Instance> Legacy::findInstance(const std::string& instanceid) |
681 | { |
682 | - return _registry->impl->jobs->existing(appId(), "application-legacy", instanceid, std::vector<Application::URL>{}); |
683 | + return registry_->jobs()->existing(appId(), "application-legacy", instanceid, std::vector<Application::URL>{}); |
684 | } |
685 | |
686 | } // namespace app_impls |
687 | |
688 | === modified file 'libubuntu-app-launch/application-impl-legacy.h' |
689 | --- libubuntu-app-launch/application-impl-legacy.h 2017-02-24 21:21:03 +0000 |
690 | +++ libubuntu-app-launch/application-impl-legacy.h 2017-04-04 21:22:36 +0000 |
691 | @@ -48,7 +48,7 @@ |
692 | class Legacy : public Base |
693 | { |
694 | public: |
695 | - Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry); |
696 | + Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry::Impl>& registry); |
697 | |
698 | AppID appId() override |
699 | { |
700 | |
701 | === modified file 'libubuntu-app-launch/application-impl-libertine.cpp' |
702 | --- libubuntu-app-launch/application-impl-libertine.cpp 2017-03-20 10:13:50 +0000 |
703 | +++ libubuntu-app-launch/application-impl-libertine.cpp 2017-04-04 21:22:36 +0000 |
704 | @@ -35,7 +35,7 @@ |
705 | |
706 | Libertine::Libertine(const AppID::Package& container, |
707 | const AppID::AppName& appname, |
708 | - const std::shared_ptr<Registry>& registry) |
709 | + const std::shared_ptr<Registry::Impl>& registry) |
710 | : Base(registry) |
711 | , _container(container) |
712 | , _appname(appname) |
713 | @@ -68,7 +68,7 @@ |
714 | container.value() + "'"}; |
715 | |
716 | appinfo_ = std::make_shared<app_info::Desktop>(appId(), _keyfile, _basedir, _container_path, |
717 | - app_info::DesktopFlags::XMIR_DEFAULT, _registry); |
718 | + app_info::DesktopFlags::XMIR_DEFAULT, registry_); |
719 | |
720 | g_debug("Application Libertine object for container '%s' app '%s'", container.value().c_str(), |
721 | appname.value().c_str()); |
722 | @@ -137,7 +137,7 @@ |
723 | |
724 | std::vector<std::shared_ptr<Application::Instance>> Libertine::instances() |
725 | { |
726 | - auto vbase = _registry->impl->jobs->instances(appId(), "application-legacy"); |
727 | + auto vbase = registry_->jobs()->instances(appId(), "application-legacy"); |
728 | return std::vector<std::shared_ptr<Application::Instance>>(vbase.begin(), vbase.end()); |
729 | } |
730 | |
731 | @@ -181,21 +181,21 @@ |
732 | { |
733 | auto instance = getInstance(appinfo_); |
734 | std::function<std::list<std::pair<std::string, std::string>>(void)> envfunc = [this]() { return launchEnv(); }; |
735 | - return _registry->impl->jobs->launch(appId(), "application-legacy", instance, urls, |
736 | - jobs::manager::launchMode::STANDARD, envfunc); |
737 | + return registry_->jobs()->launch(appId(), "application-legacy", instance, urls, jobs::manager::launchMode::STANDARD, |
738 | + envfunc); |
739 | } |
740 | |
741 | std::shared_ptr<Application::Instance> Libertine::launchTest(const std::vector<Application::URL>& urls) |
742 | { |
743 | auto instance = getInstance(appinfo_); |
744 | std::function<std::list<std::pair<std::string, std::string>>(void)> envfunc = [this]() { return launchEnv(); }; |
745 | - return _registry->impl->jobs->launch(appId(), "application-legacy", instance, urls, jobs::manager::launchMode::TEST, |
746 | - envfunc); |
747 | + return registry_->jobs()->launch(appId(), "application-legacy", instance, urls, jobs::manager::launchMode::TEST, |
748 | + envfunc); |
749 | } |
750 | |
751 | std::shared_ptr<Application::Instance> Libertine::findInstance(const std::string& instanceid) |
752 | { |
753 | - return _registry->impl->jobs->existing(appId(), "application-legacy", instanceid, std::vector<Application::URL>{}); |
754 | + return registry_->jobs()->existing(appId(), "application-legacy", instanceid, std::vector<Application::URL>{}); |
755 | } |
756 | |
757 | } // namespace app_impls |
758 | |
759 | === modified file 'libubuntu-app-launch/application-impl-libertine.h' |
760 | --- libubuntu-app-launch/application-impl-libertine.h 2017-02-24 21:25:47 +0000 |
761 | +++ libubuntu-app-launch/application-impl-libertine.h 2017-04-04 21:22:36 +0000 |
762 | @@ -52,7 +52,7 @@ |
763 | public: |
764 | Libertine(const AppID::Package& container, |
765 | const AppID::AppName& appname, |
766 | - const std::shared_ptr<Registry>& registry); |
767 | + const std::shared_ptr<Registry::Impl>& registry); |
768 | |
769 | AppID appId() override |
770 | { |
771 | |
772 | === modified file 'libubuntu-app-launch/application-impl-snap.cpp' |
773 | --- libubuntu-app-launch/application-impl-snap.cpp 2017-03-20 10:13:50 +0000 |
774 | +++ libubuntu-app-launch/application-impl-snap.cpp 2017-04-04 21:22:36 +0000 |
775 | @@ -62,7 +62,7 @@ |
776 | |
777 | public: |
778 | SnapInfo(const AppID& appid, |
779 | - const std::shared_ptr<Registry>& registry, |
780 | + const std::shared_ptr<Registry::Impl>& registry, |
781 | const Snap::InterfaceInfo& interfaceInfo, |
782 | const std::string& snapDir) |
783 | : Desktop(appid, |
784 | @@ -187,11 +187,11 @@ |
785 | \param registry Registry to use for persistent connections |
786 | \param interfaceInfo Metadata gleaned from the snap's interfaces |
787 | */ |
788 | -Snap::Snap(const AppID& appid, const std::shared_ptr<Registry>& registry, const InterfaceInfo& interfaceInfo) |
789 | +Snap::Snap(const AppID& appid, const std::shared_ptr<Registry::Impl>& registry, const InterfaceInfo& interfaceInfo) |
790 | : Base(registry) |
791 | , appid_(appid) |
792 | { |
793 | - pkgInfo_ = registry->impl->snapdInfo.pkgInfo(appid.package); |
794 | + pkgInfo_ = registry->snapdInfo.pkgInfo(appid.package); |
795 | if (!pkgInfo_) |
796 | { |
797 | throw std::runtime_error("Unable to get snap package info for AppID: " + std::string(appid)); |
798 | @@ -202,7 +202,7 @@ |
799 | throw std::runtime_error("AppID does not match installed package for: " + std::string(appid)); |
800 | } |
801 | |
802 | - info_ = std::make_shared<SnapInfo>(appid_, _registry, interfaceInfo, pkgInfo_->directory); |
803 | + info_ = std::make_shared<SnapInfo>(appid_, registry_, interfaceInfo, pkgInfo_->directory); |
804 | |
805 | g_debug("Application Snap object for AppID '%s'", std::string(appid).c_str()); |
806 | } |
807 | @@ -213,7 +213,7 @@ |
808 | \param appid Application ID of the snap |
809 | \param registry Registry to use for persistent connections |
810 | */ |
811 | -Snap::Snap(const AppID& appid, const std::shared_ptr<Registry>& registry) |
812 | +Snap::Snap(const AppID& appid, const std::shared_ptr<Registry::Impl>& registry) |
813 | : Snap(appid, registry, findInterfaceInfo(appid, registry)) |
814 | { |
815 | } |
816 | @@ -230,9 +230,9 @@ |
817 | \param appid Application ID of the snap |
818 | \param registry Registry to use for persistent connections |
819 | */ |
820 | -Snap::InterfaceInfo Snap::findInterfaceInfo(const AppID& appid, const std::shared_ptr<Registry>& registry) |
821 | +Snap::InterfaceInfo Snap::findInterfaceInfo(const AppID& appid, const std::shared_ptr<Registry::Impl>& registry) |
822 | { |
823 | - auto ifaceset = registry->impl->snapdInfo.interfacesForAppId(appid); |
824 | + auto ifaceset = registry->snapdInfo.interfacesForAppId(appid); |
825 | auto xMirEnable = app_info::Desktop::XMirEnable::from_raw(false); |
826 | auto ubuntuLifecycle = Application::Info::UbuntuLifecycle::from_raw(false); |
827 | |
828 | @@ -282,7 +282,7 @@ |
829 | /** Get all of the instances of this snap package that are running */ |
830 | std::vector<std::shared_ptr<Application::Instance>> Snap::instances() |
831 | { |
832 | - auto vbase = _registry->impl->jobs->instances(appId(), "application-snap"); |
833 | + auto vbase = registry_->jobs()->instances(appId(), "application-snap"); |
834 | return std::vector<std::shared_ptr<Application::Instance>>(vbase.begin(), vbase.end()); |
835 | } |
836 | |
837 | @@ -326,8 +326,8 @@ |
838 | { |
839 | auto instance = getInstance(info_); |
840 | std::function<std::list<std::pair<std::string, std::string>>(void)> envfunc = [this]() { return launchEnv(); }; |
841 | - return _registry->impl->jobs->launch(appid_, "application-snap", instance, urls, |
842 | - jobs::manager::launchMode::STANDARD, envfunc); |
843 | + return registry_->jobs()->launch(appid_, "application-snap", instance, urls, jobs::manager::launchMode::STANDARD, |
844 | + envfunc); |
845 | } |
846 | |
847 | /** Create a new instance of this Snap with a testing environment |
848 | @@ -339,13 +339,13 @@ |
849 | { |
850 | auto instance = getInstance(info_); |
851 | std::function<std::list<std::pair<std::string, std::string>>(void)> envfunc = [this]() { return launchEnv(); }; |
852 | - return _registry->impl->jobs->launch(appid_, "application-snap", instance, urls, jobs::manager::launchMode::TEST, |
853 | - envfunc); |
854 | + return registry_->jobs()->launch(appid_, "application-snap", instance, urls, jobs::manager::launchMode::TEST, |
855 | + envfunc); |
856 | } |
857 | |
858 | std::shared_ptr<Application::Instance> Snap::findInstance(const std::string& instanceid) |
859 | { |
860 | - return _registry->impl->jobs->existing(appId(), "application-snap", instanceid, std::vector<Application::URL>{}); |
861 | + return registry_->jobs()->existing(appId(), "application-snap", instanceid, std::vector<Application::URL>{}); |
862 | } |
863 | |
864 | } // namespace app_impls |
865 | |
866 | === modified file 'libubuntu-app-launch/application-impl-snap.h' |
867 | --- libubuntu-app-launch/application-impl-snap.h 2017-03-14 19:35:43 +0000 |
868 | +++ libubuntu-app-launch/application-impl-snap.h 2017-04-04 21:22:36 +0000 |
869 | @@ -50,10 +50,10 @@ |
870 | public: |
871 | typedef std::tuple<app_info::Desktop::XMirEnable, Application::Info::UbuntuLifecycle> InterfaceInfo; |
872 | |
873 | - Snap(const AppID& appid, const std::shared_ptr<Registry>& registry); |
874 | - Snap(const AppID& appid, const std::shared_ptr<Registry>& registry, const InterfaceInfo& interfaceInfo); |
875 | + Snap(const AppID& appid, const std::shared_ptr<Registry::Impl>& registry); |
876 | + Snap(const AppID& appid, const std::shared_ptr<Registry::Impl>& registry, const InterfaceInfo& interfaceInfo); |
877 | |
878 | - static std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry>& registry); |
879 | + static std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry::Impl>& registry); |
880 | |
881 | AppID appId() override; |
882 | |
883 | @@ -66,7 +66,7 @@ |
884 | |
885 | virtual std::shared_ptr<Application::Instance> findInstance(const std::string& instanceid) override; |
886 | |
887 | - static InterfaceInfo findInterfaceInfo(const AppID& appid, const std::shared_ptr<Registry>& registry); |
888 | + static InterfaceInfo findInterfaceInfo(const AppID& appid, const std::shared_ptr<Registry::Impl>& registry); |
889 | static bool checkPkgInfo(const std::shared_ptr<snapd::Info::PkgInfo>& pkginfo, const AppID& appid); |
890 | |
891 | private: |
892 | |
893 | === modified file 'libubuntu-app-launch/application-info-desktop.cpp' |
894 | --- libubuntu-app-launch/application-info-desktop.cpp 2017-03-20 10:13:50 +0000 |
895 | +++ libubuntu-app-launch/application-info-desktop.cpp 2017-04-04 21:22:36 +0000 |
896 | @@ -265,7 +265,7 @@ |
897 | const std::string& basePath, |
898 | const std::string& rootDir, |
899 | std::bitset<2> flags, |
900 | - std::shared_ptr<Registry> registry) |
901 | + const std::shared_ptr<Registry::Impl>& registry) |
902 | : _keyfile([keyfile, flags]() { |
903 | if (!keyfile) |
904 | { |
905 | @@ -318,7 +318,7 @@ |
906 | if (!iconName.value().empty() && iconName.value()[0] != '/') |
907 | { |
908 | /* If it is not a direct filename look it up */ |
909 | - return registry->impl->getIconFinder(basePath)->find(iconName); |
910 | + return registry->getIconFinder(basePath)->find(iconName); |
911 | } |
912 | } |
913 | return fileFromKeyfile<Application::Info::IconPath>(keyfile, basePath, rootDir, "Icon"); |
914 | @@ -331,7 +331,7 @@ |
915 | , _keywords(stringlistFromKeyfile<Application::Info::Keywords>(keyfile, "Keywords")) |
916 | , _popularity([registry, appid] { |
917 | if (registry) |
918 | - return Registry::Impl::getZgWatcher(registry)->lookupAppPopularity(appid); |
919 | + return registry->getZgWatcher()->lookupAppPopularity(appid); |
920 | else |
921 | return Application::Info::Popularity::from_raw(0); |
922 | }()) |
923 | |
924 | === modified file 'libubuntu-app-launch/application-info-desktop.h' |
925 | --- libubuntu-app-launch/application-info-desktop.h 2017-02-09 04:28:16 +0000 |
926 | +++ libubuntu-app-launch/application-info-desktop.h 2017-04-04 21:22:36 +0000 |
927 | @@ -17,13 +17,15 @@ |
928 | * Ted Gould <ted.gould@canonical.com> |
929 | */ |
930 | |
931 | +#pragma once |
932 | + |
933 | #include "application.h" |
934 | +#include "registry-impl.h" |
935 | +#include "registry.h" |
936 | #include <bitset> |
937 | #include <glib.h> |
938 | #include <mutex> |
939 | |
940 | -#pragma once |
941 | - |
942 | namespace ubuntu |
943 | { |
944 | namespace app_launch |
945 | @@ -46,7 +48,7 @@ |
946 | const std::string& basePath, |
947 | const std::string& rootDir, |
948 | std::bitset<2> flags, |
949 | - std::shared_ptr<Registry> registry); |
950 | + const std::shared_ptr<Registry::Impl>& registry); |
951 | |
952 | const Application::Info::Name& name() override |
953 | { |
954 | |
955 | === modified file 'libubuntu-app-launch/application.cpp' |
956 | --- libubuntu-app-launch/application.cpp 2017-02-25 15:58:27 +0000 |
957 | +++ libubuntu-app-launch/application.cpp 2017-04-04 21:22:36 +0000 |
958 | @@ -48,20 +48,7 @@ |
959 | throw std::runtime_error("Invalid registry object"); |
960 | } |
961 | |
962 | - if (!registry->impl->jobs) |
963 | - { |
964 | - registry->impl->jobs = jobs::manager::Base::determineFactory(registry); |
965 | - } |
966 | - |
967 | - for (const auto& appStore : registry->impl->appStores()) |
968 | - { |
969 | - if (appStore->hasAppId(appid, registry)) |
970 | - { |
971 | - return appStore->create(appid, registry); |
972 | - } |
973 | - } |
974 | - |
975 | - throw std::runtime_error("Invalid app ID: " + std::string(appid)); |
976 | + return registry->impl->createApp(appid); |
977 | } |
978 | |
979 | AppID::AppID() |
980 | @@ -110,11 +97,16 @@ |
981 | AppID AppID::find(const std::string& sappid) |
982 | { |
983 | auto registry = Registry::getDefault(); |
984 | - return find(registry, sappid); |
985 | + return registry->impl->find(sappid); |
986 | } |
987 | |
988 | AppID AppID::find(const std::shared_ptr<Registry>& registry, const std::string& sappid) |
989 | { |
990 | + return registry->impl->find(sappid); |
991 | +} |
992 | + |
993 | +AppID Registry::Impl::find(const std::string& sappid) |
994 | +{ |
995 | std::smatch match; |
996 | |
997 | if (std::regex_match(sappid, match, full_appid_regex)) |
998 | @@ -124,7 +116,7 @@ |
999 | } |
1000 | else if (std::regex_match(sappid, match, short_appid_regex)) |
1001 | { |
1002 | - return discover(registry, match[1].str(), match[2].str()); |
1003 | + return discover(match[1].str(), match[2].str(), AppID::VersionWildcard::CURRENT_USER_VERSION); |
1004 | } |
1005 | else if (std::regex_match(sappid, match, legacy_appid_regex)) |
1006 | { |
1007 | @@ -181,33 +173,38 @@ |
1008 | const std::string& appname, |
1009 | const std::string& version) |
1010 | { |
1011 | + return registry->impl->discover(package, appname, version); |
1012 | +} |
1013 | + |
1014 | +AppID Registry::Impl::discover(const std::string& package, const std::string& appname, const std::string& version) |
1015 | +{ |
1016 | auto pkg = AppID::Package::from_raw(package); |
1017 | |
1018 | - for (const auto& appStore : registry->impl->appStores()) |
1019 | + for (const auto& appStore : appStores()) |
1020 | { |
1021 | /* Figure out which type we have */ |
1022 | try |
1023 | { |
1024 | - if (appStore->verifyPackage(pkg, registry)) |
1025 | + if (appStore->verifyPackage(pkg)) |
1026 | { |
1027 | auto app = AppID::AppName::from_raw({}); |
1028 | |
1029 | if (appname.empty() || appname == "first-listed-app") |
1030 | { |
1031 | - app = appStore->findAppname(pkg, ApplicationWildcard::FIRST_LISTED, registry); |
1032 | + app = appStore->findAppname(pkg, AppID::ApplicationWildcard::FIRST_LISTED); |
1033 | } |
1034 | else if (appname == "last-listed-app") |
1035 | { |
1036 | - app = appStore->findAppname(pkg, ApplicationWildcard::LAST_LISTED, registry); |
1037 | + app = appStore->findAppname(pkg, AppID::ApplicationWildcard::LAST_LISTED); |
1038 | } |
1039 | else if (appname == "only-listed-app") |
1040 | { |
1041 | - app = appStore->findAppname(pkg, ApplicationWildcard::ONLY_LISTED, registry); |
1042 | + app = appStore->findAppname(pkg, AppID::ApplicationWildcard::ONLY_LISTED); |
1043 | } |
1044 | else |
1045 | { |
1046 | app = AppID::AppName::from_raw(appname); |
1047 | - if (!appStore->verifyAppname(pkg, app, registry)) |
1048 | + if (!appStore->verifyAppname(pkg, app)) |
1049 | { |
1050 | throw std::runtime_error("App name passed in is not valid for this package type"); |
1051 | } |
1052 | @@ -216,12 +213,12 @@ |
1053 | auto ver = AppID::Version::from_raw({}); |
1054 | if (version.empty() || version == "current-user-version") |
1055 | { |
1056 | - ver = appStore->findVersion(pkg, app, registry); |
1057 | + ver = appStore->findVersion(pkg, app); |
1058 | } |
1059 | else |
1060 | { |
1061 | ver = AppID::Version::from_raw(version); |
1062 | - if (!appStore->hasAppId({pkg, app, ver}, registry)) |
1063 | + if (!appStore->hasAppId({pkg, app, ver})) |
1064 | { |
1065 | throw std::runtime_error("Invalid version passed for this package type"); |
1066 | } |
1067 | @@ -244,16 +241,23 @@ |
1068 | ApplicationWildcard appwildcard, |
1069 | VersionWildcard versionwildcard) |
1070 | { |
1071 | + return registry->impl->discover(package, appwildcard, versionwildcard); |
1072 | +} |
1073 | + |
1074 | +AppID Registry::Impl::discover(const std::string& package, |
1075 | + AppID::ApplicationWildcard appwildcard, |
1076 | + AppID::VersionWildcard versionwildcard) |
1077 | +{ |
1078 | auto pkg = AppID::Package::from_raw(package); |
1079 | |
1080 | - for (const auto& appStore : registry->impl->appStores()) |
1081 | + for (const auto& appStore : appStores()) |
1082 | { |
1083 | try |
1084 | { |
1085 | - if (appStore->verifyPackage(pkg, registry)) |
1086 | + if (appStore->verifyPackage(pkg)) |
1087 | { |
1088 | - auto app = appStore->findAppname(pkg, appwildcard, registry); |
1089 | - auto ver = appStore->findVersion(pkg, app, registry); |
1090 | + auto app = appStore->findAppname(pkg, appwildcard); |
1091 | + auto ver = appStore->findVersion(pkg, app); |
1092 | return AppID{pkg, app, ver}; |
1093 | } |
1094 | } |
1095 | @@ -272,16 +276,23 @@ |
1096 | const std::string& appname, |
1097 | VersionWildcard versionwildcard) |
1098 | { |
1099 | + return registry->impl->discover(package, appname, versionwildcard); |
1100 | +} |
1101 | + |
1102 | +AppID Registry::Impl::discover(const std::string& package, |
1103 | + const std::string& appname, |
1104 | + AppID::VersionWildcard versionwildcard) |
1105 | +{ |
1106 | auto pkg = AppID::Package::from_raw(package); |
1107 | auto app = AppID::AppName::from_raw(appname); |
1108 | |
1109 | - for (const auto& appStore : registry->impl->appStores()) |
1110 | + for (const auto& appStore : appStores()) |
1111 | { |
1112 | try |
1113 | { |
1114 | - if (appStore->verifyPackage(pkg, registry) && appStore->verifyAppname(pkg, app, registry)) |
1115 | + if (appStore->verifyPackage(pkg) && appStore->verifyAppname(pkg, app)) |
1116 | { |
1117 | - auto ver = appStore->findVersion(pkg, app, registry); |
1118 | + auto ver = appStore->findVersion(pkg, app); |
1119 | return AppID{pkg, app, ver}; |
1120 | } |
1121 | } |
1122 | @@ -298,19 +309,19 @@ |
1123 | AppID AppID::discover(const std::string& package, const std::string& appname, const std::string& version) |
1124 | { |
1125 | auto registry = Registry::getDefault(); |
1126 | - return discover(registry, package, appname, version); |
1127 | + return registry->impl->discover(package, appname, version); |
1128 | } |
1129 | |
1130 | AppID AppID::discover(const std::string& package, ApplicationWildcard appwildcard, VersionWildcard versionwildcard) |
1131 | { |
1132 | auto registry = Registry::getDefault(); |
1133 | - return discover(registry, package, appwildcard, versionwildcard); |
1134 | + return registry->impl->discover(package, appwildcard, versionwildcard); |
1135 | } |
1136 | |
1137 | AppID AppID::discover(const std::string& package, const std::string& appname, VersionWildcard versionwildcard) |
1138 | { |
1139 | auto registry = Registry::getDefault(); |
1140 | - return discover(registry, package, appname, versionwildcard); |
1141 | + return registry->impl->discover(package, appname, versionwildcard); |
1142 | } |
1143 | |
1144 | enum class oom::Score : std::int32_t |
1145 | |
1146 | === modified file 'libubuntu-app-launch/helper-impl.h' |
1147 | --- libubuntu-app-launch/helper-impl.h 2017-03-14 03:23:02 +0000 |
1148 | +++ libubuntu-app-launch/helper-impl.h 2017-04-04 21:22:36 +0000 |
1149 | @@ -55,7 +55,7 @@ |
1150 | class Base : public Helper |
1151 | { |
1152 | public: |
1153 | - Base(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry>& registry); |
1154 | + Base(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry::Impl>& registry); |
1155 | |
1156 | AppID appId() override; |
1157 | |
1158 | @@ -70,7 +70,7 @@ |
1159 | private: |
1160 | Helper::Type _type; |
1161 | AppID _appid; |
1162 | - std::shared_ptr<Registry> _registry; |
1163 | + std::shared_ptr<Registry::Impl> registry_; |
1164 | |
1165 | std::list<std::pair<std::string, std::string>> defaultEnv(); |
1166 | }; |
1167 | |
1168 | === modified file 'libubuntu-app-launch/helper.cpp' |
1169 | --- libubuntu-app-launch/helper.cpp 2017-03-20 12:28:10 +0000 |
1170 | +++ libubuntu-app-launch/helper.cpp 2017-04-04 21:22:36 +0000 |
1171 | @@ -73,10 +73,10 @@ |
1172 | * Helper Class |
1173 | **********************/ |
1174 | |
1175 | -Base::Base(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry>& registry) |
1176 | +Base::Base(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry::Impl>& registry) |
1177 | : _type(type) |
1178 | , _appid(appid) |
1179 | - , _registry(registry) |
1180 | + , registry_(registry) |
1181 | { |
1182 | } |
1183 | |
1184 | @@ -92,7 +92,7 @@ |
1185 | |
1186 | std::vector<std::shared_ptr<Helper::Instance>> Base::instances() |
1187 | { |
1188 | - auto insts = _registry->impl->jobs->instances(_appid, _type.value()); |
1189 | + auto insts = registry_->jobs()->instances(_appid, _type.value()); |
1190 | std::vector<std::shared_ptr<Helper::Instance>> wrapped{insts.size()}; |
1191 | |
1192 | std::transform(insts.begin(), insts.end(), wrapped.begin(), |
1193 | @@ -104,7 +104,7 @@ |
1194 | /** Find an instance that we already know the ID of */ |
1195 | std::shared_ptr<Helper::Instance> Base::existingInstance(const std::string& instanceid) |
1196 | { |
1197 | - auto appinst = _registry->impl->jobs->existing(_appid, _type.value(), instanceid, {}); |
1198 | + auto appinst = registry_->jobs()->existing(_appid, _type.value(), instanceid, {}); |
1199 | |
1200 | return std::make_shared<BaseInstance>(appinst); |
1201 | } |
1202 | @@ -212,14 +212,14 @@ |
1203 | auto defaultenv = defaultEnv(); |
1204 | std::function<std::list<std::pair<std::string, std::string>>()> envfunc = [defaultenv]() { return defaultenv; }; |
1205 | |
1206 | - return std::make_shared<BaseInstance>(_registry->impl->jobs->launch( |
1207 | + return std::make_shared<BaseInstance>(registry_->jobs()->launch( |
1208 | _appid, _type.value(), genInstanceId(), appURL(urls), jobs::manager::launchMode::STANDARD, envfunc)); |
1209 | } |
1210 | |
1211 | class MirFDProxy |
1212 | { |
1213 | public: |
1214 | - std::shared_ptr<Registry> reg_; |
1215 | + std::shared_ptr<Registry::Impl> reg_; |
1216 | ResourcePtr<int, void (*)(int)> mirfd; |
1217 | std::shared_ptr<proxySocketDemangler> skel; |
1218 | ManagedSignalConnection<proxySocketDemangler> handle; |
1219 | @@ -227,7 +227,7 @@ |
1220 | std::string name; |
1221 | guint timeout{0}; |
1222 | |
1223 | - MirFDProxy(MirPromptSession* session, const AppID& appid, const std::shared_ptr<Registry>& reg) |
1224 | + MirFDProxy(MirPromptSession* session, const AppID& appid, const std::shared_ptr<Registry::Impl>& reg) |
1225 | : reg_(reg) |
1226 | , mirfd(0, |
1227 | [](int fp) { |
1228 | @@ -235,7 +235,7 @@ |
1229 | close(fp); |
1230 | }) |
1231 | , handle(SignalUnsubscriber<proxySocketDemangler>{}) |
1232 | - , name(g_dbus_connection_get_unique_name(reg->impl->_dbus.get())) |
1233 | + , name(g_dbus_connection_get_unique_name(reg->_dbus.get())) |
1234 | { |
1235 | if (appid.empty()) |
1236 | { |
1237 | @@ -268,7 +268,7 @@ |
1238 | } |
1239 | |
1240 | /* Setup the DBus interface */ |
1241 | - std::tie(skel, handle, path) = reg->impl->thread.executeOnThread<std::tuple< |
1242 | + std::tie(skel, handle, path) = reg->thread.executeOnThread<std::tuple< |
1243 | std::shared_ptr<proxySocketDemangler>, ManagedSignalConnection<proxySocketDemangler>, std::string>>( |
1244 | [this, appid, reg]() { |
1245 | auto skel = share_gobject(proxy_socket_demangler_skeleton_new()); |
1246 | @@ -285,7 +285,7 @@ |
1247 | GError* error = nullptr; |
1248 | std::string tryname = "/com/canonical/UbuntuAppLaunch/" + dbusAppid + "/" + std::to_string(rand()); |
1249 | |
1250 | - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skel.get()), reg->impl->_dbus.get(), |
1251 | + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skel.get()), reg->_dbus.get(), |
1252 | tryname.c_str(), &error); |
1253 | |
1254 | if (error == nullptr) |
1255 | @@ -355,7 +355,7 @@ |
1256 | auto reg = reg_; |
1257 | auto timeoutlocal = timeout; |
1258 | |
1259 | - reg->impl->thread.executeOnThread([reg, timeoutlocal]() { reg->impl->thread.removeSource(timeoutlocal); }); |
1260 | + reg->thread.executeOnThread([reg, timeoutlocal]() { reg->thread.removeSource(timeoutlocal); }); |
1261 | |
1262 | return true; |
1263 | } |
1264 | @@ -381,7 +381,7 @@ |
1265 | std::shared_ptr<MirFDProxy> proxy; |
1266 | try |
1267 | { |
1268 | - proxy = std::make_shared<MirFDProxy>(session, _appid, _registry); |
1269 | + proxy = std::make_shared<MirFDProxy>(session, _appid, registry_); |
1270 | } |
1271 | catch (std::runtime_error& e) |
1272 | { |
1273 | @@ -401,10 +401,9 @@ |
1274 | |
1275 | /* This will maintain a reference to the proxy for two |
1276 | seconds. And then it'll be dropped. */ |
1277 | - proxy->setTimeout( |
1278 | - _registry->impl->thread.timeout(std::chrono::seconds{2}, [proxy]() { g_debug("Mir Proxy Timeout"); })); |
1279 | + proxy->setTimeout(registry_->thread.timeout(std::chrono::seconds{2}, [proxy]() { g_debug("Mir Proxy Timeout"); })); |
1280 | |
1281 | - return std::make_shared<BaseInstance>(_registry->impl->jobs->launch( |
1282 | + return std::make_shared<BaseInstance>(registry_->jobs()->launch( |
1283 | _appid, _type.value(), genInstanceId(), appURL(urls), jobs::manager::launchMode::STANDARD, envfunc)); |
1284 | } |
1285 | |
1286 | @@ -416,8 +415,7 @@ |
1287 | |
1288 | std::shared_ptr<Helper> Helper::create(Type type, AppID appid, std::shared_ptr<Registry> registry) |
1289 | { |
1290 | - /* Only one type today */ |
1291 | - return std::make_shared<helper_impls::Base>(type, appid, registry); |
1292 | + return registry->impl->createHelper(type, appid, registry->impl); |
1293 | } |
1294 | |
1295 | /* Hardcore socket stuff */ |
1296 | |
1297 | === modified file 'libubuntu-app-launch/info-watcher-zg.cpp' |
1298 | --- libubuntu-app-launch/info-watcher-zg.cpp 2017-02-10 16:50:40 +0000 |
1299 | +++ libubuntu-app-launch/info-watcher-zg.cpp 2017-04-04 21:22:36 +0000 |
1300 | @@ -28,7 +28,7 @@ |
1301 | namespace info_watcher |
1302 | { |
1303 | |
1304 | -Zeitgeist::Zeitgeist(const std::shared_ptr<Registry>& registry) |
1305 | +Zeitgeist::Zeitgeist(const std::shared_ptr<Registry::Impl>& registry) |
1306 | : Base(registry) |
1307 | { |
1308 | g_debug("Created a ZG Watcher"); |
1309 | |
1310 | === modified file 'libubuntu-app-launch/info-watcher-zg.h' |
1311 | --- libubuntu-app-launch/info-watcher-zg.h 2017-02-10 16:50:40 +0000 |
1312 | +++ libubuntu-app-launch/info-watcher-zg.h 2017-04-04 21:22:36 +0000 |
1313 | @@ -36,7 +36,7 @@ |
1314 | class Zeitgeist : public Base |
1315 | { |
1316 | public: |
1317 | - Zeitgeist(const std::shared_ptr<Registry>& registry); |
1318 | + Zeitgeist(const std::shared_ptr<Registry::Impl>& registry); |
1319 | virtual ~Zeitgeist() = default; |
1320 | |
1321 | virtual Application::Info::Popularity lookupAppPopularity(const AppID& appid); |
1322 | |
1323 | === modified file 'libubuntu-app-launch/info-watcher.cpp' |
1324 | --- libubuntu-app-launch/info-watcher.cpp 2017-02-08 21:31:37 +0000 |
1325 | +++ libubuntu-app-launch/info-watcher.cpp 2017-04-04 21:22:36 +0000 |
1326 | @@ -18,6 +18,7 @@ |
1327 | */ |
1328 | |
1329 | #include "info-watcher.h" |
1330 | +#include <glib.h> |
1331 | |
1332 | namespace ubuntu |
1333 | { |
1334 | @@ -26,8 +27,21 @@ |
1335 | namespace info_watcher |
1336 | { |
1337 | |
1338 | -Base::Base(const std::shared_ptr<Registry>& registry) |
1339 | -{ |
1340 | +Base::Base(const std::shared_ptr<Registry::Impl>& registry) |
1341 | + : registry_(registry) |
1342 | +{ |
1343 | +} |
1344 | + |
1345 | +/** Accessor function to the registry that ensures we can still |
1346 | + get it, which we always should be able to, but in case. */ |
1347 | +std::shared_ptr<Registry::Impl> Base::getReg() |
1348 | +{ |
1349 | + auto reg = registry_.lock(); |
1350 | + if (G_UNLIKELY(!reg)) |
1351 | + { |
1352 | + throw std::runtime_error{"App Store lost track of the Registry that owns it"}; |
1353 | + } |
1354 | + return reg; |
1355 | } |
1356 | |
1357 | } // namespace info_watcher |
1358 | |
1359 | === modified file 'libubuntu-app-launch/info-watcher.h' |
1360 | --- libubuntu-app-launch/info-watcher.h 2017-02-08 21:31:37 +0000 |
1361 | +++ libubuntu-app-launch/info-watcher.h 2017-04-04 21:22:36 +0000 |
1362 | @@ -35,7 +35,7 @@ |
1363 | class Base |
1364 | { |
1365 | public: |
1366 | - Base(const std::shared_ptr<Registry>& registry); |
1367 | + Base(const std::shared_ptr<Registry::Impl>& registry); |
1368 | virtual ~Base() = default; |
1369 | |
1370 | virtual core::Signal<const std::shared_ptr<Application>&>& infoChanged() |
1371 | @@ -44,7 +44,16 @@ |
1372 | } |
1373 | |
1374 | protected: |
1375 | + /** Signal for info changed on an application */ |
1376 | core::Signal<const std::shared_ptr<Application>&> infoChanged_; |
1377 | + |
1378 | + /** Accessor function to the registry that ensures we can still |
1379 | + get it, which we always should be able to, but in case. */ |
1380 | + std::shared_ptr<Registry::Impl> getReg(); |
1381 | + |
1382 | +private: |
1383 | + /** Pointer to our implementing registry */ |
1384 | + std::weak_ptr<Registry::Impl> registry_; |
1385 | }; |
1386 | |
1387 | } // namespace info_watcher |
1388 | |
1389 | === modified file 'libubuntu-app-launch/jobs-base.cpp' |
1390 | --- libubuntu-app-launch/jobs-base.cpp 2017-03-21 03:28:22 +0000 |
1391 | +++ libubuntu-app-launch/jobs-base.cpp 2017-04-04 21:22:36 +0000 |
1392 | @@ -43,10 +43,9 @@ |
1393 | namespace manager |
1394 | { |
1395 | |
1396 | -Base::Base(const std::shared_ptr<Registry>& registry) |
1397 | - : registry_(registry) |
1398 | +Base::Base(const std::shared_ptr<Registry::Impl>& registry) |
1399 | + : registry_{registry} |
1400 | , allApplicationJobs_{"application-legacy", "application-snap"} |
1401 | - , dbus_(registry->impl->_dbus) |
1402 | { |
1403 | } |
1404 | |
1405 | @@ -56,7 +55,7 @@ |
1406 | |
1407 | /** Should determine which jobs backend to use, but we only have |
1408 | one right now. */ |
1409 | -std::shared_ptr<Base> Base::determineFactory(std::shared_ptr<Registry> registry) |
1410 | +std::shared_ptr<Base> Base::determineFactory(const std::shared_ptr<Registry::Impl>& registry) |
1411 | { |
1412 | g_debug("Building a systemd jobs manager"); |
1413 | return std::make_shared<jobs::manager::SystemD>(registry); |
1414 | @@ -79,10 +78,9 @@ |
1415 | |
1416 | try |
1417 | { |
1418 | - auto reg = registry_.lock(); |
1419 | - |
1420 | - auto appId = AppID::find(reg, appid); |
1421 | - auto app = Application::create(appId, reg); |
1422 | + auto reg = getReg(); |
1423 | + auto appId = reg->find(appid); |
1424 | + auto app = reg->createApp(appId); |
1425 | auto inst = std::dynamic_pointer_cast<app_impls::Base>(app)->findInstance(instanceid); |
1426 | |
1427 | sig_appStarted(app, inst); |
1428 | @@ -109,10 +107,9 @@ |
1429 | |
1430 | try |
1431 | { |
1432 | - auto reg = registry_.lock(); |
1433 | - |
1434 | - auto appId = AppID::find(reg, appid); |
1435 | - auto app = Application::create(appId, reg); |
1436 | + auto reg = getReg(); |
1437 | + auto appId = reg->find(appid); |
1438 | + auto app = reg->createApp(appId); |
1439 | auto inst = std::dynamic_pointer_cast<app_impls::Base>(app)->findInstance(instanceid); |
1440 | |
1441 | sig_appStopped(app, inst); |
1442 | @@ -141,10 +138,9 @@ |
1443 | |
1444 | try |
1445 | { |
1446 | - auto reg = registry_.lock(); |
1447 | - |
1448 | - auto appId = AppID::find(reg, appid); |
1449 | - auto app = Application::create(appId, reg); |
1450 | + auto reg = getReg(); |
1451 | + auto appId = reg->find(appid); |
1452 | + auto app = reg->createApp(appId); |
1453 | auto inst = std::dynamic_pointer_cast<app_impls::Base>(app)->findInstance(instanceid); |
1454 | |
1455 | sig_appFailed(app, inst, reason); |
1456 | @@ -166,7 +162,7 @@ |
1457 | { |
1458 | /** Keeping a weak pointer because the handle is held by |
1459 | the registry implementation. */ |
1460 | - std::weak_ptr<Registry> weakReg; |
1461 | + std::weak_ptr<Registry::Impl> weakReg; |
1462 | }; |
1463 | |
1464 | /** Core handler for pause and resume events. Includes turning the GVariant |
1465 | @@ -175,7 +171,7 @@ |
1466 | const std::shared_ptr<Application::Instance>&, |
1467 | const std::vector<pid_t>&>& signal, |
1468 | const std::shared_ptr<GVariant>& params, |
1469 | - const std::shared_ptr<Registry>& reg) |
1470 | + const std::shared_ptr<Registry::Impl>& reg) |
1471 | { |
1472 | std::vector<pid_t> pids; |
1473 | auto vappid = unique_glib(g_variant_get_child_value(params.get(), 0)); |
1474 | @@ -193,8 +189,8 @@ |
1475 | auto cappid = g_variant_get_string(vappid.get(), NULL); |
1476 | auto cinstid = g_variant_get_string(vinstid.get(), NULL); |
1477 | |
1478 | - auto appid = ubuntu::app_launch::AppID::find(reg, cappid); |
1479 | - auto app = Application::create(appid, reg); |
1480 | + auto appid = reg->find(cappid); |
1481 | + auto app = reg->createApp(appid); |
1482 | auto inst = std::dynamic_pointer_cast<app_impls::Base>(app)->findInstance(cinstid); |
1483 | |
1484 | signal(app, inst, pids); |
1485 | @@ -210,13 +206,12 @@ |
1486 | Base::appPaused() |
1487 | { |
1488 | std::call_once(flag_appPaused, [this]() { |
1489 | - auto reg = registry_.lock(); |
1490 | - |
1491 | - reg->impl->thread.executeOnThread<bool>([this, reg]() { |
1492 | + auto reg = getReg(); |
1493 | + reg->thread.executeOnThread<bool>([this, reg]() { |
1494 | upstartEventData* data = new upstartEventData{reg}; |
1495 | |
1496 | handle_appPaused = managedDBusSignalConnection( |
1497 | - g_dbus_connection_signal_subscribe(reg->impl->_dbus.get(), /* bus */ |
1498 | + g_dbus_connection_signal_subscribe(reg->_dbus.get(), /* bus */ |
1499 | nullptr, /* sender */ |
1500 | "com.canonical.UbuntuAppLaunch", /* interface */ |
1501 | "ApplicationPaused", /* signal */ |
1502 | @@ -235,7 +230,7 @@ |
1503 | } |
1504 | |
1505 | auto sparams = share_glib(g_variant_ref(params)); |
1506 | - auto manager = std::dynamic_pointer_cast<Base>(reg->impl->jobs); |
1507 | + auto manager = std::dynamic_pointer_cast<Base>(reg->jobs()); |
1508 | manager->pauseEventEmitted(manager->sig_appPaused, sparams, reg); |
1509 | }, /* callback */ |
1510 | data, /* user data */ |
1511 | @@ -243,7 +238,7 @@ |
1512 | auto data = reinterpret_cast<upstartEventData*>(user_data); |
1513 | delete data; |
1514 | }), /* user data destroy */ |
1515 | - reg->impl->_dbus); |
1516 | + reg->_dbus); |
1517 | |
1518 | return true; |
1519 | }); |
1520 | @@ -260,13 +255,12 @@ |
1521 | Base::appResumed() |
1522 | { |
1523 | std::call_once(flag_appResumed, [this]() { |
1524 | - auto reg = registry_.lock(); |
1525 | - |
1526 | - reg->impl->thread.executeOnThread<bool>([this, reg]() { |
1527 | + auto reg = getReg(); |
1528 | + reg->thread.executeOnThread<bool>([this, reg]() { |
1529 | upstartEventData* data = new upstartEventData{reg}; |
1530 | |
1531 | handle_appResumed = managedDBusSignalConnection( |
1532 | - g_dbus_connection_signal_subscribe(reg->impl->_dbus.get(), /* bus */ |
1533 | + g_dbus_connection_signal_subscribe(reg->_dbus.get(), /* bus */ |
1534 | nullptr, /* sender */ |
1535 | "com.canonical.UbuntuAppLaunch", /* interface */ |
1536 | "ApplicationResumed", /* signal */ |
1537 | @@ -285,7 +279,7 @@ |
1538 | } |
1539 | |
1540 | auto sparams = share_glib(g_variant_ref(params)); |
1541 | - auto manager = std::dynamic_pointer_cast<Base>(reg->impl->jobs); |
1542 | + auto manager = std::dynamic_pointer_cast<Base>(reg->jobs()); |
1543 | manager->pauseEventEmitted(manager->sig_appResumed, sparams, |
1544 | reg); |
1545 | }, /* callback */ |
1546 | @@ -294,7 +288,7 @@ |
1547 | auto data = reinterpret_cast<upstartEventData*>(user_data); |
1548 | delete data; |
1549 | }), /* user data destroy */ |
1550 | - reg->impl->_dbus); |
1551 | + reg->_dbus); |
1552 | |
1553 | return true; |
1554 | }); |
1555 | @@ -321,10 +315,9 @@ |
1556 | |
1557 | try |
1558 | { |
1559 | - auto reg = registry_.lock(); |
1560 | - |
1561 | - auto appId = ubuntu::app_launch::AppID::parse(appid); |
1562 | - auto helper = Helper::create(type, appId, reg); |
1563 | + auto reg = getReg(); |
1564 | + auto appId = reg->find(appid); |
1565 | + auto helper = reg->createHelper(type, appId, reg); |
1566 | auto inst = std::dynamic_pointer_cast<helper_impls::Base>(helper)->existingInstance(instanceid); |
1567 | |
1568 | (*sig_helpersStarted.at(type.value()))(helper, inst); |
1569 | @@ -361,10 +354,9 @@ |
1570 | |
1571 | try |
1572 | { |
1573 | - auto reg = registry_.lock(); |
1574 | - |
1575 | + auto reg = getReg(); |
1576 | auto appId = ubuntu::app_launch::AppID::parse(appid); |
1577 | - auto helper = Helper::create(type, appId, reg); |
1578 | + auto helper = reg->createHelper(type, appId, reg); |
1579 | auto inst = std::dynamic_pointer_cast<helper_impls::Base>(helper)->existingInstance(instanceid); |
1580 | |
1581 | (*sig_helpersStopped.at(type.value()))(helper, inst); |
1582 | @@ -401,10 +393,9 @@ |
1583 | |
1584 | try |
1585 | { |
1586 | - auto reg = registry_.lock(); |
1587 | - |
1588 | + auto reg = getReg(); |
1589 | auto appId = ubuntu::app_launch::AppID::parse(appid); |
1590 | - auto helper = Helper::create(type, appId, reg); |
1591 | + auto helper = reg->createHelper(type, appId, reg); |
1592 | auto inst = std::dynamic_pointer_cast<helper_impls::Base>(helper)->existingInstance(instanceid); |
1593 | |
1594 | (*sig_helpersFailed.at(type.value()))(helper, inst, reason); |
1595 | @@ -427,7 +418,7 @@ |
1596 | /** Take the GVariant of parameters and turn them into an application and |
1597 | and instance. Easier to read in the smaller function */ |
1598 | std::tuple<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>> Base::managerParams( |
1599 | - const std::shared_ptr<GVariant>& params, const std::shared_ptr<Registry>& reg) |
1600 | + const std::shared_ptr<GVariant>& params, const std::shared_ptr<Registry::Impl>& reg) |
1601 | { |
1602 | std::shared_ptr<Application> app; |
1603 | std::shared_ptr<Application::Instance> instance; |
1604 | @@ -436,8 +427,10 @@ |
1605 | const gchar* cinstid = nullptr; |
1606 | g_variant_get(params.get(), "(&s&s)", &cappid, &cinstid); |
1607 | |
1608 | - auto appid = ubuntu::app_launch::AppID::find(reg, cappid); |
1609 | - app = ubuntu::app_launch::Application::create(appid, reg); |
1610 | + auto appid = reg->find(cappid); |
1611 | + app = reg->createApp(appid); |
1612 | + |
1613 | + /* TODO Instance */ |
1614 | |
1615 | return std::make_tuple(app, instance); |
1616 | } |
1617 | @@ -448,8 +441,8 @@ |
1618 | { |
1619 | /* Keeping a weak pointer because the handle is held by |
1620 | the registry implementation. */ |
1621 | - std::weak_ptr<Registry> weakReg; |
1622 | - std::function<void(const std::shared_ptr<Registry>& reg, |
1623 | + std::weak_ptr<Registry::Impl> weakReg; |
1624 | + std::function<void(const std::shared_ptr<Registry::Impl>& reg, |
1625 | const std::shared_ptr<Application>& app, |
1626 | const std::shared_ptr<Application::Instance>& instance, |
1627 | const std::shared_ptr<GDBusConnection>&, |
1628 | @@ -462,19 +455,19 @@ |
1629 | code so it got pulled out into a function. Takes the same of the signal, the registry |
1630 | that we're using and a function to call after we've messaged all the parameters |
1631 | into being something C++-ish. */ |
1632 | -guint Base::managerSignalHelper(const std::shared_ptr<Registry>& reg, |
1633 | - const std::string& signalname, |
1634 | - std::function<void(const std::shared_ptr<Registry>& reg, |
1635 | +guint Base::managerSignalHelper(const std::string& signalname, |
1636 | + std::function<void(const std::shared_ptr<Registry::Impl>& reg, |
1637 | const std::shared_ptr<Application>& app, |
1638 | const std::shared_ptr<Application::Instance>& instance, |
1639 | const std::shared_ptr<GDBusConnection>&, |
1640 | const std::string&, |
1641 | const std::shared_ptr<GVariant>&)> responsefunc) |
1642 | { |
1643 | + auto reg = getReg(); |
1644 | managerEventData* focusdata = new managerEventData{reg, responsefunc}; |
1645 | |
1646 | return g_dbus_connection_signal_subscribe( |
1647 | - reg->impl->_dbus.get(), /* bus */ |
1648 | + reg->_dbus.get(), /* bus */ |
1649 | nullptr, /* sender */ |
1650 | "com.canonical.UbuntuAppLaunch", /* interface */ |
1651 | signalname.c_str(), /* signal */ |
1652 | @@ -494,7 +487,7 @@ |
1653 | |
1654 | /* If we're still conneted and the manager has been cleared |
1655 | we'll just be a no-op */ |
1656 | - auto ljobs = std::dynamic_pointer_cast<Base>(reg->impl->jobs); |
1657 | + auto ljobs = std::dynamic_pointer_cast<Base>(reg->jobs()); |
1658 | if (!ljobs->manager_) |
1659 | { |
1660 | return; |
1661 | @@ -540,41 +533,43 @@ |
1662 | manager_ = manager; |
1663 | |
1664 | std::call_once(flag_managerSignals, [this]() { |
1665 | - auto reg = registry_.lock(); |
1666 | - |
1667 | - if (!reg) |
1668 | - { |
1669 | - g_warning("Registry object invalid!"); |
1670 | - return; |
1671 | - } |
1672 | - |
1673 | - if (!reg->impl->thread.executeOnThread<bool>([this, reg]() { |
1674 | + auto reg = getReg(); |
1675 | + |
1676 | + if (!reg->thread.executeOnThread<bool>([this, reg]() { |
1677 | handle_managerSignalFocus = managedDBusSignalConnection( |
1678 | managerSignalHelper( |
1679 | - reg, "UnityFocusRequest", |
1680 | - [](const std::shared_ptr<Registry>& reg, const std::shared_ptr<Application>& app, |
1681 | + "UnityFocusRequest", |
1682 | + [](const std::shared_ptr<Registry::Impl>& reg, const std::shared_ptr<Application>& app, |
1683 | const std::shared_ptr<Application::Instance>& instance, |
1684 | const std::shared_ptr<GDBusConnection>& conn, const std::string& sender, |
1685 | const std::shared_ptr<GVariant>& params) { |
1686 | /* Nothing to do today */ |
1687 | - std::dynamic_pointer_cast<Base>(reg->impl->jobs) |
1688 | + std::dynamic_pointer_cast<Base>(reg->jobs()) |
1689 | ->manager_->focusRequest(app, instance, [](bool response) { |
1690 | - /* NOTE: We have no clue what thread this is gonna be |
1691 | - executed on, but since we're just talking to the GDBus |
1692 | - thread it isn't an issue today. Be careful in changing |
1693 | + /* NOTE: We have no |
1694 | + clue what thread |
1695 | + this is gonna be |
1696 | + executed on, but |
1697 | + since we're just |
1698 | + talking to the |
1699 | + GDBus |
1700 | + thread it isn't an |
1701 | + issue today. Be |
1702 | + careful in |
1703 | + changing |
1704 | this code. */ |
1705 | }); |
1706 | }), |
1707 | - reg->impl->_dbus); |
1708 | + reg->_dbus); |
1709 | handle_managerSignalStarting = managedDBusSignalConnection( |
1710 | managerSignalHelper( |
1711 | - reg, "UnityStartingBroadcast", |
1712 | - [](const std::shared_ptr<Registry>& reg, const std::shared_ptr<Application>& app, |
1713 | + "UnityStartingBroadcast", |
1714 | + [](const std::shared_ptr<Registry::Impl>& reg, const std::shared_ptr<Application>& app, |
1715 | const std::shared_ptr<Application::Instance>& instance, |
1716 | const std::shared_ptr<GDBusConnection>& conn, const std::string& sender, |
1717 | const std::shared_ptr<GVariant>& params) { |
1718 | |
1719 | - std::dynamic_pointer_cast<Base>(reg->impl->jobs) |
1720 | + std::dynamic_pointer_cast<Base>(reg->jobs()) |
1721 | ->manager_->startingRequest(app, instance, [conn, sender, params](bool response) { |
1722 | /* NOTE: We have no clue what thread this is gonna be |
1723 | executed on, but since we're just talking to the GDBus |
1724 | @@ -591,15 +586,15 @@ |
1725 | } |
1726 | }); |
1727 | }), |
1728 | - reg->impl->_dbus); |
1729 | + reg->_dbus); |
1730 | handle_managerSignalResume = managedDBusSignalConnection( |
1731 | managerSignalHelper( |
1732 | - reg, "UnityResumeRequest", |
1733 | - [](const std::shared_ptr<Registry>& reg, const std::shared_ptr<Application>& app, |
1734 | + "UnityResumeRequest", |
1735 | + [](const std::shared_ptr<Registry::Impl>& reg, const std::shared_ptr<Application>& app, |
1736 | const std::shared_ptr<Application::Instance>& instance, |
1737 | const std::shared_ptr<GDBusConnection>& conn, const std::string& sender, |
1738 | const std::shared_ptr<GVariant>& params) { |
1739 | - std::dynamic_pointer_cast<Base>(reg->impl->jobs) |
1740 | + std::dynamic_pointer_cast<Base>(reg->jobs()) |
1741 | ->manager_->resumeRequest(app, instance, [conn, sender, params](bool response) { |
1742 | /* NOTE: We have no clue what thread this is gonna be |
1743 | executed on, but since we're just talking to the GDBus |
1744 | @@ -616,7 +611,7 @@ |
1745 | } |
1746 | }); |
1747 | }), |
1748 | - reg->impl->_dbus); |
1749 | + reg->_dbus); |
1750 | |
1751 | return true; |
1752 | })) |
1753 | @@ -637,20 +632,13 @@ |
1754 | on the appids associated with the application jobs */ |
1755 | std::list<std::shared_ptr<Application>> Base::runningApps() |
1756 | { |
1757 | - auto registry = registry_.lock(); |
1758 | - |
1759 | - if (!registry) |
1760 | - { |
1761 | - g_warning("Unable to list apps without a registry"); |
1762 | - return {}; |
1763 | - } |
1764 | - |
1765 | + auto reg = getReg(); |
1766 | auto appids = runningAppIds(allApplicationJobs_); |
1767 | |
1768 | std::list<std::shared_ptr<Application>> apps; |
1769 | for (const auto& appid : appids) |
1770 | { |
1771 | - auto id = AppID::find(registry, appid); |
1772 | + auto id = reg->find(appid); |
1773 | if (id.empty()) |
1774 | { |
1775 | g_debug("Unable to handle AppID: %s", appid.c_str()); |
1776 | @@ -659,7 +647,7 @@ |
1777 | |
1778 | try |
1779 | { |
1780 | - apps.emplace_back(Application::create(id, registry)); |
1781 | + apps.emplace_back(reg->createApp(id)); |
1782 | } |
1783 | catch (std::runtime_error& e) |
1784 | { |
1785 | @@ -674,27 +662,20 @@ |
1786 | on the appids associated with the application jobs */ |
1787 | std::list<std::shared_ptr<Helper>> Base::runningHelpers(const Helper::Type& type) |
1788 | { |
1789 | - auto registry = registry_.lock(); |
1790 | - |
1791 | - if (!registry) |
1792 | - { |
1793 | - g_warning("Unable to list helpers without a registry"); |
1794 | - return {}; |
1795 | - } |
1796 | - |
1797 | + auto reg = getReg(); |
1798 | auto appids = runningAppIds({type.value()}); |
1799 | |
1800 | std::list<std::shared_ptr<Helper>> helpers; |
1801 | for (const auto& appid : appids) |
1802 | { |
1803 | - auto id = AppID::parse(appid); |
1804 | + auto id = reg->find(appid); |
1805 | if (id.empty()) |
1806 | { |
1807 | g_debug("Unable to handle AppID: %s", appid.c_str()); |
1808 | continue; |
1809 | } |
1810 | |
1811 | - helpers.emplace_back(Helper::create(type, id, registry)); |
1812 | + helpers.emplace_back(reg->createHelper(type, id, reg)); |
1813 | } |
1814 | |
1815 | return helpers; |
1816 | @@ -709,7 +690,7 @@ |
1817 | const std::string& job, |
1818 | const std::string& instance, |
1819 | const std::vector<Application::URL>& urls, |
1820 | - const std::shared_ptr<Registry>& registry) |
1821 | + const std::shared_ptr<Registry::Impl>& registry) |
1822 | : appId_(appId) |
1823 | , job_(job) |
1824 | , instance_(instance) |
1825 | @@ -742,7 +723,7 @@ |
1826 | void Base::pause() |
1827 | { |
1828 | g_debug("Pausing application: %s", std::string(appId_).c_str()); |
1829 | - registry_->impl->zgSendEvent(appId_, ZEITGEIST_ZG_LEAVE_EVENT); |
1830 | + registry_->zgSendEvent(appId_, ZEITGEIST_ZG_LEAVE_EVENT); |
1831 | |
1832 | auto pids = forAllPids([this](pid_t pid) { |
1833 | auto oomval = oom::paused(); |
1834 | @@ -759,7 +740,7 @@ |
1835 | void Base::resume() |
1836 | { |
1837 | g_debug("Resuming application: %s", std::string(appId_).c_str()); |
1838 | - registry_->impl->zgSendEvent(appId_, ZEITGEIST_ZG_ACCESS_EVENT); |
1839 | + registry_->zgSendEvent(appId_, ZEITGEIST_ZG_ACCESS_EVENT); |
1840 | |
1841 | auto pids = forAllPids([this](pid_t pid) { |
1842 | auto oomval = oom::focused(); |
1843 | @@ -782,7 +763,7 @@ |
1844 | g_variant_builder_init(¶ms, G_VARIANT_TYPE_TUPLE); |
1845 | g_variant_builder_add_value(¶ms, g_variant_new_string(std::string(appId_).c_str())); |
1846 | g_variant_builder_add_value(¶ms, g_variant_new_string(instance_.c_str())); |
1847 | - g_dbus_connection_emit_signal(registry_->impl->_dbus.get(), /* bus */ |
1848 | + g_dbus_connection_emit_signal(registry_->_dbus.get(), /* bus */ |
1849 | nullptr, /* destination */ |
1850 | "/", /* path */ |
1851 | "com.canonical.UbuntuAppLaunch", /* interface */ |
1852 | @@ -835,7 +816,7 @@ |
1853 | \param pids List of PIDs to turn into variants to send |
1854 | \param signal Name of the DBus signal to send |
1855 | */ |
1856 | -void Base::pidListToDbus(const std::shared_ptr<Registry>& reg, |
1857 | +void Base::pidListToDbus(const std::shared_ptr<Registry::Impl>& reg, |
1858 | const AppID& appid, |
1859 | const std::string& instanceid, |
1860 | const std::vector<pid_t>& pids, |
1861 | @@ -867,7 +848,7 @@ |
1862 | g_variant_builder_add_value(¶ms, vpids.get()); |
1863 | |
1864 | GError* error = nullptr; |
1865 | - g_dbus_connection_emit_signal(reg->impl->_dbus.get(), /* bus */ |
1866 | + g_dbus_connection_emit_signal(reg->_dbus.get(), /* bus */ |
1867 | nullptr, /* destination */ |
1868 | "/", /* path */ |
1869 | "com.canonical.UbuntuAppLaunch", /* interface */ |
1870 | @@ -1039,22 +1020,21 @@ |
1871 | std::array<const char*, 4> args = {OOM_HELPER, pidstr.c_str(), oomstr.c_str(), nullptr}; |
1872 | |
1873 | g_debug("Excuting OOM Helper (pid: %d, score: %d): %s", int(pid), int(oomvalue), |
1874 | - std::accumulate(args.begin(), args.end(), std::string{}, |
1875 | - [](const std::string& instr, const char* output) -> std::string { |
1876 | - if (instr.empty()) |
1877 | - { |
1878 | - return output; |
1879 | - } |
1880 | - else if (output != nullptr) |
1881 | - { |
1882 | - return instr + " " + std::string(output); |
1883 | - } |
1884 | - else |
1885 | - { |
1886 | - return instr; |
1887 | - } |
1888 | - }) |
1889 | - .c_str()); |
1890 | + std::accumulate(args.begin(), args.end(), std::string{}, [](const std::string& instr, |
1891 | + const char* output) -> std::string { |
1892 | + if (instr.empty()) |
1893 | + { |
1894 | + return output; |
1895 | + } |
1896 | + else if (output != nullptr) |
1897 | + { |
1898 | + return instr + " " + std::string(output); |
1899 | + } |
1900 | + else |
1901 | + { |
1902 | + return instr; |
1903 | + } |
1904 | + }).c_str()); |
1905 | |
1906 | g_spawn_async(nullptr, /* working dir */ |
1907 | (char**)(args.data()), /* args */ |
1908 | |
1909 | === modified file 'libubuntu-app-launch/jobs-base.h' |
1910 | --- libubuntu-app-launch/jobs-base.h 2017-03-21 03:28:22 +0000 |
1911 | +++ libubuntu-app-launch/jobs-base.h 2017-04-04 21:22:36 +0000 |
1912 | @@ -45,7 +45,7 @@ |
1913 | const std::string& job, |
1914 | const std::string& instance, |
1915 | const std::vector<Application::URL>& urls, |
1916 | - const std::shared_ptr<Registry>& registry); |
1917 | + const std::shared_ptr<Registry::Impl>& registry); |
1918 | virtual ~Base() = default; |
1919 | |
1920 | bool isRunning() override; |
1921 | @@ -74,10 +74,10 @@ |
1922 | should look at perhaps changing that. */ |
1923 | std::vector<Application::URL> urls_; |
1924 | /** A link to the registry we're using for connections */ |
1925 | - std::shared_ptr<Registry> registry_; |
1926 | + std::shared_ptr<Registry::Impl> registry_; |
1927 | |
1928 | std::vector<pid_t> forAllPids(std::function<void(pid_t)> eachPid); |
1929 | - static void pidListToDbus(const std::shared_ptr<Registry>& reg, |
1930 | + static void pidListToDbus(const std::shared_ptr<Registry::Impl>& reg, |
1931 | const AppID& appid, |
1932 | const std::string& instanceid, |
1933 | const std::vector<pid_t>& pids, |
1934 | @@ -104,7 +104,7 @@ |
1935 | class Base |
1936 | { |
1937 | public: |
1938 | - Base(const std::shared_ptr<Registry>& registry); |
1939 | + Base(const std::shared_ptr<Registry::Impl>& registry); |
1940 | virtual ~Base(); |
1941 | |
1942 | virtual std::shared_ptr<Application::Instance> launch( |
1943 | @@ -129,7 +129,7 @@ |
1944 | |
1945 | const std::list<std::string>& getAllApplicationJobs() const; |
1946 | |
1947 | - static std::shared_ptr<Base> determineFactory(std::shared_ptr<Registry> registry); |
1948 | + static std::shared_ptr<Base> determineFactory(const std::shared_ptr<Registry::Impl>& registry); |
1949 | |
1950 | /* Signals to apps */ |
1951 | virtual core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&>& |
1952 | @@ -153,9 +153,8 @@ |
1953 | Helper::Type type); |
1954 | virtual core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&>& helperStopped( |
1955 | Helper::Type type); |
1956 | - virtual core::Signal<const std::shared_ptr<Helper>&, |
1957 | - const std::shared_ptr<Helper::Instance>&, |
1958 | - Registry::FailureType>& |
1959 | + virtual core:: |
1960 | + Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&, Registry::FailureType>& |
1961 | helperFailed(Helper::Type type); |
1962 | /* Job signals from implementations */ |
1963 | virtual core::Signal<const std::string&, const std::string&, const std::string&>& jobStarted() = 0; |
1964 | @@ -168,19 +167,28 @@ |
1965 | virtual void clearManager(); |
1966 | |
1967 | protected: |
1968 | + /** Accessor function to the registry that ensures we can still |
1969 | + get it, which we always should be able to, but in case. */ |
1970 | + std::shared_ptr<Registry::Impl> getReg() |
1971 | + { |
1972 | + auto reg = registry_.lock(); |
1973 | + if (G_UNLIKELY(!reg)) |
1974 | + { |
1975 | + throw std::runtime_error{"Jobs manager lost track of the Registry that owns it"}; |
1976 | + } |
1977 | + return reg; |
1978 | + } |
1979 | + |
1980 | + /** Application manager instance */ |
1981 | + std::shared_ptr<Registry::Manager> manager_; |
1982 | + |
1983 | +private: |
1984 | /** A link to the registry */ |
1985 | - std::weak_ptr<Registry> registry_; |
1986 | + std::weak_ptr<Registry::Impl> registry_; |
1987 | |
1988 | /** A set of all the job names used by applications */ |
1989 | std::list<std::string> allApplicationJobs_; |
1990 | |
1991 | - /** The DBus connection we're connecting to */ |
1992 | - std::shared_ptr<GDBusConnection> dbus_; |
1993 | - |
1994 | - /** Application manager instance */ |
1995 | - std::shared_ptr<Registry::Manager> manager_; |
1996 | - |
1997 | -private: |
1998 | /** Signal object for applications started */ |
1999 | core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&> sig_appStarted; |
2000 | /** Signal object for applications stopped */ |
2001 | @@ -241,18 +249,17 @@ |
2002 | const std::shared_ptr<Application::Instance>&, |
2003 | const std::vector<pid_t>&>& signal, |
2004 | const std::shared_ptr<GVariant>& params, |
2005 | - const std::shared_ptr<Registry>& reg); |
2006 | + const std::shared_ptr<Registry::Impl>& reg); |
2007 | |
2008 | static std::tuple<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>> managerParams( |
2009 | - const std::shared_ptr<GVariant>& params, const std::shared_ptr<Registry>& reg); |
2010 | - static guint managerSignalHelper(const std::shared_ptr<Registry>& reg, |
2011 | - const std::string& signalname, |
2012 | - std::function<void(const std::shared_ptr<Registry>& reg, |
2013 | - const std::shared_ptr<Application>& app, |
2014 | - const std::shared_ptr<Application::Instance>& instance, |
2015 | - const std::shared_ptr<GDBusConnection>&, |
2016 | - const std::string&, |
2017 | - const std::shared_ptr<GVariant>&)> responsefunc); |
2018 | + const std::shared_ptr<GVariant>& params, const std::shared_ptr<Registry::Impl>& reg); |
2019 | + guint managerSignalHelper(const std::string& signalname, |
2020 | + std::function<void(const std::shared_ptr<Registry::Impl>& reg, |
2021 | + const std::shared_ptr<Application>& app, |
2022 | + const std::shared_ptr<Application::Instance>& instance, |
2023 | + const std::shared_ptr<GDBusConnection>&, |
2024 | + const std::string&, |
2025 | + const std::shared_ptr<GVariant>&)> responsefunc); |
2026 | }; |
2027 | |
2028 | } // namespace manager |
2029 | |
2030 | === modified file 'libubuntu-app-launch/jobs-systemd.cpp' |
2031 | --- libubuntu-app-launch/jobs-systemd.cpp 2017-03-21 03:28:22 +0000 |
2032 | +++ libubuntu-app-launch/jobs-systemd.cpp 2017-04-04 21:22:36 +0000 |
2033 | @@ -57,7 +57,7 @@ |
2034 | const std::string& job, |
2035 | const std::string& instance, |
2036 | const std::vector<Application::URL>& urls, |
2037 | - const std::shared_ptr<Registry>& registry); |
2038 | + const std::shared_ptr<Registry::Impl>& registry); |
2039 | virtual ~SystemD() |
2040 | { |
2041 | g_debug("Destroying a SystemD for '%s' instance '%s'", std::string(appId_).c_str(), instance_.c_str()); |
2042 | @@ -76,7 +76,7 @@ |
2043 | const std::string& job, |
2044 | const std::string& instance, |
2045 | const std::vector<Application::URL>& urls, |
2046 | - const std::shared_ptr<Registry>& registry) |
2047 | + const std::shared_ptr<Registry::Impl>& registry) |
2048 | : Base(appId, job, instance, urls, registry) |
2049 | { |
2050 | g_debug("Creating a new SystemD for '%s' instance '%s'", std::string(appId).c_str(), instance.c_str()); |
2051 | @@ -84,19 +84,19 @@ |
2052 | |
2053 | pid_t SystemD::primaryPid() |
2054 | { |
2055 | - auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry_->impl->jobs); |
2056 | + auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry_->jobs()); |
2057 | return manager->unitPrimaryPid(appId_, job_, instance_); |
2058 | } |
2059 | |
2060 | std::vector<pid_t> SystemD::pids() |
2061 | { |
2062 | - auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry_->impl->jobs); |
2063 | + auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry_->jobs()); |
2064 | return manager->unitPids(appId_, job_, instance_); |
2065 | } |
2066 | |
2067 | void SystemD::stop() |
2068 | { |
2069 | - auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry_->impl->jobs); |
2070 | + auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry_->jobs()); |
2071 | manager->stopUnit(appId_, job_, instance_); |
2072 | } |
2073 | |
2074 | @@ -111,7 +111,7 @@ |
2075 | // static const char * SYSTEMD_DBUS_IFACE_UNIT{"org.freedesktop.systemd1.Unit"}; |
2076 | static const char* SYSTEMD_DBUS_IFACE_SERVICE{"org.freedesktop.systemd1.Service"}; |
2077 | |
2078 | -SystemD::SystemD(std::shared_ptr<Registry> registry) |
2079 | +SystemD::SystemD(const std::shared_ptr<Registry::Impl>& registry) |
2080 | : Base(registry) |
2081 | , handle_unitNew(DBusSignalUnsubscriber{}) |
2082 | , handle_unitRemoved(DBusSignalUnsubscriber{}) |
2083 | @@ -129,8 +129,18 @@ |
2084 | cgroup_root_ = gcgroup_root; |
2085 | } |
2086 | |
2087 | - auto cancel = registry->impl->thread.getCancellable(); |
2088 | - userbus_ = registry->impl->thread.executeOnThread<std::shared_ptr<GDBusConnection>>([this, cancel]() { |
2089 | + if (getenv("UBUNTU_APP_LAUNCH_SYSTEMD_NO_RESET") != nullptr) |
2090 | + { |
2091 | + noResetUnits_ = true; |
2092 | + } |
2093 | + |
2094 | + setupUserbus(registry); |
2095 | +} |
2096 | + |
2097 | +void SystemD::setupUserbus(const std::shared_ptr<Registry::Impl>& reg) |
2098 | +{ |
2099 | + auto cancel = reg->thread.getCancellable(); |
2100 | + userbus_ = reg->thread.executeOnThread<std::shared_ptr<GDBusConnection>>([this, cancel]() { |
2101 | GError* error = nullptr; |
2102 | auto bus = std::shared_ptr<GDBusConnection>( |
2103 | [&]() -> GDBusConnection* { |
2104 | @@ -163,7 +173,7 @@ |
2105 | throw std::runtime_error(message); |
2106 | } |
2107 | |
2108 | - /* If we don't subscribe, it doesn't send us signals :-( */ |
2109 | + /* If we don't subscribe, it doesn't send us signals */ |
2110 | g_dbus_connection_call(bus.get(), /* user bus */ |
2111 | SYSTEMD_DBUS_ADDRESS, /* bus name */ |
2112 | SYSTEMD_DBUS_PATH_MANAGER, /* path */ |
2113 | @@ -301,11 +311,6 @@ |
2114 | |
2115 | return bus; |
2116 | }); |
2117 | - |
2118 | - if (getenv("UBUNTU_APP_LAUNCH_SYSTEMD_NO_RESET") != nullptr) |
2119 | - { |
2120 | - noResetUnits_ = true; |
2121 | - } |
2122 | } |
2123 | |
2124 | SystemD::~SystemD() |
2125 | @@ -354,14 +359,12 @@ |
2126 | while (g_variant_iter_loop(iter.get(), "(&s&s&s&s&s&s&ou&s&o)", &id, &description, &loadState, &activeState, |
2127 | &subState, &following, &path, &jobId, &jobType, &jobPath)) |
2128 | { |
2129 | - g_debug("List Units: %s", id); |
2130 | try |
2131 | { |
2132 | unitNew(id, jobPath, bus); |
2133 | } |
2134 | catch (std::runtime_error& e) |
2135 | { |
2136 | - g_debug("%s", e.what()); |
2137 | } |
2138 | } |
2139 | } |
2140 | @@ -511,12 +514,12 @@ |
2141 | if (g_strcmp0(remote_error, "org.freedesktop.systemd1.UnitExists") == 0) |
2142 | { |
2143 | auto urls = instance::SystemD::urlsToStrv(data->ptr->urls_); |
2144 | - second_exec(data->bus.get(), /* DBus */ |
2145 | - data->ptr->registry_->impl->thread.getCancellable().get(), /* cancellable */ |
2146 | - data->ptr->primaryPid(), /* primary pid */ |
2147 | - std::string(data->ptr->appId_).c_str(), /* appid */ |
2148 | - data->ptr->instance_.c_str(), /* instance */ |
2149 | - urls.get()); /* urls */ |
2150 | + second_exec(data->bus.get(), /* DBus */ |
2151 | + data->ptr->registry_->thread.getCancellable().get(), /* cancellable */ |
2152 | + data->ptr->primaryPid(), /* primary pid */ |
2153 | + std::string(data->ptr->appId_).c_str(), /* appid */ |
2154 | + data->ptr->instance_.c_str(), /* instance */ |
2155 | + urls.get()); /* urls */ |
2156 | } |
2157 | |
2158 | g_free(remote_error); |
2159 | @@ -579,247 +582,246 @@ |
2160 | if (appId.empty()) |
2161 | return {}; |
2162 | |
2163 | - bool isApplication = |
2164 | - std::find(allApplicationJobs_.begin(), allApplicationJobs_.end(), job) != allApplicationJobs_.end(); |
2165 | - |
2166 | - auto registry = registry_.lock(); |
2167 | - return registry->impl->thread.executeOnThread<std::shared_ptr<instance::SystemD>>( |
2168 | - [&]() -> std::shared_ptr<instance::SystemD> { |
2169 | - auto manager = std::dynamic_pointer_cast<manager::SystemD>(registry->impl->jobs); |
2170 | - std::string appIdStr{appId}; |
2171 | - g_debug("Initializing params for an new instance::SystemD for: %s", appIdStr.c_str()); |
2172 | - |
2173 | - tracepoint(ubuntu_app_launch, libual_start, appIdStr.c_str()); |
2174 | - |
2175 | - int timeout = 1; |
2176 | - if (ubuntu::app_launch::Registry::Impl::isWatchingAppStarting()) |
2177 | - { |
2178 | - timeout = 0; |
2179 | - } |
2180 | - |
2181 | - handshake_t* handshake{nullptr}; |
2182 | - |
2183 | - if (isApplication) |
2184 | - { |
2185 | - handshake = starting_handshake_start(appIdStr.c_str(), instance.c_str(), timeout); |
2186 | - if (handshake == nullptr) |
2187 | - { |
2188 | - g_warning("Unable to setup starting handshake"); |
2189 | - } |
2190 | - } |
2191 | - |
2192 | - /* Figure out the unit name for the job */ |
2193 | - auto unitname = unitName(SystemD::UnitInfo{appIdStr, job, instance}); |
2194 | - |
2195 | - /* Build up our environment */ |
2196 | - auto env = getenv(); |
2197 | - |
2198 | - env.emplace_back(std::make_pair("APP_ID", appIdStr)); /* Application ID */ |
2199 | - env.emplace_back(std::make_pair("APP_LAUNCHER_PID", std::to_string(getpid()))); /* Who we are, for bugs */ |
2200 | - |
2201 | - copyEnv("DISPLAY", env); |
2202 | - |
2203 | - for (const auto& prefix : {"DBUS_", "MIR_", "UBUNTU_APP_LAUNCH_"}) |
2204 | - { |
2205 | - copyEnvByPrefix(prefix, env); |
2206 | - } |
2207 | - |
2208 | - /* If we're in deb mode and launching legacy apps, they're gonna need |
2209 | - * more context, they really have no other way to get it. */ |
2210 | - if (g_getenv("SNAP") == nullptr && appId.package.value().empty()) |
2211 | - { |
2212 | - copyEnvByPrefix("QT_", env); |
2213 | - copyEnvByPrefix("XDG_", env); |
2214 | - copyEnv("UBUNTU_APP_LAUNCH_XMIR_PATH", env); |
2215 | - |
2216 | - /* If we're in Unity8 we don't want to pass it's platform, we want |
2217 | - * an application platform. */ |
2218 | - if (findEnv("QT_QPA_PLATFORM", env) == "mirserver") |
2219 | - { |
2220 | - removeEnv("QT_QPA_PLATFORM", env); |
2221 | - env.emplace_back(std::make_pair("QT_QPA_PLATFORM", "ubuntumirclient")); |
2222 | - } |
2223 | - } |
2224 | - |
2225 | - /* Mir socket if we don't have one in our env */ |
2226 | - if (findEnv("MIR_SOCKET", env).empty()) |
2227 | - { |
2228 | - env.emplace_back(std::make_pair("MIR_SOCKET", g_get_user_runtime_dir() + std::string{"/mir_socket"})); |
2229 | - } |
2230 | - |
2231 | - if (!urls.empty()) |
2232 | - { |
2233 | - auto accumfunc = [](const std::string& prev, Application::URL thisurl) -> std::string { |
2234 | - gchar* gescaped = g_shell_quote(thisurl.value().c_str()); |
2235 | - std::string escaped; |
2236 | - if (gescaped != nullptr) |
2237 | - { |
2238 | - escaped = gescaped; |
2239 | - g_free(gescaped); |
2240 | - } |
2241 | - else |
2242 | - { |
2243 | - g_warning("Unable to escape URL: %s", thisurl.value().c_str()); |
2244 | - return prev; |
2245 | - } |
2246 | - |
2247 | - if (prev.empty()) |
2248 | - { |
2249 | - return escaped; |
2250 | - } |
2251 | - else |
2252 | - { |
2253 | - return prev + " " + escaped; |
2254 | - } |
2255 | - }; |
2256 | - auto urlstring = std::accumulate(urls.begin(), urls.end(), std::string{}, accumfunc); |
2257 | - env.emplace_back(std::make_pair("APP_URIS", urlstring)); |
2258 | - } |
2259 | - |
2260 | - if (mode == launchMode::TEST) |
2261 | - { |
2262 | - env.emplace_back(std::make_pair("QT_LOAD_TESTABILITY", "1")); |
2263 | - } |
2264 | - |
2265 | - /* Convert to GVariant */ |
2266 | - GVariantBuilder builder; |
2267 | - g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); |
2268 | - |
2269 | - g_variant_builder_add_value(&builder, g_variant_new_string(unitname.c_str())); |
2270 | - g_variant_builder_add_value(&builder, g_variant_new_string("replace")); // Job mode |
2271 | - |
2272 | - /* Parameter Array */ |
2273 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2274 | - |
2275 | - /* ExecStart */ |
2276 | - auto commands = parseExec(env); |
2277 | - if (!commands.empty()) |
2278 | - { |
2279 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2280 | - g_variant_builder_add_value(&builder, g_variant_new_string("ExecStart")); |
2281 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2282 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2283 | - |
2284 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2285 | - |
2286 | - gchar* pathexec = g_find_program_in_path(commands[0].c_str()); |
2287 | - if (pathexec != nullptr) |
2288 | - { |
2289 | - g_variant_builder_add_value(&builder, g_variant_new_take_string(pathexec)); |
2290 | - } |
2291 | - else |
2292 | - { |
2293 | - g_debug("Unable to find '%s' in PATH=%s", commands[0].c_str(), g_getenv("PATH")); |
2294 | - g_variant_builder_add_value(&builder, g_variant_new_string(commands[0].c_str())); |
2295 | - } |
2296 | - |
2297 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2298 | - for (const auto& param : commands) |
2299 | - { |
2300 | - g_variant_builder_add_value(&builder, g_variant_new_string(param.c_str())); |
2301 | - } |
2302 | - g_variant_builder_close(&builder); |
2303 | - |
2304 | - g_variant_builder_add_value(&builder, g_variant_new_boolean(FALSE)); |
2305 | - |
2306 | - g_variant_builder_close(&builder); |
2307 | - g_variant_builder_close(&builder); |
2308 | - g_variant_builder_close(&builder); |
2309 | - g_variant_builder_close(&builder); |
2310 | - } |
2311 | - |
2312 | - /* RemainAfterExit */ |
2313 | + auto appJobs = getAllApplicationJobs(); |
2314 | + bool isApplication = std::find(appJobs.begin(), appJobs.end(), job) != appJobs.end(); |
2315 | + |
2316 | + auto reg = getReg(); |
2317 | + return reg->thread.executeOnThread<std::shared_ptr<instance::SystemD>>([&]() -> std::shared_ptr<instance::SystemD> { |
2318 | + auto manager = std::dynamic_pointer_cast<manager::SystemD>(reg->jobs()); |
2319 | + std::string appIdStr{appId}; |
2320 | + g_debug("Initializing params for an new instance::SystemD for: %s", appIdStr.c_str()); |
2321 | + |
2322 | + tracepoint(ubuntu_app_launch, libual_start, appIdStr.c_str()); |
2323 | + |
2324 | + int timeout = 1; |
2325 | + if (ubuntu::app_launch::Registry::Impl::isWatchingAppStarting()) |
2326 | + { |
2327 | + timeout = 0; |
2328 | + } |
2329 | + |
2330 | + handshake_t* handshake{nullptr}; |
2331 | + |
2332 | + if (isApplication) |
2333 | + { |
2334 | + handshake = starting_handshake_start(appIdStr.c_str(), instance.c_str(), timeout); |
2335 | + if (handshake == nullptr) |
2336 | + { |
2337 | + g_warning("Unable to setup starting handshake"); |
2338 | + } |
2339 | + } |
2340 | + |
2341 | + /* Figure out the unit name for the job */ |
2342 | + auto unitname = unitName(SystemD::UnitInfo{appIdStr, job, instance}); |
2343 | + |
2344 | + /* Build up our environment */ |
2345 | + auto env = getenv(); |
2346 | + |
2347 | + env.emplace_back(std::make_pair("APP_ID", appIdStr)); /* Application ID */ |
2348 | + env.emplace_back(std::make_pair("APP_LAUNCHER_PID", std::to_string(getpid()))); /* Who we are, for bugs */ |
2349 | + |
2350 | + copyEnv("DISPLAY", env); |
2351 | + |
2352 | + for (const auto& prefix : {"DBUS_", "MIR_", "UBUNTU_APP_LAUNCH_"}) |
2353 | + { |
2354 | + copyEnvByPrefix(prefix, env); |
2355 | + } |
2356 | + |
2357 | + /* If we're in deb mode and launching legacy apps, they're gonna need |
2358 | + * more context, they really have no other way to get it. */ |
2359 | + if (g_getenv("SNAP") == nullptr && appId.package.value().empty()) |
2360 | + { |
2361 | + copyEnvByPrefix("QT_", env); |
2362 | + copyEnvByPrefix("XDG_", env); |
2363 | + copyEnv("UBUNTU_APP_LAUNCH_XMIR_PATH", env); |
2364 | + |
2365 | + /* If we're in Unity8 we don't want to pass it's platform, we want |
2366 | + * an application platform. */ |
2367 | + if (findEnv("QT_QPA_PLATFORM", env) == "mirserver") |
2368 | + { |
2369 | + removeEnv("QT_QPA_PLATFORM", env); |
2370 | + env.emplace_back(std::make_pair("QT_QPA_PLATFORM", "ubuntumirclient")); |
2371 | + } |
2372 | + } |
2373 | + |
2374 | + /* Mir socket if we don't have one in our env */ |
2375 | + if (findEnv("MIR_SOCKET", env).empty()) |
2376 | + { |
2377 | + env.emplace_back(std::make_pair("MIR_SOCKET", g_get_user_runtime_dir() + std::string{"/mir_socket"})); |
2378 | + } |
2379 | + |
2380 | + if (!urls.empty()) |
2381 | + { |
2382 | + auto accumfunc = [](const std::string& prev, Application::URL thisurl) -> std::string { |
2383 | + gchar* gescaped = g_shell_quote(thisurl.value().c_str()); |
2384 | + std::string escaped; |
2385 | + if (gescaped != nullptr) |
2386 | + { |
2387 | + escaped = gescaped; |
2388 | + g_free(gescaped); |
2389 | + } |
2390 | + else |
2391 | + { |
2392 | + g_warning("Unable to escape URL: %s", thisurl.value().c_str()); |
2393 | + return prev; |
2394 | + } |
2395 | + |
2396 | + if (prev.empty()) |
2397 | + { |
2398 | + return escaped; |
2399 | + } |
2400 | + else |
2401 | + { |
2402 | + return prev + " " + escaped; |
2403 | + } |
2404 | + }; |
2405 | + auto urlstring = std::accumulate(urls.begin(), urls.end(), std::string{}, accumfunc); |
2406 | + env.emplace_back(std::make_pair("APP_URIS", urlstring)); |
2407 | + } |
2408 | + |
2409 | + if (mode == launchMode::TEST) |
2410 | + { |
2411 | + env.emplace_back(std::make_pair("QT_LOAD_TESTABILITY", "1")); |
2412 | + } |
2413 | + |
2414 | + /* Convert to GVariant */ |
2415 | + GVariantBuilder builder; |
2416 | + g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); |
2417 | + |
2418 | + g_variant_builder_add_value(&builder, g_variant_new_string(unitname.c_str())); |
2419 | + g_variant_builder_add_value(&builder, g_variant_new_string("replace")); // Job mode |
2420 | + |
2421 | + /* Parameter Array */ |
2422 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2423 | + |
2424 | + /* ExecStart */ |
2425 | + auto commands = parseExec(env); |
2426 | + if (!commands.empty()) |
2427 | + { |
2428 | g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2429 | - g_variant_builder_add_value(&builder, g_variant_new_string("RemainAfterExit")); |
2430 | + g_variant_builder_add_value(&builder, g_variant_new_string("ExecStart")); |
2431 | g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2432 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2433 | + |
2434 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2435 | + |
2436 | + gchar* pathexec = g_find_program_in_path(commands[0].c_str()); |
2437 | + if (pathexec != nullptr) |
2438 | + { |
2439 | + g_variant_builder_add_value(&builder, g_variant_new_take_string(pathexec)); |
2440 | + } |
2441 | + else |
2442 | + { |
2443 | + g_debug("Unable to find '%s' in PATH=%s", commands[0].c_str(), g_getenv("PATH")); |
2444 | + g_variant_builder_add_value(&builder, g_variant_new_string(commands[0].c_str())); |
2445 | + } |
2446 | + |
2447 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2448 | + for (const auto& param : commands) |
2449 | + { |
2450 | + g_variant_builder_add_value(&builder, g_variant_new_string(param.c_str())); |
2451 | + } |
2452 | + g_variant_builder_close(&builder); |
2453 | + |
2454 | g_variant_builder_add_value(&builder, g_variant_new_boolean(FALSE)); |
2455 | - g_variant_builder_close(&builder); |
2456 | - g_variant_builder_close(&builder); |
2457 | - |
2458 | - /* Type */ |
2459 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2460 | - g_variant_builder_add_value(&builder, g_variant_new_string("Type")); |
2461 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2462 | - g_variant_builder_add_value(&builder, g_variant_new_string("oneshot")); |
2463 | - g_variant_builder_close(&builder); |
2464 | - g_variant_builder_close(&builder); |
2465 | - |
2466 | - /* Working Directory */ |
2467 | - if (!findEnv("APP_DIR", env).empty()) |
2468 | - { |
2469 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2470 | - g_variant_builder_add_value(&builder, g_variant_new_string("WorkingDirectory")); |
2471 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2472 | - g_variant_builder_add_value(&builder, g_variant_new_string(findEnv("APP_DIR", env).c_str())); |
2473 | - g_variant_builder_close(&builder); |
2474 | - g_variant_builder_close(&builder); |
2475 | - } |
2476 | - |
2477 | - /* Clean up env before shipping it */ |
2478 | - for (const auto& rmenv : |
2479 | - {"APP_XMIR_ENABLE", "APP_DIR", "APP_URIS", "APP_EXEC", "APP_EXEC_POLICY", "APP_LAUNCHER_PID", |
2480 | - "INSTANCE_ID", "MIR_SERVER_PLATFORM_PATH", "MIR_SERVER_PROMPT_FILE", "MIR_SERVER_HOST_SOCKET", |
2481 | - "UBUNTU_APP_LAUNCH_OOM_HELPER", "UBUNTU_APP_LAUNCH_LEGACY_ROOT", "UBUNTU_APP_LAUNCH_XMIR_HELPER"}) |
2482 | - { |
2483 | - removeEnv(rmenv, env); |
2484 | - } |
2485 | - |
2486 | - g_debug("Environment length: %d", envSize(env)); |
2487 | - |
2488 | - /* Environment */ |
2489 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2490 | - g_variant_builder_add_value(&builder, g_variant_new_string("Environment")); |
2491 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2492 | - g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2493 | - for (const auto& envvar : env) |
2494 | - { |
2495 | - if (!envvar.first.empty() && !envvar.second.empty()) |
2496 | - { |
2497 | - g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf( |
2498 | - "%s=%s", envvar.first.c_str(), envvar.second.c_str()))); |
2499 | - // g_debug("Setting environment: %s=%s", envvar.first.c_str(), envvar.second.c_str()); |
2500 | - } |
2501 | - } |
2502 | - |
2503 | - g_variant_builder_close(&builder); |
2504 | - g_variant_builder_close(&builder); |
2505 | - g_variant_builder_close(&builder); |
2506 | - |
2507 | - /* Parameter Array */ |
2508 | - g_variant_builder_close(&builder); |
2509 | - |
2510 | - /* Dependent Units (none) */ |
2511 | - g_variant_builder_add_value(&builder, g_variant_new_array(G_VARIANT_TYPE("(sa(sv))"), nullptr, 0)); |
2512 | - |
2513 | - auto retval = std::make_shared<instance::SystemD>(appId, job, instance, urls, registry); |
2514 | - auto chelper = new StartCHelper{}; |
2515 | - chelper->ptr = retval; |
2516 | - chelper->bus = registry->impl->_dbus; |
2517 | - |
2518 | - tracepoint(ubuntu_app_launch, handshake_wait, appIdStr.c_str()); |
2519 | - starting_handshake_wait(handshake); |
2520 | - tracepoint(ubuntu_app_launch, handshake_complete, appIdStr.c_str()); |
2521 | - |
2522 | - /* Call the job start function */ |
2523 | - g_debug("Asking systemd to start task for: %s", appIdStr.c_str()); |
2524 | - g_dbus_connection_call(manager->userbus_.get(), /* bus */ |
2525 | - SYSTEMD_DBUS_ADDRESS, /* service name */ |
2526 | - SYSTEMD_DBUS_PATH_MANAGER, /* Path */ |
2527 | - SYSTEMD_DBUS_IFACE_MANAGER, /* interface */ |
2528 | - "StartTransientUnit", /* method */ |
2529 | - g_variant_builder_end(&builder), /* params */ |
2530 | - G_VARIANT_TYPE("(o)"), /* return */ |
2531 | - G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2532 | - -1, /* default timeout */ |
2533 | - registry->impl->thread.getCancellable().get(), /* cancellable */ |
2534 | - application_start_cb, /* callback */ |
2535 | - chelper /* object */ |
2536 | - ); |
2537 | - |
2538 | - tracepoint(ubuntu_app_launch, libual_start_message_sent, appIdStr.c_str()); |
2539 | - |
2540 | - return retval; |
2541 | - }); |
2542 | + |
2543 | + g_variant_builder_close(&builder); |
2544 | + g_variant_builder_close(&builder); |
2545 | + g_variant_builder_close(&builder); |
2546 | + g_variant_builder_close(&builder); |
2547 | + } |
2548 | + |
2549 | + /* RemainAfterExit */ |
2550 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2551 | + g_variant_builder_add_value(&builder, g_variant_new_string("RemainAfterExit")); |
2552 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2553 | + g_variant_builder_add_value(&builder, g_variant_new_boolean(FALSE)); |
2554 | + g_variant_builder_close(&builder); |
2555 | + g_variant_builder_close(&builder); |
2556 | + |
2557 | + /* Type */ |
2558 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2559 | + g_variant_builder_add_value(&builder, g_variant_new_string("Type")); |
2560 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2561 | + g_variant_builder_add_value(&builder, g_variant_new_string("oneshot")); |
2562 | + g_variant_builder_close(&builder); |
2563 | + g_variant_builder_close(&builder); |
2564 | + |
2565 | + /* Working Directory */ |
2566 | + if (!findEnv("APP_DIR", env).empty()) |
2567 | + { |
2568 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2569 | + g_variant_builder_add_value(&builder, g_variant_new_string("WorkingDirectory")); |
2570 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2571 | + g_variant_builder_add_value(&builder, g_variant_new_string(findEnv("APP_DIR", env).c_str())); |
2572 | + g_variant_builder_close(&builder); |
2573 | + g_variant_builder_close(&builder); |
2574 | + } |
2575 | + |
2576 | + /* Clean up env before shipping it */ |
2577 | + for (const auto& rmenv : |
2578 | + {"APP_XMIR_ENABLE", "APP_DIR", "APP_URIS", "APP_EXEC", "APP_EXEC_POLICY", "APP_LAUNCHER_PID", |
2579 | + "INSTANCE_ID", "MIR_SERVER_PLATFORM_PATH", "MIR_SERVER_PROMPT_FILE", "MIR_SERVER_HOST_SOCKET", |
2580 | + "UBUNTU_APP_LAUNCH_OOM_HELPER", "UBUNTU_APP_LAUNCH_LEGACY_ROOT", "UBUNTU_APP_LAUNCH_XMIR_HELPER"}) |
2581 | + { |
2582 | + removeEnv(rmenv, env); |
2583 | + } |
2584 | + |
2585 | + g_debug("Environment length: %d", envSize(env)); |
2586 | + |
2587 | + /* Environment */ |
2588 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE); |
2589 | + g_variant_builder_add_value(&builder, g_variant_new_string("Environment")); |
2590 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_VARIANT); |
2591 | + g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); |
2592 | + for (const auto& envvar : env) |
2593 | + { |
2594 | + if (!envvar.first.empty() && !envvar.second.empty()) |
2595 | + { |
2596 | + g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf( |
2597 | + "%s=%s", envvar.first.c_str(), envvar.second.c_str()))); |
2598 | + // g_debug("Setting environment: %s=%s", envvar.first.c_str(), envvar.second.c_str()); |
2599 | + } |
2600 | + } |
2601 | + |
2602 | + g_variant_builder_close(&builder); |
2603 | + g_variant_builder_close(&builder); |
2604 | + g_variant_builder_close(&builder); |
2605 | + |
2606 | + /* Parameter Array */ |
2607 | + g_variant_builder_close(&builder); |
2608 | + |
2609 | + /* Dependent Units (none) */ |
2610 | + g_variant_builder_add_value(&builder, g_variant_new_array(G_VARIANT_TYPE("(sa(sv))"), nullptr, 0)); |
2611 | + |
2612 | + auto retval = std::make_shared<instance::SystemD>(appId, job, instance, urls, reg); |
2613 | + auto chelper = new StartCHelper{}; |
2614 | + chelper->ptr = retval; |
2615 | + chelper->bus = reg->_dbus; |
2616 | + |
2617 | + tracepoint(ubuntu_app_launch, handshake_wait, appIdStr.c_str()); |
2618 | + starting_handshake_wait(handshake); |
2619 | + tracepoint(ubuntu_app_launch, handshake_complete, appIdStr.c_str()); |
2620 | + |
2621 | + /* Call the job start function */ |
2622 | + g_debug("Asking systemd to start task for: %s", appIdStr.c_str()); |
2623 | + g_dbus_connection_call(manager->userbus_.get(), /* bus */ |
2624 | + SYSTEMD_DBUS_ADDRESS, /* service name */ |
2625 | + SYSTEMD_DBUS_PATH_MANAGER, /* Path */ |
2626 | + SYSTEMD_DBUS_IFACE_MANAGER, /* interface */ |
2627 | + "StartTransientUnit", /* method */ |
2628 | + g_variant_builder_end(&builder), /* params */ |
2629 | + G_VARIANT_TYPE("(o)"), /* return */ |
2630 | + G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2631 | + -1, /* default timeout */ |
2632 | + reg->thread.getCancellable().get(), /* cancellable */ |
2633 | + application_start_cb, /* callback */ |
2634 | + chelper /* object */ |
2635 | + ); |
2636 | + |
2637 | + tracepoint(ubuntu_app_launch, libual_start_message_sent, appIdStr.c_str()); |
2638 | + |
2639 | + return retval; |
2640 | + }); |
2641 | } |
2642 | |
2643 | std::shared_ptr<Application::Instance> SystemD::existing(const AppID& appId, |
2644 | @@ -827,20 +829,15 @@ |
2645 | const std::string& instance, |
2646 | const std::vector<Application::URL>& urls) |
2647 | { |
2648 | - return std::make_shared<instance::SystemD>(appId, job, instance, urls, registry_.lock()); |
2649 | + return std::make_shared<instance::SystemD>(appId, job, instance, urls, getReg()); |
2650 | } |
2651 | |
2652 | std::vector<std::shared_ptr<instance::Base>> SystemD::instances(const AppID& appID, const std::string& job) |
2653 | { |
2654 | + auto reg = getReg(); |
2655 | + |
2656 | std::vector<std::shared_ptr<instance::Base>> instances; |
2657 | std::vector<Application::URL> urls; |
2658 | - auto registry = registry_.lock(); |
2659 | - |
2660 | - if (!registry) |
2661 | - { |
2662 | - g_warning("Unable to list instances without a registry"); |
2663 | - return {}; |
2664 | - } |
2665 | |
2666 | std::string sappid{appID}; |
2667 | for (const auto& unit : unitPaths) |
2668 | @@ -857,7 +854,7 @@ |
2669 | continue; |
2670 | } |
2671 | |
2672 | - instances.emplace_back(std::make_shared<instance::SystemD>(appID, job, unitinfo.inst, urls, registry)); |
2673 | + instances.emplace_back(std::make_shared<instance::SystemD>(appID, job, unitinfo.inst, urls, reg)); |
2674 | } |
2675 | |
2676 | g_debug("Found %d instances for AppID '%s'", int(instances.size()), std::string(appID).c_str()); |
2677 | @@ -867,14 +864,6 @@ |
2678 | |
2679 | std::list<std::string> SystemD::runningAppIds(const std::list<std::string>& allJobs) |
2680 | { |
2681 | - auto registry = registry_.lock(); |
2682 | - |
2683 | - if (!registry) |
2684 | - { |
2685 | - g_warning("Unable to list instances without a registry"); |
2686 | - return {}; |
2687 | - } |
2688 | - |
2689 | std::set<std::string> appids; |
2690 | |
2691 | for (const auto& unit : unitPaths) |
2692 | @@ -923,6 +912,7 @@ |
2693 | |
2694 | std::string SystemD::unitPath(const SystemD::UnitInfo& info) |
2695 | { |
2696 | + auto reg = getReg(); |
2697 | auto data = unitPaths[info]; |
2698 | |
2699 | if (!data) |
2700 | @@ -930,17 +920,9 @@ |
2701 | return {}; |
2702 | } |
2703 | |
2704 | - auto registry = registry_.lock(); |
2705 | - |
2706 | - if (!registry) |
2707 | - { |
2708 | - g_warning("Unable to get registry to determine path"); |
2709 | - return {}; |
2710 | - } |
2711 | - |
2712 | /* Execute on the thread so that we're sure that we're not in |
2713 | a dbus call to get the value. No racey for you! */ |
2714 | - return registry->impl->thread.executeOnThread<std::string>([&data]() { return data->unitpath; }); |
2715 | + return reg->thread.executeOnThread<std::string>([&data]() { return data->unitpath; }); |
2716 | } |
2717 | |
2718 | SystemD::UnitInfo SystemD::unitNew(const std::string& name, |
2719 | @@ -952,9 +934,11 @@ |
2720 | throw std::runtime_error{"Job path for unit is '/' so likely failed"}; |
2721 | } |
2722 | |
2723 | + auto info = parseUnit(name); |
2724 | + |
2725 | g_debug("New Unit: %s", name.c_str()); |
2726 | |
2727 | - auto info = parseUnit(name); |
2728 | + auto reg = getReg(); |
2729 | |
2730 | auto data = std::make_shared<UnitData>(); |
2731 | data->jobpath = path; |
2732 | @@ -971,24 +955,16 @@ |
2733 | comes an asking at this point we'll think that we have the |
2734 | app, but not yet its path */ |
2735 | GError* error{nullptr}; |
2736 | - auto reg = registry_.lock(); |
2737 | - |
2738 | - if (!reg) |
2739 | - { |
2740 | - g_warning("Unable to get SystemD unit path for '%s': Registry out of scope", name.c_str()); |
2741 | - throw std::runtime_error{"Unable to get SystemD unit path for '" + name + "': Registry out of scope"}; |
2742 | - } |
2743 | - |
2744 | - auto call = unique_glib(g_dbus_connection_call_sync(bus.get(), /* user bus */ |
2745 | - SYSTEMD_DBUS_ADDRESS, /* bus name */ |
2746 | - SYSTEMD_DBUS_PATH_MANAGER, /* path */ |
2747 | - SYSTEMD_DBUS_IFACE_MANAGER, /* interface */ |
2748 | - "GetUnit", /* method */ |
2749 | - g_variant_new("(s)", name.c_str()), /* params */ |
2750 | - G_VARIANT_TYPE("(o)"), /* ret type */ |
2751 | - G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2752 | - -1, /* timeout */ |
2753 | - reg->impl->thread.getCancellable().get(), /* cancellable */ |
2754 | + auto call = unique_glib(g_dbus_connection_call_sync(bus.get(), /* user bus */ |
2755 | + SYSTEMD_DBUS_ADDRESS, /* bus name */ |
2756 | + SYSTEMD_DBUS_PATH_MANAGER, /* path */ |
2757 | + SYSTEMD_DBUS_IFACE_MANAGER, /* interface */ |
2758 | + "GetUnit", /* method */ |
2759 | + g_variant_new("(s)", name.c_str()), /* params */ |
2760 | + G_VARIANT_TYPE("(o)"), /* ret type */ |
2761 | + G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2762 | + -1, /* timeout */ |
2763 | + reg->thread.getCancellable().get(), /* cancellable */ |
2764 | &error)); |
2765 | |
2766 | if (error != nullptr) |
2767 | @@ -1023,14 +999,6 @@ |
2768 | |
2769 | pid_t SystemD::unitPrimaryPid(const AppID& appId, const std::string& job, const std::string& instance) |
2770 | { |
2771 | - auto registry = registry_.lock(); |
2772 | - |
2773 | - if (!registry) |
2774 | - { |
2775 | - g_warning("Unable to get registry to determine primary PID"); |
2776 | - return 0; |
2777 | - } |
2778 | - |
2779 | auto unitinfo = SystemD::UnitInfo{appId, job, instance}; |
2780 | auto unitname = unitName(unitinfo); |
2781 | auto unitpath = unitPath(unitinfo); |
2782 | @@ -1040,7 +1008,9 @@ |
2783 | return 0; |
2784 | } |
2785 | |
2786 | - return registry->impl->thread.executeOnThread<pid_t>([this, registry, unitname, unitpath]() { |
2787 | + auto reg = getReg(); |
2788 | + |
2789 | + return reg->thread.executeOnThread<pid_t>([this, unitname, unitpath, reg]() { |
2790 | GError* error{nullptr}; |
2791 | auto call = unique_glib( |
2792 | g_dbus_connection_call_sync(userbus_.get(), /* user bus */ |
2793 | @@ -1052,7 +1022,7 @@ |
2794 | G_VARIANT_TYPE("(v)"), /* ret type */ |
2795 | G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2796 | -1, /* timeout */ |
2797 | - registry->impl->thread.getCancellable().get(), /* cancellable */ |
2798 | + reg->thread.getCancellable().get(), /* cancellable */ |
2799 | &error)); |
2800 | |
2801 | if (error != nullptr) |
2802 | @@ -1080,14 +1050,6 @@ |
2803 | |
2804 | std::vector<pid_t> SystemD::unitPids(const AppID& appId, const std::string& job, const std::string& instance) |
2805 | { |
2806 | - auto registry = registry_.lock(); |
2807 | - |
2808 | - if (!registry) |
2809 | - { |
2810 | - g_warning("Unable to get registry to determine primary PID"); |
2811 | - return {}; |
2812 | - } |
2813 | - |
2814 | auto unitinfo = SystemD::UnitInfo{appId, job, instance}; |
2815 | auto unitname = unitName(unitinfo); |
2816 | auto unitpath = unitPath(unitinfo); |
2817 | @@ -1097,7 +1059,9 @@ |
2818 | return {}; |
2819 | } |
2820 | |
2821 | - auto cgrouppath = registry->impl->thread.executeOnThread<std::string>([this, registry, unitname, unitpath]() { |
2822 | + auto reg = getReg(); |
2823 | + |
2824 | + auto cgrouppath = reg->thread.executeOnThread<std::string>([this, unitname, unitpath, reg]() { |
2825 | GError* error{nullptr}; |
2826 | auto call = unique_glib( |
2827 | g_dbus_connection_call_sync(userbus_.get(), /* user bus */ |
2828 | @@ -1106,10 +1070,10 @@ |
2829 | "org.freedesktop.DBus.Properties", /* interface */ |
2830 | "Get", /* method */ |
2831 | g_variant_new("(ss)", SYSTEMD_DBUS_IFACE_SERVICE, "ControlGroup"), /* params */ |
2832 | - G_VARIANT_TYPE("(v)"), /* ret type */ |
2833 | - G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2834 | - -1, /* timeout */ |
2835 | - registry->impl->thread.getCancellable().get(), /* cancellable */ |
2836 | + G_VARIANT_TYPE("(v)"), /* ret type */ |
2837 | + G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2838 | + -1, /* timeout */ |
2839 | + reg->thread.getCancellable().get(), /* cancellable */ |
2840 | &error)); |
2841 | |
2842 | if (error != nullptr) |
2843 | @@ -1182,10 +1146,10 @@ |
2844 | |
2845 | void SystemD::stopUnit(const AppID& appId, const std::string& job, const std::string& instance) |
2846 | { |
2847 | - auto registry = registry_.lock(); |
2848 | auto unitname = unitName(SystemD::UnitInfo{appId, job, instance}); |
2849 | + auto reg = getReg(); |
2850 | |
2851 | - registry->impl->thread.executeOnThread<bool>([this, registry, unitname] { |
2852 | + reg->thread.executeOnThread<bool>([this, unitname, reg] { |
2853 | GError* error{nullptr}; |
2854 | unique_glib(g_dbus_connection_call_sync( |
2855 | userbus_.get(), /* user bus */ |
2856 | @@ -1194,13 +1158,13 @@ |
2857 | SYSTEMD_DBUS_IFACE_MANAGER, /* interface */ |
2858 | "StopUnit", /* method */ |
2859 | g_variant_new( |
2860 | - "(ss)", /* params */ |
2861 | - unitname.c_str(), /* param: specify unit */ |
2862 | - "replace-irreversibly"), /* param: replace the current job but don't allow us to be replaced */ |
2863 | - G_VARIANT_TYPE("(o)"), /* ret type */ |
2864 | - G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2865 | - -1, /* timeout */ |
2866 | - registry->impl->thread.getCancellable().get(), /* cancellable */ |
2867 | + "(ss)", /* params */ |
2868 | + unitname.c_str(), /* param: specify unit */ |
2869 | + "replace-irreversibly"), /* param: replace the current job but don't allow us to be replaced */ |
2870 | + G_VARIANT_TYPE("(o)"), /* ret type */ |
2871 | + G_DBUS_CALL_FLAGS_NONE, /* flags */ |
2872 | + -1, /* timeout */ |
2873 | + reg->thread.getCancellable().get(), /* cancellable */ |
2874 | &error)); |
2875 | |
2876 | if (error != nullptr) |
2877 | @@ -1217,29 +1181,26 @@ |
2878 | |
2879 | core::Signal<const std::string&, const std::string&, const std::string&>& SystemD::jobStarted() |
2880 | { |
2881 | - /* For systemd we're automatically listening to the UnitNew signal |
2882 | - and emitting on the object */ |
2883 | + /* Ensure we're connecting to the signals */ |
2884 | return sig_jobStarted; |
2885 | } |
2886 | |
2887 | core::Signal<const std::string&, const std::string&, const std::string&>& SystemD::jobStopped() |
2888 | { |
2889 | - /* For systemd we're automatically listening to the UnitRemoved signal |
2890 | - and emitting on the object */ |
2891 | + /* Ensure we're connecting to the signals */ |
2892 | return sig_jobStopped; |
2893 | } |
2894 | |
2895 | struct FailedData |
2896 | { |
2897 | - std::weak_ptr<Registry> registry; |
2898 | + std::weak_ptr<Registry::Impl> registry; |
2899 | }; |
2900 | |
2901 | core::Signal<const std::string&, const std::string&, const std::string&, Registry::FailureType>& SystemD::jobFailed() |
2902 | { |
2903 | std::call_once(flag_appFailed, [this]() { |
2904 | - auto reg = registry_.lock(); |
2905 | - |
2906 | - reg->impl->thread.executeOnThread<bool>([this, reg]() { |
2907 | + auto reg = getReg(); |
2908 | + reg->thread.executeOnThread<bool>([this, reg]() { |
2909 | auto data = new FailedData{reg}; |
2910 | |
2911 | handle_appFailed = managedDBusSignalConnection( |
2912 | @@ -1258,11 +1219,10 @@ |
2913 | |
2914 | if (!reg) |
2915 | { |
2916 | - g_warning("Registry object invalid!"); |
2917 | - return; |
2918 | + throw std::runtime_error{"Lost our connection with the registry"}; |
2919 | } |
2920 | |
2921 | - auto manager = std::dynamic_pointer_cast<SystemD>(reg->impl->jobs); |
2922 | + auto manager = std::dynamic_pointer_cast<SystemD>(reg->jobs()); |
2923 | |
2924 | /* Check to see if this is a path we care about */ |
2925 | bool pathfound{false}; |
2926 | @@ -1334,19 +1294,19 @@ |
2927 | failed so that we can continue to work with it. This includes |
2928 | starting it anew, which can fail if it is left in the failed |
2929 | state. */ |
2930 | -void SystemD::resetUnit(const UnitInfo& info) const |
2931 | +void SystemD::resetUnit(const UnitInfo& info) |
2932 | { |
2933 | if (noResetUnits_) |
2934 | { |
2935 | return; |
2936 | } |
2937 | |
2938 | - auto registry = registry_.lock(); |
2939 | + auto reg = getReg(); |
2940 | auto unitname = unitName(info); |
2941 | auto bus = userbus_; |
2942 | - auto cancel = registry->impl->thread.getCancellable(); |
2943 | + auto cancel = reg->thread.getCancellable(); |
2944 | |
2945 | - registry->impl->thread.executeOnThread([bus, unitname, cancel] { |
2946 | + reg->thread.executeOnThread([bus, unitname, cancel] { |
2947 | if (g_cancellable_is_cancelled(cancel.get())) |
2948 | { |
2949 | return; |
2950 | |
2951 | === modified file 'libubuntu-app-launch/jobs-systemd.h' |
2952 | --- libubuntu-app-launch/jobs-systemd.h 2017-03-20 10:13:50 +0000 |
2953 | +++ libubuntu-app-launch/jobs-systemd.h 2017-04-04 21:22:36 +0000 |
2954 | @@ -41,7 +41,7 @@ |
2955 | class SystemD : public Base |
2956 | { |
2957 | public: |
2958 | - SystemD(std::shared_ptr<Registry> registry); |
2959 | + SystemD(const std::shared_ptr<Registry::Impl>& registry); |
2960 | virtual ~SystemD(); |
2961 | |
2962 | virtual std::shared_ptr<Application::Instance> launch( |
2963 | @@ -73,7 +73,11 @@ |
2964 | |
2965 | private: |
2966 | std::string cgroup_root_; |
2967 | + |
2968 | + /** Connection to the User DBus bus */ |
2969 | std::shared_ptr<GDBusConnection> userbus_; |
2970 | + /** Setup the bus and all the details in it */ |
2971 | + void setupUserbus(const std::shared_ptr<Registry::Impl>& reg); |
2972 | |
2973 | core::Signal<const std::string&, const std::string&, const std::string&> sig_jobStarted; |
2974 | core::Signal<const std::string&, const std::string&, const std::string&> sig_jobStopped; |
2975 | @@ -131,7 +135,7 @@ |
2976 | static std::vector<std::string> parseExec(std::list<std::pair<std::string, std::string>>& env); |
2977 | static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data); |
2978 | |
2979 | - void resetUnit(const UnitInfo& info) const; |
2980 | + void resetUnit(const UnitInfo& info); |
2981 | }; |
2982 | |
2983 | } // namespace manager |
2984 | |
2985 | === modified file 'libubuntu-app-launch/registry-impl.cpp' |
2986 | --- libubuntu-app-launch/registry-impl.cpp 2017-03-20 12:28:10 +0000 |
2987 | +++ libubuntu-app-launch/registry-impl.cpp 2017-04-04 21:22:36 +0000 |
2988 | @@ -20,6 +20,7 @@ |
2989 | #include "registry-impl.h" |
2990 | #include "application-icon-finder.h" |
2991 | #include "application-impl-base.h" |
2992 | +#include "helper-impl.h" |
2993 | #include <regex> |
2994 | #include <unity/util/GObjectMemory.h> |
2995 | #include <unity/util/GlibMemory.h> |
2996 | @@ -31,24 +32,19 @@ |
2997 | namespace app_launch |
2998 | { |
2999 | |
3000 | -Registry::Impl::Impl(Registry& registry) |
3001 | - : Impl(registry, app_store::Base::allAppStores()) |
3002 | -{ |
3003 | -} |
3004 | - |
3005 | -Registry::Impl::Impl(Registry& registry, std::list<std::shared_ptr<app_store::Base>> appStores) |
3006 | +Registry::Impl::Impl() |
3007 | : thread([]() {}, |
3008 | [this]() { |
3009 | zgLog_.reset(); |
3010 | - jobs.reset(); |
3011 | + jobs_.reset(); |
3012 | |
3013 | if (_dbus) |
3014 | g_dbus_connection_flush_sync(_dbus.get(), nullptr, nullptr); |
3015 | _dbus.reset(); |
3016 | }) |
3017 | - , _registry{registry} |
3018 | - , _iconFinders() |
3019 | - , _appStores(appStores) |
3020 | + , jobs_{} |
3021 | + , _iconFinders{} |
3022 | + , _appStores{} |
3023 | { |
3024 | auto cancel = thread.getCancellable(); |
3025 | _dbus = thread.executeOnThread<std::shared_ptr<GDBusConnection>>( |
3026 | @@ -145,7 +141,7 @@ |
3027 | }); |
3028 | } |
3029 | |
3030 | -std::shared_ptr<IconFinder> Registry::Impl::getIconFinder(std::string basePath) |
3031 | +std::shared_ptr<IconFinder>& Registry::Impl::getIconFinder(std::string basePath) |
3032 | { |
3033 | if (_iconFinders.find(basePath) == _iconFinders.end()) |
3034 | { |
3035 | @@ -175,23 +171,45 @@ |
3036 | return watchingAppStarting_; |
3037 | } |
3038 | |
3039 | -core::Signal<const std::shared_ptr<Application>&>& Registry::Impl::appInfoUpdated(const std::shared_ptr<Registry>& reg) |
3040 | +core::Signal<const std::shared_ptr<Application>&>& Registry::Impl::appInfoUpdated() |
3041 | { |
3042 | - std::call_once(flag_appInfoUpdated, [this, reg] { |
3043 | + std::call_once(flag_appInfoUpdated, [this] { |
3044 | g_debug("App Info Updated Signal Initialized"); |
3045 | |
3046 | std::list<std::shared_ptr<info_watcher::Base>> apps{_appStores.begin(), _appStores.end()}; |
3047 | - apps.push_back(Registry::Impl::getZgWatcher(reg)); |
3048 | + apps.push_back(getZgWatcher()); |
3049 | |
3050 | for (const auto& app : apps) |
3051 | { |
3052 | infoWatchers_.emplace_back( |
3053 | - std::make_pair(app, app->infoChanged().connect( |
3054 | - [this](const std::shared_ptr<Application>& app) { sig_appInfoUpdated(app); }))); |
3055 | + std::make_pair(app, app->infoChanged().connect([this](const std::shared_ptr<Application>& app) { |
3056 | + sig_appInfoUpdated(app); |
3057 | + }))); |
3058 | } |
3059 | }); |
3060 | return sig_appInfoUpdated; |
3061 | } |
3062 | |
3063 | +std::shared_ptr<Application> Registry::Impl::createApp(const AppID& appid) |
3064 | +{ |
3065 | + for (const auto& appStore : appStores()) |
3066 | + { |
3067 | + if (appStore->hasAppId(appid)) |
3068 | + { |
3069 | + return appStore->create(appid); |
3070 | + } |
3071 | + } |
3072 | + |
3073 | + throw std::runtime_error("Invalid app ID: " + std::string(appid)); |
3074 | +} |
3075 | + |
3076 | +std::shared_ptr<Helper> Registry::Impl::createHelper(const Helper::Type& type, |
3077 | + const AppID& appid, |
3078 | + const std::shared_ptr<Registry::Impl>& sharedimpl) |
3079 | +{ |
3080 | + /* Only one type today */ |
3081 | + return std::make_shared<helper_impls::Base>(type, appid, sharedimpl); |
3082 | +} |
3083 | + |
3084 | } // namespace app_launch |
3085 | } // namespace ubuntu |
3086 | |
3087 | === modified file 'libubuntu-app-launch/registry-impl.h' |
3088 | --- libubuntu-app-launch/registry-impl.h 2017-03-20 10:13:50 +0000 |
3089 | +++ libubuntu-app-launch/registry-impl.h 2017-04-04 21:22:36 +0000 |
3090 | @@ -17,6 +17,8 @@ |
3091 | * Ted Gould <ted.gould@canonical.com> |
3092 | */ |
3093 | |
3094 | +#pragma once |
3095 | + |
3096 | #include "app-store-base.h" |
3097 | #include "glib-thread.h" |
3098 | #include "info-watcher-zg.h" |
3099 | @@ -29,14 +31,16 @@ |
3100 | #include <unordered_map> |
3101 | #include <zeitgeist.h> |
3102 | |
3103 | -#pragma once |
3104 | - |
3105 | namespace ubuntu |
3106 | { |
3107 | namespace app_launch |
3108 | { |
3109 | |
3110 | class IconFinder; |
3111 | +namespace app_store |
3112 | +{ |
3113 | +class Base; |
3114 | +} |
3115 | |
3116 | /** \private |
3117 | \brief Private implementation of the Registry object |
3118 | @@ -45,8 +49,7 @@ |
3119 | class Registry::Impl |
3120 | { |
3121 | public: |
3122 | - Impl(Registry& registry); |
3123 | - Impl(Registry& registry, std::list<std::shared_ptr<app_store::Base>> appStores); |
3124 | + Impl(); |
3125 | |
3126 | virtual ~Impl() |
3127 | { |
3128 | @@ -66,9 +69,7 @@ |
3129 | /** Snapd information object */ |
3130 | snapd::Info snapdInfo; |
3131 | |
3132 | - std::shared_ptr<jobs::manager::Base> jobs; |
3133 | - |
3134 | - std::shared_ptr<IconFinder> getIconFinder(std::string basePath); |
3135 | + std::shared_ptr<IconFinder>& getIconFinder(std::string basePath); |
3136 | |
3137 | virtual void zgSendEvent(AppID appid, const std::string& eventtype); |
3138 | |
3139 | @@ -86,27 +87,59 @@ |
3140 | return oomHelper_; |
3141 | } |
3142 | |
3143 | - static std::shared_ptr<info_watcher::Zeitgeist> getZgWatcher(const std::shared_ptr<Registry>& reg) |
3144 | - { |
3145 | - std::call_once(reg->impl->zgWatcherOnce_, |
3146 | - [reg] { reg->impl->zgWatcher_ = std::make_shared<info_watcher::Zeitgeist>(reg); }); |
3147 | - return reg->impl->zgWatcher_; |
3148 | - } |
3149 | - |
3150 | - core::Signal<const std::shared_ptr<Application>&>& appInfoUpdated(const std::shared_ptr<Registry>& reg); |
3151 | - |
3152 | - std::list<std::shared_ptr<app_store::Base>> appStores() |
3153 | + std::shared_ptr<info_watcher::Zeitgeist> getZgWatcher() |
3154 | + { |
3155 | + return zgWatcher_; |
3156 | + } |
3157 | + |
3158 | + void setZgWatcher(const std::shared_ptr<info_watcher::Zeitgeist>& watcher) |
3159 | + { |
3160 | + zgWatcher_ = watcher; |
3161 | + } |
3162 | + |
3163 | + core::Signal<const std::shared_ptr<Application>&>& appInfoUpdated(); |
3164 | + |
3165 | + const std::list<std::shared_ptr<app_store::Base>>& appStores() |
3166 | { |
3167 | return _appStores; |
3168 | } |
3169 | |
3170 | - void setAppStores(std::list<std::shared_ptr<app_store::Base>>& newlist) |
3171 | + void setAppStores(const std::list<std::shared_ptr<app_store::Base>>& newlist) |
3172 | { |
3173 | _appStores = newlist; |
3174 | } |
3175 | |
3176 | + const std::shared_ptr<jobs::manager::Base>& jobs() |
3177 | + { |
3178 | + if (G_UNLIKELY(!jobs_)) |
3179 | + { |
3180 | + throw std::runtime_error{"Registry Implmentation has no Jobs object"}; |
3181 | + } |
3182 | + return jobs_; |
3183 | + } |
3184 | + |
3185 | + void setJobs(const std::shared_ptr<jobs::manager::Base>& jobs) |
3186 | + { |
3187 | + jobs_ = jobs; |
3188 | + } |
3189 | + |
3190 | + /* Create functions */ |
3191 | + std::shared_ptr<Application> createApp(const AppID& appid); |
3192 | + std::shared_ptr<Helper> createHelper(const Helper::Type& type, |
3193 | + const AppID& appid, |
3194 | + const std::shared_ptr<Registry::Impl>& sharedimpl); |
3195 | + |
3196 | + /* AppID functions */ |
3197 | + AppID find(const std::string& sappid); |
3198 | + AppID discover(const std::string& package, const std::string& appname, const std::string& version); |
3199 | + AppID discover(const std::string& package, |
3200 | + AppID::ApplicationWildcard appwildcard, |
3201 | + AppID::VersionWildcard versionwildcard); |
3202 | + AppID discover(const std::string& package, const std::string& appname, AppID::VersionWildcard versionwildcard); |
3203 | + |
3204 | private: |
3205 | - Registry& _registry; /**< The Registry that we're spawned from */ |
3206 | + /** The job creation engine */ |
3207 | + std::shared_ptr<jobs::manager::Base> jobs_; |
3208 | |
3209 | /** Shared instance of the Zeitgeist Log */ |
3210 | std::shared_ptr<ZeitgeistLog> zgLog_; |
3211 | @@ -128,11 +161,8 @@ |
3212 | /** List of info watchers along with a signal handle to our connection to their update signal */ |
3213 | std::list<std::pair<std::shared_ptr<info_watcher::Base>, core::ScopedConnection>> infoWatchers_; |
3214 | |
3215 | -protected: |
3216 | /** ZG Info Watcher */ |
3217 | std::shared_ptr<info_watcher::Zeitgeist> zgWatcher_; |
3218 | - /** Init checker for ZG Watcher */ |
3219 | - std::once_flag zgWatcherOnce_; |
3220 | }; |
3221 | |
3222 | } // namespace app_launch |
3223 | |
3224 | === modified file 'libubuntu-app-launch/registry.cpp' |
3225 | --- libubuntu-app-launch/registry.cpp 2017-03-20 10:13:50 +0000 |
3226 | +++ libubuntu-app-launch/registry.cpp 2017-04-04 21:22:36 +0000 |
3227 | @@ -21,6 +21,8 @@ |
3228 | #include <numeric> |
3229 | #include <regex> |
3230 | |
3231 | +#include "info-watcher-zg.h" |
3232 | +#include "jobs-base.h" |
3233 | #include "registry-impl.h" |
3234 | #include "registry.h" |
3235 | |
3236 | @@ -30,8 +32,17 @@ |
3237 | { |
3238 | |
3239 | Registry::Registry() |
3240 | -{ |
3241 | - impl = std::unique_ptr<Impl>(new Impl(*this)); |
3242 | + : impl{std::make_shared<Impl>()} |
3243 | +{ |
3244 | + impl->setJobs(jobs::manager::Base::determineFactory(impl)); |
3245 | + impl->setAppStores(app_store::Base::allAppStores(impl)); |
3246 | + impl->setZgWatcher(std::make_shared<info_watcher::Zeitgeist>(impl)); |
3247 | +} |
3248 | + |
3249 | +Registry::Registry(const std::shared_ptr<Impl>& inimpl) |
3250 | + : impl{inimpl} |
3251 | +{ |
3252 | + /* We're assuming the impl has been setup */ |
3253 | } |
3254 | |
3255 | Registry::~Registry() |
3256 | @@ -40,12 +51,7 @@ |
3257 | |
3258 | std::list<std::shared_ptr<Application>> Registry::runningApps(std::shared_ptr<Registry> registry) |
3259 | { |
3260 | - if (!registry->impl->jobs) |
3261 | - { |
3262 | - registry->impl->jobs = jobs::manager::Base::determineFactory(registry); |
3263 | - } |
3264 | - |
3265 | - return registry->impl->jobs->runningApps(); |
3266 | + return registry->impl->jobs()->runningApps(); |
3267 | } |
3268 | |
3269 | std::list<std::shared_ptr<Application>> Registry::installedApps(std::shared_ptr<Registry> connection) |
3270 | @@ -54,7 +60,7 @@ |
3271 | |
3272 | for (const auto& appStore : connection->impl->appStores()) |
3273 | { |
3274 | - list.splice(list.begin(), appStore->list(connection)); |
3275 | + list.splice(list.begin(), appStore->list()); |
3276 | } |
3277 | |
3278 | return list; |
3279 | @@ -62,37 +68,17 @@ |
3280 | |
3281 | std::list<std::shared_ptr<Helper>> Registry::runningHelpers(Helper::Type type, std::shared_ptr<Registry> registry) |
3282 | { |
3283 | - if (!registry->impl->jobs) |
3284 | - { |
3285 | - registry->impl->jobs = jobs::manager::Base::determineFactory(registry); |
3286 | - } |
3287 | - |
3288 | - return registry->impl->jobs->runningHelpers(type); |
3289 | -} |
3290 | - |
3291 | -/* Quick little helper to bundle up standard code */ |
3292 | -inline void setJobs(const std::shared_ptr<Registry>& registry) |
3293 | -{ |
3294 | - if (!registry->impl->jobs) |
3295 | - { |
3296 | - registry->impl->jobs = jobs::manager::Base::determineFactory(registry); |
3297 | - } |
3298 | + return registry->impl->jobs()->runningHelpers(type); |
3299 | } |
3300 | |
3301 | void Registry::setManager(const std::shared_ptr<Manager>& manager, const std::shared_ptr<Registry>& registry) |
3302 | { |
3303 | - setJobs(registry); |
3304 | - registry->impl->jobs->setManager(manager); |
3305 | + registry->impl->jobs()->setManager(manager); |
3306 | } |
3307 | |
3308 | void Registry::clearManager() |
3309 | { |
3310 | - if (!impl->jobs) |
3311 | - { |
3312 | - return; |
3313 | - } |
3314 | - |
3315 | - impl->jobs->clearManager(); |
3316 | + impl->jobs()->clearManager(); |
3317 | } |
3318 | |
3319 | std::shared_ptr<Registry> defaultRegistry; |
3320 | @@ -114,22 +100,19 @@ |
3321 | core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&>& Registry::appStarted( |
3322 | const std::shared_ptr<Registry>& reg) |
3323 | { |
3324 | - setJobs(reg); |
3325 | - return reg->impl->jobs->appStarted(); |
3326 | + return reg->impl->jobs()->appStarted(); |
3327 | } |
3328 | |
3329 | core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&>& Registry::appStopped( |
3330 | const std::shared_ptr<Registry>& reg) |
3331 | { |
3332 | - setJobs(reg); |
3333 | - return reg->impl->jobs->appStopped(); |
3334 | + return reg->impl->jobs()->appStopped(); |
3335 | } |
3336 | |
3337 | core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&, Registry::FailureType>& |
3338 | Registry::appFailed(const std::shared_ptr<Registry>& reg) |
3339 | { |
3340 | - setJobs(reg); |
3341 | - return reg->impl->jobs->appFailed(); |
3342 | + return reg->impl->jobs()->appFailed(); |
3343 | } |
3344 | |
3345 | core::Signal<const std::shared_ptr<Application>&, |
3346 | @@ -137,8 +120,7 @@ |
3347 | const std::vector<pid_t>&>& |
3348 | Registry::appPaused(const std::shared_ptr<Registry>& reg) |
3349 | { |
3350 | - setJobs(reg); |
3351 | - return reg->impl->jobs->appPaused(); |
3352 | + return reg->impl->jobs()->appPaused(); |
3353 | } |
3354 | |
3355 | core::Signal<const std::shared_ptr<Application>&, |
3356 | @@ -146,34 +128,30 @@ |
3357 | const std::vector<pid_t>&>& |
3358 | Registry::appResumed(const std::shared_ptr<Registry>& reg) |
3359 | { |
3360 | - setJobs(reg); |
3361 | - return reg->impl->jobs->appResumed(); |
3362 | + return reg->impl->jobs()->appResumed(); |
3363 | } |
3364 | |
3365 | core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&>& Registry::helperStarted( |
3366 | Helper::Type type, const std::shared_ptr<Registry>& reg) |
3367 | { |
3368 | - setJobs(reg); |
3369 | - return reg->impl->jobs->helperStarted(type); |
3370 | + return reg->impl->jobs()->helperStarted(type); |
3371 | } |
3372 | |
3373 | core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&>& Registry::helperStopped( |
3374 | Helper::Type type, const std::shared_ptr<Registry>& reg) |
3375 | { |
3376 | - setJobs(reg); |
3377 | - return reg->impl->jobs->helperStopped(type); |
3378 | + return reg->impl->jobs()->helperStopped(type); |
3379 | } |
3380 | |
3381 | core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&, Registry::FailureType>& |
3382 | Registry::helperFailed(Helper::Type type, const std::shared_ptr<Registry>& reg) |
3383 | { |
3384 | - setJobs(reg); |
3385 | - return reg->impl->jobs->helperFailed(type); |
3386 | + return reg->impl->jobs()->helperFailed(type); |
3387 | } |
3388 | |
3389 | core::Signal<const std::shared_ptr<Application>&>& Registry::appInfoUpdated(const std::shared_ptr<Registry>& reg) |
3390 | { |
3391 | - return reg->impl->appInfoUpdated(reg); |
3392 | + return reg->impl->appInfoUpdated(); |
3393 | } |
3394 | |
3395 | } // namespace app_launch |
3396 | |
3397 | === modified file 'libubuntu-app-launch/registry.h' |
3398 | --- libubuntu-app-launch/registry.h 2017-03-20 12:28:10 +0000 |
3399 | +++ libubuntu-app-launch/registry.h 2017-04-04 21:22:36 +0000 |
3400 | @@ -99,9 +99,8 @@ |
3401 | |
3402 | \param reg Registry to get the handler from |
3403 | */ |
3404 | - static core::Signal<const std::shared_ptr<Application>&, |
3405 | - const std::shared_ptr<Application::Instance>&, |
3406 | - FailureType>& |
3407 | + static core:: |
3408 | + Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&, FailureType>& |
3409 | appFailed(const std::shared_ptr<Registry>& reg = getDefault()); |
3410 | |
3411 | /** Get the signal object that is signaled when an application has been |
3412 | @@ -269,7 +268,10 @@ |
3413 | /** \private */ |
3414 | class Impl; |
3415 | /** \private */ |
3416 | - std::unique_ptr<Impl> impl; |
3417 | + std::shared_ptr<Impl> impl; |
3418 | + |
3419 | +protected: |
3420 | + Registry(const std::shared_ptr<Impl>& inimpl); |
3421 | }; |
3422 | |
3423 | } // namespace app_launch |
3424 | |
3425 | === modified file 'tests/application-info-desktop.cpp' |
3426 | --- tests/application-info-desktop.cpp 2017-03-14 02:58:43 +0000 |
3427 | +++ tests/application-info-desktop.cpp 2017-04-04 21:22:36 +0000 |
3428 | @@ -88,7 +88,7 @@ |
3429 | { |
3430 | auto reg = registry(); |
3431 | |
3432 | - return std::dynamic_pointer_cast<zgWatcherMock>(reg->impl->getZgWatcher(reg)); |
3433 | + return std::dynamic_pointer_cast<zgWatcherMock>(reg->impl->getZgWatcher()); |
3434 | } |
3435 | }; |
3436 | |
3437 | @@ -410,7 +410,7 @@ |
3438 | auto keyfile = defaultKeyfile(); |
3439 | EXPECT_EQ(5u, |
3440 | ubuntu::app_launch::app_info::Desktop(simpleAppID(), keyfile, "/", {}, |
3441 | - ubuntu::app_launch::app_info::DesktopFlags::NONE, registry()) |
3442 | + ubuntu::app_launch::app_info::DesktopFlags::NONE, registry()->impl) |
3443 | .popularity() |
3444 | .value()); |
3445 | } |
3446 | |
3447 | === modified file 'tests/info-watcher-zg.cpp' |
3448 | --- tests/info-watcher-zg.cpp 2017-02-10 16:50:40 +0000 |
3449 | +++ tests/info-watcher-zg.cpp 2017-04-04 21:22:36 +0000 |
3450 | @@ -49,7 +49,6 @@ |
3451 | |
3452 | TEST_F(InfoWatcherZg, InitTest) |
3453 | { |
3454 | - auto watcher = std::make_shared<ubuntu::app_launch::info_watcher::Zeitgeist>(registry); |
3455 | - |
3456 | - watcher.reset(); |
3457 | + /* Gets init by part of the mock now, we may need to split |
3458 | + * that out when we want to test this more. */ |
3459 | } |
3460 | |
3461 | === modified file 'tests/jobs-base-test.cpp' |
3462 | --- tests/jobs-base-test.cpp 2017-01-19 18:39:44 +0000 |
3463 | +++ tests/jobs-base-test.cpp 2017-04-04 21:22:36 +0000 |
3464 | @@ -34,7 +34,7 @@ |
3465 | const std::string& job, |
3466 | const std::string& instance, |
3467 | const std::vector<ubuntu::app_launch::Application::URL>& urls, |
3468 | - const std::shared_ptr<ubuntu::app_launch::Registry>& registry) |
3469 | + const std::shared_ptr<ubuntu::app_launch::Registry::Impl>& registry) |
3470 | : ubuntu::app_launch::jobs::instance::Base(appId, job, instance, urls, registry) |
3471 | { |
3472 | } |
3473 | @@ -76,7 +76,7 @@ |
3474 | std::shared_ptr<instanceMock> simpleInstance() |
3475 | { |
3476 | return std::make_shared<instanceMock>(simpleAppID(), "application-job", "1234567890", |
3477 | - std::vector<ubuntu::app_launch::Application::URL>{}, registry); |
3478 | + std::vector<ubuntu::app_launch::Application::URL>{}, registry->impl); |
3479 | } |
3480 | }; |
3481 | |
3482 | |
3483 | === modified file 'tests/jobs-systemd.cpp' |
3484 | --- tests/jobs-systemd.cpp 2017-02-04 03:53:34 +0000 |
3485 | +++ tests/jobs-systemd.cpp 2017-04-04 21:22:36 +0000 |
3486 | @@ -18,6 +18,7 @@ |
3487 | */ |
3488 | |
3489 | #include "jobs-systemd.h" |
3490 | +#include "app-store-legacy.h" |
3491 | |
3492 | #include "eventually-fixture.h" |
3493 | #include "registry-mock.h" |
3494 | @@ -57,6 +58,7 @@ |
3495 | |
3496 | dbus_test_service_start_tasks(service.get()); |
3497 | registry = std::make_shared<RegistryMock>(); |
3498 | + registry->impl->setAppStores({std::make_shared<ubuntu::app_launch::app_store::Legacy>(registry->impl)}); |
3499 | |
3500 | bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); |
3501 | g_dbus_connection_set_exit_on_close(bus, FALSE); |
3502 | @@ -96,13 +98,15 @@ |
3503 | /* Make sure we can build an object and destroy it */ |
3504 | TEST_F(JobsSystemd, Init) |
3505 | { |
3506 | - registry->impl->jobs = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3507 | + registry->impl->setJobs(std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl)); |
3508 | } |
3509 | |
3510 | /* Make sure we make the initial call to get signals and an initial list */ |
3511 | TEST_F(JobsSystemd, Startup) |
3512 | { |
3513 | - registry->impl->jobs = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3514 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3515 | + registry->impl->setJobs(manager); |
3516 | + manager->runningApps(); |
3517 | |
3518 | EXPECT_EVENTUALLY_FUNC_EQ(true, std::function<bool()>([this]() { return systemd->subscribeCallsCnt() > 0; })); |
3519 | EXPECT_EVENTUALLY_FUNC_EQ(true, std::function<bool()>([this]() -> bool { return systemd->listCallsCnt() > 0; })); |
3520 | @@ -117,8 +121,8 @@ |
3521 | /* Get the running apps and check out their instances */ |
3522 | TEST_F(JobsSystemd, RunningApps) |
3523 | { |
3524 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3525 | - registry->impl->jobs = manager; |
3526 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3527 | + registry->impl->setJobs(manager); |
3528 | |
3529 | auto apps = manager->runningApps(); |
3530 | ASSERT_FALSE(apps.empty()); |
3531 | @@ -144,8 +148,8 @@ |
3532 | /* Check to make sure we're getting the user bus path correctly */ |
3533 | TEST_F(JobsSystemd, UserBusPath) |
3534 | { |
3535 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3536 | - registry->impl->jobs = manager; |
3537 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3538 | + registry->impl->setJobs(manager); |
3539 | |
3540 | EXPECT_EQ(std::string{"/this/should/not/exist"}, manager->userBusPath()); |
3541 | |
3542 | @@ -156,8 +160,8 @@ |
3543 | /* PID Tools */ |
3544 | TEST_F(JobsSystemd, PidTools) |
3545 | { |
3546 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3547 | - registry->impl->jobs = manager; |
3548 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3549 | + registry->impl->setJobs(manager); |
3550 | |
3551 | EXPECT_EQ(5, manager->unitPrimaryPid(singleAppID(), defaultJobName(), {})); |
3552 | std::vector<pid_t> pidlist{1, 2, 3, 4, 5}; |
3553 | @@ -167,8 +171,8 @@ |
3554 | /* PID Instance */ |
3555 | TEST_F(JobsSystemd, PidInstance) |
3556 | { |
3557 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3558 | - registry->impl->jobs = manager; |
3559 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3560 | + registry->impl->setJobs(manager); |
3561 | |
3562 | auto inst = manager->existing(singleAppID(), defaultJobName(), {}, {}); |
3563 | EXPECT_TRUE(bool(inst)); |
3564 | @@ -181,8 +185,8 @@ |
3565 | /* Stopping a Job */ |
3566 | TEST_F(JobsSystemd, StopUnit) |
3567 | { |
3568 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3569 | - registry->impl->jobs = manager; |
3570 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3571 | + registry->impl->setJobs(manager); |
3572 | |
3573 | manager->stopUnit(singleAppID(), defaultJobName(), {}); |
3574 | |
3575 | @@ -211,8 +215,8 @@ |
3576 | /* Stop Instance */ |
3577 | TEST_F(JobsSystemd, StopInstance) |
3578 | { |
3579 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3580 | - registry->impl->jobs = manager; |
3581 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3582 | + registry->impl->setJobs(manager); |
3583 | |
3584 | auto inst = manager->existing(singleAppID(), defaultJobName(), {}, {}); |
3585 | EXPECT_TRUE(bool(inst)); |
3586 | @@ -231,8 +235,8 @@ |
3587 | /* Starting a new job */ |
3588 | TEST_F(JobsSystemd, LaunchJob) |
3589 | { |
3590 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3591 | - registry->impl->jobs = manager; |
3592 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3593 | + registry->impl->setJobs(manager); |
3594 | |
3595 | bool gotenv{false}; |
3596 | std::function<std::list<std::pair<std::string, std::string>>()> getenvfunc = |
3597 | @@ -291,8 +295,8 @@ |
3598 | |
3599 | TEST_F(JobsSystemd, SignalNew) |
3600 | { |
3601 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3602 | - registry->impl->jobs = manager; |
3603 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3604 | + registry->impl->setJobs(manager); |
3605 | |
3606 | std::promise<ubuntu::app_launch::AppID> newunit; |
3607 | manager->appStarted().connect([&](const std::shared_ptr<ubuntu::app_launch::Application> &app, |
3608 | @@ -327,8 +331,8 @@ |
3609 | |
3610 | TEST_F(JobsSystemd, SignalRemove) |
3611 | { |
3612 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3613 | - registry->impl->jobs = manager; |
3614 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3615 | + registry->impl->setJobs(manager); |
3616 | |
3617 | std::promise<ubuntu::app_launch::AppID> removeunit; |
3618 | manager->appStopped().connect([&](const std::shared_ptr<ubuntu::app_launch::Application> &app, |
3619 | @@ -363,8 +367,8 @@ |
3620 | |
3621 | TEST_F(JobsSystemd, UnitFailure) |
3622 | { |
3623 | - auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry); |
3624 | - registry->impl->jobs = manager; |
3625 | + auto manager = std::make_shared<ubuntu::app_launch::jobs::manager::SystemD>(registry->impl); |
3626 | + registry->impl->setJobs(manager); |
3627 | |
3628 | ubuntu::app_launch::AppID failedappid; |
3629 | manager->appFailed().connect([&](const std::shared_ptr<ubuntu::app_launch::Application> &app, |
3630 | |
3631 | === modified file 'tests/libual-cpp-test.cc' |
3632 | --- tests/libual-cpp-test.cc 2017-03-20 15:17:02 +0000 |
3633 | +++ tests/libual-cpp-test.cc 2017-04-04 21:22:36 +0000 |
3634 | @@ -258,16 +258,16 @@ |
3635 | { |
3636 | auto store = storeForHelper(appid); |
3637 | |
3638 | - ON_CALL(*store, list(testing::_)) |
3639 | + ON_CALL(*store, list()) |
3640 | .WillByDefault(testing::Return(std::list<std::shared_ptr<ubuntu::app_launch::Application>>{})); |
3641 | |
3642 | - auto app = std::make_shared<MockApp>(appid, registry); |
3643 | - ON_CALL(*store, create(appid, testing::_)).WillByDefault(testing::Return(app)); |
3644 | + auto app = std::make_shared<MockApp>(appid, registry->impl); |
3645 | + ON_CALL(*store, create(appid)).WillByDefault(testing::Return(app)); |
3646 | |
3647 | if (!instanceid.empty()) |
3648 | { |
3649 | std::vector<ubuntu::app_launch::Application::URL> urls; |
3650 | - auto inst = std::make_shared<MockInst>(appid, jobtype, instanceid, urls, registry); |
3651 | + auto inst = std::make_shared<MockInst>(appid, jobtype, instanceid, urls, registry->impl); |
3652 | ON_CALL(*app, findInstance(instanceid)).WillByDefault(testing::Return(inst)); |
3653 | ON_CALL(*app, launch(testing::_)).WillByDefault(testing::Return(inst)); |
3654 | ON_CALL(*app, launchTest(testing::_)).WillByDefault(testing::Return(inst)); |
3655 | @@ -286,15 +286,13 @@ |
3656 | std::shared_ptr<MockStore> storeForHelper(const ubuntu::app_launch::AppID& appid) |
3657 | { |
3658 | /* Setup a store for looking up the AppID */ |
3659 | - auto store = std::make_shared<MockStore>(); |
3660 | + auto store = std::make_shared<MockStore>(registry->impl); |
3661 | |
3662 | - ON_CALL(*store, verifyPackage(appid.package, testing::_)).WillByDefault(testing::Return(true)); |
3663 | - ON_CALL(*store, verifyAppname(appid.package, appid.appname, testing::_)).WillByDefault(testing::Return(true)); |
3664 | - ON_CALL(*store, findAppname(appid.package, testing::_, testing::_)) |
3665 | - .WillByDefault(testing::Return(appid.appname)); |
3666 | - ON_CALL(*store, findVersion(appid.package, appid.appname, testing::_)) |
3667 | - .WillByDefault(testing::Return(appid.version)); |
3668 | - ON_CALL(*store, hasAppId(appid, testing::_)).WillByDefault(testing::Return(true)); |
3669 | + ON_CALL(*store, verifyPackage(appid.package)).WillByDefault(testing::Return(true)); |
3670 | + ON_CALL(*store, verifyAppname(appid.package, appid.appname)).WillByDefault(testing::Return(true)); |
3671 | + ON_CALL(*store, findAppname(appid.package, testing::_)).WillByDefault(testing::Return(appid.appname)); |
3672 | + ON_CALL(*store, findVersion(appid.package, appid.appname)).WillByDefault(testing::Return(appid.version)); |
3673 | + ON_CALL(*store, hasAppId(appid)).WillByDefault(testing::Return(true)); |
3674 | |
3675 | std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>> list; |
3676 | list.push_back(store); |
3677 | @@ -435,46 +433,46 @@ |
3678 | |
3679 | TEST_F(LibUAL, ApplicationId) |
3680 | { |
3681 | - auto mockstore = std::make_shared<MockStore>(); |
3682 | + auto mockstore = std::make_shared<MockStore>(registry->impl); |
3683 | registry = |
3684 | - std::make_shared<RegistryMock>(std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>>{mockstore}); |
3685 | + std::make_shared<RegistryMock>(std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>>{mockstore}, |
3686 | + std::shared_ptr<ubuntu::app_launch::jobs::manager::Base>{}); |
3687 | |
3688 | - EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), testing::_)) |
3689 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"))) |
3690 | .WillOnce(testing::Return(true)); |
3691 | EXPECT_CALL(*mockstore, verifyAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3692 | - ubuntu::app_launch::AppID::AppName::from_raw("application"), testing::_)) |
3693 | + ubuntu::app_launch::AppID::AppName::from_raw("application"))) |
3694 | .WillOnce(testing::Return(true)); |
3695 | EXPECT_CALL(*mockstore, findVersion(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3696 | - ubuntu::app_launch::AppID::AppName::from_raw("application"), testing::_)) |
3697 | + ubuntu::app_launch::AppID::AppName::from_raw("application"))) |
3698 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::Version::from_raw("1.2.3"))); |
3699 | |
3700 | /* Test with current-user-version, should return the version in the manifest */ |
3701 | EXPECT_EQ("com.test.good_application_1.2.3", |
3702 | (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.good", "application")); |
3703 | |
3704 | - EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), testing::_)) |
3705 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"))) |
3706 | .WillOnce(testing::Return(true)); |
3707 | EXPECT_CALL(*mockstore, verifyAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3708 | - ubuntu::app_launch::AppID::AppName::from_raw("application"), testing::_)) |
3709 | + ubuntu::app_launch::AppID::AppName::from_raw("application"))) |
3710 | .WillOnce(testing::Return(true)); |
3711 | EXPECT_CALL(*mockstore, |
3712 | hasAppId(ubuntu::app_launch::AppID{ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3713 | ubuntu::app_launch::AppID::AppName::from_raw("application"), |
3714 | - ubuntu::app_launch::AppID::Version::from_raw("1.2.4")}, |
3715 | - testing::_)) |
3716 | + ubuntu::app_launch::AppID::Version::from_raw("1.2.4")})) |
3717 | .WillOnce(testing::Return(true)); |
3718 | |
3719 | /* Test with version specified, shouldn't even read the manifest */ |
3720 | EXPECT_EQ("com.test.good_application_1.2.4", |
3721 | (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.good", "application", "1.2.4")); |
3722 | |
3723 | - EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), testing::_)) |
3724 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"))) |
3725 | .WillOnce(testing::Return(true)); |
3726 | EXPECT_CALL(*mockstore, findAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3727 | - ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED, testing::_)) |
3728 | + ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED)) |
3729 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::AppName::from_raw("application"))); |
3730 | EXPECT_CALL(*mockstore, findVersion(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3731 | - ubuntu::app_launch::AppID::AppName::from_raw("application"), testing::_)) |
3732 | + ubuntu::app_launch::AppID::AppName::from_raw("application"))) |
3733 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::Version::from_raw("1.2.3"))); |
3734 | |
3735 | /* Test with out a version or app, should return the version in the manifest */ |
3736 | @@ -483,79 +481,72 @@ |
3737 | "current-user-version")); |
3738 | |
3739 | /* Make sure we can select the app from a list correctly */ |
3740 | - EXPECT_CALL(*mockstore, |
3741 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), testing::_)) |
3742 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"))) |
3743 | .WillOnce(testing::Return(true)); |
3744 | EXPECT_CALL(*mockstore, findAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3745 | - ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED, testing::_)) |
3746 | + ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED)) |
3747 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::AppName::from_raw("first"))); |
3748 | EXPECT_CALL(*mockstore, findVersion(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3749 | - ubuntu::app_launch::AppID::AppName::from_raw("first"), testing::_)) |
3750 | + ubuntu::app_launch::AppID::AppName::from_raw("first"))) |
3751 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::Version::from_raw("1.2.3"))); |
3752 | EXPECT_EQ("com.test.multiple_first_1.2.3", |
3753 | (std::string)ubuntu::app_launch::AppID::discover( |
3754 | registry, "com.test.multiple", ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED)); |
3755 | |
3756 | - EXPECT_CALL(*mockstore, |
3757 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), testing::_)) |
3758 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"))) |
3759 | .WillOnce(testing::Return(true)); |
3760 | EXPECT_CALL(*mockstore, findAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3761 | - ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED, testing::_)) |
3762 | + ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED)) |
3763 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::AppName::from_raw("first"))); |
3764 | EXPECT_CALL(*mockstore, findVersion(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3765 | - ubuntu::app_launch::AppID::AppName::from_raw("first"), testing::_)) |
3766 | + ubuntu::app_launch::AppID::AppName::from_raw("first"))) |
3767 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::Version::from_raw("1.2.3"))); |
3768 | EXPECT_EQ("com.test.multiple_first_1.2.3", |
3769 | (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.multiple")); |
3770 | |
3771 | - EXPECT_CALL(*mockstore, |
3772 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), testing::_)) |
3773 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"))) |
3774 | .WillOnce(testing::Return(true)); |
3775 | EXPECT_CALL(*mockstore, findAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3776 | - ubuntu::app_launch::AppID::ApplicationWildcard::LAST_LISTED, testing::_)) |
3777 | + ubuntu::app_launch::AppID::ApplicationWildcard::LAST_LISTED)) |
3778 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::AppName::from_raw("fifth"))); |
3779 | EXPECT_CALL(*mockstore, findVersion(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3780 | - ubuntu::app_launch::AppID::AppName::from_raw("fifth"), testing::_)) |
3781 | + ubuntu::app_launch::AppID::AppName::from_raw("fifth"))) |
3782 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::Version::from_raw("1.2.3"))); |
3783 | EXPECT_EQ("com.test.multiple_fifth_1.2.3", |
3784 | (std::string)ubuntu::app_launch::AppID::discover( |
3785 | registry, "com.test.multiple", ubuntu::app_launch::AppID::ApplicationWildcard::LAST_LISTED)); |
3786 | |
3787 | - EXPECT_CALL(*mockstore, |
3788 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), testing::_)) |
3789 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"))) |
3790 | .WillOnce(testing::Return(true)); |
3791 | EXPECT_CALL(*mockstore, findAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.multiple"), |
3792 | - ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED, testing::_)) |
3793 | + ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED)) |
3794 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::AppName::from_raw(""))); |
3795 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover( |
3796 | registry, "com.test.multiple", ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED)); |
3797 | |
3798 | - EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), testing::_)) |
3799 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"))) |
3800 | .WillOnce(testing::Return(true)); |
3801 | EXPECT_CALL(*mockstore, findAppname(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3802 | - ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED, testing::_)) |
3803 | + ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED)) |
3804 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::AppName::from_raw("application"))); |
3805 | EXPECT_CALL(*mockstore, findVersion(ubuntu::app_launch::AppID::Package::from_raw("com.test.good"), |
3806 | - ubuntu::app_launch::AppID::AppName::from_raw("application"), testing::_)) |
3807 | + ubuntu::app_launch::AppID::AppName::from_raw("application"))) |
3808 | .WillOnce(testing::Return(ubuntu::app_launch::AppID::Version::from_raw("1.2.3"))); |
3809 | EXPECT_EQ("com.test.good_application_1.2.3", |
3810 | (std::string)ubuntu::app_launch::AppID::discover( |
3811 | registry, "com.test.good", ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED)); |
3812 | |
3813 | /* A bunch that should be NULL */ |
3814 | - EXPECT_CALL(*mockstore, |
3815 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-hooks"), testing::_)) |
3816 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-hooks"))) |
3817 | .WillOnce(testing::Return(false)); |
3818 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.no-hooks")); |
3819 | - EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-json"), testing::_)) |
3820 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-json"))) |
3821 | .WillOnce(testing::Return(false)); |
3822 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.no-json")); |
3823 | - EXPECT_CALL(*mockstore, |
3824 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-object"), testing::_)) |
3825 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-object"))) |
3826 | .WillOnce(testing::Return(false)); |
3827 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.no-object")); |
3828 | - EXPECT_CALL(*mockstore, |
3829 | - verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-version"), testing::_)) |
3830 | + EXPECT_CALL(*mockstore, verifyPackage(ubuntu::app_launch::AppID::Package::from_raw("com.test.no-version"))) |
3831 | .WillOnce(testing::Return(false)); |
3832 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover(registry, "com.test.no-version")); |
3833 | } |
3834 | |
3835 | === modified file 'tests/list-apps.cpp' |
3836 | --- tests/list-apps.cpp 2017-03-14 21:41:39 +0000 |
3837 | +++ tests/list-apps.cpp 2017-04-04 21:22:36 +0000 |
3838 | @@ -139,8 +139,8 @@ |
3839 | TEST_F(ListApps, ListLegacy) |
3840 | { |
3841 | auto registry = std::make_shared<ubuntu::app_launch::Registry>(); |
3842 | - ubuntu::app_launch::app_store::Legacy store; |
3843 | - auto apps = store.list(registry); |
3844 | + ubuntu::app_launch::app_store::Legacy store(registry->impl); |
3845 | + auto apps = store.list(); |
3846 | |
3847 | printApps(apps); |
3848 | |
3849 | @@ -154,8 +154,8 @@ |
3850 | TEST_F(ListApps, ListLibertine) |
3851 | { |
3852 | auto registry = std::make_shared<ubuntu::app_launch::Registry>(); |
3853 | - ubuntu::app_launch::app_store::Libertine store; |
3854 | - auto apps = store.list(registry); |
3855 | + ubuntu::app_launch::app_store::Libertine store(registry->impl); |
3856 | + auto apps = store.list(); |
3857 | |
3858 | printApps(apps); |
3859 | |
3860 | @@ -197,8 +197,8 @@ |
3861 | interfaces, x11Package, x11Package, x11Package}}; /* x11 check */ |
3862 | auto registry = std::make_shared<ubuntu::app_launch::Registry>(); |
3863 | |
3864 | - ubuntu::app_launch::app_store::Snap store; |
3865 | - auto apps = store.list(registry); |
3866 | + ubuntu::app_launch::app_store::Snap store(registry->impl); |
3867 | + auto apps = store.list(); |
3868 | |
3869 | printApps(apps); |
3870 | |
3871 | |
3872 | === modified file 'tests/registry-mock.h' |
3873 | --- tests/registry-mock.h 2017-03-20 10:13:50 +0000 |
3874 | +++ tests/registry-mock.h 2017-04-04 21:22:36 +0000 |
3875 | @@ -29,8 +29,8 @@ |
3876 | class MockStore : public ubuntu::app_launch::app_store::Base |
3877 | { |
3878 | public: |
3879 | - MockStore() |
3880 | - : ubuntu::app_launch::app_store::Base() |
3881 | + MockStore(const std::shared_ptr<ubuntu::app_launch::Registry::Impl>& registry) |
3882 | + : ubuntu::app_launch::app_store::Base(registry) |
3883 | { |
3884 | } |
3885 | |
3886 | @@ -38,32 +38,22 @@ |
3887 | { |
3888 | } |
3889 | |
3890 | - MOCK_METHOD2(verifyPackage, |
3891 | - bool(const ubuntu::app_launch::AppID::Package&, const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3892 | - MOCK_METHOD3(verifyAppname, |
3893 | - bool(const ubuntu::app_launch::AppID::Package&, |
3894 | - const ubuntu::app_launch::AppID::AppName&, |
3895 | - const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3896 | - MOCK_METHOD3(findAppname, |
3897 | + MOCK_METHOD1(verifyPackage, bool(const ubuntu::app_launch::AppID::Package&)); |
3898 | + MOCK_METHOD2(verifyAppname, |
3899 | + bool(const ubuntu::app_launch::AppID::Package&, const ubuntu::app_launch::AppID::AppName&)); |
3900 | + MOCK_METHOD2(findAppname, |
3901 | ubuntu::app_launch::AppID::AppName(const ubuntu::app_launch::AppID::Package&, |
3902 | - ubuntu::app_launch::AppID::ApplicationWildcard, |
3903 | - const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3904 | - MOCK_METHOD3(findVersion, |
3905 | + ubuntu::app_launch::AppID::ApplicationWildcard)); |
3906 | + MOCK_METHOD2(findVersion, |
3907 | ubuntu::app_launch::AppID::Version(const ubuntu::app_launch::AppID::Package&, |
3908 | - const ubuntu::app_launch::AppID::AppName&, |
3909 | - const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3910 | - MOCK_METHOD2(hasAppId, |
3911 | - bool(const ubuntu::app_launch::AppID&, const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3912 | + const ubuntu::app_launch::AppID::AppName&)); |
3913 | + MOCK_METHOD1(hasAppId, bool(const ubuntu::app_launch::AppID&)); |
3914 | |
3915 | /* Possible apps */ |
3916 | - MOCK_METHOD1(list, |
3917 | - std::list<std::shared_ptr<ubuntu::app_launch::Application>>( |
3918 | - const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3919 | + MOCK_METHOD0(list, std::list<std::shared_ptr<ubuntu::app_launch::Application>>()); |
3920 | |
3921 | /* Application Creation */ |
3922 | - MOCK_METHOD2(create, |
3923 | - std::shared_ptr<ubuntu::app_launch::app_impls::Base>( |
3924 | - const ubuntu::app_launch::AppID&, const std::shared_ptr<ubuntu::app_launch::Registry>&)); |
3925 | + MOCK_METHOD1(create, std::shared_ptr<ubuntu::app_launch::app_impls::Base>(const ubuntu::app_launch::AppID&)); |
3926 | }; |
3927 | |
3928 | class MockApp : public ubuntu::app_launch::app_impls::Base |
3929 | @@ -71,7 +61,7 @@ |
3930 | public: |
3931 | ubuntu::app_launch::AppID appid_; |
3932 | |
3933 | - MockApp(const ubuntu::app_launch::AppID& appid, const std::shared_ptr<ubuntu::app_launch::Registry>& reg) |
3934 | + MockApp(const ubuntu::app_launch::AppID& appid, const std::shared_ptr<ubuntu::app_launch::Registry::Impl>& reg) |
3935 | : ubuntu::app_launch::app_impls::Base(reg) |
3936 | , appid_(appid) |
3937 | { |
3938 | @@ -105,7 +95,7 @@ |
3939 | const std::string& job, |
3940 | const std::string& instance, |
3941 | const std::vector<ubuntu::app_launch::Application::URL>& urls, |
3942 | - const std::shared_ptr<ubuntu::app_launch::Registry>& registry) |
3943 | + const std::shared_ptr<ubuntu::app_launch::Registry::Impl>& registry) |
3944 | : ubuntu::app_launch::jobs::instance::Base(appId, job, instance, urls, registry){}; |
3945 | ~MockInst(){}; |
3946 | |
3947 | @@ -117,7 +107,7 @@ |
3948 | class MockJobsManager : public ubuntu::app_launch::jobs::manager::Base |
3949 | { |
3950 | public: |
3951 | - MockJobsManager(const std::shared_ptr<ubuntu::app_launch::Registry>& reg) |
3952 | + MockJobsManager(const std::shared_ptr<ubuntu::app_launch::Registry::Impl>& reg) |
3953 | : ubuntu::app_launch::jobs::manager::Base(reg) |
3954 | { |
3955 | } |
3956 | @@ -164,8 +154,8 @@ |
3957 | class zgWatcherMock : public ubuntu::app_launch::info_watcher::Zeitgeist |
3958 | { |
3959 | public: |
3960 | - zgWatcherMock() |
3961 | - : ubuntu::app_launch::info_watcher::Zeitgeist({}) |
3962 | + zgWatcherMock(const std::shared_ptr<ubuntu::app_launch::Registry::Impl>& registry) |
3963 | + : ubuntu::app_launch::info_watcher::Zeitgeist(registry) |
3964 | { |
3965 | } |
3966 | |
3967 | @@ -180,31 +170,10 @@ |
3968 | class RegistryImplMock : public ubuntu::app_launch::Registry::Impl |
3969 | { |
3970 | public: |
3971 | - RegistryImplMock(ubuntu::app_launch::Registry& reg) |
3972 | - : ubuntu::app_launch::Registry::Impl(reg) |
3973 | - { |
3974 | - setupZgWatcher(); |
3975 | - |
3976 | - g_debug("Registry Mock Implementation Created"); |
3977 | - } |
3978 | - |
3979 | - RegistryImplMock(ubuntu::app_launch::Registry& reg, |
3980 | - std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>> appStores) |
3981 | - : ubuntu::app_launch::Registry::Impl(reg, appStores) |
3982 | - { |
3983 | - setupZgWatcher(); |
3984 | - |
3985 | - g_debug("Registry Mock Implementation Created"); |
3986 | - } |
3987 | - |
3988 | - void setupZgWatcher() |
3989 | - { |
3990 | - auto zgWatcher = std::make_shared<zgWatcherMock>(); |
3991 | - zgWatcher_ = zgWatcher; |
3992 | - std::call_once(zgWatcherOnce_, [] {}); |
3993 | - |
3994 | - ON_CALL(*zgWatcher, lookupAppPopularity(testing::_)) |
3995 | - .WillByDefault(testing::Return(ubuntu::app_launch::Application::Info::Popularity::from_raw(1u))); |
3996 | + RegistryImplMock() |
3997 | + : ubuntu::app_launch::Registry::Impl() |
3998 | + { |
3999 | + g_debug("Registry Mock Implementation Created"); |
4000 | } |
4001 | |
4002 | ~RegistryImplMock() |
4003 | @@ -219,15 +188,29 @@ |
4004 | { |
4005 | public: |
4006 | RegistryMock() |
4007 | + : Registry(std::make_shared<RegistryImplMock>()) |
4008 | { |
4009 | + auto zgWatcher = std::make_shared<zgWatcherMock>(impl); |
4010 | + ON_CALL(*zgWatcher, lookupAppPopularity(testing::_)) |
4011 | + .WillByDefault(testing::Return(ubuntu::app_launch::Application::Info::Popularity::from_raw(1u))); |
4012 | + impl->setZgWatcher(zgWatcher); |
4013 | + |
4014 | g_debug("Registry Mock Created"); |
4015 | - impl = std::unique_ptr<RegistryImplMock>(new RegistryImplMock(*this)); |
4016 | } |
4017 | |
4018 | - RegistryMock(std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>> appStores) |
4019 | + RegistryMock(std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>> appStores, |
4020 | + std::shared_ptr<ubuntu::app_launch::jobs::manager::Base> jobManager) |
4021 | + : Registry(std::make_shared<RegistryImplMock>()) |
4022 | { |
4023 | + impl->setAppStores(appStores); |
4024 | + impl->setJobs(jobManager); |
4025 | + |
4026 | + auto zgWatcher = std::make_shared<zgWatcherMock>(impl); |
4027 | + ON_CALL(*zgWatcher, lookupAppPopularity(testing::_)) |
4028 | + .WillByDefault(testing::Return(ubuntu::app_launch::Application::Info::Popularity::from_raw(1u))); |
4029 | + impl->setZgWatcher(zgWatcher); |
4030 | + |
4031 | g_debug("Registry Mock Created"); |
4032 | - impl = std::unique_ptr<RegistryImplMock>(new RegistryImplMock(*this, appStores)); |
4033 | } |
4034 | |
4035 | ~RegistryMock() |
FAILED: Continuous integration, rev:317 /jenkins. canonical. com/unity- api-1/job/ lp-ubuntu- app-launch- ci/281/ /jenkins. canonical. com/unity- api-1/job/ build/1879/ console /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/1886 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 1668/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= zesty/1668/ console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 1668 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 1668/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= zesty/1668 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= zesty/1668/ artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 1668 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 1668/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= zesty/1668/ console
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/unity- api-1/job/ lp-ubuntu- app-launch- ci/281/ rebuild
https:/