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