Merge lp:~bregma/ubuntu-app-launch/app-object into lp:ubuntu-app-launch/16.04
- app-object
- Merge into trunk.16.04
Status: | Rejected |
---|---|
Rejected by: | Ted Gould |
Proposed branch: | lp:~bregma/ubuntu-app-launch/app-object |
Merge into: | lp:ubuntu-app-launch/16.04 |
Diff against target: |
5605 lines (+4756/-236) 57 files modified
.bzrignore (+6/-0) CMakeLists.txt (+5/-1) _clang-format (+48/-0) debian/changelog (+13/-0) debian/control (+2/-0) debian/libubuntu-app-launch2.shlibs (+1/-0) debian/libubuntu-app-launch2.symbols (+0/-41) debian/rules (+0/-3) helpers-shared.c (+11/-2) libubuntu-app-launch/CMakeLists.txt (+34/-0) libubuntu-app-launch/appid.h (+83/-0) libubuntu-app-launch/application-impl-base.cpp (+162/-0) libubuntu-app-launch/application-impl-base.h (+52/-0) libubuntu-app-launch/application-impl-click.cpp (+157/-0) libubuntu-app-launch/application-impl-click.h (+56/-0) libubuntu-app-launch/application-impl-legacy.cpp (+128/-0) libubuntu-app-launch/application-impl-legacy.h (+57/-0) libubuntu-app-launch/application-impl-libertine.cpp (+127/-0) libubuntu-app-launch/application-impl-libertine.h (+56/-0) libubuntu-app-launch/application-info-desktop.cpp (+202/-0) libubuntu-app-launch/application-info-desktop.h (+87/-0) libubuntu-app-launch/application.cpp (+225/-0) libubuntu-app-launch/application.h (+150/-0) libubuntu-app-launch/desktop-exec.c (+1/-1) libubuntu-app-launch/glib-thread.cpp (+156/-0) libubuntu-app-launch/glib-thread.h (+90/-0) libubuntu-app-launch/helper-impl-click.cpp (+175/-0) libubuntu-app-launch/helper-impl-click.h (+62/-0) libubuntu-app-launch/helper.cpp (+36/-0) libubuntu-app-launch/helper.h (+71/-0) libubuntu-app-launch/libubuntu-app-launch.map (+17/-0) libubuntu-app-launch/registry-impl.cpp (+185/-0) libubuntu-app-launch/registry-impl.h (+69/-0) libubuntu-app-launch/registry.cpp (+99/-0) libubuntu-app-launch/registry.h (+91/-0) libubuntu-app-launch/type-tagger.h (+37/-0) libubuntu-app-launch/ubuntu-app-launch.c (+7/-7) libubuntu-app-launch/ubuntu-app-launch.h (+12/-0) tests/CMakeLists.txt (+20/-0) tests/application-info-desktop.cpp (+148/-0) tests/click-app-dir/application.desktop (+3/-1) tests/exec-util-test.cc (+1/-1) tests/helper-handshake-test.cc (+3/-0) tests/helper-test.cc (+0/-2) tests/libertine-data/libertine-container/container-name/rootfs/usr/share/applications/test.desktop (+1/-0) tests/libual-cpp-test.cc (+1599/-0) tests/libual-test.cc (+1/-2) tests/mir-mock.cpp (+1/-1) tools/CMakeLists.txt (+16/-7) tools/ubuntu-app-list-pids.cpp (+44/-0) tools/ubuntu-app-list.cpp (+11/-17) tools/ubuntu-app-pid.cpp (+25/-19) tools/ubuntu-app-stop.cpp (+21/-15) tools/ubuntu-app-triplet.cpp (+26/-32) tools/ubuntu-helper-list.cpp (+20/-31) tools/ubuntu-helper-start.cpp (+21/-27) tools/ubuntu-helper-stop.cpp (+25/-26) |
To merge this branch: | bzr merge lp:~bregma/ubuntu-app-launch/app-object |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Indicator Applet Developers | Pending | ||
Review via email: mp+284521@code.launchpad.net |
Commit message
fix build deps
Description of the change
test merge for Libertine demo
- 229. By Ted Gould
-
Removing signals from the API for this MR
- 230. By Ted Gould
-
Revert back to 'C' versions of these tools
- 231. By Ted Gould
-
Fix symbols
- 232. By Ted Gould
-
Switch to a different arbitrary style
- 233. By Ted Gould
-
Switch from symbols to shlibs
- 234. By Ted Gould
-
Namespace bike shedding
- 235. By Ted Gould
-
Remove as member functions
- 236. By Ted Gould
-
Adding the class keyword to enums
- 237. By Ted Gould
-
Optimize constructors
- 238. By Ted Gould
-
Explicit constructor
- 239. By Ted Gould
-
Check to ensure cpath isn't null
- 240. By Ted Gould
-
Make URL vectors const references
- 241. By Ted Gould
-
Make the constructor fail if there is no keyfile instead of waiting when we get info()
- 242. By Ted Gould
-
Passing the manifests by const reference
- 243. By Ted Gould
-
Adding a format target
- 244. By Ted Gould
-
Exception on manifest failures and ensure that we have it early
- 245. By Ted Gould
-
Stop incrementing ref counts to make the code faster
- 246. By Ted Gould
-
Check for keyfile in constructor
- 247. By Ted Gould
-
Check for keyfile in constructor
- 248. By Ted Gould
-
Move prototype
- 249. By Ted Gould
-
Making voids implicit instead of explicit
- 250. By Ted Gould
-
Move from one implementation only location to another implementation only location
- 251. By Ted Gould
-
Constexpr
- 252. By Ted Gould
-
Adding extra commas
- 253. By Ted Gould
-
Less splash, more namespacing
- 254. By Ted Gould
-
Change to supportsUbuntuL
ifecycle - 255. By Stephen M. Webb
-
added missing build-dep on libproperties-
cpp-dev - 256. By Stephen M. Webb
-
use -std=gnu99 instead of c99 to fix FTBFS on some architectures
- 257. By Stephen M. Webb
-
Fixed a coupla FTBFS and bumped version for Silo 58 testing.
- 258. By Stephen M. Webb
-
Disabled a bunch of chronically-failing tests.
- 259. By Stephen M. Webb
-
merge latest ted upstream branch
Unmerged revisions
- 259. By Stephen M. Webb
-
merge latest ted upstream branch
- 258. By Stephen M. Webb
-
Disabled a bunch of chronically-failing tests.
- 257. By Stephen M. Webb
-
Fixed a coupla FTBFS and bumped version for Silo 58 testing.
- 256. By Stephen M. Webb
-
use -std=gnu99 instead of c99 to fix FTBFS on some architectures
- 255. By Stephen M. Webb
-
added missing build-dep on libproperties-
cpp-dev
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2014-06-14 16:32:00 +0000 | |||
3 | +++ .bzrignore 2016-03-04 11:34:19 +0000 | |||
4 | @@ -5,3 +5,9 @@ | |||
5 | 5 | cmake_install.cmake | 5 | cmake_install.cmake |
6 | 6 | *-trace.[ch] | 6 | *-trace.[ch] |
7 | 7 | cgroup-reap-all | 7 | cgroup-reap-all |
8 | 8 | libubuntu-app-launch/UbuntuAppLaunch-2.gir | ||
9 | 9 | libubuntu-app-launch/UbuntuAppLaunch-2.typelib | ||
10 | 10 | libubuntu-app-launch/libubuntu-app-launch.so.2* | ||
11 | 11 | libubuntu-app-launch/proxy-socket-demangler.c | ||
12 | 12 | libubuntu-app-launch/proxy-socket-demangler.h | ||
13 | 13 | libubuntu-app-launch/ubuntu-app-launch-2.pc | ||
14 | 8 | 14 | ||
15 | === modified file 'CMakeLists.txt' | |||
16 | --- CMakeLists.txt 2015-08-11 02:45:49 +0000 | |||
17 | +++ CMakeLists.txt 2016-03-04 11:34:19 +0000 | |||
18 | @@ -37,7 +37,8 @@ | |||
19 | 37 | set(ubuntu_app_launch_arch "${UBUNTU_APP_LAUNCH_ARCH}") | 37 | set(ubuntu_app_launch_arch "${UBUNTU_APP_LAUNCH_ARCH}") |
20 | 38 | 38 | ||
21 | 39 | # Deprecated needed for g_atexit() in libual | 39 | # Deprecated needed for g_atexit() in libual |
23 | 40 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-error=unused-function -Wno-error=deprecated-declarations -std=c99") | 40 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-error=unused-function -Wno-error=deprecated-declarations -std=gnu99") |
24 | 41 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -pthread") | ||
25 | 41 | 42 | ||
26 | 42 | enable_testing() | 43 | enable_testing() |
27 | 43 | 44 | ||
28 | @@ -77,6 +78,9 @@ | |||
29 | 77 | pkg_check_modules(MIR mirclient) | 78 | pkg_check_modules(MIR mirclient) |
30 | 78 | include_directories(${MIR_INCLUDE_DIRS}) | 79 | include_directories(${MIR_INCLUDE_DIRS}) |
31 | 79 | 80 | ||
32 | 81 | pkg_check_modules(LIBERTINE libertine) | ||
33 | 82 | include_directories(${LIBERTINE_INCLUDE_DIRS}) | ||
34 | 83 | |||
35 | 80 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | 84 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
36 | 81 | 85 | ||
37 | 82 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | 86 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") |
38 | 83 | 87 | ||
39 | === added file '_clang-format' | |||
40 | --- _clang-format 1970-01-01 00:00:00 +0000 | |||
41 | +++ _clang-format 2016-03-04 11:34:19 +0000 | |||
42 | @@ -0,0 +1,48 @@ | |||
43 | 1 | --- | ||
44 | 2 | AccessModifierOffset: -4 | ||
45 | 3 | AlignEscapedNewlinesLeft: true | ||
46 | 4 | AlignTrailingComments: true | ||
47 | 5 | AllowAllParametersOfDeclarationOnNextLine: true | ||
48 | 6 | AllowShortFunctionsOnASingleLine: false | ||
49 | 7 | AllowShortIfStatementsOnASingleLine: false | ||
50 | 8 | AllowShortLoopsOnASingleLine: false | ||
51 | 9 | AlwaysBreakBeforeMultilineStrings: true | ||
52 | 10 | AlwaysBreakTemplateDeclarations: true | ||
53 | 11 | BinPackParameters: false | ||
54 | 12 | BreakBeforeBinaryOperators: false | ||
55 | 13 | BreakBeforeBraces: Allman | ||
56 | 14 | BreakBeforeTernaryOperators: false | ||
57 | 15 | BreakConstructorInitializersBeforeComma: true | ||
58 | 16 | ColumnLimit: 120 | ||
59 | 17 | ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
60 | 18 | ConstructorInitializerIndentWidth: 4 | ||
61 | 19 | ContinuationIndentWidth: 4 | ||
62 | 20 | Cpp11BracedListStyle: true | ||
63 | 21 | DerivePointerBinding: true | ||
64 | 22 | ExperimentalAutoDetectBinPacking: false | ||
65 | 23 | IndentCaseLabels: true | ||
66 | 24 | IndentFunctionDeclarationAfterType: true | ||
67 | 25 | IndentWidth: 4 | ||
68 | 26 | Language: Cpp | ||
69 | 27 | MaxEmptyLinesToKeep: 1 | ||
70 | 28 | NamespaceIndentation: None | ||
71 | 29 | ObjCSpaceBeforeProtocolList: false | ||
72 | 30 | PenaltyBreakBeforeFirstCallParameter: 1 | ||
73 | 31 | PenaltyBreakComment: 60 | ||
74 | 32 | PenaltyBreakFirstLessLess: 120 | ||
75 | 33 | PenaltyBreakString: 1000 | ||
76 | 34 | PenaltyExcessCharacter: 1000000 | ||
77 | 35 | PenaltyReturnTypeOnItsOwnLine: 200 | ||
78 | 36 | PointerBindsToType: true | ||
79 | 37 | SpaceBeforeAssignmentOperators: true | ||
80 | 38 | SpaceBeforeParens: ControlStatements | ||
81 | 39 | SpaceInEmptyParentheses: false | ||
82 | 40 | SpacesBeforeTrailingComments: 2 | ||
83 | 41 | SpacesInAngles: false | ||
84 | 42 | SpacesInCStyleCastParentheses: false | ||
85 | 43 | SpacesInParentheses: false | ||
86 | 44 | Standard: Cpp11 | ||
87 | 45 | TabWidth: 8 | ||
88 | 46 | UseTab: Never | ||
89 | 47 | ... | ||
90 | 48 | |||
91 | 0 | 49 | ||
92 | === modified file 'debian/changelog' | |||
93 | --- debian/changelog 2015-08-17 21:38:34 +0000 | |||
94 | +++ debian/changelog 2016-03-04 11:34:19 +0000 | |||
95 | @@ -1,3 +1,16 @@ | |||
96 | 1 | ubuntu-app-launch (0.9~smw2) UNRELEASED; urgency=medium | ||
97 | 2 | |||
98 | 3 | [ Ted Gould ] | ||
99 | 4 | * Add new C++ API that has a retained object for maintaining | ||
100 | 5 | connections through multiple calls. Also provides for getting | ||
101 | 6 | consistent application metadata. | ||
102 | 7 | |||
103 | 8 | [ Stephen M. Webb ] | ||
104 | 9 | * Fixed a coupla FTBFS and bumped version for Silo 58 testing. | ||
105 | 10 | * Disabled a bunch of chronically-failing tests. | ||
106 | 11 | |||
107 | 12 | -- Ted Gould <ted@ubuntu.com> Tue, 26 Jan 2016 15:22:06 -0600 | ||
108 | 13 | |||
109 | 1 | ubuntu-app-launch (0.5+15.10.20150817-0ubuntu1) wily; urgency=medium | 14 | ubuntu-app-launch (0.5+15.10.20150817-0ubuntu1) wily; urgency=medium |
110 | 2 | 15 | ||
111 | 3 | [ CI Train Bot ] | 16 | [ CI Train Bot ] |
112 | 4 | 17 | ||
113 | === modified file 'debian/control' | |||
114 | --- debian/control 2015-07-31 00:15:57 +0000 | |||
115 | +++ debian/control 2016-03-04 11:34:19 +0000 | |||
116 | @@ -15,10 +15,12 @@ | |||
117 | 15 | libglib2.0-dev, | 15 | libglib2.0-dev, |
118 | 16 | libgtest-dev, | 16 | libgtest-dev, |
119 | 17 | libjson-glib-dev, | 17 | libjson-glib-dev, |
120 | 18 | liblibertine-dev, | ||
121 | 18 | liblttng-ust-dev, | 19 | liblttng-ust-dev, |
122 | 19 | libmirclient-dev (>= 0.5), | 20 | libmirclient-dev (>= 0.5), |
123 | 20 | libnih-dbus-dev, | 21 | libnih-dbus-dev, |
124 | 21 | libnih-dev, | 22 | libnih-dev, |
125 | 23 | libproperties-cpp-dev, | ||
126 | 22 | libupstart-dev, | 24 | libupstart-dev, |
127 | 23 | libzeitgeist-2.0-dev, | 25 | libzeitgeist-2.0-dev, |
128 | 24 | gobject-introspection, | 26 | gobject-introspection, |
129 | 25 | 27 | ||
130 | === added file 'debian/libubuntu-app-launch2.shlibs' | |||
131 | --- debian/libubuntu-app-launch2.shlibs 1970-01-01 00:00:00 +0000 | |||
132 | +++ debian/libubuntu-app-launch2.shlibs 2016-03-04 11:34:19 +0000 | |||
133 | @@ -0,0 +1,1 @@ | |||
134 | 1 | libubuntu-app-launch 2 libubuntu-app-launch2 (>= 0.9) | ||
135 | 0 | 2 | ||
136 | === removed file 'debian/libubuntu-app-launch2.symbols' | |||
137 | --- debian/libubuntu-app-launch2.symbols 2015-08-17 21:38:34 +0000 | |||
138 | +++ debian/libubuntu-app-launch2.symbols 1970-01-01 00:00:00 +0000 | |||
139 | @@ -1,41 +0,0 @@ | |||
140 | 1 | libubuntu-app-launch.so.2 libubuntu-app-launch2 #MINVER# | ||
141 | 2 | ubuntu_app_launch_app_id_parse@Base 0.4 | ||
142 | 3 | ubuntu_app_launch_application_info@Base 0.5+15.10.20150817 | ||
143 | 4 | ubuntu_app_launch_application_log_path@Base 0.4 | ||
144 | 5 | ubuntu_app_launch_get_primary_pid@Base 0.4 | ||
145 | 6 | ubuntu_app_launch_helper_set_exec@Base 0.5+15.10.20150604 | ||
146 | 7 | ubuntu_app_launch_list_helper_instances@Base 0.4 | ||
147 | 8 | ubuntu_app_launch_list_helpers@Base 0.4 | ||
148 | 9 | ubuntu_app_launch_list_running_apps@Base 0.4 | ||
149 | 10 | ubuntu_app_launch_observer_add_app_failed@Base 0.4 | ||
150 | 11 | ubuntu_app_launch_observer_add_app_focus@Base 0.4 | ||
151 | 12 | ubuntu_app_launch_observer_add_app_paused@Base 0.4+15.04.20150305.1 | ||
152 | 13 | ubuntu_app_launch_observer_add_app_resume@Base 0.4 | ||
153 | 14 | ubuntu_app_launch_observer_add_app_resumed@Base 0.4+15.04.20150305.1 | ||
154 | 15 | ubuntu_app_launch_observer_add_app_started@Base 0.4 | ||
155 | 16 | ubuntu_app_launch_observer_add_app_starting@Base 0.4 | ||
156 | 17 | ubuntu_app_launch_observer_add_app_stop@Base 0.4 | ||
157 | 18 | ubuntu_app_launch_observer_add_helper_started@Base 0.4 | ||
158 | 19 | ubuntu_app_launch_observer_add_helper_stop@Base 0.4 | ||
159 | 20 | ubuntu_app_launch_observer_delete_app_failed@Base 0.4 | ||
160 | 21 | ubuntu_app_launch_observer_delete_app_focus@Base 0.4 | ||
161 | 22 | ubuntu_app_launch_observer_delete_app_paused@Base 0.4+15.04.20150305.1 | ||
162 | 23 | ubuntu_app_launch_observer_delete_app_resume@Base 0.4 | ||
163 | 24 | ubuntu_app_launch_observer_delete_app_resumed@Base 0.4+15.04.20150305.1 | ||
164 | 25 | ubuntu_app_launch_observer_delete_app_started@Base 0.4 | ||
165 | 26 | ubuntu_app_launch_observer_delete_app_starting@Base 0.4 | ||
166 | 27 | ubuntu_app_launch_observer_delete_app_stop@Base 0.4 | ||
167 | 28 | ubuntu_app_launch_observer_delete_helper_started@Base 0.4 | ||
168 | 29 | ubuntu_app_launch_observer_delete_helper_stop@Base 0.4 | ||
169 | 30 | ubuntu_app_launch_pause_application@Base 0.4+14.10.20140915.3 | ||
170 | 31 | ubuntu_app_launch_pid_in_app_id@Base 0.4 | ||
171 | 32 | ubuntu_app_launch_resume_application@Base 0.4+14.10.20140915.3 | ||
172 | 33 | ubuntu_app_launch_start_application@Base 0.4 | ||
173 | 34 | ubuntu_app_launch_start_application_test@Base 0.4 | ||
174 | 35 | ubuntu_app_launch_start_helper@Base 0.4 | ||
175 | 36 | ubuntu_app_launch_start_multiple_helper@Base 0.4 | ||
176 | 37 | ubuntu_app_launch_start_session_helper@Base 0.5+15.10.20150604 | ||
177 | 38 | ubuntu_app_launch_stop_application@Base 0.4 | ||
178 | 39 | ubuntu_app_launch_stop_helper@Base 0.4 | ||
179 | 40 | ubuntu_app_launch_stop_multiple_helper@Base 0.4 | ||
180 | 41 | ubuntu_app_launch_triplet_to_app_id@Base 0.4 | ||
181 | 42 | 0 | ||
182 | === modified file 'debian/rules' | |||
183 | --- debian/rules 2014-11-21 16:43:12 +0000 | |||
184 | +++ debian/rules 2016-03-04 11:34:19 +0000 | |||
185 | @@ -1,9 +1,6 @@ | |||
186 | 1 | #!/usr/bin/make -f | 1 | #!/usr/bin/make -f |
187 | 2 | # -*- makefile -*- | 2 | # -*- makefile -*- |
188 | 3 | 3 | ||
189 | 4 | # Error on symbol errors | ||
190 | 5 | export DPKG_GENSYMBOLS_CHECK_LEVEL=4 | ||
191 | 6 | |||
192 | 7 | # Get full logs in tests | 4 | # Get full logs in tests |
193 | 8 | export G_MESSAGES_DEBUG=all | 5 | export G_MESSAGES_DEBUG=all |
194 | 9 | 6 | ||
195 | 10 | 7 | ||
196 | === modified file 'helpers-shared.c' | |||
197 | --- helpers-shared.c 2015-07-15 02:32:54 +0000 | |||
198 | +++ helpers-shared.c 2016-03-04 11:34:19 +0000 | |||
199 | @@ -145,6 +145,8 @@ | |||
200 | 145 | cgroup_manager_connection_core_cb(g_dbus_connection_new_for_address_finish, res, (cgm_connection_t *)data); | 145 | cgroup_manager_connection_core_cb(g_dbus_connection_new_for_address_finish, res, (cgm_connection_t *)data); |
201 | 146 | } | 146 | } |
202 | 147 | 147 | ||
203 | 148 | G_DEFINE_QUARK(CGMANAGER_CONTEXT, cgmanager_context); | ||
204 | 149 | |||
205 | 148 | /* Get the connection to the cgroup manager */ | 150 | /* Get the connection to the cgroup manager */ |
206 | 149 | GDBusConnection * | 151 | GDBusConnection * |
207 | 150 | cgroup_manager_connection (void) | 152 | cgroup_manager_connection (void) |
208 | @@ -191,7 +193,9 @@ | |||
209 | 191 | g_main_context_pop_thread_default(context); | 193 | g_main_context_pop_thread_default(context); |
210 | 192 | 194 | ||
211 | 193 | if (!use_session_bus && connection.con != NULL) { | 195 | if (!use_session_bus && connection.con != NULL) { |
213 | 194 | g_object_set_data(G_OBJECT(connection.con), "cgmanager-context", context); | 196 | g_object_set_qdata(G_OBJECT(connection.con), |
214 | 197 | cgmanager_context_quark(), | ||
215 | 198 | context); | ||
216 | 195 | } else { | 199 | } else { |
217 | 196 | g_main_context_unref(context); | 200 | g_main_context_unref(context); |
218 | 197 | } | 201 | } |
219 | @@ -213,7 +217,7 @@ | |||
220 | 213 | if (cgmanager == NULL) | 217 | if (cgmanager == NULL) |
221 | 214 | return; | 218 | return; |
222 | 215 | 219 | ||
224 | 216 | GMainContext * creationcontext = g_object_get_data(G_OBJECT(cgmanager), "cgmanager-context"); | 220 | GMainContext * creationcontext = g_object_get_qdata(G_OBJECT(cgmanager), cgmanager_context_quark()); |
225 | 217 | if (creationcontext == NULL) { | 221 | if (creationcontext == NULL) { |
226 | 218 | g_object_unref(cgmanager); | 222 | g_object_unref(cgmanager); |
227 | 219 | return; | 223 | return; |
228 | @@ -228,6 +232,11 @@ | |||
229 | 228 | } | 232 | } |
230 | 229 | 233 | ||
231 | 230 | g_object_unref(cgmanager); | 234 | g_object_unref(cgmanager); |
232 | 235 | |||
233 | 236 | while (g_main_context_pending(creationcontext)) { | ||
234 | 237 | g_main_context_iteration(creationcontext, TRUE /* may block */); | ||
235 | 238 | } | ||
236 | 239 | |||
237 | 231 | g_main_context_unref(creationcontext); | 240 | g_main_context_unref(creationcontext); |
238 | 232 | } | 241 | } |
239 | 233 | 242 | ||
240 | 234 | 243 | ||
241 | === modified file 'libubuntu-app-launch/CMakeLists.txt' | |||
242 | --- libubuntu-app-launch/CMakeLists.txt 2015-08-11 19:11:15 +0000 | |||
243 | +++ libubuntu-app-launch/CMakeLists.txt 2016-03-04 11:34:19 +0000 | |||
244 | @@ -17,6 +17,7 @@ | |||
245 | 17 | add_lttng_gen_tp(NAME ubuntu-app-launch-trace) | 17 | add_lttng_gen_tp(NAME ubuntu-app-launch-trace) |
246 | 18 | 18 | ||
247 | 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") | 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") |
248 | 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") | ||
249 | 20 | add_definitions ( -DOOM_HELPER="${pkglibexecdir}/oom-adjust-setuid-helper" -DDEMANGLER_PATH="${pkglibexecdir}/socket-demangler" ) | 21 | add_definitions ( -DOOM_HELPER="${pkglibexecdir}/oom-adjust-setuid-helper" -DDEMANGLER_PATH="${pkglibexecdir}/socket-demangler" ) |
250 | 21 | add_definitions ( -DLIBERTINE_LAUNCH="${CMAKE_INSTALL_FULL_BINDIR}/libertine-launch" ) | 22 | add_definitions ( -DLIBERTINE_LAUNCH="${CMAKE_INSTALL_FULL_BINDIR}/libertine-launch" ) |
251 | 22 | 23 | ||
252 | @@ -24,6 +25,28 @@ | |||
253 | 24 | ubuntu-app-launch.h | 25 | ubuntu-app-launch.h |
254 | 25 | ) | 26 | ) |
255 | 26 | 27 | ||
256 | 28 | set(LAUNCHER_CPP_HEADERS | ||
257 | 29 | appid.h | ||
258 | 30 | application.h | ||
259 | 31 | helper.h | ||
260 | 32 | registry.h | ||
261 | 33 | type-tagger.h | ||
262 | 34 | ) | ||
263 | 35 | |||
264 | 36 | set(LAUNCHER_CPP_SOURCES | ||
265 | 37 | application.cpp | ||
266 | 38 | helper.cpp | ||
267 | 39 | registry.cpp | ||
268 | 40 | registry-impl.cpp | ||
269 | 41 | application-impl-base.cpp | ||
270 | 42 | application-impl-click.cpp | ||
271 | 43 | application-impl-legacy.cpp | ||
272 | 44 | application-impl-libertine.cpp | ||
273 | 45 | application-info-desktop.cpp | ||
274 | 46 | helper-impl-click.cpp | ||
275 | 47 | glib-thread.cpp | ||
276 | 48 | ) | ||
277 | 49 | |||
278 | 27 | set(LAUNCHER_SOURCES | 50 | set(LAUNCHER_SOURCES |
279 | 28 | ubuntu-app-launch.c | 51 | ubuntu-app-launch.c |
280 | 29 | second-exec-core.c | 52 | second-exec-core.c |
281 | @@ -31,6 +54,11 @@ | |||
282 | 31 | desktop-exec.c | 54 | desktop-exec.c |
283 | 32 | ubuntu-app-launch-trace.c | 55 | ubuntu-app-launch-trace.c |
284 | 33 | app-info.c | 56 | app-info.c |
285 | 57 | ${LAUNCHER_CPP_SOURCES} | ||
286 | 58 | ) | ||
287 | 59 | |||
288 | 60 | add_custom_target(format | ||
289 | 61 | COMMAND clang-format -i -style=file ${LAUNCHER_CPP_HEADERS} ${LAUNCHER_CPP_SOURCES} | ||
290 | 34 | ) | 62 | ) |
291 | 35 | 63 | ||
292 | 36 | set(LAUNCHER_GEN_SOURCES | 64 | set(LAUNCHER_GEN_SOURCES |
293 | @@ -59,6 +87,7 @@ | |||
294 | 59 | ${CLICK_LIBRARIES} | 87 | ${CLICK_LIBRARIES} |
295 | 60 | ${ZEITGEIST_LIBRARIES} | 88 | ${ZEITGEIST_LIBRARIES} |
296 | 61 | ${MIR_LIBRARIES} | 89 | ${MIR_LIBRARIES} |
297 | 90 | ${LIBERTINE_LIBRARIES} | ||
298 | 62 | helpers | 91 | helpers |
299 | 63 | -Wl,--no-undefined | 92 | -Wl,--no-undefined |
300 | 64 | ) | 93 | ) |
301 | @@ -69,6 +98,11 @@ | |||
302 | 69 | ) | 98 | ) |
303 | 70 | 99 | ||
304 | 71 | install( | 100 | install( |
305 | 101 | FILES ${LAUNCHER_CPP_HEADERS} | ||
306 | 102 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libubuntu-app-launch-${API_VERSION}/ubuntu-app-launch" | ||
307 | 103 | ) | ||
308 | 104 | |||
309 | 105 | install( | ||
310 | 72 | TARGETS ubuntu-launcher | 106 | TARGETS ubuntu-launcher |
311 | 73 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | 107 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
312 | 74 | ) | 108 | ) |
313 | 75 | 109 | ||
314 | === added file 'libubuntu-app-launch/appid.h' | |||
315 | --- libubuntu-app-launch/appid.h 1970-01-01 00:00:00 +0000 | |||
316 | +++ libubuntu-app-launch/appid.h 2016-03-04 11:34:19 +0000 | |||
317 | @@ -0,0 +1,83 @@ | |||
318 | 1 | /* | ||
319 | 2 | * Copyright © 2016 Canonical Ltd. | ||
320 | 3 | * | ||
321 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
322 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
323 | 6 | * by the Free Software Foundation. | ||
324 | 7 | * | ||
325 | 8 | * This program is distributed in the hope that it will be useful, but | ||
326 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
327 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
328 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
329 | 12 | * | ||
330 | 13 | * You should have received a copy of the GNU General Public License along | ||
331 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
332 | 15 | * | ||
333 | 16 | * Authors: | ||
334 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
335 | 18 | */ | ||
336 | 19 | |||
337 | 20 | #include <string> | ||
338 | 21 | |||
339 | 22 | #include "type-tagger.h" | ||
340 | 23 | |||
341 | 24 | #pragma once | ||
342 | 25 | #pragma GCC visibility push(default) | ||
343 | 26 | |||
344 | 27 | namespace ubuntu | ||
345 | 28 | { | ||
346 | 29 | namespace app_launch | ||
347 | 30 | { | ||
348 | 31 | |||
349 | 32 | struct AppID | ||
350 | 33 | { | ||
351 | 34 | struct PackageTag; | ||
352 | 35 | struct AppNameTag; | ||
353 | 36 | struct VersionTag; | ||
354 | 37 | |||
355 | 38 | typedef TypeTagger<PackageTag, std::string> Package; | ||
356 | 39 | typedef TypeTagger<AppNameTag, std::string> AppName; | ||
357 | 40 | typedef TypeTagger<VersionTag, std::string> Version; | ||
358 | 41 | |||
359 | 42 | Package package; | ||
360 | 43 | AppName appname; | ||
361 | 44 | Version version; | ||
362 | 45 | |||
363 | 46 | operator std::string() const; | ||
364 | 47 | |||
365 | 48 | AppID(); | ||
366 | 49 | AppID(Package pkg, AppName app, Version ver); | ||
367 | 50 | bool empty() const; | ||
368 | 51 | |||
369 | 52 | static AppID parse(const std::string& appid); | ||
370 | 53 | |||
371 | 54 | enum class ApplicationWildcard | ||
372 | 55 | { | ||
373 | 56 | FIRST_LISTED, | ||
374 | 57 | LAST_LISTED, | ||
375 | 58 | ONLY_LISTED, | ||
376 | 59 | }; | ||
377 | 60 | enum class VersionWildcard | ||
378 | 61 | { | ||
379 | 62 | CURRENT_USER_VERSION, | ||
380 | 63 | }; | ||
381 | 64 | |||
382 | 65 | static AppID discover(const std::string& package, | ||
383 | 66 | ApplicationWildcard appwildcard = ApplicationWildcard::FIRST_LISTED, | ||
384 | 67 | VersionWildcard versionwildcard = VersionWildcard::CURRENT_USER_VERSION); | ||
385 | 68 | static AppID discover(const std::string& package, | ||
386 | 69 | const std::string& appname, | ||
387 | 70 | VersionWildcard versionwildcard = VersionWildcard::CURRENT_USER_VERSION); | ||
388 | 71 | static AppID discover(const std::string& package, const std::string& appname, const std::string& version); | ||
389 | 72 | |||
390 | 73 | static AppID find(const std::string& sappid); | ||
391 | 74 | static bool valid(const std::string& sappid); | ||
392 | 75 | }; | ||
393 | 76 | |||
394 | 77 | bool operator==(const AppID& a, const AppID& b); | ||
395 | 78 | bool operator!=(const AppID& a, const AppID& b); | ||
396 | 79 | |||
397 | 80 | }; // namespace app_launch | ||
398 | 81 | }; // namespace ubuntu | ||
399 | 82 | |||
400 | 83 | #pragma GCC visibility pop | ||
401 | 0 | 84 | ||
402 | === added file 'libubuntu-app-launch/application-impl-base.cpp' | |||
403 | --- libubuntu-app-launch/application-impl-base.cpp 1970-01-01 00:00:00 +0000 | |||
404 | +++ libubuntu-app-launch/application-impl-base.cpp 2016-03-04 11:34:19 +0000 | |||
405 | @@ -0,0 +1,162 @@ | |||
406 | 1 | /* | ||
407 | 2 | * Copyright © 2016 Canonical Ltd. | ||
408 | 3 | * | ||
409 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
410 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
411 | 6 | * by the Free Software Foundation. | ||
412 | 7 | * | ||
413 | 8 | * This program is distributed in the hope that it will be useful, but | ||
414 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
415 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
416 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
417 | 12 | * | ||
418 | 13 | * You should have received a copy of the GNU General Public License along | ||
419 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
420 | 15 | * | ||
421 | 16 | * Authors: | ||
422 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
423 | 18 | */ | ||
424 | 19 | |||
425 | 20 | #include "application-impl-base.h" | ||
426 | 21 | |||
427 | 22 | namespace ubuntu | ||
428 | 23 | { | ||
429 | 24 | namespace app_launch | ||
430 | 25 | { | ||
431 | 26 | namespace app_impls | ||
432 | 27 | { | ||
433 | 28 | |||
434 | 29 | Base::Base(const std::shared_ptr<Registry>& registry) | ||
435 | 30 | : _registry(registry) | ||
436 | 31 | { | ||
437 | 32 | } | ||
438 | 33 | |||
439 | 34 | bool Base::hasInstances() | ||
440 | 35 | { | ||
441 | 36 | std::string sappid = appId(); | ||
442 | 37 | return ubuntu_app_launch_get_primary_pid(sappid.c_str()) != 0; | ||
443 | 38 | } | ||
444 | 39 | |||
445 | 40 | class BaseInstance : public Application::Instance | ||
446 | 41 | { | ||
447 | 42 | public: | ||
448 | 43 | explicit BaseInstance(const std::string& appId); | ||
449 | 44 | |||
450 | 45 | /* Query lifecycle */ | ||
451 | 46 | bool isRunning() override | ||
452 | 47 | { | ||
453 | 48 | return ubuntu_app_launch_get_primary_pid(_appId.c_str()) != 0; | ||
454 | 49 | } | ||
455 | 50 | pid_t primaryPid() override | ||
456 | 51 | { | ||
457 | 52 | return ubuntu_app_launch_get_primary_pid(_appId.c_str()); | ||
458 | 53 | } | ||
459 | 54 | bool hasPid(pid_t pid) override | ||
460 | 55 | { | ||
461 | 56 | return ubuntu_app_launch_pid_in_app_id(pid, _appId.c_str()) == TRUE; | ||
462 | 57 | } | ||
463 | 58 | std::string logPath() override | ||
464 | 59 | { | ||
465 | 60 | auto cpath = ubuntu_app_launch_application_log_path(_appId.c_str()); | ||
466 | 61 | if (cpath != nullptr) | ||
467 | 62 | { | ||
468 | 63 | std::string retval(cpath); | ||
469 | 64 | g_free(cpath); | ||
470 | 65 | return retval; | ||
471 | 66 | } | ||
472 | 67 | else | ||
473 | 68 | { | ||
474 | 69 | return {}; | ||
475 | 70 | } | ||
476 | 71 | } | ||
477 | 72 | std::vector<pid_t> pids() override | ||
478 | 73 | { | ||
479 | 74 | std::vector<pid_t> vector; | ||
480 | 75 | GList* list = ubuntu_app_launch_get_pids(_appId.c_str()); | ||
481 | 76 | |||
482 | 77 | for (GList* pntr = list; pntr != nullptr; pntr = g_list_next(pntr)) | ||
483 | 78 | { | ||
484 | 79 | vector.push_back(static_cast<pid_t>(GPOINTER_TO_INT(list->data))); | ||
485 | 80 | } | ||
486 | 81 | |||
487 | 82 | g_list_free(list); | ||
488 | 83 | |||
489 | 84 | return vector; | ||
490 | 85 | } | ||
491 | 86 | |||
492 | 87 | /* Manage lifecycle */ | ||
493 | 88 | void pause() override | ||
494 | 89 | { | ||
495 | 90 | ubuntu_app_launch_pause_application(_appId.c_str()); | ||
496 | 91 | } | ||
497 | 92 | void resume() override | ||
498 | 93 | { | ||
499 | 94 | ubuntu_app_launch_resume_application(_appId.c_str()); | ||
500 | 95 | } | ||
501 | 96 | void stop() override | ||
502 | 97 | { | ||
503 | 98 | ubuntu_app_launch_stop_application(_appId.c_str()); | ||
504 | 99 | } | ||
505 | 100 | |||
506 | 101 | private: | ||
507 | 102 | std::string _appId; | ||
508 | 103 | }; | ||
509 | 104 | |||
510 | 105 | BaseInstance::BaseInstance(const std::string& appId) | ||
511 | 106 | : _appId(appId) | ||
512 | 107 | { | ||
513 | 108 | } | ||
514 | 109 | |||
515 | 110 | std::vector<std::shared_ptr<Application::Instance>> Base::instances() | ||
516 | 111 | { | ||
517 | 112 | std::vector<std::shared_ptr<Instance>> vect; | ||
518 | 113 | vect.emplace_back(std::make_shared<BaseInstance>(appId())); | ||
519 | 114 | return vect; | ||
520 | 115 | } | ||
521 | 116 | |||
522 | 117 | std::shared_ptr<gchar*> urlsToStrv(std::vector<Application::URL> urls) | ||
523 | 118 | { | ||
524 | 119 | auto array = g_array_new(TRUE, FALSE, sizeof(gchar*)); | ||
525 | 120 | |||
526 | 121 | for (auto url : urls) | ||
527 | 122 | { | ||
528 | 123 | auto str = g_strdup(url.value().c_str()); | ||
529 | 124 | g_array_append_val(array, str); | ||
530 | 125 | } | ||
531 | 126 | |||
532 | 127 | return std::shared_ptr<gchar*>((gchar**)g_array_free(array, FALSE), g_strfreev); | ||
533 | 128 | } | ||
534 | 129 | |||
535 | 130 | std::shared_ptr<Application::Instance> Base::launch(const std::vector<Application::URL>& urls) | ||
536 | 131 | { | ||
537 | 132 | std::string appIdStr = appId(); | ||
538 | 133 | std::shared_ptr<gchar*> urlstrv; | ||
539 | 134 | |||
540 | 135 | if (urls.size() > 0) | ||
541 | 136 | { | ||
542 | 137 | urlstrv = urlsToStrv(urls); | ||
543 | 138 | } | ||
544 | 139 | |||
545 | 140 | ubuntu_app_launch_start_application(appIdStr.c_str(), urlstrv.get()); | ||
546 | 141 | |||
547 | 142 | return std::make_shared<BaseInstance>(appIdStr); | ||
548 | 143 | } | ||
549 | 144 | |||
550 | 145 | std::shared_ptr<Application::Instance> Base::launchTest(const std::vector<Application::URL>& urls) | ||
551 | 146 | { | ||
552 | 147 | std::string appIdStr = appId(); | ||
553 | 148 | std::shared_ptr<gchar*> urlstrv; | ||
554 | 149 | |||
555 | 150 | if (urls.size() > 0) | ||
556 | 151 | { | ||
557 | 152 | urlstrv = urlsToStrv(urls); | ||
558 | 153 | } | ||
559 | 154 | |||
560 | 155 | ubuntu_app_launch_start_application_test(appIdStr.c_str(), urlstrv.get()); | ||
561 | 156 | |||
562 | 157 | return std::make_shared<BaseInstance>(appIdStr); | ||
563 | 158 | } | ||
564 | 159 | |||
565 | 160 | }; // namespace app_impls | ||
566 | 161 | }; // namespace app_launch | ||
567 | 162 | }; // namespace ubuntu | ||
568 | 0 | 163 | ||
569 | === added file 'libubuntu-app-launch/application-impl-base.h' | |||
570 | --- libubuntu-app-launch/application-impl-base.h 1970-01-01 00:00:00 +0000 | |||
571 | +++ libubuntu-app-launch/application-impl-base.h 2016-03-04 11:34:19 +0000 | |||
572 | @@ -0,0 +1,52 @@ | |||
573 | 1 | /* | ||
574 | 2 | * Copyright © 2016 Canonical Ltd. | ||
575 | 3 | * | ||
576 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
577 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
578 | 6 | * by the Free Software Foundation. | ||
579 | 7 | * | ||
580 | 8 | * This program is distributed in the hope that it will be useful, but | ||
581 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
582 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
583 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
584 | 12 | * | ||
585 | 13 | * You should have received a copy of the GNU General Public License along | ||
586 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
587 | 15 | * | ||
588 | 16 | * Authors: | ||
589 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
590 | 18 | */ | ||
591 | 19 | |||
592 | 20 | #include "application.h" | ||
593 | 21 | |||
594 | 22 | extern "C" { | ||
595 | 23 | #include "ubuntu-app-launch.h" | ||
596 | 24 | } | ||
597 | 25 | |||
598 | 26 | #pragma once | ||
599 | 27 | |||
600 | 28 | namespace ubuntu | ||
601 | 29 | { | ||
602 | 30 | namespace app_launch | ||
603 | 31 | { | ||
604 | 32 | namespace app_impls | ||
605 | 33 | { | ||
606 | 34 | |||
607 | 35 | class Base : public ubuntu::app_launch::Application | ||
608 | 36 | { | ||
609 | 37 | public: | ||
610 | 38 | Base(const std::shared_ptr<Registry> ®istry); | ||
611 | 39 | |||
612 | 40 | bool hasInstances() override; | ||
613 | 41 | std::vector<std::shared_ptr<Instance>> instances() override; | ||
614 | 42 | |||
615 | 43 | std::shared_ptr<Instance> launch(const std::vector<Application::URL> &urls = {}) override; | ||
616 | 44 | std::shared_ptr<Instance> launchTest(const std::vector<Application::URL> &urls = {}) override; | ||
617 | 45 | |||
618 | 46 | protected: | ||
619 | 47 | std::shared_ptr<Registry> _registry; | ||
620 | 48 | }; | ||
621 | 49 | |||
622 | 50 | }; // namespace app_impls | ||
623 | 51 | }; // namespace app_launch | ||
624 | 52 | }; // namespace ubuntu | ||
625 | 0 | 53 | ||
626 | === added file 'libubuntu-app-launch/application-impl-click.cpp' | |||
627 | --- libubuntu-app-launch/application-impl-click.cpp 1970-01-01 00:00:00 +0000 | |||
628 | +++ libubuntu-app-launch/application-impl-click.cpp 2016-03-04 11:34:19 +0000 | |||
629 | @@ -0,0 +1,157 @@ | |||
630 | 1 | /* | ||
631 | 2 | * Copyright © 2016 Canonical Ltd. | ||
632 | 3 | * | ||
633 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
634 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
635 | 6 | * by the Free Software Foundation. | ||
636 | 7 | * | ||
637 | 8 | * This program is distributed in the hope that it will be useful, but | ||
638 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
639 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
640 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
641 | 12 | * | ||
642 | 13 | * You should have received a copy of the GNU General Public License along | ||
643 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
644 | 15 | * | ||
645 | 16 | * Authors: | ||
646 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
647 | 18 | */ | ||
648 | 19 | |||
649 | 20 | #include "application-impl-click.h" | ||
650 | 21 | #include "application-info-desktop.h" | ||
651 | 22 | #include "registry-impl.h" | ||
652 | 23 | |||
653 | 24 | namespace ubuntu | ||
654 | 25 | { | ||
655 | 26 | namespace app_launch | ||
656 | 27 | { | ||
657 | 28 | namespace app_impls | ||
658 | 29 | { | ||
659 | 30 | |||
660 | 31 | AppID::Version manifestVersion(const std::shared_ptr<JsonObject>& manifest); | ||
661 | 32 | std::list<AppID::AppName> manifestApps(const std::shared_ptr<JsonObject>& manifest); | ||
662 | 33 | std::shared_ptr<GKeyFile> manifestAppDesktop(const std::shared_ptr<JsonObject>& manifest, | ||
663 | 34 | const std::string& app, | ||
664 | 35 | const std::string& clickDir); | ||
665 | 36 | |||
666 | 37 | Click::Click(const AppID& appid, const std::shared_ptr<Registry>& registry) | ||
667 | 38 | : Click(appid, registry->impl->getClickManifest(appid.package), registry) | ||
668 | 39 | { | ||
669 | 40 | } | ||
670 | 41 | |||
671 | 42 | Click::Click(const AppID& appid, const std::shared_ptr<JsonObject>& manifest, const std::shared_ptr<Registry>& registry) | ||
672 | 43 | : Base(registry) | ||
673 | 44 | , _appid(appid) | ||
674 | 45 | , _manifest(manifest) | ||
675 | 46 | , _clickDir(registry->impl->getClickDir(appid.package)) | ||
676 | 47 | , _keyfile(manifestAppDesktop(manifest, appid.appname, _clickDir)) | ||
677 | 48 | { | ||
678 | 49 | if (!_keyfile) | ||
679 | 50 | throw std::runtime_error{"No keyfile found for click application: " + (std::string)appid}; | ||
680 | 51 | } | ||
681 | 52 | |||
682 | 53 | AppID Click::appId() | ||
683 | 54 | { | ||
684 | 55 | return _appid; | ||
685 | 56 | } | ||
686 | 57 | |||
687 | 58 | std::shared_ptr<Application::Info> Click::info() | ||
688 | 59 | { | ||
689 | 60 | return std::make_shared<app_info::Desktop>(_keyfile, _clickDir); | ||
690 | 61 | } | ||
691 | 62 | |||
692 | 63 | AppID::Version manifestVersion(const std::shared_ptr<JsonObject>& manifest) | ||
693 | 64 | { | ||
694 | 65 | auto cstr = json_object_get_string_member(manifest.get(), "version"); | ||
695 | 66 | |||
696 | 67 | if (cstr == nullptr) | ||
697 | 68 | throw std::runtime_error("Unable to find version number in manifest"); | ||
698 | 69 | |||
699 | 70 | auto cppstr = AppID::Version::from_raw((const gchar*)cstr); | ||
700 | 71 | return cppstr; | ||
701 | 72 | } | ||
702 | 73 | |||
703 | 74 | std::list<AppID::AppName> manifestApps(const std::shared_ptr<JsonObject>& manifest) | ||
704 | 75 | { | ||
705 | 76 | auto hooks = json_object_get_object_member(manifest.get(), "hooks"); | ||
706 | 77 | if (hooks == nullptr) | ||
707 | 78 | throw std::runtime_error("Manifest for application does not have a 'hooks' field"); | ||
708 | 79 | |||
709 | 80 | auto gapps = json_object_get_members(hooks); | ||
710 | 81 | if (gapps == nullptr) | ||
711 | 82 | throw std::runtime_error("GLib JSON confusion, please talk to your library vendor"); | ||
712 | 83 | |||
713 | 84 | std::list<AppID::AppName> apps; | ||
714 | 85 | |||
715 | 86 | for (GList* item = gapps; item != nullptr; item = g_list_next(item)) | ||
716 | 87 | { | ||
717 | 88 | auto appname = (const gchar*)item->data; | ||
718 | 89 | |||
719 | 90 | auto hooklist = json_object_get_object_member(hooks, appname); | ||
720 | 91 | |||
721 | 92 | if (json_object_has_member(hooklist, "desktop") == TRUE) | ||
722 | 93 | { | ||
723 | 94 | apps.emplace_back(AppID::AppName::from_raw(appname)); | ||
724 | 95 | } | ||
725 | 96 | } | ||
726 | 97 | |||
727 | 98 | g_list_free_full(gapps, g_free); | ||
728 | 99 | return apps; | ||
729 | 100 | } | ||
730 | 101 | |||
731 | 102 | std::shared_ptr<GKeyFile> manifestAppDesktop(const std::shared_ptr<JsonObject>& manifest, | ||
732 | 103 | const std::string& app, | ||
733 | 104 | const std::string& clickDir) | ||
734 | 105 | { | ||
735 | 106 | auto hooks = json_object_get_object_member(manifest.get(), "hooks"); | ||
736 | 107 | if (hooks == nullptr) | ||
737 | 108 | throw std::runtime_error("Manifest for application '" + app + "' does not have a 'hooks' field"); | ||
738 | 109 | |||
739 | 110 | auto gapps = json_object_get_members(hooks); | ||
740 | 111 | if (gapps == nullptr) | ||
741 | 112 | throw std::runtime_error("GLib JSON confusion, please talk to your library vendor"); | ||
742 | 113 | |||
743 | 114 | auto hooklist = json_object_get_object_member(hooks, app.c_str()); | ||
744 | 115 | if (hooklist == nullptr) | ||
745 | 116 | throw std::runtime_error("Manifest for does not have an application '" + app + "'"); | ||
746 | 117 | |||
747 | 118 | auto desktoppath = json_object_get_string_member(hooklist, "desktop"); | ||
748 | 119 | if (desktoppath == nullptr) | ||
749 | 120 | throw std::runtime_error("Manifest for application '" + app + "' does not have a 'desktop' hook"); | ||
750 | 121 | |||
751 | 122 | auto path = std::shared_ptr<gchar>(g_build_filename(clickDir.c_str(), desktoppath, nullptr), g_free); | ||
752 | 123 | |||
753 | 124 | std::shared_ptr<GKeyFile> keyfile(g_key_file_new(), g_key_file_free); | ||
754 | 125 | GError* error = nullptr; | ||
755 | 126 | g_key_file_load_from_file(keyfile.get(), path.get(), G_KEY_FILE_NONE, &error); | ||
756 | 127 | if (error != nullptr) | ||
757 | 128 | { | ||
758 | 129 | auto perror = std::shared_ptr<GError>(error, g_error_free); | ||
759 | 130 | throw std::runtime_error(perror.get()->message); | ||
760 | 131 | } | ||
761 | 132 | |||
762 | 133 | return keyfile; | ||
763 | 134 | } | ||
764 | 135 | |||
765 | 136 | std::list<std::shared_ptr<Application>> Click::list(const std::shared_ptr<Registry>& registry) | ||
766 | 137 | { | ||
767 | 138 | std::list<std::shared_ptr<Application>> applist; | ||
768 | 139 | |||
769 | 140 | for (auto pkg : registry->impl->getClickPackages()) | ||
770 | 141 | { | ||
771 | 142 | auto manifest = registry->impl->getClickManifest(pkg); | ||
772 | 143 | |||
773 | 144 | for (auto appname : manifestApps(manifest)) | ||
774 | 145 | { | ||
775 | 146 | AppID appid{package : pkg, appname : appname, version : manifestVersion(manifest)}; | ||
776 | 147 | auto app = std::make_shared<Click>(appid, manifest, registry); | ||
777 | 148 | applist.push_back(app); | ||
778 | 149 | } | ||
779 | 150 | } | ||
780 | 151 | |||
781 | 152 | return applist; | ||
782 | 153 | } | ||
783 | 154 | |||
784 | 155 | }; // namespace app_impls | ||
785 | 156 | }; // namespace app_launch | ||
786 | 157 | }; // namespace ubuntu | ||
787 | 0 | 158 | ||
788 | === added file 'libubuntu-app-launch/application-impl-click.h' | |||
789 | --- libubuntu-app-launch/application-impl-click.h 1970-01-01 00:00:00 +0000 | |||
790 | +++ libubuntu-app-launch/application-impl-click.h 2016-03-04 11:34:19 +0000 | |||
791 | @@ -0,0 +1,56 @@ | |||
792 | 1 | /* | ||
793 | 2 | * Copyright © 2016 Canonical Ltd. | ||
794 | 3 | * | ||
795 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
796 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
797 | 6 | * by the Free Software Foundation. | ||
798 | 7 | * | ||
799 | 8 | * This program is distributed in the hope that it will be useful, but | ||
800 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
801 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
802 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
803 | 12 | * | ||
804 | 13 | * You should have received a copy of the GNU General Public License along | ||
805 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
806 | 15 | * | ||
807 | 16 | * Authors: | ||
808 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
809 | 18 | */ | ||
810 | 19 | |||
811 | 20 | #include <gio/gdesktopappinfo.h> | ||
812 | 21 | #include <json-glib/json-glib.h> | ||
813 | 22 | #include "application-impl-base.h" | ||
814 | 23 | |||
815 | 24 | #pragma once | ||
816 | 25 | |||
817 | 26 | namespace ubuntu | ||
818 | 27 | { | ||
819 | 28 | namespace app_launch | ||
820 | 29 | { | ||
821 | 30 | namespace app_impls | ||
822 | 31 | { | ||
823 | 32 | |||
824 | 33 | class Click : public Base | ||
825 | 34 | { | ||
826 | 35 | public: | ||
827 | 36 | Click(const AppID& appid, const std::shared_ptr<Registry>& registry); | ||
828 | 37 | Click(const AppID& appid, const std::shared_ptr<JsonObject>& manifest, const std::shared_ptr<Registry>& registry); | ||
829 | 38 | |||
830 | 39 | static std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry>& registry); | ||
831 | 40 | |||
832 | 41 | AppID appId() override; | ||
833 | 42 | |||
834 | 43 | std::shared_ptr<Info> info() override; | ||
835 | 44 | |||
836 | 45 | private: | ||
837 | 46 | AppID _appid; | ||
838 | 47 | |||
839 | 48 | std::shared_ptr<JsonObject> _manifest; | ||
840 | 49 | |||
841 | 50 | std::string _clickDir; | ||
842 | 51 | std::shared_ptr<GKeyFile> _keyfile; | ||
843 | 52 | }; | ||
844 | 53 | |||
845 | 54 | }; // namespace app_impls | ||
846 | 55 | }; // namespace app_launch | ||
847 | 56 | }; // namespace ubuntu | ||
848 | 0 | 57 | ||
849 | === added file 'libubuntu-app-launch/application-impl-legacy.cpp' | |||
850 | --- libubuntu-app-launch/application-impl-legacy.cpp 1970-01-01 00:00:00 +0000 | |||
851 | +++ libubuntu-app-launch/application-impl-legacy.cpp 2016-03-04 11:34:19 +0000 | |||
852 | @@ -0,0 +1,128 @@ | |||
853 | 1 | /* | ||
854 | 2 | * Copyright © 2016 Canonical Ltd. | ||
855 | 3 | * | ||
856 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
857 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
858 | 6 | * by the Free Software Foundation. | ||
859 | 7 | * | ||
860 | 8 | * This program is distributed in the hope that it will be useful, but | ||
861 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
862 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
863 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
864 | 12 | * | ||
865 | 13 | * You should have received a copy of the GNU General Public License along | ||
866 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
867 | 15 | * | ||
868 | 16 | * Authors: | ||
869 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
870 | 18 | */ | ||
871 | 19 | |||
872 | 20 | #include "application-impl-legacy.h" | ||
873 | 21 | #include "application-info-desktop.h" | ||
874 | 22 | |||
875 | 23 | namespace ubuntu | ||
876 | 24 | { | ||
877 | 25 | namespace app_launch | ||
878 | 26 | { | ||
879 | 27 | namespace app_impls | ||
880 | 28 | { | ||
881 | 29 | |||
882 | 30 | std::shared_ptr<GKeyFile> keyfileForApp(const AppID::AppName& name); | ||
883 | 31 | |||
884 | 32 | void clear_keyfile(GKeyFile* keyfile) | ||
885 | 33 | { | ||
886 | 34 | if (keyfile != nullptr) | ||
887 | 35 | { | ||
888 | 36 | g_key_file_free(keyfile); | ||
889 | 37 | } | ||
890 | 38 | } | ||
891 | 39 | |||
892 | 40 | Legacy::Legacy(const AppID::AppName& appname, | ||
893 | 41 | const std::shared_ptr<GKeyFile>& keyfile, | ||
894 | 42 | const std::shared_ptr<Registry>& registry) | ||
895 | 43 | : Base(registry) | ||
896 | 44 | , _appname(appname) | ||
897 | 45 | , _keyfile(keyfile) | ||
898 | 46 | { | ||
899 | 47 | if (!_keyfile) | ||
900 | 48 | throw std::runtime_error{"Unable to find keyfile for legacy application: " + appname.value()}; | ||
901 | 49 | } | ||
902 | 50 | |||
903 | 51 | Legacy::Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry) | ||
904 | 52 | : Legacy(appname, keyfileForApp(appname), registry) | ||
905 | 53 | { | ||
906 | 54 | } | ||
907 | 55 | |||
908 | 56 | std::shared_ptr<GKeyFile> keyfileForApp(const AppID::AppName& name) | ||
909 | 57 | { | ||
910 | 58 | std::string desktopName = name.value() + ".desktop"; | ||
911 | 59 | auto keyfilecheck = [desktopName](const gchar* dir) -> std::shared_ptr<GKeyFile> { | ||
912 | 60 | auto fullname = g_build_filename(dir, "applications", desktopName.c_str(), nullptr); | ||
913 | 61 | if (!g_file_test(fullname, G_FILE_TEST_EXISTS)) | ||
914 | 62 | { | ||
915 | 63 | g_free(fullname); | ||
916 | 64 | return {}; | ||
917 | 65 | } | ||
918 | 66 | |||
919 | 67 | auto keyfile = std::shared_ptr<GKeyFile>(g_key_file_new(), clear_keyfile); | ||
920 | 68 | |||
921 | 69 | GError* error = nullptr; | ||
922 | 70 | g_key_file_load_from_file(keyfile.get(), fullname, G_KEY_FILE_NONE, &error); | ||
923 | 71 | g_free(fullname); | ||
924 | 72 | |||
925 | 73 | if (error != nullptr) | ||
926 | 74 | { | ||
927 | 75 | g_debug("Unable to load keyfile '%s' becuase: %s", desktopName.c_str(), error->message); | ||
928 | 76 | g_error_free(error); | ||
929 | 77 | return {}; | ||
930 | 78 | } | ||
931 | 79 | |||
932 | 80 | return keyfile; | ||
933 | 81 | }; | ||
934 | 82 | |||
935 | 83 | auto retval = keyfilecheck(g_get_user_data_dir()); | ||
936 | 84 | |||
937 | 85 | auto systemDirs = g_get_system_data_dirs(); | ||
938 | 86 | for (auto i = 0; !retval && systemDirs[i] != nullptr; i++) | ||
939 | 87 | { | ||
940 | 88 | retval = keyfilecheck(systemDirs[i]); | ||
941 | 89 | } | ||
942 | 90 | |||
943 | 91 | return retval; | ||
944 | 92 | } | ||
945 | 93 | |||
946 | 94 | std::shared_ptr<Application::Info> Legacy::info() | ||
947 | 95 | { | ||
948 | 96 | return std::make_shared<app_info::Desktop>(_keyfile, "/usr/share/icons/"); | ||
949 | 97 | } | ||
950 | 98 | |||
951 | 99 | std::list<std::shared_ptr<Application>> Legacy::list(const std::shared_ptr<Registry>& registry) | ||
952 | 100 | { | ||
953 | 101 | std::list<std::shared_ptr<Application>> list; | ||
954 | 102 | GList* head = g_app_info_get_all(); | ||
955 | 103 | for (GList* item = head; item != nullptr; item = g_list_next(item)) | ||
956 | 104 | { | ||
957 | 105 | GDesktopAppInfo* appinfo = G_DESKTOP_APP_INFO(item->data); | ||
958 | 106 | |||
959 | 107 | if (appinfo == nullptr) | ||
960 | 108 | { | ||
961 | 109 | continue; | ||
962 | 110 | } | ||
963 | 111 | |||
964 | 112 | if (g_app_info_should_show(G_APP_INFO(appinfo)) == FALSE) | ||
965 | 113 | { | ||
966 | 114 | continue; | ||
967 | 115 | } | ||
968 | 116 | |||
969 | 117 | auto app = std::make_shared<Legacy>(AppID::AppName::from_raw(g_app_info_get_id(G_APP_INFO(appinfo))), registry); | ||
970 | 118 | list.push_back(app); | ||
971 | 119 | } | ||
972 | 120 | |||
973 | 121 | g_list_free_full(head, g_object_unref); | ||
974 | 122 | |||
975 | 123 | return list; | ||
976 | 124 | } | ||
977 | 125 | |||
978 | 126 | }; // namespace app_impls | ||
979 | 127 | }; // namespace app_launch | ||
980 | 128 | }; // namespace ubuntu | ||
981 | 0 | 129 | ||
982 | === added file 'libubuntu-app-launch/application-impl-legacy.h' | |||
983 | --- libubuntu-app-launch/application-impl-legacy.h 1970-01-01 00:00:00 +0000 | |||
984 | +++ libubuntu-app-launch/application-impl-legacy.h 2016-03-04 11:34:19 +0000 | |||
985 | @@ -0,0 +1,57 @@ | |||
986 | 1 | /* | ||
987 | 2 | * Copyright © 2016 Canonical Ltd. | ||
988 | 3 | * | ||
989 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
990 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
991 | 6 | * by the Free Software Foundation. | ||
992 | 7 | * | ||
993 | 8 | * This program is distributed in the hope that it will be useful, but | ||
994 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
995 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
996 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
997 | 12 | * | ||
998 | 13 | * You should have received a copy of the GNU General Public License along | ||
999 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1000 | 15 | * | ||
1001 | 16 | * Authors: | ||
1002 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1003 | 18 | */ | ||
1004 | 19 | |||
1005 | 20 | #include <gio/gdesktopappinfo.h> | ||
1006 | 21 | |||
1007 | 22 | #include "application-impl-base.h" | ||
1008 | 23 | |||
1009 | 24 | #pragma once | ||
1010 | 25 | |||
1011 | 26 | namespace ubuntu | ||
1012 | 27 | { | ||
1013 | 28 | namespace app_launch | ||
1014 | 29 | { | ||
1015 | 30 | namespace app_impls | ||
1016 | 31 | { | ||
1017 | 32 | |||
1018 | 33 | class Legacy : public Base | ||
1019 | 34 | { | ||
1020 | 35 | public: | ||
1021 | 36 | Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry); | ||
1022 | 37 | Legacy(const AppID::AppName& appname, | ||
1023 | 38 | const std::shared_ptr<GKeyFile>& keyfile, | ||
1024 | 39 | const std::shared_ptr<Registry>& registry); | ||
1025 | 40 | |||
1026 | 41 | AppID appId() override | ||
1027 | 42 | { | ||
1028 | 43 | return {package : AppID::Package::from_raw({}), appname : _appname, version : AppID::Version::from_raw({})}; | ||
1029 | 44 | } | ||
1030 | 45 | |||
1031 | 46 | std::shared_ptr<Info> info() override; | ||
1032 | 47 | |||
1033 | 48 | static std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry> ®istry); | ||
1034 | 49 | |||
1035 | 50 | private: | ||
1036 | 51 | AppID::AppName _appname; | ||
1037 | 52 | std::shared_ptr<GKeyFile> _keyfile; | ||
1038 | 53 | }; | ||
1039 | 54 | |||
1040 | 55 | }; // namespace app_impls | ||
1041 | 56 | }; // namespace app_launch | ||
1042 | 57 | }; // namespace ubuntu | ||
1043 | 0 | 58 | ||
1044 | === added file 'libubuntu-app-launch/application-impl-libertine.cpp' | |||
1045 | --- libubuntu-app-launch/application-impl-libertine.cpp 1970-01-01 00:00:00 +0000 | |||
1046 | +++ libubuntu-app-launch/application-impl-libertine.cpp 2016-03-04 11:34:19 +0000 | |||
1047 | @@ -0,0 +1,127 @@ | |||
1048 | 1 | /* | ||
1049 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1050 | 3 | * | ||
1051 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1052 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1053 | 6 | * by the Free Software Foundation. | ||
1054 | 7 | * | ||
1055 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1056 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1057 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1058 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1059 | 12 | * | ||
1060 | 13 | * You should have received a copy of the GNU General Public License along | ||
1061 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1062 | 15 | * | ||
1063 | 16 | * Authors: | ||
1064 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1065 | 18 | */ | ||
1066 | 19 | |||
1067 | 20 | #include "application-impl-libertine.h" | ||
1068 | 21 | #include "application-info-desktop.h" | ||
1069 | 22 | #include "libertine.h" | ||
1070 | 23 | |||
1071 | 24 | namespace ubuntu | ||
1072 | 25 | { | ||
1073 | 26 | namespace app_launch | ||
1074 | 27 | { | ||
1075 | 28 | namespace app_impls | ||
1076 | 29 | { | ||
1077 | 30 | |||
1078 | 31 | std::shared_ptr<GKeyFile> keyfileFromPath(const gchar* pathname); | ||
1079 | 32 | |||
1080 | 33 | Libertine::Libertine(const AppID::Package& container, | ||
1081 | 34 | const AppID::AppName& appname, | ||
1082 | 35 | const std::shared_ptr<Registry>& registry) | ||
1083 | 36 | : Base(registry) | ||
1084 | 37 | , _container(container) | ||
1085 | 38 | , _appname(appname) | ||
1086 | 39 | { | ||
1087 | 40 | if (!_keyfile) | ||
1088 | 41 | { | ||
1089 | 42 | auto container_path = libertine_container_path(container.value().c_str()); | ||
1090 | 43 | auto container_app_path = g_build_filename(container_path, "usr", "share", "applications", | ||
1091 | 44 | (appname.value() + ".desktop").c_str(), NULL); | ||
1092 | 45 | |||
1093 | 46 | _keyfile = keyfileFromPath(container_app_path); | ||
1094 | 47 | |||
1095 | 48 | g_free(container_app_path); | ||
1096 | 49 | g_free(container_path); | ||
1097 | 50 | } | ||
1098 | 51 | |||
1099 | 52 | if (!_keyfile) | ||
1100 | 53 | { | ||
1101 | 54 | auto home_path = libertine_container_home_path(container.value().c_str()); | ||
1102 | 55 | auto home_app_path = g_build_filename(home_path, ".local", "share", "applications", | ||
1103 | 56 | (appname.value() + ".desktop").c_str(), NULL); | ||
1104 | 57 | |||
1105 | 58 | _keyfile = keyfileFromPath(home_app_path); | ||
1106 | 59 | |||
1107 | 60 | g_free(home_app_path); | ||
1108 | 61 | g_free(home_path); | ||
1109 | 62 | } | ||
1110 | 63 | |||
1111 | 64 | if (!_keyfile) | ||
1112 | 65 | throw std::runtime_error{"Unable to find a keyfile for application '" + appname.value() + "' in container '" + | ||
1113 | 66 | container.value() + "'"}; | ||
1114 | 67 | } | ||
1115 | 68 | |||
1116 | 69 | std::shared_ptr<GKeyFile> keyfileFromPath(const gchar* pathname) | ||
1117 | 70 | { | ||
1118 | 71 | if (!g_file_test(pathname, G_FILE_TEST_EXISTS)) | ||
1119 | 72 | { | ||
1120 | 73 | return {}; | ||
1121 | 74 | } | ||
1122 | 75 | |||
1123 | 76 | std::shared_ptr<GKeyFile> keyfile(g_key_file_new(), [](GKeyFile* keyfile) { | ||
1124 | 77 | if (keyfile != nullptr) | ||
1125 | 78 | { | ||
1126 | 79 | g_key_file_free(keyfile); | ||
1127 | 80 | } | ||
1128 | 81 | }); | ||
1129 | 82 | GError* error = nullptr; | ||
1130 | 83 | |||
1131 | 84 | g_key_file_load_from_file(keyfile.get(), pathname, G_KEY_FILE_NONE, &error); | ||
1132 | 85 | |||
1133 | 86 | if (error != nullptr) | ||
1134 | 87 | { | ||
1135 | 88 | g_error_free(error); | ||
1136 | 89 | return {}; | ||
1137 | 90 | } | ||
1138 | 91 | |||
1139 | 92 | return keyfile; | ||
1140 | 93 | } | ||
1141 | 94 | |||
1142 | 95 | std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry) | ||
1143 | 96 | { | ||
1144 | 97 | std::list<std::shared_ptr<Application>> applist; | ||
1145 | 98 | |||
1146 | 99 | auto containers = libertine_list_containers(); | ||
1147 | 100 | |||
1148 | 101 | for (int i = 0; containers[i] != nullptr; i++) | ||
1149 | 102 | { | ||
1150 | 103 | auto container = containers[i]; | ||
1151 | 104 | auto apps = libertine_list_apps_for_container(container); | ||
1152 | 105 | |||
1153 | 106 | for (int i = 0; apps[i] != nullptr; i++) | ||
1154 | 107 | { | ||
1155 | 108 | auto sapp = std::make_shared<Libertine>(AppID::Package::from_raw(container), | ||
1156 | 109 | AppID::AppName::from_raw(apps[i]), registry); | ||
1157 | 110 | applist.push_back(sapp); | ||
1158 | 111 | } | ||
1159 | 112 | |||
1160 | 113 | g_strfreev(apps); | ||
1161 | 114 | } | ||
1162 | 115 | g_strfreev(containers); | ||
1163 | 116 | |||
1164 | 117 | return applist; | ||
1165 | 118 | } | ||
1166 | 119 | |||
1167 | 120 | std::shared_ptr<Application::Info> Libertine::info() | ||
1168 | 121 | { | ||
1169 | 122 | return std::make_shared<app_info::Desktop>(_keyfile, libertine_container_path(_container.value().c_str())); | ||
1170 | 123 | } | ||
1171 | 124 | |||
1172 | 125 | }; // namespace app_impls | ||
1173 | 126 | }; // namespace app_launch | ||
1174 | 127 | }; // namespace ubuntu | ||
1175 | 0 | 128 | ||
1176 | === added file 'libubuntu-app-launch/application-impl-libertine.h' | |||
1177 | --- libubuntu-app-launch/application-impl-libertine.h 1970-01-01 00:00:00 +0000 | |||
1178 | +++ libubuntu-app-launch/application-impl-libertine.h 2016-03-04 11:34:19 +0000 | |||
1179 | @@ -0,0 +1,56 @@ | |||
1180 | 1 | /* | ||
1181 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1182 | 3 | * | ||
1183 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1184 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1185 | 6 | * by the Free Software Foundation. | ||
1186 | 7 | * | ||
1187 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1188 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1189 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1190 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1191 | 12 | * | ||
1192 | 13 | * You should have received a copy of the GNU General Public License along | ||
1193 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1194 | 15 | * | ||
1195 | 16 | * Authors: | ||
1196 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1197 | 18 | */ | ||
1198 | 19 | |||
1199 | 20 | #include "application-impl-base.h" | ||
1200 | 21 | #include <gio/gdesktopappinfo.h> | ||
1201 | 22 | |||
1202 | 23 | #pragma once | ||
1203 | 24 | |||
1204 | 25 | namespace ubuntu | ||
1205 | 26 | { | ||
1206 | 27 | namespace app_launch | ||
1207 | 28 | { | ||
1208 | 29 | namespace app_impls | ||
1209 | 30 | { | ||
1210 | 31 | |||
1211 | 32 | class Libertine : public Base | ||
1212 | 33 | { | ||
1213 | 34 | public: | ||
1214 | 35 | Libertine(const AppID::Package& container, | ||
1215 | 36 | const AppID::AppName& appname, | ||
1216 | 37 | const std::shared_ptr<Registry>& registry); | ||
1217 | 38 | |||
1218 | 39 | static std::list<std::shared_ptr<Application>> list(const std::shared_ptr<Registry> ®istry); | ||
1219 | 40 | |||
1220 | 41 | AppID appId() override | ||
1221 | 42 | { | ||
1222 | 43 | return {package : _container, appname : _appname, version : AppID::Version::from_raw("0.0")}; | ||
1223 | 44 | } | ||
1224 | 45 | |||
1225 | 46 | std::shared_ptr<Info> info() override; | ||
1226 | 47 | |||
1227 | 48 | private: | ||
1228 | 49 | AppID::Package _container; | ||
1229 | 50 | AppID::AppName _appname; | ||
1230 | 51 | std::shared_ptr<GKeyFile> _keyfile; | ||
1231 | 52 | }; | ||
1232 | 53 | |||
1233 | 54 | }; // namespace app_impls | ||
1234 | 55 | }; // namespace app_launch | ||
1235 | 56 | }; // namespace ubuntu | ||
1236 | 0 | 57 | ||
1237 | === added file 'libubuntu-app-launch/application-info-desktop.cpp' | |||
1238 | --- libubuntu-app-launch/application-info-desktop.cpp 1970-01-01 00:00:00 +0000 | |||
1239 | +++ libubuntu-app-launch/application-info-desktop.cpp 2016-03-04 11:34:19 +0000 | |||
1240 | @@ -0,0 +1,202 @@ | |||
1241 | 1 | /* | ||
1242 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1243 | 3 | * | ||
1244 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1245 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1246 | 6 | * by the Free Software Foundation. | ||
1247 | 7 | * | ||
1248 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1249 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1250 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1251 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1252 | 12 | * | ||
1253 | 13 | * You should have received a copy of the GNU General Public License along | ||
1254 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1255 | 15 | * | ||
1256 | 16 | * Authors: | ||
1257 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1258 | 18 | */ | ||
1259 | 19 | |||
1260 | 20 | #include "application-info-desktop.h" | ||
1261 | 21 | |||
1262 | 22 | namespace ubuntu | ||
1263 | 23 | { | ||
1264 | 24 | namespace app_launch | ||
1265 | 25 | { | ||
1266 | 26 | namespace app_info | ||
1267 | 27 | { | ||
1268 | 28 | |||
1269 | 29 | constexpr const char* DESKTOP_GROUP = "Desktop Entry"; | ||
1270 | 30 | |||
1271 | 31 | template <typename T> | ||
1272 | 32 | auto stringFromKeyfile(std::shared_ptr<GKeyFile> keyfile, const std::string& key, const std::string& exceptionText = {}) | ||
1273 | 33 | -> T | ||
1274 | 34 | { | ||
1275 | 35 | GError* error = nullptr; | ||
1276 | 36 | auto keyval = g_key_file_get_locale_string(keyfile.get(), DESKTOP_GROUP, key.c_str(), nullptr, &error); | ||
1277 | 37 | |||
1278 | 38 | if (error != nullptr) | ||
1279 | 39 | { | ||
1280 | 40 | auto perror = std::shared_ptr<GError>(error, g_error_free); | ||
1281 | 41 | if (!exceptionText.empty()) | ||
1282 | 42 | { | ||
1283 | 43 | throw std::runtime_error(exceptionText + perror.get()->message); | ||
1284 | 44 | } | ||
1285 | 45 | |||
1286 | 46 | return T::from_raw({}); | ||
1287 | 47 | } | ||
1288 | 48 | |||
1289 | 49 | T retval = T::from_raw(keyval); | ||
1290 | 50 | g_free(keyval); | ||
1291 | 51 | return retval; | ||
1292 | 52 | } | ||
1293 | 53 | |||
1294 | 54 | template <typename T> | ||
1295 | 55 | auto fileFromKeyfile(std::shared_ptr<GKeyFile> keyfile, | ||
1296 | 56 | const std::string basePath, | ||
1297 | 57 | const std::string& key, | ||
1298 | 58 | const std::string& exceptionText = {}) -> T | ||
1299 | 59 | { | ||
1300 | 60 | GError* error = nullptr; | ||
1301 | 61 | auto keyval = g_key_file_get_locale_string(keyfile.get(), DESKTOP_GROUP, key.c_str(), nullptr, &error); | ||
1302 | 62 | |||
1303 | 63 | if (error != nullptr) | ||
1304 | 64 | { | ||
1305 | 65 | auto perror = std::shared_ptr<GError>(error, g_error_free); | ||
1306 | 66 | if (!exceptionText.empty()) | ||
1307 | 67 | { | ||
1308 | 68 | throw std::runtime_error(exceptionText + perror.get()->message); | ||
1309 | 69 | } | ||
1310 | 70 | |||
1311 | 71 | return T::from_raw({}); | ||
1312 | 72 | } | ||
1313 | 73 | |||
1314 | 74 | /* If we're already an absolute path, don't prepend the base path */ | ||
1315 | 75 | if (keyval[0] == '/') | ||
1316 | 76 | { | ||
1317 | 77 | T retval = T::from_raw(keyval); | ||
1318 | 78 | g_free(keyval); | ||
1319 | 79 | return retval; | ||
1320 | 80 | } | ||
1321 | 81 | |||
1322 | 82 | auto cpath = g_build_filename(basePath.c_str(), keyval, nullptr); | ||
1323 | 83 | |||
1324 | 84 | T retval = T::from_raw(cpath); | ||
1325 | 85 | |||
1326 | 86 | g_free(keyval); | ||
1327 | 87 | g_free(cpath); | ||
1328 | 88 | |||
1329 | 89 | return retval; | ||
1330 | 90 | } | ||
1331 | 91 | |||
1332 | 92 | template <typename T> | ||
1333 | 93 | auto boolFromKeyfile(std::shared_ptr<GKeyFile> keyfile, | ||
1334 | 94 | const std::string& key, | ||
1335 | 95 | bool defaultReturn, | ||
1336 | 96 | const std::string& exceptionText = {}) -> T | ||
1337 | 97 | { | ||
1338 | 98 | GError* error = nullptr; | ||
1339 | 99 | auto keyval = g_key_file_get_boolean(keyfile.get(), DESKTOP_GROUP, key.c_str(), &error); | ||
1340 | 100 | |||
1341 | 101 | if (error != nullptr) | ||
1342 | 102 | { | ||
1343 | 103 | auto perror = std::shared_ptr<GError>(error, g_error_free); | ||
1344 | 104 | if (!exceptionText.empty()) | ||
1345 | 105 | { | ||
1346 | 106 | throw std::runtime_error(exceptionText + perror.get()->message); | ||
1347 | 107 | } | ||
1348 | 108 | |||
1349 | 109 | return T::from_raw(defaultReturn); | ||
1350 | 110 | } | ||
1351 | 111 | |||
1352 | 112 | T retval = T::from_raw(keyval == TRUE); | ||
1353 | 113 | return retval; | ||
1354 | 114 | } | ||
1355 | 115 | |||
1356 | 116 | Desktop::Desktop(std::shared_ptr<GKeyFile> keyfile, const std::string& basePath) | ||
1357 | 117 | : _keyfile([keyfile]() { | ||
1358 | 118 | if (!keyfile) | ||
1359 | 119 | { | ||
1360 | 120 | throw std::runtime_error("Can not build a desktop application info object with a null keyfile"); | ||
1361 | 121 | } | ||
1362 | 122 | return keyfile; | ||
1363 | 123 | }()) | ||
1364 | 124 | , _basePath(basePath) | ||
1365 | 125 | , _name(stringFromKeyfile<Application::Info::Name>(keyfile, "Name", "Unable to get name from keyfile")) | ||
1366 | 126 | , _description(stringFromKeyfile<Application::Info::Description>(keyfile, "Comment")) | ||
1367 | 127 | , _iconPath( | ||
1368 | 128 | fileFromKeyfile<Application::Info::IconPath>(keyfile, basePath, "Icon", "Missing icon for desktop file")) | ||
1369 | 129 | , _splashInfo({ | ||
1370 | 130 | title : stringFromKeyfile<Application::Info::Splash::Title>(keyfile, "X-Ubuntu-Splash-Title"), | ||
1371 | 131 | image : fileFromKeyfile<Application::Info::Splash::Image>(keyfile, basePath, "X-Ubuntu-Splash-Image"), | ||
1372 | 132 | backgroundColor : stringFromKeyfile<Application::Info::Splash::Color>(keyfile, "X-Ubuntu-Splash-Color"), | ||
1373 | 133 | headerColor : stringFromKeyfile<Application::Info::Splash::Color>(keyfile, "X-Ubuntu-Splash-Color-Header"), | ||
1374 | 134 | footerColor : stringFromKeyfile<Application::Info::Splash::Color>(keyfile, "X-Ubuntu-Splash-Color-Footer"), | ||
1375 | 135 | showHeader : | ||
1376 | 136 | boolFromKeyfile<Application::Info::Splash::ShowHeader>(keyfile, "X-Ubuntu-Splash-Show-Header", false) | ||
1377 | 137 | }) | ||
1378 | 138 | , _supportedOrientations([keyfile]() { | ||
1379 | 139 | Orientations all = {portrait : true, landscape : true, invertedPortrait : true, invertedLandscape : true}; | ||
1380 | 140 | |||
1381 | 141 | GError* error = nullptr; | ||
1382 | 142 | auto orientationStrv = g_key_file_get_string_list(keyfile.get(), DESKTOP_GROUP, | ||
1383 | 143 | "X-Ubuntu-Supported-Orientations", nullptr, &error); | ||
1384 | 144 | |||
1385 | 145 | if (error != nullptr) | ||
1386 | 146 | { | ||
1387 | 147 | g_error_free(error); | ||
1388 | 148 | return all; | ||
1389 | 149 | } | ||
1390 | 150 | |||
1391 | 151 | Orientations retval = | ||
1392 | 152 | {portrait : false, landscape : false, invertedPortrait : false, invertedLandscape : false}; | ||
1393 | 153 | |||
1394 | 154 | try | ||
1395 | 155 | { | ||
1396 | 156 | for (auto i = 0; orientationStrv[i] != nullptr; i++) | ||
1397 | 157 | { | ||
1398 | 158 | g_strstrip(orientationStrv[i]); /* remove whitespace */ | ||
1399 | 159 | |||
1400 | 160 | if (g_ascii_strcasecmp("portrait", orientationStrv[i]) == 0) | ||
1401 | 161 | { | ||
1402 | 162 | retval.portrait = true; | ||
1403 | 163 | } | ||
1404 | 164 | else if (g_ascii_strcasecmp("landscape", orientationStrv[i]) == 0) | ||
1405 | 165 | { | ||
1406 | 166 | retval.landscape = true; | ||
1407 | 167 | } | ||
1408 | 168 | else if (g_ascii_strcasecmp("invertedPortrait", orientationStrv[i]) == 0) | ||
1409 | 169 | { | ||
1410 | 170 | retval.invertedPortrait = true; | ||
1411 | 171 | } | ||
1412 | 172 | else if (g_ascii_strcasecmp("invertedLandscape", orientationStrv[i]) == 0) | ||
1413 | 173 | { | ||
1414 | 174 | retval.invertedLandscape = true; | ||
1415 | 175 | } | ||
1416 | 176 | else if (g_ascii_strcasecmp("primary", orientationStrv[i]) == 0 && i == 0) | ||
1417 | 177 | { | ||
1418 | 178 | /* Pass, we'll let primary be the first entry, it should be the only. */ | ||
1419 | 179 | } | ||
1420 | 180 | else | ||
1421 | 181 | { | ||
1422 | 182 | throw std::runtime_error("Invalid orientation string '" + std::string(orientationStrv[i]) + "'"); | ||
1423 | 183 | } | ||
1424 | 184 | } | ||
1425 | 185 | } | ||
1426 | 186 | catch (...) | ||
1427 | 187 | { | ||
1428 | 188 | retval = all; | ||
1429 | 189 | } | ||
1430 | 190 | |||
1431 | 191 | g_strfreev(orientationStrv); | ||
1432 | 192 | return retval; | ||
1433 | 193 | }()) | ||
1434 | 194 | , _rotatesWindow( | ||
1435 | 195 | boolFromKeyfile<Application::Info::RotatesWindow>(keyfile, "X-Ubuntu-Rotates-Window-Content", false)) | ||
1436 | 196 | , _ubuntuLifecycle(boolFromKeyfile<Application::Info::UbuntuLifecycle>(keyfile, "X-Ubuntu-Touch", false)) | ||
1437 | 197 | { | ||
1438 | 198 | } | ||
1439 | 199 | |||
1440 | 200 | }; // namespace app_info | ||
1441 | 201 | }; // namespace app_launch | ||
1442 | 202 | }; // namespace ubuntu | ||
1443 | 0 | 203 | ||
1444 | === added file 'libubuntu-app-launch/application-info-desktop.h' | |||
1445 | --- libubuntu-app-launch/application-info-desktop.h 1970-01-01 00:00:00 +0000 | |||
1446 | +++ libubuntu-app-launch/application-info-desktop.h 2016-03-04 11:34:19 +0000 | |||
1447 | @@ -0,0 +1,87 @@ | |||
1448 | 1 | /* | ||
1449 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1450 | 3 | * | ||
1451 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1452 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1453 | 6 | * by the Free Software Foundation. | ||
1454 | 7 | * | ||
1455 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1456 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1457 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1458 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1459 | 12 | * | ||
1460 | 13 | * You should have received a copy of the GNU General Public License along | ||
1461 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1462 | 15 | * | ||
1463 | 16 | * Authors: | ||
1464 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1465 | 18 | */ | ||
1466 | 19 | |||
1467 | 20 | #include "application.h" | ||
1468 | 21 | #include <glib.h> | ||
1469 | 22 | #include <mutex> | ||
1470 | 23 | |||
1471 | 24 | #pragma once | ||
1472 | 25 | |||
1473 | 26 | namespace ubuntu | ||
1474 | 27 | { | ||
1475 | 28 | namespace app_launch | ||
1476 | 29 | { | ||
1477 | 30 | namespace app_info | ||
1478 | 31 | { | ||
1479 | 32 | |||
1480 | 33 | class Desktop : public Application::Info | ||
1481 | 34 | { | ||
1482 | 35 | public: | ||
1483 | 36 | Desktop(std::shared_ptr<GKeyFile> keyfile, const std::string& basePath); | ||
1484 | 37 | |||
1485 | 38 | const Application::Info::Name& name() override | ||
1486 | 39 | { | ||
1487 | 40 | return _name; | ||
1488 | 41 | } | ||
1489 | 42 | const Application::Info::Description& description() override | ||
1490 | 43 | { | ||
1491 | 44 | return _description; | ||
1492 | 45 | } | ||
1493 | 46 | const Application::Info::IconPath& iconPath() override | ||
1494 | 47 | { | ||
1495 | 48 | return _iconPath; | ||
1496 | 49 | } | ||
1497 | 50 | |||
1498 | 51 | Application::Info::Splash splash() override | ||
1499 | 52 | { | ||
1500 | 53 | return _splashInfo; | ||
1501 | 54 | } | ||
1502 | 55 | |||
1503 | 56 | Application::Info::Orientations supportedOrientations() override | ||
1504 | 57 | { | ||
1505 | 58 | return _supportedOrientations; | ||
1506 | 59 | } | ||
1507 | 60 | |||
1508 | 61 | Application::Info::RotatesWindow rotatesWindowContents() override | ||
1509 | 62 | { | ||
1510 | 63 | return _rotatesWindow; | ||
1511 | 64 | } | ||
1512 | 65 | |||
1513 | 66 | Application::Info::UbuntuLifecycle supportsUbuntuLifecycle() override | ||
1514 | 67 | { | ||
1515 | 68 | return _ubuntuLifecycle; | ||
1516 | 69 | } | ||
1517 | 70 | |||
1518 | 71 | private: | ||
1519 | 72 | std::shared_ptr<GKeyFile> _keyfile; | ||
1520 | 73 | std::string _basePath; | ||
1521 | 74 | |||
1522 | 75 | Application::Info::Name _name; | ||
1523 | 76 | Application::Info::Description _description; | ||
1524 | 77 | Application::Info::IconPath _iconPath; | ||
1525 | 78 | |||
1526 | 79 | Application::Info::Splash _splashInfo; | ||
1527 | 80 | Application::Info::Orientations _supportedOrientations; | ||
1528 | 81 | Application::Info::RotatesWindow _rotatesWindow; | ||
1529 | 82 | Application::Info::UbuntuLifecycle _ubuntuLifecycle; | ||
1530 | 83 | }; | ||
1531 | 84 | |||
1532 | 85 | }; // namespace AppInfo | ||
1533 | 86 | }; // namespace AppLaunch | ||
1534 | 87 | }; // namespace Ubuntu | ||
1535 | 0 | 88 | ||
1536 | === added file 'libubuntu-app-launch/application.cpp' | |||
1537 | --- libubuntu-app-launch/application.cpp 1970-01-01 00:00:00 +0000 | |||
1538 | +++ libubuntu-app-launch/application.cpp 2016-03-04 11:34:19 +0000 | |||
1539 | @@ -0,0 +1,225 @@ | |||
1540 | 1 | /* | ||
1541 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1542 | 3 | * | ||
1543 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1544 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1545 | 6 | * by the Free Software Foundation. | ||
1546 | 7 | * | ||
1547 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1548 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1549 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1550 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1551 | 12 | * | ||
1552 | 13 | * You should have received a copy of the GNU General Public License along | ||
1553 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1554 | 15 | * | ||
1555 | 16 | * Authors: | ||
1556 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1557 | 18 | */ | ||
1558 | 19 | |||
1559 | 20 | extern "C" { | ||
1560 | 21 | #include "app-info.h" | ||
1561 | 22 | #include "ubuntu-app-launch.h" | ||
1562 | 23 | } | ||
1563 | 24 | |||
1564 | 25 | #include "application-impl-click.h" | ||
1565 | 26 | #include "application-impl-legacy.h" | ||
1566 | 27 | #include "application-impl-libertine.h" | ||
1567 | 28 | #include "application.h" | ||
1568 | 29 | |||
1569 | 30 | #include <iostream> | ||
1570 | 31 | #include <regex> | ||
1571 | 32 | |||
1572 | 33 | namespace ubuntu | ||
1573 | 34 | { | ||
1574 | 35 | namespace app_launch | ||
1575 | 36 | { | ||
1576 | 37 | |||
1577 | 38 | std::shared_ptr<Application> Application::create(const AppID& appid, const std::shared_ptr<Registry>& registry) | ||
1578 | 39 | { | ||
1579 | 40 | if (appid.empty()) | ||
1580 | 41 | { | ||
1581 | 42 | throw std::runtime_error("AppID is empty"); | ||
1582 | 43 | } | ||
1583 | 44 | |||
1584 | 45 | std::string sappid = appid; | ||
1585 | 46 | if (app_info_click(sappid.c_str(), NULL, NULL)) | ||
1586 | 47 | { | ||
1587 | 48 | return std::make_shared<app_impls::Click>(appid, registry); | ||
1588 | 49 | } | ||
1589 | 50 | else if (app_info_libertine(sappid.c_str(), NULL, NULL)) | ||
1590 | 51 | { | ||
1591 | 52 | return std::make_shared<app_impls::Libertine>(appid.package, appid.appname, registry); | ||
1592 | 53 | } | ||
1593 | 54 | else if (app_info_legacy(sappid.c_str(), NULL, NULL)) | ||
1594 | 55 | { | ||
1595 | 56 | return std::make_shared<app_impls::Legacy>(appid.appname, registry); | ||
1596 | 57 | } | ||
1597 | 58 | else | ||
1598 | 59 | { | ||
1599 | 60 | throw std::runtime_error("Invalid app ID: " + sappid); | ||
1600 | 61 | } | ||
1601 | 62 | } | ||
1602 | 63 | |||
1603 | 64 | AppID::AppID() | ||
1604 | 65 | : package(Package::from_raw({})) | ||
1605 | 66 | , appname(AppName::from_raw({})) | ||
1606 | 67 | , version(Version::from_raw({})) | ||
1607 | 68 | { | ||
1608 | 69 | } | ||
1609 | 70 | |||
1610 | 71 | AppID::AppID(Package pkg, AppName app, Version ver) | ||
1611 | 72 | : package(pkg) | ||
1612 | 73 | , appname(app) | ||
1613 | 74 | , version(ver) | ||
1614 | 75 | { | ||
1615 | 76 | } | ||
1616 | 77 | |||
1617 | 78 | /* These are the Regex's taken from the Click Reviewer Tools | ||
1618 | 79 | on Jan 16, 2016 revision 566 */ | ||
1619 | 80 | #define REGEX_PKGNAME "([a-z0-9][a-z0-9+.-]+)" | ||
1620 | 81 | #define REGEX_APPNAME "([A-Za-z0-9+-.:~-]+)" | ||
1621 | 82 | #define REGEX_VERSION "([\\d+:]?[A-Za-z0-9.+:~-]+?[-[A-Za-z0-9+.~]+]?)" | ||
1622 | 83 | |||
1623 | 84 | const std::regex full_appid_regex("^" REGEX_PKGNAME "_" REGEX_APPNAME "_" REGEX_VERSION "$"); | ||
1624 | 85 | const std::regex short_appid_regex("^" REGEX_PKGNAME "_" REGEX_APPNAME "$"); | ||
1625 | 86 | const std::regex legacy_appid_regex("^" REGEX_APPNAME "$"); | ||
1626 | 87 | |||
1627 | 88 | AppID AppID::parse(const std::string& sappid) | ||
1628 | 89 | { | ||
1629 | 90 | std::smatch match; | ||
1630 | 91 | |||
1631 | 92 | if (std::regex_match(sappid, match, full_appid_regex)) | ||
1632 | 93 | { | ||
1633 | 94 | return {AppID::Package::from_raw(match[1].str()), AppID::AppName::from_raw(match[2].str()), | ||
1634 | 95 | AppID::Version::from_raw(match[3].str())}; | ||
1635 | 96 | } | ||
1636 | 97 | else | ||
1637 | 98 | { | ||
1638 | 99 | /* Allow returning an empty AppID with empty internal */ | ||
1639 | 100 | return {AppID::Package::from_raw({}), AppID::AppName::from_raw({}), AppID::Version::from_raw({})}; | ||
1640 | 101 | } | ||
1641 | 102 | } | ||
1642 | 103 | |||
1643 | 104 | bool AppID::valid(const std::string& sappid) | ||
1644 | 105 | { | ||
1645 | 106 | return std::regex_match(sappid, full_appid_regex); | ||
1646 | 107 | } | ||
1647 | 108 | |||
1648 | 109 | AppID AppID::find(const std::string& sappid) | ||
1649 | 110 | { | ||
1650 | 111 | std::smatch match; | ||
1651 | 112 | |||
1652 | 113 | if (std::regex_match(sappid, match, full_appid_regex)) | ||
1653 | 114 | { | ||
1654 | 115 | return {AppID::Package::from_raw(match[1].str()), AppID::AppName::from_raw(match[2].str()), | ||
1655 | 116 | AppID::Version::from_raw(match[3].str())}; | ||
1656 | 117 | } | ||
1657 | 118 | else if (std::regex_match(sappid, match, short_appid_regex)) | ||
1658 | 119 | { | ||
1659 | 120 | return discover(match[1].str(), match[2].str()); | ||
1660 | 121 | } | ||
1661 | 122 | else if (std::regex_match(sappid, match, legacy_appid_regex)) | ||
1662 | 123 | { | ||
1663 | 124 | return {AppID::Package::from_raw({}), AppID::AppName::from_raw(sappid), AppID::Version::from_raw({})}; | ||
1664 | 125 | } | ||
1665 | 126 | else | ||
1666 | 127 | { | ||
1667 | 128 | return {AppID::Package::from_raw({}), AppID::AppName::from_raw({}), AppID::Version::from_raw({})}; | ||
1668 | 129 | } | ||
1669 | 130 | } | ||
1670 | 131 | |||
1671 | 132 | AppID::operator std::string() const | ||
1672 | 133 | { | ||
1673 | 134 | if (package.value().empty() && version.value().empty()) | ||
1674 | 135 | { | ||
1675 | 136 | if (appname.value().empty()) | ||
1676 | 137 | { | ||
1677 | 138 | return {}; | ||
1678 | 139 | } | ||
1679 | 140 | else | ||
1680 | 141 | { | ||
1681 | 142 | return appname.value(); | ||
1682 | 143 | } | ||
1683 | 144 | } | ||
1684 | 145 | |||
1685 | 146 | return package.value() + "_" + appname.value() + "_" + version.value(); | ||
1686 | 147 | } | ||
1687 | 148 | |||
1688 | 149 | bool operator==(const AppID& a, const AppID& b) | ||
1689 | 150 | { | ||
1690 | 151 | return a.package.value() == b.package.value() && a.appname.value() == b.appname.value() && | ||
1691 | 152 | a.version.value() == b.version.value(); | ||
1692 | 153 | } | ||
1693 | 154 | |||
1694 | 155 | bool operator!=(const AppID& a, const AppID& b) | ||
1695 | 156 | { | ||
1696 | 157 | return a.package.value() != b.package.value() || a.appname.value() != b.appname.value() || | ||
1697 | 158 | a.version.value() != b.version.value(); | ||
1698 | 159 | } | ||
1699 | 160 | |||
1700 | 161 | bool AppID::empty() const | ||
1701 | 162 | { | ||
1702 | 163 | return package.value().empty() && appname.value().empty() && version.value().empty(); | ||
1703 | 164 | } | ||
1704 | 165 | |||
1705 | 166 | std::string app_wildcard(AppID::ApplicationWildcard card) | ||
1706 | 167 | { | ||
1707 | 168 | switch (card) | ||
1708 | 169 | { | ||
1709 | 170 | case AppID::ApplicationWildcard::FIRST_LISTED: | ||
1710 | 171 | return "first-listed-app"; | ||
1711 | 172 | case AppID::ApplicationWildcard::LAST_LISTED: | ||
1712 | 173 | return "last-listed-app"; | ||
1713 | 174 | case AppID::ApplicationWildcard::ONLY_LISTED: | ||
1714 | 175 | return "only-listed-app"; | ||
1715 | 176 | } | ||
1716 | 177 | |||
1717 | 178 | return ""; | ||
1718 | 179 | } | ||
1719 | 180 | |||
1720 | 181 | std::string ver_wildcard(AppID::VersionWildcard card) | ||
1721 | 182 | { | ||
1722 | 183 | switch (card) | ||
1723 | 184 | { | ||
1724 | 185 | case AppID::VersionWildcard::CURRENT_USER_VERSION: | ||
1725 | 186 | return "current-user-version"; | ||
1726 | 187 | } | ||
1727 | 188 | |||
1728 | 189 | return ""; | ||
1729 | 190 | } | ||
1730 | 191 | |||
1731 | 192 | AppID AppID::discover(const std::string& package, const std::string& appname, const std::string& version) | ||
1732 | 193 | { | ||
1733 | 194 | auto cappid = ubuntu_app_launch_triplet_to_app_id(package.c_str(), appname.c_str(), version.c_str()); | ||
1734 | 195 | |||
1735 | 196 | auto appid = cappid != nullptr ? AppID::parse(cappid) : AppID::parse(""); | ||
1736 | 197 | |||
1737 | 198 | g_free(cappid); | ||
1738 | 199 | |||
1739 | 200 | return appid; | ||
1740 | 201 | } | ||
1741 | 202 | |||
1742 | 203 | AppID AppID::discover(const std::string& package, ApplicationWildcard appwildcard, VersionWildcard versionwildcard) | ||
1743 | 204 | { | ||
1744 | 205 | return discover(package, app_wildcard(appwildcard), ver_wildcard(versionwildcard)); | ||
1745 | 206 | } | ||
1746 | 207 | |||
1747 | 208 | AppID AppID::discover(const std::string& package, const std::string& appname, VersionWildcard versionwildcard) | ||
1748 | 209 | { | ||
1749 | 210 | auto appid = discover(package, appname, ver_wildcard(versionwildcard)); | ||
1750 | 211 | |||
1751 | 212 | if (appid.empty()) | ||
1752 | 213 | { | ||
1753 | 214 | /* If we weren't able to go that route, we can see if it's libertine */ | ||
1754 | 215 | if (app_info_libertine((package + "_" + appname + "_0.0").c_str(), nullptr, nullptr)) | ||
1755 | 216 | { | ||
1756 | 217 | appid = AppID(Package::from_raw(package), AppName::from_raw(appname), Version::from_raw("0.0")); | ||
1757 | 218 | } | ||
1758 | 219 | } | ||
1759 | 220 | |||
1760 | 221 | return appid; | ||
1761 | 222 | } | ||
1762 | 223 | |||
1763 | 224 | }; // namespace app_launch | ||
1764 | 225 | }; // namespace ubuntu | ||
1765 | 0 | 226 | ||
1766 | === added file 'libubuntu-app-launch/application.h' | |||
1767 | --- libubuntu-app-launch/application.h 1970-01-01 00:00:00 +0000 | |||
1768 | +++ libubuntu-app-launch/application.h 2016-03-04 11:34:19 +0000 | |||
1769 | @@ -0,0 +1,150 @@ | |||
1770 | 1 | /* | ||
1771 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1772 | 3 | * | ||
1773 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1774 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1775 | 6 | * by the Free Software Foundation. | ||
1776 | 7 | * | ||
1777 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1778 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1779 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1780 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1781 | 12 | * | ||
1782 | 13 | * You should have received a copy of the GNU General Public License along | ||
1783 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1784 | 15 | * | ||
1785 | 16 | * Authors: | ||
1786 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1787 | 18 | */ | ||
1788 | 19 | |||
1789 | 20 | #include <list> | ||
1790 | 21 | #include <memory> | ||
1791 | 22 | #include <sys/types.h> | ||
1792 | 23 | #include <vector> | ||
1793 | 24 | |||
1794 | 25 | #include "appid.h" | ||
1795 | 26 | #include "type-tagger.h" | ||
1796 | 27 | |||
1797 | 28 | #pragma once | ||
1798 | 29 | #pragma GCC visibility push(default) | ||
1799 | 30 | |||
1800 | 31 | namespace ubuntu | ||
1801 | 32 | { | ||
1802 | 33 | namespace app_launch | ||
1803 | 34 | { | ||
1804 | 35 | |||
1805 | 36 | class Registry; | ||
1806 | 37 | |||
1807 | 38 | class Application | ||
1808 | 39 | { | ||
1809 | 40 | public: | ||
1810 | 41 | struct URLTag; | ||
1811 | 42 | typedef TypeTagger<URLTag, std::string> URL; | ||
1812 | 43 | |||
1813 | 44 | static std::shared_ptr<Application> create(const AppID& appid, const std::shared_ptr<Registry>& registry); | ||
1814 | 45 | |||
1815 | 46 | /* System level info */ | ||
1816 | 47 | virtual AppID appId() = 0; | ||
1817 | 48 | |||
1818 | 49 | class Info | ||
1819 | 50 | { | ||
1820 | 51 | public: | ||
1821 | 52 | /* Basic information */ | ||
1822 | 53 | struct NameTag; | ||
1823 | 54 | struct DescriptionTag; | ||
1824 | 55 | struct IconPathTag; | ||
1825 | 56 | |||
1826 | 57 | typedef TypeTagger<NameTag, std::string> Name; | ||
1827 | 58 | typedef TypeTagger<DescriptionTag, std::string> Description; | ||
1828 | 59 | typedef TypeTagger<IconPathTag, std::string> IconPath; | ||
1829 | 60 | |||
1830 | 61 | virtual const Name& name() = 0; | ||
1831 | 62 | virtual const Description& description() = 0; | ||
1832 | 63 | virtual const IconPath& iconPath() = 0; | ||
1833 | 64 | |||
1834 | 65 | /* Splash information */ | ||
1835 | 66 | struct Splash | ||
1836 | 67 | { | ||
1837 | 68 | struct TitleTag; | ||
1838 | 69 | struct ImageTag; | ||
1839 | 70 | struct ColorTag; | ||
1840 | 71 | struct ShowHeaderTag; | ||
1841 | 72 | |||
1842 | 73 | typedef TypeTagger<TitleTag, std::string> Title; | ||
1843 | 74 | typedef TypeTagger<ImageTag, std::string> Image; | ||
1844 | 75 | typedef TypeTagger<ColorTag, std::string> Color; | ||
1845 | 76 | typedef TypeTagger<ShowHeaderTag, bool> ShowHeader; | ||
1846 | 77 | |||
1847 | 78 | Title title; | ||
1848 | 79 | Image image; | ||
1849 | 80 | Color backgroundColor; | ||
1850 | 81 | Color headerColor; | ||
1851 | 82 | Color footerColor; | ||
1852 | 83 | ShowHeader showHeader; | ||
1853 | 84 | }; | ||
1854 | 85 | |||
1855 | 86 | virtual Splash splash() = 0; | ||
1856 | 87 | |||
1857 | 88 | /* Orientation and placement */ | ||
1858 | 89 | struct Orientations | ||
1859 | 90 | { | ||
1860 | 91 | bool portrait; | ||
1861 | 92 | bool landscape; | ||
1862 | 93 | bool invertedPortrait; | ||
1863 | 94 | bool invertedLandscape; | ||
1864 | 95 | |||
1865 | 96 | bool operator==(const Orientations& b) const | ||
1866 | 97 | { | ||
1867 | 98 | return portrait == b.portrait && landscape == b.landscape && invertedPortrait == b.invertedPortrait && | ||
1868 | 99 | invertedLandscape == b.invertedLandscape; | ||
1869 | 100 | } | ||
1870 | 101 | }; | ||
1871 | 102 | |||
1872 | 103 | struct RotatesWindowTag; | ||
1873 | 104 | |||
1874 | 105 | typedef TypeTagger<RotatesWindowTag, bool> RotatesWindow; | ||
1875 | 106 | |||
1876 | 107 | virtual Orientations supportedOrientations() = 0; | ||
1877 | 108 | virtual RotatesWindow rotatesWindowContents() = 0; | ||
1878 | 109 | |||
1879 | 110 | /* Lifecycle */ | ||
1880 | 111 | struct UbuntuLifecycleTag; | ||
1881 | 112 | |||
1882 | 113 | typedef TypeTagger<UbuntuLifecycleTag, bool> UbuntuLifecycle; | ||
1883 | 114 | |||
1884 | 115 | virtual UbuntuLifecycle supportsUbuntuLifecycle() = 0; | ||
1885 | 116 | }; | ||
1886 | 117 | |||
1887 | 118 | virtual std::shared_ptr<Info> info() = 0; | ||
1888 | 119 | |||
1889 | 120 | class Instance | ||
1890 | 121 | { | ||
1891 | 122 | public: | ||
1892 | 123 | /* Query lifecycle */ | ||
1893 | 124 | virtual bool isRunning() = 0; | ||
1894 | 125 | |||
1895 | 126 | /* Instance Info */ | ||
1896 | 127 | virtual std::string logPath() = 0; | ||
1897 | 128 | |||
1898 | 129 | /* PIDs */ | ||
1899 | 130 | virtual pid_t primaryPid() = 0; | ||
1900 | 131 | virtual bool hasPid(pid_t pid) = 0; | ||
1901 | 132 | virtual std::vector<pid_t> pids() = 0; | ||
1902 | 133 | |||
1903 | 134 | /* Manage lifecycle */ | ||
1904 | 135 | virtual void pause() = 0; | ||
1905 | 136 | virtual void resume() = 0; | ||
1906 | 137 | virtual void stop() = 0; | ||
1907 | 138 | }; | ||
1908 | 139 | |||
1909 | 140 | virtual bool hasInstances() = 0; | ||
1910 | 141 | virtual std::vector<std::shared_ptr<Instance>> instances() = 0; | ||
1911 | 142 | |||
1912 | 143 | virtual std::shared_ptr<Instance> launch(const std::vector<URL>& urls = {}) = 0; | ||
1913 | 144 | virtual std::shared_ptr<Instance> launchTest(const std::vector<URL>& urls = {}) = 0; | ||
1914 | 145 | }; | ||
1915 | 146 | |||
1916 | 147 | }; // namespace app_launch | ||
1917 | 148 | }; // namespace ubuntu | ||
1918 | 149 | |||
1919 | 150 | #pragma GCC visibility pop | ||
1920 | 0 | 151 | ||
1921 | === modified file 'libubuntu-app-launch/desktop-exec.c' | |||
1922 | --- libubuntu-app-launch/desktop-exec.c 2015-08-12 02:52:05 +0000 | |||
1923 | +++ libubuntu-app-launch/desktop-exec.c 2016-03-04 11:34:19 +0000 | |||
1924 | @@ -186,7 +186,7 @@ | |||
1925 | 186 | /* This string is quoted using desktop file quoting: | 186 | /* This string is quoted using desktop file quoting: |
1926 | 187 | http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */ | 187 | http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */ |
1927 | 188 | gchar * execline = desktop_to_exec(keyfile, app_id); | 188 | gchar * execline = desktop_to_exec(keyfile, app_id); |
1929 | 189 | g_return_val_if_fail(execline != NULL, 1); | 189 | g_return_val_if_fail(execline != NULL, FALSE); |
1930 | 190 | 190 | ||
1931 | 191 | if (is_libertine) { | 191 | if (is_libertine) { |
1932 | 192 | static const gchar * libertine_launch = NULL; | 192 | static const gchar * libertine_launch = NULL; |
1933 | 193 | 193 | ||
1934 | === added file 'libubuntu-app-launch/glib-thread.cpp' | |||
1935 | --- libubuntu-app-launch/glib-thread.cpp 1970-01-01 00:00:00 +0000 | |||
1936 | +++ libubuntu-app-launch/glib-thread.cpp 2016-03-04 11:34:19 +0000 | |||
1937 | @@ -0,0 +1,156 @@ | |||
1938 | 1 | /* | ||
1939 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1940 | 3 | * | ||
1941 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1942 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1943 | 6 | * by the Free Software Foundation. | ||
1944 | 7 | * | ||
1945 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1946 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1947 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1948 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1949 | 12 | * | ||
1950 | 13 | * You should have received a copy of the GNU General Public License along | ||
1951 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1952 | 15 | * | ||
1953 | 16 | * Authors: | ||
1954 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
1955 | 18 | */ | ||
1956 | 19 | |||
1957 | 20 | #include "glib-thread.h" | ||
1958 | 21 | |||
1959 | 22 | namespace GLib | ||
1960 | 23 | { | ||
1961 | 24 | |||
1962 | 25 | ContextThread::ContextThread(std::function<void()> beforeLoop, std::function<void()> afterLoop) | ||
1963 | 26 | { | ||
1964 | 27 | _cancel = std::shared_ptr<GCancellable>(g_cancellable_new(), [](GCancellable* cancel) { | ||
1965 | 28 | if (cancel != nullptr) | ||
1966 | 29 | { | ||
1967 | 30 | g_cancellable_cancel(cancel); | ||
1968 | 31 | g_object_unref(cancel); | ||
1969 | 32 | } | ||
1970 | 33 | }); | ||
1971 | 34 | std::promise<std::pair<std::shared_ptr<GMainContext>, std::shared_ptr<GMainLoop>>> context_promise; | ||
1972 | 35 | |||
1973 | 36 | /* NOTE: We copy afterLoop but reference beforeLoop. We're blocking so we | ||
1974 | 37 | know that beforeLoop will stay valid long enough, but we can't say the | ||
1975 | 38 | same for afterLoop */ | ||
1976 | 39 | _thread = std::thread([&context_promise, &beforeLoop, afterLoop, this]() { | ||
1977 | 40 | /* Build up the context and loop for the async events and a place | ||
1978 | 41 | for GDBus to send its events back to */ | ||
1979 | 42 | auto context = std::shared_ptr<GMainContext>( | ||
1980 | 43 | g_main_context_new(), [](GMainContext* context) { g_clear_pointer(&context, g_main_context_unref); }); | ||
1981 | 44 | auto loop = std::shared_ptr<GMainLoop>(g_main_loop_new(context.get(), FALSE), | ||
1982 | 45 | [](GMainLoop* loop) { g_clear_pointer(&loop, g_main_loop_unref); }); | ||
1983 | 46 | |||
1984 | 47 | g_main_context_push_thread_default(context.get()); | ||
1985 | 48 | |||
1986 | 49 | beforeLoop(); | ||
1987 | 50 | |||
1988 | 51 | /* Free's the constructor to continue */ | ||
1989 | 52 | auto pair = std::pair<std::shared_ptr<GMainContext>, std::shared_ptr<GMainLoop>>(context, loop); | ||
1990 | 53 | context_promise.set_value(pair); | ||
1991 | 54 | |||
1992 | 55 | if (!g_cancellable_is_cancelled(_cancel.get())) | ||
1993 | 56 | { | ||
1994 | 57 | g_main_loop_run(loop.get()); | ||
1995 | 58 | } | ||
1996 | 59 | |||
1997 | 60 | afterLoop(); | ||
1998 | 61 | }); | ||
1999 | 62 | |||
2000 | 63 | /* We need to have the context and the mainloop ready before | ||
2001 | 64 | other functions on this object can work properly. So we wait | ||
2002 | 65 | for them and set them on this thread. */ | ||
2003 | 66 | auto context_future = context_promise.get_future(); | ||
2004 | 67 | context_future.wait(); | ||
2005 | 68 | auto context_value = context_future.get(); | ||
2006 | 69 | |||
2007 | 70 | _context = context_value.first; | ||
2008 | 71 | _loop = context_value.second; | ||
2009 | 72 | |||
2010 | 73 | if (!_context || !_loop) | ||
2011 | 74 | { | ||
2012 | 75 | throw std::runtime_error("Unable to create GLib Thread"); | ||
2013 | 76 | } | ||
2014 | 77 | } | ||
2015 | 78 | |||
2016 | 79 | ContextThread::~ContextThread() | ||
2017 | 80 | { | ||
2018 | 81 | quit(); | ||
2019 | 82 | } | ||
2020 | 83 | |||
2021 | 84 | void ContextThread::quit() | ||
2022 | 85 | { | ||
2023 | 86 | g_cancellable_cancel(_cancel.get()); /* Force the cancellation on ongoing tasks */ | ||
2024 | 87 | if (_loop) | ||
2025 | 88 | { | ||
2026 | 89 | g_main_loop_quit(_loop.get()); /* Quit the loop */ | ||
2027 | 90 | } | ||
2028 | 91 | |||
2029 | 92 | /* Joining here because we want to ensure that the final afterLoop() | ||
2030 | 93 | function is run before returning */ | ||
2031 | 94 | if (std::this_thread::get_id() != _thread.get_id()) | ||
2032 | 95 | { | ||
2033 | 96 | if (_thread.joinable()) | ||
2034 | 97 | { | ||
2035 | 98 | _thread.join(); | ||
2036 | 99 | } | ||
2037 | 100 | } | ||
2038 | 101 | } | ||
2039 | 102 | |||
2040 | 103 | bool ContextThread::isCancelled() | ||
2041 | 104 | { | ||
2042 | 105 | return g_cancellable_is_cancelled(_cancel.get()) == TRUE; | ||
2043 | 106 | } | ||
2044 | 107 | |||
2045 | 108 | std::shared_ptr<GCancellable> ContextThread::getCancellable() | ||
2046 | 109 | { | ||
2047 | 110 | return _cancel; | ||
2048 | 111 | } | ||
2049 | 112 | |||
2050 | 113 | void ContextThread::simpleSource(std::function<GSource*()> srcBuilder, std::function<void()> work) | ||
2051 | 114 | { | ||
2052 | 115 | if (isCancelled()) | ||
2053 | 116 | { | ||
2054 | 117 | throw std::runtime_error("Trying to execute work on a GLib thread that is shutting down."); | ||
2055 | 118 | } | ||
2056 | 119 | |||
2057 | 120 | /* Copy the work so that we can reuse it */ | ||
2058 | 121 | /* Lifecycle is handled with the source pointer when we attach | ||
2059 | 122 | it to the context. */ | ||
2060 | 123 | auto heapWork = new std::function<void()>(work); | ||
2061 | 124 | |||
2062 | 125 | auto source = std::shared_ptr<GSource>(srcBuilder(), [](GSource* src) { g_clear_pointer(&src, g_source_unref); }); | ||
2063 | 126 | g_source_set_callback(source.get(), | ||
2064 | 127 | [](gpointer data) { | ||
2065 | 128 | auto heapWork = static_cast<std::function<void()>*>(data); | ||
2066 | 129 | (*heapWork)(); | ||
2067 | 130 | return G_SOURCE_REMOVE; | ||
2068 | 131 | }, | ||
2069 | 132 | heapWork, | ||
2070 | 133 | [](gpointer data) { | ||
2071 | 134 | auto heapWork = static_cast<std::function<void()>*>(data); | ||
2072 | 135 | delete heapWork; | ||
2073 | 136 | }); | ||
2074 | 137 | |||
2075 | 138 | g_source_attach(source.get(), _context.get()); | ||
2076 | 139 | } | ||
2077 | 140 | |||
2078 | 141 | void ContextThread::executeOnThread(std::function<void()> work) | ||
2079 | 142 | { | ||
2080 | 143 | simpleSource(g_idle_source_new, work); | ||
2081 | 144 | } | ||
2082 | 145 | |||
2083 | 146 | void ContextThread::timeout(const std::chrono::milliseconds& length, std::function<void()> work) | ||
2084 | 147 | { | ||
2085 | 148 | simpleSource([length]() { return g_timeout_source_new(length.count()); }, work); | ||
2086 | 149 | } | ||
2087 | 150 | |||
2088 | 151 | void ContextThread::timeoutSeconds(const std::chrono::seconds& length, std::function<void()> work) | ||
2089 | 152 | { | ||
2090 | 153 | simpleSource([length]() { return g_timeout_source_new_seconds(length.count()); }, work); | ||
2091 | 154 | } | ||
2092 | 155 | |||
2093 | 156 | } // ns GLib | ||
2094 | 0 | 157 | ||
2095 | === added file 'libubuntu-app-launch/glib-thread.h' | |||
2096 | --- libubuntu-app-launch/glib-thread.h 1970-01-01 00:00:00 +0000 | |||
2097 | +++ libubuntu-app-launch/glib-thread.h 2016-03-04 11:34:19 +0000 | |||
2098 | @@ -0,0 +1,90 @@ | |||
2099 | 1 | /* | ||
2100 | 2 | * Copyright © 2015 Canonical Ltd. | ||
2101 | 3 | * | ||
2102 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2103 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2104 | 6 | * by the Free Software Foundation. | ||
2105 | 7 | * | ||
2106 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2107 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2108 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2109 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2110 | 12 | * | ||
2111 | 13 | * You should have received a copy of the GNU General Public License along | ||
2112 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2113 | 15 | * | ||
2114 | 16 | * Authors: | ||
2115 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2116 | 18 | */ | ||
2117 | 19 | |||
2118 | 20 | #include <thread> | ||
2119 | 21 | #include <future> | ||
2120 | 22 | |||
2121 | 23 | #include <gio/gio.h> | ||
2122 | 24 | |||
2123 | 25 | namespace GLib | ||
2124 | 26 | { | ||
2125 | 27 | |||
2126 | 28 | class ContextThread | ||
2127 | 29 | { | ||
2128 | 30 | std::thread _thread; | ||
2129 | 31 | std::shared_ptr<GMainContext> _context; | ||
2130 | 32 | std::shared_ptr<GMainLoop> _loop; | ||
2131 | 33 | std::shared_ptr<GCancellable> _cancel; | ||
2132 | 34 | |||
2133 | 35 | public: | ||
2134 | 36 | ContextThread(std::function<void()> beforeLoop = | ||
2135 | 37 | [] | ||
2136 | 38 | { | ||
2137 | 39 | }, | ||
2138 | 40 | std::function<void()> afterLoop = | ||
2139 | 41 | [] | ||
2140 | 42 | { | ||
2141 | 43 | }); | ||
2142 | 44 | ~ContextThread(); | ||
2143 | 45 | |||
2144 | 46 | void quit(); | ||
2145 | 47 | bool isCancelled(); | ||
2146 | 48 | std::shared_ptr<GCancellable> getCancellable(); | ||
2147 | 49 | |||
2148 | 50 | void executeOnThread(std::function<void()> work); | ||
2149 | 51 | template <typename T> | ||
2150 | 52 | auto executeOnThread(std::function<T()> work) -> T | ||
2151 | 53 | { | ||
2152 | 54 | if (std::this_thread::get_id() == _thread.get_id()) | ||
2153 | 55 | { | ||
2154 | 56 | /* Don't block if we're on the same thread */ | ||
2155 | 57 | return work(); | ||
2156 | 58 | } | ||
2157 | 59 | |||
2158 | 60 | std::promise<T> promise; | ||
2159 | 61 | std::function<void()> magicFunc = [&promise, &work]() | ||
2160 | 62 | { | ||
2161 | 63 | promise.set_value(work()); | ||
2162 | 64 | }; | ||
2163 | 65 | |||
2164 | 66 | executeOnThread(magicFunc); | ||
2165 | 67 | |||
2166 | 68 | auto future = promise.get_future(); | ||
2167 | 69 | future.wait(); | ||
2168 | 70 | return future.get(); | ||
2169 | 71 | } | ||
2170 | 72 | |||
2171 | 73 | void timeout(const std::chrono::milliseconds& length, std::function<void()> work); | ||
2172 | 74 | template <class Rep, class Period> | ||
2173 | 75 | void timeout(const std::chrono::duration<Rep, Period>& length, std::function<void()> work) | ||
2174 | 76 | { | ||
2175 | 77 | return timeout(std::chrono::duration_cast<std::chrono::milliseconds>(length), work); | ||
2176 | 78 | } | ||
2177 | 79 | |||
2178 | 80 | void timeoutSeconds(const std::chrono::seconds& length, std::function<void()> work); | ||
2179 | 81 | template <class Rep, class Period> | ||
2180 | 82 | void timeoutSeconds(const std::chrono::duration<Rep, Period>& length, std::function<void()> work) | ||
2181 | 83 | { | ||
2182 | 84 | return timeoutSeconds(std::chrono::duration_cast<std::chrono::seconds>(length), work); | ||
2183 | 85 | } | ||
2184 | 86 | |||
2185 | 87 | private: | ||
2186 | 88 | void simpleSource(std::function<GSource*()> srcBuilder, std::function<void()> work); | ||
2187 | 89 | }; | ||
2188 | 90 | } | ||
2189 | 0 | 91 | ||
2190 | === added file 'libubuntu-app-launch/helper-impl-click.cpp' | |||
2191 | --- libubuntu-app-launch/helper-impl-click.cpp 1970-01-01 00:00:00 +0000 | |||
2192 | +++ libubuntu-app-launch/helper-impl-click.cpp 2016-03-04 11:34:19 +0000 | |||
2193 | @@ -0,0 +1,175 @@ | |||
2194 | 1 | /* | ||
2195 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2196 | 3 | * | ||
2197 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2198 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2199 | 6 | * by the Free Software Foundation. | ||
2200 | 7 | * | ||
2201 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2202 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2203 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2204 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2205 | 12 | * | ||
2206 | 13 | * You should have received a copy of the GNU General Public License along | ||
2207 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2208 | 15 | * | ||
2209 | 16 | * Authors: | ||
2210 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2211 | 18 | */ | ||
2212 | 19 | |||
2213 | 20 | #include "helper-impl-click.h" | ||
2214 | 21 | #include "registry-impl.h" | ||
2215 | 22 | |||
2216 | 23 | #include "ubuntu-app-launch.h" | ||
2217 | 24 | |||
2218 | 25 | namespace ubuntu | ||
2219 | 26 | { | ||
2220 | 27 | namespace app_launch | ||
2221 | 28 | { | ||
2222 | 29 | namespace helper_impls | ||
2223 | 30 | { | ||
2224 | 31 | |||
2225 | 32 | bool Click::hasInstances() | ||
2226 | 33 | { | ||
2227 | 34 | return _registry->impl->thread.executeOnThread<bool>([this]() { | ||
2228 | 35 | auto instances = ubuntu_app_launch_list_helper_instances(_type.value().c_str(), ((std::string)_appid).c_str()); | ||
2229 | 36 | auto retval = (g_strv_length(instances) != 0); | ||
2230 | 37 | |||
2231 | 38 | g_strfreev(instances); | ||
2232 | 39 | |||
2233 | 40 | return retval; | ||
2234 | 41 | }); | ||
2235 | 42 | } | ||
2236 | 43 | |||
2237 | 44 | class ClickInstance : public Helper::Instance | ||
2238 | 45 | { | ||
2239 | 46 | public: /* all one file, no one to hide from */ | ||
2240 | 47 | AppID _appid; | ||
2241 | 48 | Helper::Type _type; | ||
2242 | 49 | std::string _instanceid; | ||
2243 | 50 | std::shared_ptr<Registry> _registry; | ||
2244 | 51 | |||
2245 | 52 | ClickInstance(const AppID& appid, | ||
2246 | 53 | const Helper::Type& type, | ||
2247 | 54 | const std::string& instanceid, | ||
2248 | 55 | std::shared_ptr<Registry> registry) | ||
2249 | 56 | : _appid(appid) | ||
2250 | 57 | , _type(type) | ||
2251 | 58 | , _instanceid(instanceid) | ||
2252 | 59 | , _registry(registry) | ||
2253 | 60 | { | ||
2254 | 61 | } | ||
2255 | 62 | |||
2256 | 63 | bool isRunning() override | ||
2257 | 64 | { | ||
2258 | 65 | return _registry->impl->thread.executeOnThread<bool>([this]() { | ||
2259 | 66 | bool found = false; | ||
2260 | 67 | |||
2261 | 68 | auto instances = | ||
2262 | 69 | ubuntu_app_launch_list_helper_instances(_type.value().c_str(), ((std::string)_appid).c_str()); | ||
2263 | 70 | for (int i = 0; instances[i] != nullptr; i++) | ||
2264 | 71 | { | ||
2265 | 72 | if (_instanceid == std::string(instances[i])) | ||
2266 | 73 | { | ||
2267 | 74 | found = true; | ||
2268 | 75 | break; | ||
2269 | 76 | } | ||
2270 | 77 | } | ||
2271 | 78 | |||
2272 | 79 | g_strfreev(instances); | ||
2273 | 80 | |||
2274 | 81 | return found; | ||
2275 | 82 | }); | ||
2276 | 83 | } | ||
2277 | 84 | |||
2278 | 85 | void stop() override | ||
2279 | 86 | { | ||
2280 | 87 | _registry->impl->thread.executeOnThread<bool>([this]() { | ||
2281 | 88 | return ubuntu_app_launch_stop_multiple_helper(_type.value().c_str(), ((std::string)_appid).c_str(), | ||
2282 | 89 | _instanceid.c_str()) == TRUE; | ||
2283 | 90 | }); | ||
2284 | 91 | } | ||
2285 | 92 | }; | ||
2286 | 93 | |||
2287 | 94 | std::vector<std::shared_ptr<Click::Instance>> Click::instances() | ||
2288 | 95 | { | ||
2289 | 96 | return _registry->impl->thread.executeOnThread<std::vector<std::shared_ptr<Click::Instance>>>( | ||
2290 | 97 | [this]() -> std::vector<std::shared_ptr<Click::Instance>> { | ||
2291 | 98 | std::vector<std::shared_ptr<Click::Instance>> vect; | ||
2292 | 99 | auto instances = | ||
2293 | 100 | ubuntu_app_launch_list_helper_instances(_type.value().c_str(), ((std::string)_appid).c_str()); | ||
2294 | 101 | for (int i = 0; instances[i] != nullptr; i++) | ||
2295 | 102 | { | ||
2296 | 103 | auto inst = std::make_shared<ClickInstance>(_appid, _type, instances[i], _registry); | ||
2297 | 104 | vect.push_back(inst); | ||
2298 | 105 | } | ||
2299 | 106 | |||
2300 | 107 | g_strfreev(instances); | ||
2301 | 108 | |||
2302 | 109 | return vect; | ||
2303 | 110 | }); | ||
2304 | 111 | } | ||
2305 | 112 | |||
2306 | 113 | std::shared_ptr<gchar*> urlsToStrv(std::vector<Helper::URL> urls) | ||
2307 | 114 | { | ||
2308 | 115 | if (urls.size() == 0) | ||
2309 | 116 | { | ||
2310 | 117 | return {}; | ||
2311 | 118 | } | ||
2312 | 119 | |||
2313 | 120 | auto array = g_array_new(TRUE, FALSE, sizeof(gchar*)); | ||
2314 | 121 | |||
2315 | 122 | for (auto url : urls) | ||
2316 | 123 | { | ||
2317 | 124 | auto str = g_strdup(url.value().c_str()); | ||
2318 | 125 | g_array_append_val(array, str); | ||
2319 | 126 | } | ||
2320 | 127 | |||
2321 | 128 | return std::shared_ptr<gchar*>((gchar**)g_array_free(array, FALSE), g_strfreev); | ||
2322 | 129 | } | ||
2323 | 130 | |||
2324 | 131 | std::shared_ptr<Click::Instance> Click::launch(std::vector<Helper::URL> urls) | ||
2325 | 132 | { | ||
2326 | 133 | auto urlstrv = urlsToStrv(urls); | ||
2327 | 134 | |||
2328 | 135 | return _registry->impl->thread.executeOnThread<std::shared_ptr<Click::Instance>>([this, urlstrv]() { | ||
2329 | 136 | auto instanceid = ubuntu_app_launch_start_multiple_helper(_type.value().c_str(), ((std::string)_appid).c_str(), | ||
2330 | 137 | urlstrv.get()); | ||
2331 | 138 | |||
2332 | 139 | return std::make_shared<ClickInstance>(_appid, _type, instanceid, _registry); | ||
2333 | 140 | }); | ||
2334 | 141 | } | ||
2335 | 142 | |||
2336 | 143 | std::shared_ptr<Click::Instance> Click::launch(MirPromptSession* session, std::vector<Helper::URL> urls) | ||
2337 | 144 | { | ||
2338 | 145 | auto urlstrv = urlsToStrv(urls); | ||
2339 | 146 | |||
2340 | 147 | return _registry->impl->thread.executeOnThread<std::shared_ptr<Click::Instance>>([this, session, urlstrv]() { | ||
2341 | 148 | auto instanceid = ubuntu_app_launch_start_session_helper(_type.value().c_str(), session, | ||
2342 | 149 | ((std::string)_appid).c_str(), urlstrv.get()); | ||
2343 | 150 | |||
2344 | 151 | return std::make_shared<ClickInstance>(_appid, _type, instanceid, _registry); | ||
2345 | 152 | }); | ||
2346 | 153 | } | ||
2347 | 154 | |||
2348 | 155 | std::list<std::shared_ptr<Helper>> Click::running(Helper::Type type, std::shared_ptr<Registry> registry) | ||
2349 | 156 | { | ||
2350 | 157 | return registry->impl->thread.executeOnThread<std::list<std::shared_ptr<Helper>>>([type, registry]() { | ||
2351 | 158 | std::list<std::shared_ptr<Helper>> helpers; | ||
2352 | 159 | |||
2353 | 160 | auto appidv = ubuntu_app_launch_list_helpers(type.value().c_str()); | ||
2354 | 161 | for (int i = 0; appidv[i] != nullptr; i++) | ||
2355 | 162 | { | ||
2356 | 163 | auto helper = std::make_shared<Click>(type, AppID::parse(appidv[i]), registry); | ||
2357 | 164 | helpers.push_back(helper); | ||
2358 | 165 | } | ||
2359 | 166 | |||
2360 | 167 | g_strfreev(appidv); | ||
2361 | 168 | |||
2362 | 169 | return helpers; | ||
2363 | 170 | }); | ||
2364 | 171 | } | ||
2365 | 172 | |||
2366 | 173 | }; // namespace helper_impl | ||
2367 | 174 | }; // namespace app_launch | ||
2368 | 175 | }; // namespace ubuntu | ||
2369 | 0 | 176 | ||
2370 | === added file 'libubuntu-app-launch/helper-impl-click.h' | |||
2371 | --- libubuntu-app-launch/helper-impl-click.h 1970-01-01 00:00:00 +0000 | |||
2372 | +++ libubuntu-app-launch/helper-impl-click.h 2016-03-04 11:34:19 +0000 | |||
2373 | @@ -0,0 +1,62 @@ | |||
2374 | 1 | /* | ||
2375 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2376 | 3 | * | ||
2377 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2378 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2379 | 6 | * by the Free Software Foundation. | ||
2380 | 7 | * | ||
2381 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2382 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2383 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2384 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2385 | 12 | * | ||
2386 | 13 | * You should have received a copy of the GNU General Public License along | ||
2387 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2388 | 15 | * | ||
2389 | 16 | * Authors: | ||
2390 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2391 | 18 | */ | ||
2392 | 19 | |||
2393 | 20 | #include <list> | ||
2394 | 21 | |||
2395 | 22 | #include "helper.h" | ||
2396 | 23 | |||
2397 | 24 | namespace ubuntu | ||
2398 | 25 | { | ||
2399 | 26 | namespace app_launch | ||
2400 | 27 | { | ||
2401 | 28 | namespace helper_impls | ||
2402 | 29 | { | ||
2403 | 30 | |||
2404 | 31 | class Click : public Helper | ||
2405 | 32 | { | ||
2406 | 33 | public: | ||
2407 | 34 | Click(const Helper::Type& type, const AppID& appid, const std::shared_ptr<Registry>& registry) | ||
2408 | 35 | : _type(type) | ||
2409 | 36 | , _appid(appid) | ||
2410 | 37 | , _registry(registry) | ||
2411 | 38 | { | ||
2412 | 39 | } | ||
2413 | 40 | |||
2414 | 41 | AppID appId() override | ||
2415 | 42 | { | ||
2416 | 43 | return _appid; | ||
2417 | 44 | } | ||
2418 | 45 | |||
2419 | 46 | bool hasInstances() override; | ||
2420 | 47 | std::vector<std::shared_ptr<Helper::Instance>> instances() override; | ||
2421 | 48 | |||
2422 | 49 | std::shared_ptr<Helper::Instance> launch(std::vector<Helper::URL> urls = {}) override; | ||
2423 | 50 | std::shared_ptr<Helper::Instance> launch(MirPromptSession* session, std::vector<Helper::URL> urls = {}) override; | ||
2424 | 51 | |||
2425 | 52 | static std::list<std::shared_ptr<Helper>> running(Helper::Type type, std::shared_ptr<Registry> registry); | ||
2426 | 53 | |||
2427 | 54 | private: | ||
2428 | 55 | Helper::Type _type; | ||
2429 | 56 | AppID _appid; | ||
2430 | 57 | std::shared_ptr<Registry> _registry; | ||
2431 | 58 | }; | ||
2432 | 59 | |||
2433 | 60 | }; // namespace helper_impl | ||
2434 | 61 | }; // namespace app_launch | ||
2435 | 62 | }; // namespace ubuntu | ||
2436 | 0 | 63 | ||
2437 | === added file 'libubuntu-app-launch/helper.cpp' | |||
2438 | --- libubuntu-app-launch/helper.cpp 1970-01-01 00:00:00 +0000 | |||
2439 | +++ libubuntu-app-launch/helper.cpp 2016-03-04 11:34:19 +0000 | |||
2440 | @@ -0,0 +1,36 @@ | |||
2441 | 1 | /* | ||
2442 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2443 | 3 | * | ||
2444 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2445 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2446 | 6 | * by the Free Software Foundation. | ||
2447 | 7 | * | ||
2448 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2449 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2450 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2451 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2452 | 12 | * | ||
2453 | 13 | * You should have received a copy of the GNU General Public License along | ||
2454 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2455 | 15 | * | ||
2456 | 16 | * Authors: | ||
2457 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2458 | 18 | */ | ||
2459 | 19 | |||
2460 | 20 | #include "helper.h" | ||
2461 | 21 | |||
2462 | 22 | #include "helper-impl-click.h" | ||
2463 | 23 | |||
2464 | 24 | namespace ubuntu | ||
2465 | 25 | { | ||
2466 | 26 | namespace app_launch | ||
2467 | 27 | { | ||
2468 | 28 | |||
2469 | 29 | std::shared_ptr<Helper> Helper::create(Type type, AppID appid, std::shared_ptr<Registry> registry) | ||
2470 | 30 | { | ||
2471 | 31 | /* Only one type today */ | ||
2472 | 32 | return std::make_shared<helper_impls::Click>(type, appid, registry); | ||
2473 | 33 | } | ||
2474 | 34 | |||
2475 | 35 | }; // namespace AppLaunch | ||
2476 | 36 | }; // namespace Ubuntu | ||
2477 | 0 | 37 | ||
2478 | === added file 'libubuntu-app-launch/helper.h' | |||
2479 | --- libubuntu-app-launch/helper.h 1970-01-01 00:00:00 +0000 | |||
2480 | +++ libubuntu-app-launch/helper.h 2016-03-04 11:34:19 +0000 | |||
2481 | @@ -0,0 +1,71 @@ | |||
2482 | 1 | /* | ||
2483 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2484 | 3 | * | ||
2485 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2486 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2487 | 6 | * by the Free Software Foundation. | ||
2488 | 7 | * | ||
2489 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2490 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2491 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2492 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2493 | 12 | * | ||
2494 | 13 | * You should have received a copy of the GNU General Public License along | ||
2495 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2496 | 15 | * | ||
2497 | 16 | * Authors: | ||
2498 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2499 | 18 | */ | ||
2500 | 19 | |||
2501 | 20 | #include <memory> | ||
2502 | 21 | #include <vector> | ||
2503 | 22 | |||
2504 | 23 | #include <mir_toolkit/mir_prompt_session.h> | ||
2505 | 24 | |||
2506 | 25 | #include "appid.h" | ||
2507 | 26 | #include "type-tagger.h" | ||
2508 | 27 | |||
2509 | 28 | #pragma once | ||
2510 | 29 | #pragma GCC visibility push(default) | ||
2511 | 30 | |||
2512 | 31 | namespace ubuntu | ||
2513 | 32 | { | ||
2514 | 33 | namespace app_launch | ||
2515 | 34 | { | ||
2516 | 35 | |||
2517 | 36 | class Registry; | ||
2518 | 37 | |||
2519 | 38 | class Helper | ||
2520 | 39 | { | ||
2521 | 40 | public: | ||
2522 | 41 | struct TypeTag; | ||
2523 | 42 | struct URLTag; | ||
2524 | 43 | |||
2525 | 44 | typedef TypeTagger<TypeTag, std::string> Type; | ||
2526 | 45 | typedef TypeTagger<URLTag, std::string> URL; | ||
2527 | 46 | |||
2528 | 47 | static std::shared_ptr<Helper> create(Type type, AppID appid, std::shared_ptr<Registry> registry); | ||
2529 | 48 | |||
2530 | 49 | virtual AppID appId() = 0; | ||
2531 | 50 | |||
2532 | 51 | class Instance | ||
2533 | 52 | { | ||
2534 | 53 | public: | ||
2535 | 54 | /* Query lifecycle */ | ||
2536 | 55 | virtual bool isRunning() = 0; | ||
2537 | 56 | |||
2538 | 57 | /* Manage lifecycle */ | ||
2539 | 58 | virtual void stop() = 0; | ||
2540 | 59 | }; | ||
2541 | 60 | |||
2542 | 61 | virtual bool hasInstances() = 0; | ||
2543 | 62 | virtual std::vector<std::shared_ptr<Instance>> instances() = 0; | ||
2544 | 63 | |||
2545 | 64 | virtual std::shared_ptr<Instance> launch(std::vector<URL> urls = {}) = 0; | ||
2546 | 65 | virtual std::shared_ptr<Instance> launch(MirPromptSession* session, std::vector<URL> urls = {}) = 0; | ||
2547 | 66 | }; | ||
2548 | 67 | |||
2549 | 68 | }; // namespace app_launch | ||
2550 | 69 | }; // namespace ubuntu | ||
2551 | 70 | |||
2552 | 71 | #pragma GCC visibility pop | ||
2553 | 0 | 72 | ||
2554 | === modified file 'libubuntu-app-launch/libubuntu-app-launch.map' | |||
2555 | --- libubuntu-app-launch/libubuntu-app-launch.map 2014-11-21 15:57:08 +0000 | |||
2556 | +++ libubuntu-app-launch/libubuntu-app-launch.map 2016-03-04 11:34:19 +0000 | |||
2557 | @@ -1,6 +1,23 @@ | |||
2558 | 1 | { | 1 | { |
2559 | 2 | global: | 2 | global: |
2560 | 3 | ubuntu_app_launch_*; | 3 | ubuntu_app_launch_*; |
2561 | 4 | extern "C++" { | ||
2562 | 5 | ubuntu::app_launch::Registry::[!I]*; | ||
2563 | 6 | typeinfo?for?ubuntu::app_launch::Registry; | ||
2564 | 7 | typeinfo?name?for?ubuntu::app_launch::Registry; | ||
2565 | 8 | ubuntu::app_launch::Application::*; | ||
2566 | 9 | typeinfo?for?ubuntu::app_launch::Application; | ||
2567 | 10 | typeinfo?name?for?ubuntu::app_launch::Application; | ||
2568 | 11 | ubuntu::app_launch::AppID::*; | ||
2569 | 12 | typeinfo?for?ubuntu::app_launch::AppID; | ||
2570 | 13 | typeinfo?name?for?ubuntu::app_launch::AppID; | ||
2571 | 14 | ubuntu::app_launch::Helper::*; | ||
2572 | 15 | typeinfo?for?ubuntu::app_launch::Helper; | ||
2573 | 16 | typeinfo?name?for?ubuntu::app_launch::Helper; | ||
2574 | 17 | }; | ||
2575 | 4 | local: | 18 | local: |
2576 | 5 | *; | 19 | *; |
2577 | 20 | extern "C++" { | ||
2578 | 21 | *; | ||
2579 | 22 | }; | ||
2580 | 6 | }; | 23 | }; |
2581 | 7 | 24 | ||
2582 | === added file 'libubuntu-app-launch/registry-impl.cpp' | |||
2583 | --- libubuntu-app-launch/registry-impl.cpp 1970-01-01 00:00:00 +0000 | |||
2584 | +++ libubuntu-app-launch/registry-impl.cpp 2016-03-04 11:34:19 +0000 | |||
2585 | @@ -0,0 +1,185 @@ | |||
2586 | 1 | /* | ||
2587 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2588 | 3 | * | ||
2589 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2590 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2591 | 6 | * by the Free Software Foundation. | ||
2592 | 7 | * | ||
2593 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2594 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2595 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2596 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2597 | 12 | * | ||
2598 | 13 | * You should have received a copy of the GNU General Public License along | ||
2599 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2600 | 15 | * | ||
2601 | 16 | * Authors: | ||
2602 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2603 | 18 | */ | ||
2604 | 19 | |||
2605 | 20 | #include "registry-impl.h" | ||
2606 | 21 | |||
2607 | 22 | namespace ubuntu | ||
2608 | 23 | { | ||
2609 | 24 | namespace app_launch | ||
2610 | 25 | { | ||
2611 | 26 | |||
2612 | 27 | Registry::Impl::Impl(Registry* registry) | ||
2613 | 28 | : thread([]() {}, | ||
2614 | 29 | [this]() { | ||
2615 | 30 | _clickUser.reset(); | ||
2616 | 31 | _clickDB.reset(); | ||
2617 | 32 | |||
2618 | 33 | g_dbus_connection_flush_sync(_dbus.get(), nullptr, nullptr); | ||
2619 | 34 | _dbus.reset(); | ||
2620 | 35 | }) | ||
2621 | 36 | , _registry(registry) | ||
2622 | 37 | // _manager(nullptr) | ||
2623 | 38 | { | ||
2624 | 39 | auto cancel = thread.getCancellable(); | ||
2625 | 40 | _dbus = thread.executeOnThread<std::shared_ptr<GDBusConnection>>([cancel]() { | ||
2626 | 41 | return std::shared_ptr<GDBusConnection>(g_bus_get_sync(G_BUS_TYPE_SESSION, cancel.get(), nullptr), | ||
2627 | 42 | [](GDBusConnection* bus) { g_clear_object(&bus); }); | ||
2628 | 43 | }); | ||
2629 | 44 | } | ||
2630 | 45 | |||
2631 | 46 | void Registry::Impl::initClick() | ||
2632 | 47 | { | ||
2633 | 48 | if (_clickDB && _clickUser) | ||
2634 | 49 | { | ||
2635 | 50 | return; | ||
2636 | 51 | } | ||
2637 | 52 | |||
2638 | 53 | auto init = thread.executeOnThread<bool>([this]() { | ||
2639 | 54 | GError* error = nullptr; | ||
2640 | 55 | |||
2641 | 56 | if (!_clickDB) | ||
2642 | 57 | { | ||
2643 | 58 | _clickDB = std::shared_ptr<ClickDB>(click_db_new(), [](ClickDB* db) { g_clear_object(&db); }); | ||
2644 | 59 | /* If TEST_CLICK_DB is unset, this reads the system database. */ | ||
2645 | 60 | click_db_read(_clickDB.get(), g_getenv("TEST_CLICK_DB"), &error); | ||
2646 | 61 | |||
2647 | 62 | if (error != nullptr) | ||
2648 | 63 | { | ||
2649 | 64 | auto perror = std::shared_ptr<GError>(error, [](GError* error) { g_error_free(error); }); | ||
2650 | 65 | throw std::runtime_error(perror->message); | ||
2651 | 66 | } | ||
2652 | 67 | } | ||
2653 | 68 | |||
2654 | 69 | if (!_clickUser) | ||
2655 | 70 | { | ||
2656 | 71 | _clickUser = | ||
2657 | 72 | std::shared_ptr<ClickUser>(click_user_new_for_user(_clickDB.get(), g_getenv("TEST_CLICK_USER"), &error), | ||
2658 | 73 | [](ClickUser* user) { g_clear_object(&user); }); | ||
2659 | 74 | |||
2660 | 75 | if (error != nullptr) | ||
2661 | 76 | { | ||
2662 | 77 | auto perror = std::shared_ptr<GError>(error, [](GError* error) { g_error_free(error); }); | ||
2663 | 78 | throw std::runtime_error(perror->message); | ||
2664 | 79 | } | ||
2665 | 80 | } | ||
2666 | 81 | |||
2667 | 82 | return true; | ||
2668 | 83 | }); | ||
2669 | 84 | |||
2670 | 85 | if (!init) | ||
2671 | 86 | { | ||
2672 | 87 | throw std::runtime_error("Unable to initialize the Click Database"); | ||
2673 | 88 | } | ||
2674 | 89 | } | ||
2675 | 90 | |||
2676 | 91 | std::shared_ptr<JsonObject> Registry::Impl::getClickManifest(const std::string& package) | ||
2677 | 92 | { | ||
2678 | 93 | initClick(); | ||
2679 | 94 | |||
2680 | 95 | auto retval = thread.executeOnThread<std::shared_ptr<JsonObject>>([this, package]() { | ||
2681 | 96 | GError* error = nullptr; | ||
2682 | 97 | auto retval = std::shared_ptr<JsonObject>(click_user_get_manifest(_clickUser.get(), package.c_str(), &error), | ||
2683 | 98 | [](JsonObject* obj) { | ||
2684 | 99 | if (obj != nullptr) | ||
2685 | 100 | { | ||
2686 | 101 | json_object_unref(obj); | ||
2687 | 102 | } | ||
2688 | 103 | }); | ||
2689 | 104 | |||
2690 | 105 | if (error != nullptr) | ||
2691 | 106 | { | ||
2692 | 107 | auto perror = std::shared_ptr<GError>(error, [](GError* error) { g_error_free(error); }); | ||
2693 | 108 | throw std::runtime_error(perror->message); | ||
2694 | 109 | } | ||
2695 | 110 | |||
2696 | 111 | return retval; | ||
2697 | 112 | }); | ||
2698 | 113 | |||
2699 | 114 | if (!retval) | ||
2700 | 115 | throw std::runtime_error("Unable to get Click manifest for package: " + package); | ||
2701 | 116 | |||
2702 | 117 | return retval; | ||
2703 | 118 | } | ||
2704 | 119 | |||
2705 | 120 | std::list<AppID::Package> Registry::Impl::getClickPackages() | ||
2706 | 121 | { | ||
2707 | 122 | initClick(); | ||
2708 | 123 | |||
2709 | 124 | return thread.executeOnThread<std::list<AppID::Package>>([this]() { | ||
2710 | 125 | GError* error = nullptr; | ||
2711 | 126 | GList* pkgs = click_db_get_packages(_clickDB.get(), FALSE, &error); | ||
2712 | 127 | |||
2713 | 128 | if (error != nullptr) | ||
2714 | 129 | { | ||
2715 | 130 | auto perror = std::shared_ptr<GError>(error, [](GError* error) { g_error_free(error); }); | ||
2716 | 131 | throw std::runtime_error(perror->message); | ||
2717 | 132 | } | ||
2718 | 133 | |||
2719 | 134 | std::list<AppID::Package> list; | ||
2720 | 135 | for (GList* item = pkgs; item != NULL; item = g_list_next(item)) | ||
2721 | 136 | { | ||
2722 | 137 | list.emplace_back(AppID::Package::from_raw((gchar*)item->data)); | ||
2723 | 138 | } | ||
2724 | 139 | |||
2725 | 140 | g_list_free_full(pkgs, g_free); | ||
2726 | 141 | return list; | ||
2727 | 142 | }); | ||
2728 | 143 | } | ||
2729 | 144 | |||
2730 | 145 | std::string Registry::Impl::getClickDir(const std::string& package) | ||
2731 | 146 | { | ||
2732 | 147 | initClick(); | ||
2733 | 148 | |||
2734 | 149 | return thread.executeOnThread<std::string>([this, package]() { | ||
2735 | 150 | GError* error = nullptr; | ||
2736 | 151 | auto dir = click_user_get_path(_clickUser.get(), package.c_str(), &error); | ||
2737 | 152 | |||
2738 | 153 | if (error != nullptr) | ||
2739 | 154 | { | ||
2740 | 155 | auto perror = std::shared_ptr<GError>(error, [](GError* error) { g_error_free(error); }); | ||
2741 | 156 | throw std::runtime_error(perror->message); | ||
2742 | 157 | } | ||
2743 | 158 | |||
2744 | 159 | std::string cppdir(dir); | ||
2745 | 160 | g_free(dir); | ||
2746 | 161 | return cppdir; | ||
2747 | 162 | }); | ||
2748 | 163 | } | ||
2749 | 164 | |||
2750 | 165 | #if 0 | ||
2751 | 166 | void | ||
2752 | 167 | Registry::Impl::setManager (Registry::Manager* manager) | ||
2753 | 168 | { | ||
2754 | 169 | if (_manager != nullptr) | ||
2755 | 170 | { | ||
2756 | 171 | throw std::runtime_error("Already have a manager and trying to set another"); | ||
2757 | 172 | } | ||
2758 | 173 | |||
2759 | 174 | _manager = manager; | ||
2760 | 175 | } | ||
2761 | 176 | |||
2762 | 177 | void | ||
2763 | 178 | Registry::Impl::clearManager () | ||
2764 | 179 | { | ||
2765 | 180 | _manager = nullptr; | ||
2766 | 181 | } | ||
2767 | 182 | #endif | ||
2768 | 183 | |||
2769 | 184 | }; // namespace app_launch | ||
2770 | 185 | }; // namespace ubuntu | ||
2771 | 0 | 186 | ||
2772 | === added file 'libubuntu-app-launch/registry-impl.h' | |||
2773 | --- libubuntu-app-launch/registry-impl.h 1970-01-01 00:00:00 +0000 | |||
2774 | +++ libubuntu-app-launch/registry-impl.h 2016-03-04 11:34:19 +0000 | |||
2775 | @@ -0,0 +1,69 @@ | |||
2776 | 1 | /* | ||
2777 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2778 | 3 | * | ||
2779 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2780 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2781 | 6 | * by the Free Software Foundation. | ||
2782 | 7 | * | ||
2783 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2784 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2785 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2786 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2787 | 12 | * | ||
2788 | 13 | * You should have received a copy of the GNU General Public License along | ||
2789 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2790 | 15 | * | ||
2791 | 16 | * Authors: | ||
2792 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2793 | 18 | */ | ||
2794 | 19 | |||
2795 | 20 | #include "registry.h" | ||
2796 | 21 | #include "glib-thread.h" | ||
2797 | 22 | |||
2798 | 23 | #include <json-glib/json-glib.h> | ||
2799 | 24 | #include <click.h> | ||
2800 | 25 | #include <gio/gio.h> | ||
2801 | 26 | |||
2802 | 27 | #pragma once | ||
2803 | 28 | |||
2804 | 29 | namespace ubuntu | ||
2805 | 30 | { | ||
2806 | 31 | namespace app_launch | ||
2807 | 32 | { | ||
2808 | 33 | |||
2809 | 34 | class Registry::Impl | ||
2810 | 35 | { | ||
2811 | 36 | public: | ||
2812 | 37 | Impl(Registry* registry); | ||
2813 | 38 | virtual ~Impl() | ||
2814 | 39 | { | ||
2815 | 40 | thread.quit(); | ||
2816 | 41 | } | ||
2817 | 42 | |||
2818 | 43 | std::shared_ptr<JsonObject> getClickManifest(const std::string& package); | ||
2819 | 44 | std::list<AppID::Package> getClickPackages(); | ||
2820 | 45 | std::string getClickDir(const std::string& package); | ||
2821 | 46 | |||
2822 | 47 | #if 0 | ||
2823 | 48 | void setManager (Registry::Manager* manager); | ||
2824 | 49 | void clearManager (); | ||
2825 | 50 | #endif | ||
2826 | 51 | |||
2827 | 52 | GLib::ContextThread thread; | ||
2828 | 53 | |||
2829 | 54 | private: | ||
2830 | 55 | Registry* _registry; | ||
2831 | 56 | #if 0 | ||
2832 | 57 | Registry::Manager* _manager; | ||
2833 | 58 | #endif | ||
2834 | 59 | |||
2835 | 60 | std::shared_ptr<ClickDB> _clickDB; | ||
2836 | 61 | std::shared_ptr<ClickUser> _clickUser; | ||
2837 | 62 | |||
2838 | 63 | std::shared_ptr<GDBusConnection> _dbus; | ||
2839 | 64 | |||
2840 | 65 | void initClick(); | ||
2841 | 66 | }; | ||
2842 | 67 | |||
2843 | 68 | }; // namespace app_launch | ||
2844 | 69 | }; // namespace ubuntu | ||
2845 | 0 | 70 | ||
2846 | === added file 'libubuntu-app-launch/registry.cpp' | |||
2847 | --- libubuntu-app-launch/registry.cpp 1970-01-01 00:00:00 +0000 | |||
2848 | +++ libubuntu-app-launch/registry.cpp 2016-03-04 11:34:19 +0000 | |||
2849 | @@ -0,0 +1,99 @@ | |||
2850 | 1 | /* | ||
2851 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2852 | 3 | * | ||
2853 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2854 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2855 | 6 | * by the Free Software Foundation. | ||
2856 | 7 | * | ||
2857 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2858 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2859 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2860 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2861 | 12 | * | ||
2862 | 13 | * You should have received a copy of the GNU General Public License along | ||
2863 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2864 | 15 | * | ||
2865 | 16 | * Authors: | ||
2866 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2867 | 18 | */ | ||
2868 | 19 | |||
2869 | 20 | #include "registry.h" | ||
2870 | 21 | #include "registry-impl.h" | ||
2871 | 22 | |||
2872 | 23 | #include "application-impl-click.h" | ||
2873 | 24 | #include "application-impl-legacy.h" | ||
2874 | 25 | #include "application-impl-libertine.h" | ||
2875 | 26 | |||
2876 | 27 | #include "helper-impl-click.h" | ||
2877 | 28 | |||
2878 | 29 | namespace ubuntu | ||
2879 | 30 | { | ||
2880 | 31 | namespace app_launch | ||
2881 | 32 | { | ||
2882 | 33 | |||
2883 | 34 | Registry::Registry() | ||
2884 | 35 | { | ||
2885 | 36 | impl = std::unique_ptr<Impl>(new Impl(this)); | ||
2886 | 37 | } | ||
2887 | 38 | |||
2888 | 39 | Registry::~Registry() | ||
2889 | 40 | { | ||
2890 | 41 | } | ||
2891 | 42 | |||
2892 | 43 | std::list<std::shared_ptr<Application>> Registry::runningApps(std::shared_ptr<Registry> connection) | ||
2893 | 44 | { | ||
2894 | 45 | return connection->impl->thread.executeOnThread<std::list<std::shared_ptr<Application>>>( | ||
2895 | 46 | [connection]() -> std::list<std::shared_ptr<Application>> { | ||
2896 | 47 | auto strv = ubuntu_app_launch_list_running_apps(); | ||
2897 | 48 | if (strv == nullptr) | ||
2898 | 49 | { | ||
2899 | 50 | return {}; | ||
2900 | 51 | } | ||
2901 | 52 | |||
2902 | 53 | std::list<std::shared_ptr<Application>> list; | ||
2903 | 54 | for (int i = 0; strv[i] != nullptr; i++) | ||
2904 | 55 | { | ||
2905 | 56 | auto appid = AppID::find(strv[i]); | ||
2906 | 57 | auto app = Application::create(appid, connection); | ||
2907 | 58 | list.push_back(app); | ||
2908 | 59 | } | ||
2909 | 60 | |||
2910 | 61 | g_strfreev(strv); | ||
2911 | 62 | |||
2912 | 63 | return list; | ||
2913 | 64 | }); | ||
2914 | 65 | } | ||
2915 | 66 | |||
2916 | 67 | std::list<std::shared_ptr<Application>> Registry::installedApps(std::shared_ptr<Registry> connection) | ||
2917 | 68 | { | ||
2918 | 69 | std::list<std::shared_ptr<Application>> list; | ||
2919 | 70 | |||
2920 | 71 | list.splice(list.begin(), app_impls::Click::list(connection)); | ||
2921 | 72 | list.splice(list.begin(), app_impls::Legacy::list(connection)); | ||
2922 | 73 | list.splice(list.begin(), app_impls::Libertine::list(connection)); | ||
2923 | 74 | |||
2924 | 75 | return list; | ||
2925 | 76 | } | ||
2926 | 77 | |||
2927 | 78 | std::list<std::shared_ptr<Helper>> Registry::runningHelpers(Helper::Type type, std::shared_ptr<Registry> connection) | ||
2928 | 79 | { | ||
2929 | 80 | std::list<std::shared_ptr<Helper>> list; | ||
2930 | 81 | |||
2931 | 82 | list.splice(list.begin(), helper_impls::Click::running(type, connection)); | ||
2932 | 83 | |||
2933 | 84 | return list; | ||
2934 | 85 | } | ||
2935 | 86 | |||
2936 | 87 | std::shared_ptr<Registry> defaultRegistry; | ||
2937 | 88 | std::shared_ptr<Registry> Registry::getDefault() | ||
2938 | 89 | { | ||
2939 | 90 | if (!defaultRegistry) | ||
2940 | 91 | { | ||
2941 | 92 | defaultRegistry = std::make_shared<Registry>(); | ||
2942 | 93 | } | ||
2943 | 94 | |||
2944 | 95 | return defaultRegistry; | ||
2945 | 96 | } | ||
2946 | 97 | |||
2947 | 98 | }; // namespace app_launch | ||
2948 | 99 | }; // namespace ubuntu | ||
2949 | 0 | 100 | ||
2950 | === added file 'libubuntu-app-launch/registry.h' | |||
2951 | --- libubuntu-app-launch/registry.h 1970-01-01 00:00:00 +0000 | |||
2952 | +++ libubuntu-app-launch/registry.h 2016-03-04 11:34:19 +0000 | |||
2953 | @@ -0,0 +1,91 @@ | |||
2954 | 1 | /* | ||
2955 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2956 | 3 | * | ||
2957 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2958 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2959 | 6 | * by the Free Software Foundation. | ||
2960 | 7 | * | ||
2961 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2962 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2963 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2964 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2965 | 12 | * | ||
2966 | 13 | * You should have received a copy of the GNU General Public License along | ||
2967 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2968 | 15 | * | ||
2969 | 16 | * Authors: | ||
2970 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
2971 | 18 | */ | ||
2972 | 19 | |||
2973 | 20 | #include <core/signal.h> | ||
2974 | 21 | #include <functional> | ||
2975 | 22 | #include <list> | ||
2976 | 23 | #include <memory> | ||
2977 | 24 | |||
2978 | 25 | #include "application.h" | ||
2979 | 26 | #include "helper.h" | ||
2980 | 27 | |||
2981 | 28 | #pragma once | ||
2982 | 29 | #pragma GCC visibility push(default) | ||
2983 | 30 | |||
2984 | 31 | namespace ubuntu | ||
2985 | 32 | { | ||
2986 | 33 | namespace app_launch | ||
2987 | 34 | { | ||
2988 | 35 | |||
2989 | 36 | class Registry | ||
2990 | 37 | { | ||
2991 | 38 | public: | ||
2992 | 39 | enum class FailureType | ||
2993 | 40 | { | ||
2994 | 41 | CRASH, | ||
2995 | 42 | START_FAILURE, | ||
2996 | 43 | }; | ||
2997 | 44 | |||
2998 | 45 | Registry(); | ||
2999 | 46 | virtual ~Registry(); | ||
3000 | 47 | |||
3001 | 48 | /* Lots of application lists */ | ||
3002 | 49 | static std::list<std::shared_ptr<Application>> runningApps(std::shared_ptr<Registry> registry = getDefault()); | ||
3003 | 50 | static std::list<std::shared_ptr<Application>> installedApps(std::shared_ptr<Registry> registry = getDefault()); | ||
3004 | 51 | |||
3005 | 52 | #if 0 /* TODO -- In next MR */ | ||
3006 | 53 | /* Signals to discover what is happening to apps */ | ||
3007 | 54 | core::Signal<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>> appStarted; | ||
3008 | 55 | core::Signal<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>> appStopped; | ||
3009 | 56 | core::Signal<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>, FailureType> appFailed; | ||
3010 | 57 | core::Signal<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>> appPaused; | ||
3011 | 58 | core::Signal<std::shared_ptr<Application>, std::shared_ptr<Application::Instance>> appResumed; | ||
3012 | 59 | |||
3013 | 60 | /* The Application Manager, almost always if you're not Unity8, don't | ||
3014 | 61 | use this API. Testing is a special case. */ | ||
3015 | 62 | class Manager | ||
3016 | 63 | { | ||
3017 | 64 | virtual bool focusRequest (std::shared_ptr<Application> app, std::shared_ptr<Application::Instance> instance) = 0; | ||
3018 | 65 | virtual bool startingRequest (std::shared_ptr<Application> app, std::shared_ptr<Application::Instance> instance) = 0; | ||
3019 | 66 | |||
3020 | 67 | protected: | ||
3021 | 68 | Manager() = default; | ||
3022 | 69 | }; | ||
3023 | 70 | |||
3024 | 71 | void setManager (Manager* manager); | ||
3025 | 72 | void clearManager (); | ||
3026 | 73 | #endif | ||
3027 | 74 | |||
3028 | 75 | /* Helper Lists */ | ||
3029 | 76 | static std::list<std::shared_ptr<Helper>> runningHelpers(Helper::Type type, | ||
3030 | 77 | std::shared_ptr<Registry> registry = getDefault()); | ||
3031 | 78 | |||
3032 | 79 | /* Default Junk */ | ||
3033 | 80 | static std::shared_ptr<Registry> getDefault(); | ||
3034 | 81 | static void clearDefault(); | ||
3035 | 82 | |||
3036 | 83 | /* Hide our implementation */ | ||
3037 | 84 | class Impl; | ||
3038 | 85 | std::unique_ptr<Impl> impl; | ||
3039 | 86 | }; | ||
3040 | 87 | |||
3041 | 88 | }; // namespace app_launch | ||
3042 | 89 | }; // namespace ubuntu | ||
3043 | 90 | |||
3044 | 91 | #pragma GCC visibility pop | ||
3045 | 0 | 92 | ||
3046 | === added file 'libubuntu-app-launch/type-tagger.h' | |||
3047 | --- libubuntu-app-launch/type-tagger.h 1970-01-01 00:00:00 +0000 | |||
3048 | +++ libubuntu-app-launch/type-tagger.h 2016-03-04 11:34:19 +0000 | |||
3049 | @@ -0,0 +1,37 @@ | |||
3050 | 1 | #pragma once | ||
3051 | 2 | |||
3052 | 3 | namespace ubuntu | ||
3053 | 4 | { | ||
3054 | 5 | namespace app_launch | ||
3055 | 6 | { | ||
3056 | 7 | |||
3057 | 8 | template <typename Tag, typename T> | ||
3058 | 9 | class TypeTagger | ||
3059 | 10 | { | ||
3060 | 11 | public: | ||
3061 | 12 | static TypeTagger<Tag, T> from_raw(const T& value) | ||
3062 | 13 | { | ||
3063 | 14 | return TypeTagger<Tag, T>(value); | ||
3064 | 15 | } | ||
3065 | 16 | const T& value() const | ||
3066 | 17 | { | ||
3067 | 18 | return _value; | ||
3068 | 19 | } | ||
3069 | 20 | operator T() const | ||
3070 | 21 | { | ||
3071 | 22 | return _value; | ||
3072 | 23 | } | ||
3073 | 24 | ~TypeTagger() | ||
3074 | 25 | { | ||
3075 | 26 | } | ||
3076 | 27 | |||
3077 | 28 | private: | ||
3078 | 29 | TypeTagger(const T& value) | ||
3079 | 30 | : _value(value) | ||
3080 | 31 | { | ||
3081 | 32 | } | ||
3082 | 33 | T _value; | ||
3083 | 34 | }; | ||
3084 | 35 | |||
3085 | 36 | }; // namespace app_launch | ||
3086 | 37 | }; // namespace ubuntu | ||
3087 | 0 | 38 | ||
3088 | === modified file 'libubuntu-app-launch/ubuntu-app-launch.c' | |||
3089 | --- libubuntu-app-launch/ubuntu-app-launch.c 2015-08-17 21:38:29 +0000 | |||
3090 | +++ libubuntu-app-launch/ubuntu-app-launch.c 2016-03-04 11:34:19 +0000 | |||
3091 | @@ -38,7 +38,6 @@ | |||
3092 | 38 | 38 | ||
3093 | 39 | static void apps_for_job (GDBusConnection * con, const gchar * name, GArray * apps, gboolean truncate_legacy); | 39 | static void apps_for_job (GDBusConnection * con, const gchar * name, GArray * apps, gboolean truncate_legacy); |
3094 | 40 | static void free_helper (gpointer value); | 40 | static void free_helper (gpointer value); |
3095 | 41 | static GList * pids_for_appid (const gchar * appid); | ||
3096 | 42 | int kill (pid_t pid, int signal); | 41 | int kill (pid_t pid, int signal); |
3097 | 43 | static gchar * escape_dbus_string (const gchar * input); | 42 | static gchar * escape_dbus_string (const gchar * input); |
3098 | 44 | 43 | ||
3099 | @@ -588,7 +587,7 @@ | |||
3100 | 588 | 587 | ||
3101 | 589 | do { | 588 | do { |
3102 | 590 | hash_table_size = g_hash_table_size(pidssignaled); | 589 | hash_table_size = g_hash_table_size(pidssignaled); |
3104 | 591 | GList * pidlist = pids_for_appid(appid); | 590 | GList * pidlist = ubuntu_app_launch_get_pids(appid); |
3105 | 592 | GList * iter; | 591 | GList * iter; |
3106 | 593 | 592 | ||
3107 | 594 | if (pidlist == NULL) { | 593 | if (pidlist == NULL) { |
3108 | @@ -1506,9 +1505,10 @@ | |||
3109 | 1506 | /* Get the PIDs for an AppID. If it's click or legacy single instance that's | 1505 | /* Get the PIDs for an AppID. If it's click or legacy single instance that's |
3110 | 1507 | a simple call to the helper. But if it's not, we have to make a call for | 1506 | a simple call to the helper. But if it's not, we have to make a call for |
3111 | 1508 | each instance of the app that we have running. */ | 1507 | each instance of the app that we have running. */ |
3114 | 1509 | static GList * | 1508 | GList * |
3115 | 1510 | pids_for_appid (const gchar * appid) | 1509 | ubuntu_app_launch_get_pids (const gchar * appid) |
3116 | 1511 | { | 1510 | { |
3117 | 1511 | g_return_val_if_fail(appid != NULL, NULL); | ||
3118 | 1512 | ual_tracepoint(pids_list_start, appid); | 1512 | ual_tracepoint(pids_list_start, appid); |
3119 | 1513 | 1513 | ||
3120 | 1514 | GDBusConnection * cgmanager = cgroup_manager_connection(); | 1514 | GDBusConnection * cgmanager = cgroup_manager_connection(); |
3121 | @@ -1522,7 +1522,7 @@ | |||
3122 | 1522 | 1522 | ||
3123 | 1523 | ual_tracepoint(pids_list_finished, appid, g_list_length(pids)); | 1523 | ual_tracepoint(pids_list_finished, appid, g_list_length(pids)); |
3124 | 1524 | return pids; | 1524 | return pids; |
3126 | 1525 | } else if (!is_libertine(appid) && legacy_single_instance(appid)) { | 1525 | } else if (is_libertine(appid) || legacy_single_instance(appid)) { |
3127 | 1526 | gchar * jobname = g_strdup_printf("%s-", appid); | 1526 | gchar * jobname = g_strdup_printf("%s-", appid); |
3128 | 1527 | GList * pids = pids_from_cgroup(cgmanager, "application-legacy", jobname); | 1527 | GList * pids = pids_from_cgroup(cgmanager, "application-legacy", jobname); |
3129 | 1528 | g_free(jobname); | 1528 | g_free(jobname); |
3130 | @@ -1572,7 +1572,7 @@ | |||
3131 | 1572 | return FALSE; | 1572 | return FALSE; |
3132 | 1573 | } | 1573 | } |
3133 | 1574 | 1574 | ||
3135 | 1575 | GList * pidlist = pids_for_appid(appid); | 1575 | GList * pidlist = ubuntu_app_launch_get_pids(appid); |
3136 | 1576 | GList * head; | 1576 | GList * head; |
3137 | 1577 | 1577 | ||
3138 | 1578 | for (head = pidlist; head != NULL; head = g_list_next(head)) { | 1578 | for (head = pidlist; head != NULL; head = g_list_next(head)) { |
3139 | @@ -2403,7 +2403,7 @@ | |||
3140 | 2403 | const gchar * job_name = g_getenv("UPSTART_JOB"); | 2403 | const gchar * job_name = g_getenv("UPSTART_JOB"); |
3141 | 2404 | const gchar * instance_name = g_getenv("UPSTART_INSTANCE"); | 2404 | const gchar * instance_name = g_getenv("UPSTART_INSTANCE"); |
3142 | 2405 | const gchar * demangler = g_getenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); | 2405 | const gchar * demangler = g_getenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); |
3144 | 2406 | g_return_if_fail(job_name != NULL); | 2406 | g_return_val_if_fail(job_name != NULL, FALSE); |
3145 | 2407 | 2407 | ||
3146 | 2408 | GError * error = NULL; | 2408 | GError * error = NULL; |
3147 | 2409 | GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); | 2409 | GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); |
3148 | 2410 | 2410 | ||
3149 | === modified file 'libubuntu-app-launch/ubuntu-app-launch.h' | |||
3150 | --- libubuntu-app-launch/ubuntu-app-launch.h 2015-08-10 14:19:05 +0000 | |||
3151 | +++ libubuntu-app-launch/ubuntu-app-launch.h 2016-03-04 11:34:19 +0000 | |||
3152 | @@ -388,6 +388,18 @@ | |||
3153 | 388 | GPid ubuntu_app_launch_get_primary_pid (const gchar * appid); | 388 | GPid ubuntu_app_launch_get_primary_pid (const gchar * appid); |
3154 | 389 | 389 | ||
3155 | 390 | /** | 390 | /** |
3156 | 391 | * ubuntu_app_launch_get_pids: | ||
3157 | 392 | * @appid: ID of the application to look for | ||
3158 | 393 | * | ||
3159 | 394 | * Checks to see if an application is running and returns | ||
3160 | 395 | * the PIDs associated with it. | ||
3161 | 396 | * | ||
3162 | 397 | * Return Value: (transfer full) (element-type GLib.Pid): A list | ||
3163 | 398 | * of PIDs associated with @appid, empty if not running. | ||
3164 | 399 | */ | ||
3165 | 400 | GList * ubuntu_app_launch_get_pids (const gchar * appid); | ||
3166 | 401 | |||
3167 | 402 | /** | ||
3168 | 391 | * ubuntu_app_launch_pid_in_app_id: | 403 | * ubuntu_app_launch_pid_in_app_id: |
3169 | 392 | * @pid: Process ID to check on | 404 | * @pid: Process ID to check on |
3170 | 393 | * @appid: ID of the application to look in | 405 | * @appid: ID of the application to look in |
3171 | 394 | 406 | ||
3172 | === modified file 'tests/CMakeLists.txt' | |||
3173 | --- tests/CMakeLists.txt 2015-06-26 17:26:50 +0000 | |||
3174 | +++ tests/CMakeLists.txt 2016-03-04 11:34:19 +0000 | |||
3175 | @@ -42,6 +42,11 @@ | |||
3176 | 42 | mir-mock.cpp) | 42 | mir-mock.cpp) |
3177 | 43 | target_link_libraries (libual-test gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} ubuntu-launcher) | 43 | target_link_libraries (libual-test gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} ubuntu-launcher) |
3178 | 44 | 44 | ||
3179 | 45 | add_executable (libual-cpp-test | ||
3180 | 46 | libual-cpp-test.cc | ||
3181 | 47 | mir-mock.cpp) | ||
3182 | 48 | target_link_libraries (libual-cpp-test gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} ubuntu-launcher) | ||
3183 | 49 | |||
3184 | 45 | add_executable (data-spew | 50 | add_executable (data-spew |
3185 | 46 | data-spew.c) | 51 | data-spew.c) |
3186 | 47 | target_link_libraries (data-spew ${GLIB2_LIBRARIES}) | 52 | target_link_libraries (data-spew ${GLIB2_LIBRARIES}) |
3187 | @@ -50,6 +55,16 @@ | |||
3188 | 50 | socket-tool.c) | 55 | socket-tool.c) |
3189 | 51 | 56 | ||
3190 | 52 | add_test (NAME libual-test COMMAND libual-test) | 57 | add_test (NAME libual-test COMMAND libual-test) |
3191 | 58 | add_test (NAME libual-cpp-test COMMAND libual-cpp-test) | ||
3192 | 59 | |||
3193 | 60 | # Application Info Desktop | ||
3194 | 61 | |||
3195 | 62 | add_executable (application-info-desktop-test | ||
3196 | 63 | application-info-desktop.cpp | ||
3197 | 64 | ${CMAKE_SOURCE_DIR}/libubuntu-app-launch/application-info-desktop.cpp) | ||
3198 | 65 | target_link_libraries (application-info-desktop-test gtest ${GTEST_LIBS} ubuntu-launcher) | ||
3199 | 66 | |||
3200 | 67 | add_test (NAME application-info-desktop-test COMMAND application-info-desktop-test) | ||
3201 | 53 | 68 | ||
3202 | 54 | # Failure Test | 69 | # Failure Test |
3203 | 55 | 70 | ||
3204 | @@ -101,3 +116,8 @@ | |||
3205 | 101 | configure_file ("xmir-helper-test.in" "${CMAKE_CURRENT_BINARY_DIR}/xmir-helper-test" @ONLY) | 116 | configure_file ("xmir-helper-test.in" "${CMAKE_CURRENT_BINARY_DIR}/xmir-helper-test" @ONLY) |
3206 | 102 | add_test (xmir-helper-test xmir-helper-test) | 117 | add_test (xmir-helper-test xmir-helper-test) |
3207 | 103 | 118 | ||
3208 | 119 | # Formatted code | ||
3209 | 120 | |||
3210 | 121 | add_custom_target(format-tests | ||
3211 | 122 | COMMAND clang-format -i -style=file libual-cpp-test.cc | ||
3212 | 123 | ) | ||
3213 | 104 | 124 | ||
3214 | === added file 'tests/application-info-desktop.cpp' | |||
3215 | --- tests/application-info-desktop.cpp 1970-01-01 00:00:00 +0000 | |||
3216 | +++ tests/application-info-desktop.cpp 2016-03-04 11:34:19 +0000 | |||
3217 | @@ -0,0 +1,148 @@ | |||
3218 | 1 | /* | ||
3219 | 2 | * Copyright © 2016 Canonical Ltd. | ||
3220 | 3 | * | ||
3221 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3222 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3223 | 6 | * by the Free Software Foundation. | ||
3224 | 7 | * | ||
3225 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3226 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3227 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3228 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3229 | 12 | * | ||
3230 | 13 | * You should have received a copy of the GNU General Public License along | ||
3231 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3232 | 15 | * | ||
3233 | 16 | * Authors: | ||
3234 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
3235 | 18 | */ | ||
3236 | 19 | |||
3237 | 20 | #include "application-info-desktop.h" | ||
3238 | 21 | |||
3239 | 22 | #include <gtest/gtest.h> | ||
3240 | 23 | |||
3241 | 24 | class ApplicationInfoDesktop : public ::testing::Test | ||
3242 | 25 | { | ||
3243 | 26 | virtual void SetUp() | ||
3244 | 27 | { | ||
3245 | 28 | } | ||
3246 | 29 | |||
3247 | 30 | virtual void TearDown() | ||
3248 | 31 | { | ||
3249 | 32 | } | ||
3250 | 33 | }; | ||
3251 | 34 | |||
3252 | 35 | #define DESKTOP "Desktop Entry" | ||
3253 | 36 | |||
3254 | 37 | TEST_F(ApplicationInfoDesktop, DefaultState) | ||
3255 | 38 | { | ||
3256 | 39 | auto keyfile = std::shared_ptr<GKeyFile>(g_key_file_new(), g_key_file_free); | ||
3257 | 40 | g_key_file_set_string(keyfile.get(), DESKTOP, "Name", "Foo App"); | ||
3258 | 41 | g_key_file_set_string(keyfile.get(), DESKTOP, "Exec", "foo"); | ||
3259 | 42 | g_key_file_set_string(keyfile.get(), DESKTOP, "Icon", "foo.png"); | ||
3260 | 43 | |||
3261 | 44 | auto appinfo = ubuntu::app_launch::app_info::Desktop(keyfile, "/"); | ||
3262 | 45 | |||
3263 | 46 | EXPECT_EQ("Foo App", appinfo.name().value()); | ||
3264 | 47 | EXPECT_EQ("", appinfo.description().value()); | ||
3265 | 48 | EXPECT_EQ("/foo.png", appinfo.iconPath().value()); | ||
3266 | 49 | |||
3267 | 50 | EXPECT_EQ("", appinfo.splash().title.value()); | ||
3268 | 51 | EXPECT_EQ("", appinfo.splash().image.value()); | ||
3269 | 52 | EXPECT_EQ("", appinfo.splash().backgroundColor.value()); | ||
3270 | 53 | EXPECT_EQ("", appinfo.splash().headerColor.value()); | ||
3271 | 54 | EXPECT_EQ("", appinfo.splash().footerColor.value()); | ||
3272 | 55 | EXPECT_FALSE( appinfo.splash().showHeader.value()); | ||
3273 | 56 | |||
3274 | 57 | EXPECT_TRUE(appinfo.supportedOrientations().portrait); | ||
3275 | 58 | EXPECT_TRUE(appinfo.supportedOrientations().landscape); | ||
3276 | 59 | EXPECT_TRUE(appinfo.supportedOrientations().invertedPortrait); | ||
3277 | 60 | EXPECT_TRUE(appinfo.supportedOrientations().invertedLandscape); | ||
3278 | 61 | |||
3279 | 62 | EXPECT_FALSE(appinfo.rotatesWindowContents().value()); | ||
3280 | 63 | |||
3281 | 64 | EXPECT_FALSE(appinfo.supportsUbuntuLifecycle().value()); | ||
3282 | 65 | } | ||
3283 | 66 | |||
3284 | 67 | TEST_F(ApplicationInfoDesktop, KeyfileErrors) | ||
3285 | 68 | { | ||
3286 | 69 | EXPECT_THROW(ubuntu::app_launch::app_info::Desktop({}, "/"), std::runtime_error); | ||
3287 | 70 | |||
3288 | 71 | auto noname = std::shared_ptr<GKeyFile>(g_key_file_new(), g_key_file_free); | ||
3289 | 72 | g_key_file_set_string(noname.get(), DESKTOP, "Comment", "This is a comment"); | ||
3290 | 73 | g_key_file_set_string(noname.get(), DESKTOP, "Exec", "foo"); | ||
3291 | 74 | g_key_file_set_string(noname.get(), DESKTOP, "Icon", "foo.png"); | ||
3292 | 75 | |||
3293 | 76 | EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(noname, "/"), std::runtime_error); | ||
3294 | 77 | |||
3295 | 78 | auto noicon = std::shared_ptr<GKeyFile>(g_key_file_new(), g_key_file_free); | ||
3296 | 79 | g_key_file_set_string(noicon.get(), DESKTOP, "Name", "Foo App"); | ||
3297 | 80 | g_key_file_set_string(noicon.get(), DESKTOP, "Comment", "This is a comment"); | ||
3298 | 81 | g_key_file_set_string(noicon.get(), DESKTOP, "Exec", "foo"); | ||
3299 | 82 | |||
3300 | 83 | EXPECT_THROW(ubuntu::app_launch::app_info::Desktop(noicon, "/"), std::runtime_error); | ||
3301 | 84 | } | ||
3302 | 85 | |||
3303 | 86 | TEST_F(ApplicationInfoDesktop, Orientations) | ||
3304 | 87 | { | ||
3305 | 88 | ubuntu::app_launch::Application::Info::Orientations defaultOrientations = | ||
3306 | 89 | { | ||
3307 | 90 | portrait: | ||
3308 | 91 | true, | ||
3309 | 92 | landscape: | ||
3310 | 93 | true, | ||
3311 | 94 | invertedPortrait: | ||
3312 | 95 | true, | ||
3313 | 96 | invertedLandscape: | ||
3314 | 97 | true | ||
3315 | 98 | }; | ||
3316 | 99 | |||
3317 | 100 | auto keyfile = std::shared_ptr<GKeyFile>(g_key_file_new(), g_key_file_free); | ||
3318 | 101 | g_key_file_set_string(keyfile.get(), DESKTOP, "Name", "Foo App"); | ||
3319 | 102 | g_key_file_set_string(keyfile.get(), DESKTOP, "Exec", "foo"); | ||
3320 | 103 | g_key_file_set_string(keyfile.get(), DESKTOP, "Icon", "foo.png"); | ||
3321 | 104 | |||
3322 | 105 | EXPECT_EQ(defaultOrientations, ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3323 | 106 | |||
3324 | 107 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "this should not parse"); | ||
3325 | 108 | EXPECT_EQ(defaultOrientations, ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3326 | 109 | |||
3327 | 110 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "this;should;not;parse;"); | ||
3328 | 111 | EXPECT_EQ(defaultOrientations, ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3329 | 112 | |||
3330 | 113 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "portrait;"); | ||
3331 | 114 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: false, invertedPortrait: false, invertedLandscape: false}), | ||
3332 | 115 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3333 | 116 | |||
3334 | 117 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "landscape;portrait;"); | ||
3335 | 118 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: true, invertedPortrait: false, invertedLandscape: false}), | ||
3336 | 119 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3337 | 120 | |||
3338 | 121 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "landscape ; portrait; invertedPortrait"); | ||
3339 | 122 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: true, invertedPortrait: true, invertedLandscape: false}), | ||
3340 | 123 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3341 | 124 | |||
3342 | 125 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "portrait;landscape;"); | ||
3343 | 126 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: true, invertedPortrait: false, invertedLandscape: false}), | ||
3344 | 127 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3345 | 128 | |||
3346 | 129 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "portrait;landscape;invertedportrait;invertedlandscape;"); | ||
3347 | 130 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: true, invertedPortrait: true, invertedLandscape: true}), | ||
3348 | 131 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3349 | 132 | |||
3350 | 133 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "PORTRAIT;"); | ||
3351 | 134 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: false, invertedPortrait: false, invertedLandscape: false}), | ||
3352 | 135 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3353 | 136 | |||
3354 | 137 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "pOrTraIt;lANDscApE;inVErtEDpORtrAit;iNVErtEDLAnDsCapE;"); | ||
3355 | 138 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: true, landscape: true, invertedPortrait: true, invertedLandscape: true}), | ||
3356 | 139 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3357 | 140 | |||
3358 | 141 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "primary;"); | ||
3359 | 142 | EXPECT_EQ((ubuntu::app_launch::Application::Info::Orientations {portrait: false, landscape: false, invertedPortrait: false, invertedLandscape: false}), | ||
3360 | 143 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3361 | 144 | |||
3362 | 145 | g_key_file_set_string(keyfile.get(), DESKTOP, "X-Ubuntu-Supported-Orientations", "foobar;primary;"); | ||
3363 | 146 | EXPECT_EQ(defaultOrientations, | ||
3364 | 147 | ubuntu::app_launch::app_info::Desktop(keyfile, "/").supportedOrientations()); | ||
3365 | 148 | } | ||
3366 | 0 | 149 | ||
3367 | === modified file 'tests/click-app-dir/application.desktop' | |||
3368 | --- tests/click-app-dir/application.desktop 2013-09-24 03:39:27 +0000 | |||
3369 | +++ tests/click-app-dir/application.desktop 2016-03-04 11:34:19 +0000 | |||
3370 | @@ -1,4 +1,6 @@ | |||
3371 | 1 | [Desktop Entry] | 1 | [Desktop Entry] |
3372 | 2 | Version=1.0 | ||
3373 | 2 | Name=Application | 3 | Name=Application |
3374 | 3 | Type=Application | 4 | Type=Application |
3376 | 4 | Exec=foo | 5 | Exec=grep |
3377 | 6 | Icon=foo | ||
3378 | 5 | 7 | ||
3379 | === modified file 'tests/exec-util-test.cc' | |||
3380 | --- tests/exec-util-test.cc 2015-08-11 19:11:15 +0000 | |||
3381 | +++ tests/exec-util-test.cc 2016-03-04 11:34:19 +0000 | |||
3382 | @@ -172,7 +172,7 @@ | |||
3383 | 172 | {"APP_DIR", [](const gchar * value) { | 172 | {"APP_DIR", [](const gchar * value) { |
3384 | 173 | EXPECT_STREQ(APP_DIR, value); }}, | 173 | EXPECT_STREQ(APP_DIR, value); }}, |
3385 | 174 | {"APP_EXEC", [](const gchar * value) { | 174 | {"APP_EXEC", [](const gchar * value) { |
3387 | 175 | EXPECT_STREQ("foo", value); }}, | 175 | EXPECT_STREQ("grep", value); }}, |
3388 | 176 | {"APP_ID", [](const gchar * value) { | 176 | {"APP_ID", [](const gchar * value) { |
3389 | 177 | EXPECT_STREQ("com.test.good_application_1.2.3", value); }}, | 177 | EXPECT_STREQ("com.test.good_application_1.2.3", value); }}, |
3390 | 178 | {"APP_LAUNCHER_PID", [](const gchar * value) { | 178 | {"APP_LAUNCHER_PID", [](const gchar * value) { |
3391 | 179 | 179 | ||
3392 | === modified file 'tests/helper-handshake-test.cc' | |||
3393 | --- tests/helper-handshake-test.cc 2014-04-30 16:18:29 +0000 | |||
3394 | +++ tests/helper-handshake-test.cc 2016-03-04 11:34:19 +0000 | |||
3395 | @@ -103,6 +103,7 @@ | |||
3396 | 103 | { | 103 | { |
3397 | 104 | bool * reached = static_cast<bool *>(user_data); | 104 | bool * reached = static_cast<bool *>(user_data); |
3398 | 105 | *reached = true; | 105 | *reached = true; |
3399 | 106 | return true; | ||
3400 | 106 | } | 107 | } |
3401 | 107 | 108 | ||
3402 | 108 | TEST_F(HelperHandshakeTest, HandshakeTimeout) | 109 | TEST_F(HelperHandshakeTest, HandshakeTimeout) |
3403 | @@ -114,6 +115,8 @@ | |||
3404 | 114 | 115 | ||
3405 | 115 | starting_handshake_wait(handshake); | 116 | starting_handshake_wait(handshake); |
3406 | 116 | 117 | ||
3407 | 118 | g_source_remove(outertimeout); | ||
3408 | 119 | |||
3409 | 117 | ASSERT_FALSE(timeout_reached); | 120 | ASSERT_FALSE(timeout_reached); |
3410 | 118 | 121 | ||
3411 | 119 | return; | 122 | return; |
3412 | 120 | 123 | ||
3413 | === modified file 'tests/helper-test.cc' | |||
3414 | --- tests/helper-test.cc 2014-11-11 22:05:30 +0000 | |||
3415 | +++ tests/helper-test.cc 2016-03-04 11:34:19 +0000 | |||
3416 | @@ -297,8 +297,6 @@ | |||
3417 | 297 | ASSERT_NE(calls, nullptr); | 297 | ASSERT_NE(calls, nullptr); |
3418 | 298 | ASSERT_STREQ("SetEnvList", calls[0].name); | 298 | ASSERT_STREQ("SetEnvList", calls[0].name); |
3419 | 299 | 299 | ||
3420 | 300 | unsigned int i; | ||
3421 | 301 | |||
3422 | 302 | bool got_app_isolation = false; | 300 | bool got_app_isolation = false; |
3423 | 303 | bool got_cache_home = false; | 301 | bool got_cache_home = false; |
3424 | 304 | bool got_config_home = false; | 302 | bool got_config_home = false; |
3425 | 305 | 303 | ||
3426 | === modified file 'tests/libertine-data/libertine-container/container-name/rootfs/usr/share/applications/test.desktop' | |||
3427 | --- tests/libertine-data/libertine-container/container-name/rootfs/usr/share/applications/test.desktop 2015-08-06 21:38:31 +0000 | |||
3428 | +++ tests/libertine-data/libertine-container/container-name/rootfs/usr/share/applications/test.desktop 2016-03-04 11:34:19 +0000 | |||
3429 | @@ -2,3 +2,4 @@ | |||
3430 | 2 | Name=Test | 2 | Name=Test |
3431 | 3 | Type=Application | 3 | Type=Application |
3432 | 4 | Exec=test | 4 | Exec=test |
3433 | 5 | Icon=test | ||
3434 | 5 | 6 | ||
3435 | === added file 'tests/libual-cpp-test.cc' | |||
3436 | --- tests/libual-cpp-test.cc 1970-01-01 00:00:00 +0000 | |||
3437 | +++ tests/libual-cpp-test.cc 2016-03-04 11:34:19 +0000 | |||
3438 | @@ -0,0 +1,1599 @@ | |||
3439 | 1 | /* | ||
3440 | 2 | * Copyright 2013 Canonical Ltd. | ||
3441 | 3 | * | ||
3442 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3443 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3444 | 6 | * by the Free Software Foundation. | ||
3445 | 7 | * | ||
3446 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3447 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3448 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3449 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3450 | 12 | * | ||
3451 | 13 | * You should have received a copy of the GNU General Public License along | ||
3452 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3453 | 15 | * | ||
3454 | 16 | * Authors: | ||
3455 | 17 | * Ted Gould <ted.gould@canonical.com> | ||
3456 | 18 | */ | ||
3457 | 19 | |||
3458 | 20 | #include <future> | ||
3459 | 21 | #include <thread> | ||
3460 | 22 | |||
3461 | 23 | #include <gtest/gtest.h> | ||
3462 | 24 | #include <gio/gio.h> | ||
3463 | 25 | #include <zeitgeist.h> | ||
3464 | 26 | #include "mir-mock.h" | ||
3465 | 27 | |||
3466 | 28 | #include "registry.h" | ||
3467 | 29 | #include "application.h" | ||
3468 | 30 | #include "helper.h" | ||
3469 | 31 | |||
3470 | 32 | extern "C" { | ||
3471 | 33 | #include "ubuntu-app-launch.h" | ||
3472 | 34 | #include "libdbustest/dbus-test.h" | ||
3473 | 35 | #include <fcntl.h> | ||
3474 | 36 | } | ||
3475 | 37 | |||
3476 | 38 | class LibUAL : public ::testing::Test | ||
3477 | 39 | { | ||
3478 | 40 | protected: | ||
3479 | 41 | DbusTestService* service = NULL; | ||
3480 | 42 | DbusTestDbusMock* mock = NULL; | ||
3481 | 43 | DbusTestDbusMock* cgmock = NULL; | ||
3482 | 44 | GDBusConnection* bus = NULL; | ||
3483 | 45 | std::string last_focus_appid; | ||
3484 | 46 | std::string last_resume_appid; | ||
3485 | 47 | guint resume_timeout = 0; | ||
3486 | 48 | std::shared_ptr<ubuntu::app_launch::Registry> registry; | ||
3487 | 49 | |||
3488 | 50 | private: | ||
3489 | 51 | static void focus_cb(const gchar* appid, gpointer user_data) | ||
3490 | 52 | { | ||
3491 | 53 | g_debug("Focus Callback: %s", appid); | ||
3492 | 54 | LibUAL* _this = static_cast<LibUAL*>(user_data); | ||
3493 | 55 | _this->last_focus_appid = appid; | ||
3494 | 56 | } | ||
3495 | 57 | |||
3496 | 58 | static void resume_cb(const gchar* appid, gpointer user_data) | ||
3497 | 59 | { | ||
3498 | 60 | g_debug("Resume Callback: %s", appid); | ||
3499 | 61 | LibUAL* _this = static_cast<LibUAL*>(user_data); | ||
3500 | 62 | _this->last_resume_appid = appid; | ||
3501 | 63 | |||
3502 | 64 | if (_this->resume_timeout > 0) | ||
3503 | 65 | { | ||
3504 | 66 | _this->pause(_this->resume_timeout); | ||
3505 | 67 | } | ||
3506 | 68 | } | ||
3507 | 69 | |||
3508 | 70 | protected: | ||
3509 | 71 | /* Useful debugging stuff, but not on by default. You really want to | ||
3510 | 72 | not get all this noise typically */ | ||
3511 | 73 | void debugConnection() | ||
3512 | 74 | { | ||
3513 | 75 | if (true) | ||
3514 | 76 | { | ||
3515 | 77 | return; | ||
3516 | 78 | } | ||
3517 | 79 | |||
3518 | 80 | DbusTestBustle* bustle = dbus_test_bustle_new("test.bustle"); | ||
3519 | 81 | dbus_test_service_add_task(service, DBUS_TEST_TASK(bustle)); | ||
3520 | 82 | g_object_unref(bustle); | ||
3521 | 83 | |||
3522 | 84 | DbusTestProcess* monitor = dbus_test_process_new("dbus-monitor"); | ||
3523 | 85 | dbus_test_service_add_task(service, DBUS_TEST_TASK(monitor)); | ||
3524 | 86 | g_object_unref(monitor); | ||
3525 | 87 | } | ||
3526 | 88 | |||
3527 | 89 | virtual void SetUp() | ||
3528 | 90 | { | ||
3529 | 91 | /* Click DB test mode */ | ||
3530 | 92 | g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); | ||
3531 | 93 | g_setenv("TEST_CLICK_USER", "test-user", TRUE); | ||
3532 | 94 | |||
3533 | 95 | gchar* linkfarmpath = g_build_filename(CMAKE_SOURCE_DIR, "link-farm", NULL); | ||
3534 | 96 | g_setenv("UBUNTU_APP_LAUNCH_LINK_FARM", linkfarmpath, TRUE); | ||
3535 | 97 | g_free(linkfarmpath); | ||
3536 | 98 | |||
3537 | 99 | g_setenv("XDG_DATA_DIRS", CMAKE_SOURCE_DIR, TRUE); | ||
3538 | 100 | g_setenv("XDG_CACHE_HOME", CMAKE_SOURCE_DIR "/libertine-data", TRUE); | ||
3539 | 101 | g_setenv("XDG_DATA_HOME", CMAKE_SOURCE_DIR "/libertine-home", TRUE); | ||
3540 | 102 | |||
3541 | 103 | service = dbus_test_service_new(NULL); | ||
3542 | 104 | |||
3543 | 105 | debugConnection(); | ||
3544 | 106 | |||
3545 | 107 | mock = dbus_test_dbus_mock_new("com.ubuntu.Upstart"); | ||
3546 | 108 | |||
3547 | 109 | DbusTestDbusMockObject* obj = | ||
3548 | 110 | dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); | ||
3549 | 111 | |||
3550 | 112 | dbus_test_dbus_mock_object_add_method(mock, obj, "EmitEvent", G_VARIANT_TYPE("(sasb)"), NULL, "", NULL); | ||
3551 | 113 | |||
3552 | 114 | dbus_test_dbus_mock_object_add_method(mock, obj, "GetJobByName", G_VARIANT_TYPE("s"), G_VARIANT_TYPE("o"), | ||
3553 | 115 | "if args[0] == 'application-click':\n" | ||
3554 | 116 | " ret = dbus.ObjectPath('/com/test/application_click')\n" | ||
3555 | 117 | "elif args[0] == 'application-legacy':\n" | ||
3556 | 118 | " ret = dbus.ObjectPath('/com/test/application_legacy')\n" | ||
3557 | 119 | "elif args[0] == 'untrusted-helper':\n" | ||
3558 | 120 | " ret = dbus.ObjectPath('/com/test/untrusted/helper')\n", | ||
3559 | 121 | NULL); | ||
3560 | 122 | |||
3561 | 123 | dbus_test_dbus_mock_object_add_method(mock, obj, "SetEnv", G_VARIANT_TYPE("(assb)"), NULL, "", NULL); | ||
3562 | 124 | |||
3563 | 125 | /* Click App */ | ||
3564 | 126 | DbusTestDbusMockObject* jobobj = | ||
3565 | 127 | dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); | ||
3566 | 128 | |||
3567 | 129 | dbus_test_dbus_mock_object_add_method( | ||
3568 | 130 | mock, jobobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, | ||
3569 | 131 | "if args[0][0] == 'APP_ID=com.test.good_application_1.2.3':" | ||
3570 | 132 | " raise dbus.exceptions.DBusException('Foo running', name='com.ubuntu.Upstart0_6.Error.AlreadyStarted')", | ||
3571 | 133 | NULL); | ||
3572 | 134 | |||
3573 | 135 | dbus_test_dbus_mock_object_add_method(mock, jobobj, "Stop", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); | ||
3574 | 136 | |||
3575 | 137 | dbus_test_dbus_mock_object_add_method(mock, jobobj, "GetAllInstances", NULL, G_VARIANT_TYPE("ao"), | ||
3576 | 138 | "ret = [ dbus.ObjectPath('/com/test/app_instance') ]", NULL); | ||
3577 | 139 | |||
3578 | 140 | DbusTestDbusMockObject* instobj = | ||
3579 | 141 | dbus_test_dbus_mock_get_object(mock, "/com/test/app_instance", "com.ubuntu.Upstart0_6.Instance", NULL); | ||
3580 | 142 | dbus_test_dbus_mock_object_add_property(mock, instobj, "name", G_VARIANT_TYPE_STRING, | ||
3581 | 143 | g_variant_new_string("com.test.good_application_1.2.3"), NULL); | ||
3582 | 144 | gchar* process_var = g_strdup_printf("[('main', %d)]", getpid()); | ||
3583 | 145 | dbus_test_dbus_mock_object_add_property(mock, instobj, "processes", G_VARIANT_TYPE("a(si)"), | ||
3584 | 146 | g_variant_new_parsed(process_var), NULL); | ||
3585 | 147 | g_free(process_var); | ||
3586 | 148 | |||
3587 | 149 | /* Legacy App */ | ||
3588 | 150 | DbusTestDbusMockObject* ljobobj = | ||
3589 | 151 | dbus_test_dbus_mock_get_object(mock, "/com/test/application_legacy", "com.ubuntu.Upstart0_6.Job", NULL); | ||
3590 | 152 | |||
3591 | 153 | dbus_test_dbus_mock_object_add_method(mock, ljobobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); | ||
3592 | 154 | |||
3593 | 155 | dbus_test_dbus_mock_object_add_method(mock, ljobobj, "Stop", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); | ||
3594 | 156 | |||
3595 | 157 | dbus_test_dbus_mock_object_add_method(mock, ljobobj, "GetAllInstances", NULL, G_VARIANT_TYPE("ao"), | ||
3596 | 158 | "ret = [ dbus.ObjectPath('/com/test/legacy_app_instance') ]", NULL); | ||
3597 | 159 | |||
3598 | 160 | DbusTestDbusMockObject* linstobj = dbus_test_dbus_mock_get_object(mock, "/com/test/legacy_app_instance", | ||
3599 | 161 | "com.ubuntu.Upstart0_6.Instance", NULL); | ||
3600 | 162 | dbus_test_dbus_mock_object_add_property(mock, linstobj, "name", G_VARIANT_TYPE_STRING, | ||
3601 | 163 | g_variant_new_string("multiple-2342345"), NULL); | ||
3602 | 164 | dbus_test_dbus_mock_object_add_property(mock, linstobj, "processes", G_VARIANT_TYPE("a(si)"), | ||
3603 | 165 | g_variant_new_parsed("[('main', 5678)]"), NULL); | ||
3604 | 166 | |||
3605 | 167 | /* Untrusted Helper */ | ||
3606 | 168 | DbusTestDbusMockObject* uhelperobj = | ||
3607 | 169 | dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); | ||
3608 | 170 | |||
3609 | 171 | dbus_test_dbus_mock_object_add_method(mock, uhelperobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); | ||
3610 | 172 | |||
3611 | 173 | dbus_test_dbus_mock_object_add_method(mock, uhelperobj, "Stop", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); | ||
3612 | 174 | |||
3613 | 175 | dbus_test_dbus_mock_object_add_method(mock, uhelperobj, "GetAllInstances", NULL, G_VARIANT_TYPE("ao"), | ||
3614 | 176 | "ret = [ dbus.ObjectPath('/com/test/untrusted/helper/instance'), " | ||
3615 | 177 | "dbus.ObjectPath('/com/test/untrusted/helper/multi_instance') ]", | ||
3616 | 178 | NULL); | ||
3617 | 179 | |||
3618 | 180 | DbusTestDbusMockObject* uhelperinstance = dbus_test_dbus_mock_get_object( | ||
3619 | 181 | mock, "/com/test/untrusted/helper/instance", "com.ubuntu.Upstart0_6.Instance", NULL); | ||
3620 | 182 | dbus_test_dbus_mock_object_add_property(mock, uhelperinstance, "name", G_VARIANT_TYPE_STRING, | ||
3621 | 183 | g_variant_new_string("untrusted-type::com.foo_bar_43.23.12"), NULL); | ||
3622 | 184 | |||
3623 | 185 | DbusTestDbusMockObject* unhelpermulti = dbus_test_dbus_mock_get_object( | ||
3624 | 186 | mock, "/com/test/untrusted/helper/multi_instance", "com.ubuntu.Upstart0_6.Instance", NULL); | ||
3625 | 187 | dbus_test_dbus_mock_object_add_property( | ||
3626 | 188 | mock, unhelpermulti, "name", G_VARIANT_TYPE_STRING, | ||
3627 | 189 | g_variant_new_string("untrusted-type:24034582324132:com.bar_foo_8432.13.1"), NULL); | ||
3628 | 190 | |||
3629 | 191 | /* Create the cgroup manager mock */ | ||
3630 | 192 | cgmock = dbus_test_dbus_mock_new("org.test.cgmock"); | ||
3631 | 193 | g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock", TRUE); | ||
3632 | 194 | |||
3633 | 195 | DbusTestDbusMockObject* cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", | ||
3634 | 196 | "org.linuxcontainers.cgmanager0_0", NULL); | ||
3635 | 197 | dbus_test_dbus_mock_object_add_method(cgmock, cgobject, "GetTasksRecursive", G_VARIANT_TYPE("(ss)"), | ||
3636 | 198 | G_VARIANT_TYPE("ai"), "ret = [100, 200, 300]", NULL); | ||
3637 | 199 | |||
3638 | 200 | /* Put it together */ | ||
3639 | 201 | dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); | ||
3640 | 202 | dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock)); | ||
3641 | 203 | dbus_test_service_start_tasks(service); | ||
3642 | 204 | |||
3643 | 205 | bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); | ||
3644 | 206 | g_dbus_connection_set_exit_on_close(bus, FALSE); | ||
3645 | 207 | g_object_add_weak_pointer(G_OBJECT(bus), (gpointer*)&bus); | ||
3646 | 208 | |||
3647 | 209 | /* Make sure we pretend the CG manager is just on our bus */ | ||
3648 | 210 | g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS", "YES", TRUE); | ||
3649 | 211 | |||
3650 | 212 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_focus(focus_cb, this)); | ||
3651 | 213 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_resume(resume_cb, this)); | ||
3652 | 214 | |||
3653 | 215 | registry = std::make_shared<ubuntu::app_launch::Registry>(); | ||
3654 | 216 | } | ||
3655 | 217 | |||
3656 | 218 | virtual void TearDown() | ||
3657 | 219 | { | ||
3658 | 220 | registry.reset(); | ||
3659 | 221 | |||
3660 | 222 | ubuntu_app_launch_observer_delete_app_focus(focus_cb, this); | ||
3661 | 223 | ubuntu_app_launch_observer_delete_app_resume(resume_cb, this); | ||
3662 | 224 | |||
3663 | 225 | g_clear_object(&mock); | ||
3664 | 226 | g_clear_object(&cgmock); | ||
3665 | 227 | g_clear_object(&service); | ||
3666 | 228 | |||
3667 | 229 | g_object_unref(bus); | ||
3668 | 230 | |||
3669 | 231 | unsigned int cleartry = 0; | ||
3670 | 232 | while (bus != NULL && cleartry < 100) | ||
3671 | 233 | { | ||
3672 | 234 | pause(100); | ||
3673 | 235 | cleartry++; | ||
3674 | 236 | } | ||
3675 | 237 | ASSERT_EQ(nullptr, bus); | ||
3676 | 238 | } | ||
3677 | 239 | |||
3678 | 240 | GVariant* find_env(GVariant* env_array, const gchar* var) | ||
3679 | 241 | { | ||
3680 | 242 | unsigned int i; | ||
3681 | 243 | GVariant* retval = nullptr; | ||
3682 | 244 | |||
3683 | 245 | for (i = 0; i < g_variant_n_children(env_array); i++) | ||
3684 | 246 | { | ||
3685 | 247 | GVariant* child = g_variant_get_child_value(env_array, i); | ||
3686 | 248 | const gchar* envvar = g_variant_get_string(child, nullptr); | ||
3687 | 249 | |||
3688 | 250 | if (g_str_has_prefix(envvar, var)) | ||
3689 | 251 | { | ||
3690 | 252 | if (retval != nullptr) | ||
3691 | 253 | { | ||
3692 | 254 | g_warning("Found the env var more than once!"); | ||
3693 | 255 | g_variant_unref(retval); | ||
3694 | 256 | return nullptr; | ||
3695 | 257 | } | ||
3696 | 258 | |||
3697 | 259 | retval = child; | ||
3698 | 260 | } | ||
3699 | 261 | else | ||
3700 | 262 | { | ||
3701 | 263 | g_variant_unref(child); | ||
3702 | 264 | } | ||
3703 | 265 | } | ||
3704 | 266 | |||
3705 | 267 | if (!retval) | ||
3706 | 268 | { | ||
3707 | 269 | gchar* envstr = g_variant_print(env_array, FALSE); | ||
3708 | 270 | g_warning("Unable to find '%s' in '%s'", var, envstr); | ||
3709 | 271 | g_free(envstr); | ||
3710 | 272 | } | ||
3711 | 273 | |||
3712 | 274 | return retval; | ||
3713 | 275 | } | ||
3714 | 276 | |||
3715 | 277 | bool check_env(GVariant* env_array, const gchar* var, const gchar* value) | ||
3716 | 278 | { | ||
3717 | 279 | bool found = false; | ||
3718 | 280 | GVariant* val = find_env(env_array, var); | ||
3719 | 281 | if (val == nullptr) | ||
3720 | 282 | { | ||
3721 | 283 | return false; | ||
3722 | 284 | } | ||
3723 | 285 | |||
3724 | 286 | const gchar* envvar = g_variant_get_string(val, nullptr); | ||
3725 | 287 | |||
3726 | 288 | gchar* combined = g_strdup_printf("%s=%s", var, value); | ||
3727 | 289 | if (g_strcmp0(envvar, combined) == 0) | ||
3728 | 290 | { | ||
3729 | 291 | found = true; | ||
3730 | 292 | } | ||
3731 | 293 | |||
3732 | 294 | g_variant_unref(val); | ||
3733 | 295 | |||
3734 | 296 | return found; | ||
3735 | 297 | } | ||
3736 | 298 | |||
3737 | 299 | void pause(guint time = 0) | ||
3738 | 300 | { | ||
3739 | 301 | if (time > 0) | ||
3740 | 302 | { | ||
3741 | 303 | GMainLoop* mainloop = g_main_loop_new(NULL, FALSE); | ||
3742 | 304 | |||
3743 | 305 | g_timeout_add(time, | ||
3744 | 306 | [](gpointer pmainloop) -> gboolean | ||
3745 | 307 | { | ||
3746 | 308 | g_main_loop_quit(static_cast<GMainLoop*>(pmainloop)); | ||
3747 | 309 | return G_SOURCE_REMOVE; | ||
3748 | 310 | }, | ||
3749 | 311 | mainloop); | ||
3750 | 312 | |||
3751 | 313 | g_main_loop_run(mainloop); | ||
3752 | 314 | |||
3753 | 315 | g_main_loop_unref(mainloop); | ||
3754 | 316 | } | ||
3755 | 317 | |||
3756 | 318 | while (g_main_pending()) | ||
3757 | 319 | { | ||
3758 | 320 | g_main_iteration(TRUE); | ||
3759 | 321 | } | ||
3760 | 322 | } | ||
3761 | 323 | }; | ||
3762 | 324 | |||
3763 | 325 | TEST_F(LibUAL, DISABLED_StartApplication) | ||
3764 | 326 | { | ||
3765 | 327 | DbusTestDbusMockObject* obj = | ||
3766 | 328 | dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); | ||
3767 | 329 | |||
3768 | 330 | /* Basic make sure we can send the event */ | ||
3769 | 331 | auto appid = ubuntu::app_launch::AppID::parse("com.test.multiple_first_1.2.3"); | ||
3770 | 332 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
3771 | 333 | app->launch(); | ||
3772 | 334 | |||
3773 | 335 | EXPECT_EQ(1, dbus_test_dbus_mock_object_check_method_call(mock, obj, "Start", NULL, NULL)); | ||
3774 | 336 | |||
3775 | 337 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
3776 | 338 | |||
3777 | 339 | /* Now look at the details of the call */ | ||
3778 | 340 | app->launch(); | ||
3779 | 341 | |||
3780 | 342 | guint len = 0; | ||
3781 | 343 | const DbusTestDbusMockCall* calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
3782 | 344 | EXPECT_NE(nullptr, calls); | ||
3783 | 345 | EXPECT_EQ(1, len); | ||
3784 | 346 | |||
3785 | 347 | EXPECT_STREQ("Start", calls->name); | ||
3786 | 348 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
3787 | 349 | |||
3788 | 350 | GVariant* block = g_variant_get_child_value(calls->params, 1); | ||
3789 | 351 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
3790 | 352 | g_variant_unref(block); | ||
3791 | 353 | |||
3792 | 354 | GVariant* env = g_variant_get_child_value(calls->params, 0); | ||
3793 | 355 | EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); | ||
3794 | 356 | g_variant_unref(env); | ||
3795 | 357 | |||
3796 | 358 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
3797 | 359 | |||
3798 | 360 | /* Let's pass some URLs */ | ||
3799 | 361 | std::vector<ubuntu::app_launch::Application::URL> urls{ | ||
3800 | 362 | ubuntu::app_launch::Application::URL::from_raw("http://ubuntu.com/"), | ||
3801 | 363 | ubuntu::app_launch::Application::URL::from_raw("https://ubuntu.com/"), | ||
3802 | 364 | ubuntu::app_launch::Application::URL::from_raw("file:///home/phablet/test.txt")}; | ||
3803 | 365 | |||
3804 | 366 | app->launch(urls); | ||
3805 | 367 | |||
3806 | 368 | len = 0; | ||
3807 | 369 | calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
3808 | 370 | EXPECT_NE(nullptr, calls); | ||
3809 | 371 | EXPECT_EQ(1, len); | ||
3810 | 372 | |||
3811 | 373 | env = g_variant_get_child_value(calls->params, 0); | ||
3812 | 374 | EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); | ||
3813 | 375 | EXPECT_TRUE( | ||
3814 | 376 | check_env(env, "APP_URIS", "'http://ubuntu.com/' 'https://ubuntu.com/' 'file:///home/phablet/test.txt'")); | ||
3815 | 377 | g_variant_unref(env); | ||
3816 | 378 | |||
3817 | 379 | return; | ||
3818 | 380 | } | ||
3819 | 381 | |||
3820 | 382 | TEST_F(LibUAL, DISABLED_StartApplicationTest) | ||
3821 | 383 | { | ||
3822 | 384 | DbusTestDbusMockObject* obj = | ||
3823 | 385 | dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); | ||
3824 | 386 | |||
3825 | 387 | /* Basic make sure we can send the event */ | ||
3826 | 388 | auto appid = ubuntu::app_launch::AppID::parse("com.test.multiple_first_1.2.3"); | ||
3827 | 389 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
3828 | 390 | app->launchTest(); | ||
3829 | 391 | |||
3830 | 392 | guint len = 0; | ||
3831 | 393 | const DbusTestDbusMockCall* calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
3832 | 394 | EXPECT_NE(nullptr, calls); | ||
3833 | 395 | EXPECT_EQ(1, len); | ||
3834 | 396 | |||
3835 | 397 | EXPECT_STREQ("Start", calls->name); | ||
3836 | 398 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
3837 | 399 | |||
3838 | 400 | GVariant* block = g_variant_get_child_value(calls->params, 1); | ||
3839 | 401 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
3840 | 402 | g_variant_unref(block); | ||
3841 | 403 | |||
3842 | 404 | GVariant* env = g_variant_get_child_value(calls->params, 0); | ||
3843 | 405 | EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); | ||
3844 | 406 | EXPECT_TRUE(check_env(env, "QT_LOAD_TESTABILITY", "1")); | ||
3845 | 407 | g_variant_unref(env); | ||
3846 | 408 | } | ||
3847 | 409 | |||
3848 | 410 | TEST_F(LibUAL, DISABLED_StopApplication) | ||
3849 | 411 | { | ||
3850 | 412 | DbusTestDbusMockObject* obj = | ||
3851 | 413 | dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); | ||
3852 | 414 | |||
3853 | 415 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
3854 | 416 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
3855 | 417 | |||
3856 | 418 | ASSERT_TRUE(app->hasInstances()); | ||
3857 | 419 | EXPECT_EQ(1, app->instances().size()); | ||
3858 | 420 | |||
3859 | 421 | app->instances()[0]->stop(); | ||
3860 | 422 | |||
3861 | 423 | ASSERT_EQ(dbus_test_dbus_mock_object_check_method_call(mock, obj, "Stop", NULL, NULL), 1); | ||
3862 | 424 | } | ||
3863 | 425 | |||
3864 | 426 | /* NOTE: The fact that there is 'libertine-data' in these strings is because | ||
3865 | 427 | we're using one CACHE_HOME for this test suite and the libertine functions | ||
3866 | 428 | need to pull things from there, where these are only comparisons. It's just | ||
3867 | 429 | what value is in the environment variable */ | ||
3868 | 430 | TEST_F(LibUAL, DISABLED_ApplicationLog) | ||
3869 | 431 | { | ||
3870 | 432 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
3871 | 433 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
3872 | 434 | |||
3873 | 435 | EXPECT_EQ( | ||
3874 | 436 | std::string(CMAKE_SOURCE_DIR "/libertine-data/upstart/application-click-com.test.good_application_1.2.3.log"), | ||
3875 | 437 | app->instances()[0]->logPath()); | ||
3876 | 438 | |||
3877 | 439 | appid = ubuntu::app_launch::AppID::find("single"); | ||
3878 | 440 | app = ubuntu::app_launch::Application::create(appid, registry); | ||
3879 | 441 | |||
3880 | 442 | EXPECT_EQ(std::string(CMAKE_SOURCE_DIR "/libertine-data/upstart/application-legacy-single-.log"), | ||
3881 | 443 | app->instances()[0]->logPath()); | ||
3882 | 444 | |||
3883 | 445 | appid = ubuntu::app_launch::AppID::find("multiple"); | ||
3884 | 446 | app = ubuntu::app_launch::Application::create(appid, registry); | ||
3885 | 447 | |||
3886 | 448 | EXPECT_EQ(std::string(CMAKE_SOURCE_DIR "/libertine-data/upstart/application-legacy-multiple-2342345.log"), | ||
3887 | 449 | app->instances()[0]->logPath()); | ||
3888 | 450 | } | ||
3889 | 451 | |||
3890 | 452 | TEST_F(LibUAL, DISABLED_ApplicationPid) | ||
3891 | 453 | { | ||
3892 | 454 | /* Check bad params */ | ||
3893 | 455 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
3894 | 456 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
3895 | 457 | |||
3896 | 458 | EXPECT_FALSE(app->instances()[0]->hasPid(0)); | ||
3897 | 459 | |||
3898 | 460 | /* Check primary pid, which comes from Upstart */ | ||
3899 | 461 | EXPECT_EQ(getpid(), app->instances()[0]->primaryPid()); | ||
3900 | 462 | |||
3901 | 463 | auto multiappid = ubuntu::app_launch::AppID::find("multiple"); | ||
3902 | 464 | auto multiapp = ubuntu::app_launch::Application::create(multiappid, registry); | ||
3903 | 465 | EXPECT_EQ(5678, multiapp->instances()[0]->primaryPid()); | ||
3904 | 466 | |||
3905 | 467 | /* Look at the full PID list from CG Manager */ | ||
3906 | 468 | DbusTestDbusMockObject* cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", | ||
3907 | 469 | "org.linuxcontainers.cgmanager0_0", NULL); | ||
3908 | 470 | const DbusTestDbusMockCall* calls = NULL; | ||
3909 | 471 | guint len = 0; | ||
3910 | 472 | |||
3911 | 473 | /* Click in the set */ | ||
3912 | 474 | EXPECT_TRUE(app->instances()[0]->hasPid(100)); | ||
3913 | 475 | calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); | ||
3914 | 476 | EXPECT_EQ(1, len); | ||
3915 | 477 | EXPECT_STREQ("GetTasksRecursive", calls->name); | ||
3916 | 478 | EXPECT_TRUE(g_variant_equal( | ||
3917 | 479 | calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-com.test.good_application_1.2.3"))); | ||
3918 | 480 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); | ||
3919 | 481 | |||
3920 | 482 | /* Click out of the set */ | ||
3921 | 483 | EXPECT_FALSE(app->instances()[0]->hasPid(101)); | ||
3922 | 484 | calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); | ||
3923 | 485 | EXPECT_EQ(1, len); | ||
3924 | 486 | EXPECT_STREQ("GetTasksRecursive", calls->name); | ||
3925 | 487 | EXPECT_TRUE(g_variant_equal( | ||
3926 | 488 | calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-com.test.good_application_1.2.3"))); | ||
3927 | 489 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); | ||
3928 | 490 | |||
3929 | 491 | /* Legacy Single Instance */ | ||
3930 | 492 | auto singleappid = ubuntu::app_launch::AppID::find("single"); | ||
3931 | 493 | auto singleapp = ubuntu::app_launch::Application::create(singleappid, registry); | ||
3932 | 494 | |||
3933 | 495 | EXPECT_TRUE(singleapp->instances()[0]->hasPid(100)); | ||
3934 | 496 | |||
3935 | 497 | calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); | ||
3936 | 498 | EXPECT_EQ(1, len); | ||
3937 | 499 | EXPECT_STREQ("GetTasksRecursive", calls->name); | ||
3938 | 500 | EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-legacy-single-"))); | ||
3939 | 501 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); | ||
3940 | 502 | |||
3941 | 503 | /* Legacy Multi Instance */ | ||
3942 | 504 | EXPECT_TRUE(multiapp->instances()[0]->hasPid(100)); | ||
3943 | 505 | calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); | ||
3944 | 506 | EXPECT_EQ(1, len); | ||
3945 | 507 | EXPECT_STREQ("GetTasksRecursive", calls->name); | ||
3946 | 508 | EXPECT_TRUE(g_variant_equal(calls->params, | ||
3947 | 509 | g_variant_new("(ss)", "freezer", "upstart/application-legacy-multiple-2342345"))); | ||
3948 | 510 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); | ||
3949 | 511 | } | ||
3950 | 512 | |||
3951 | 513 | TEST_F(LibUAL, DISABLED_ApplicationId) | ||
3952 | 514 | { | ||
3953 | 515 | g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); | ||
3954 | 516 | g_setenv("TEST_CLICK_USER", "test-user", TRUE); | ||
3955 | 517 | |||
3956 | 518 | /* Test with current-user-version, should return the version in the manifest */ | ||
3957 | 519 | EXPECT_EQ("com.test.good_application_1.2.3", | ||
3958 | 520 | (std::string)ubuntu::app_launch::AppID::discover("com.test.good", "application")); | ||
3959 | 521 | |||
3960 | 522 | /* Test with version specified, shouldn't even read the manifest */ | ||
3961 | 523 | EXPECT_EQ("com.test.good_application_1.2.4", | ||
3962 | 524 | (std::string)ubuntu::app_launch::AppID::discover("com.test.good", "application", "1.2.4")); | ||
3963 | 525 | |||
3964 | 526 | /* Test with out a version or app, should return the version in the manifest */ | ||
3965 | 527 | EXPECT_EQ("com.test.good_application_1.2.3", (std::string)ubuntu::app_launch::AppID::discover( | ||
3966 | 528 | "com.test.good", "first-listed-app", "current-user-version")); | ||
3967 | 529 | |||
3968 | 530 | /* Make sure we can select the app from a list correctly */ | ||
3969 | 531 | EXPECT_EQ("com.test.multiple_first_1.2.3", | ||
3970 | 532 | (std::string)ubuntu::app_launch::AppID::discover( | ||
3971 | 533 | "com.test.multiple", ubuntu::app_launch::AppID::ApplicationWildcard::FIRST_LISTED)); | ||
3972 | 534 | EXPECT_EQ("com.test.multiple_first_1.2.3", (std::string)ubuntu::app_launch::AppID::discover("com.test.multiple")); | ||
3973 | 535 | EXPECT_EQ("com.test.multiple_fifth_1.2.3", | ||
3974 | 536 | (std::string)ubuntu::app_launch::AppID::discover( | ||
3975 | 537 | "com.test.multiple", ubuntu::app_launch::AppID::ApplicationWildcard::LAST_LISTED)); | ||
3976 | 538 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover( | ||
3977 | 539 | "com.test.multiple", ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED)); | ||
3978 | 540 | EXPECT_EQ("com.test.good_application_1.2.3", | ||
3979 | 541 | (std::string)ubuntu::app_launch::AppID::discover( | ||
3980 | 542 | "com.test.good", ubuntu::app_launch::AppID::ApplicationWildcard::ONLY_LISTED)); | ||
3981 | 543 | |||
3982 | 544 | /* A bunch that should be NULL */ | ||
3983 | 545 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover("com.test.no-hooks")); | ||
3984 | 546 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover("com.test.no-json")); | ||
3985 | 547 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover("com.test.no-object")); | ||
3986 | 548 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover("com.test.no-version")); | ||
3987 | 549 | |||
3988 | 550 | /* Libertine tests */ | ||
3989 | 551 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover("container-name")); | ||
3990 | 552 | EXPECT_EQ("", (std::string)ubuntu::app_launch::AppID::discover("container-name", "not-exist")); | ||
3991 | 553 | EXPECT_EQ("container-name_test_0.0", (std::string)ubuntu::app_launch::AppID::discover("container-name", "test")); | ||
3992 | 554 | EXPECT_EQ("container-name_user-app_0.0", | ||
3993 | 555 | (std::string)ubuntu::app_launch::AppID::discover("container-name", "user-app")); | ||
3994 | 556 | } | ||
3995 | 557 | |||
3996 | 558 | TEST_F(LibUAL, AppIdParse) | ||
3997 | 559 | { | ||
3998 | 560 | EXPECT_FALSE(ubuntu::app_launch::AppID::parse("com.ubuntu.test_test_123").empty()); | ||
3999 | 561 | EXPECT_FALSE(ubuntu::app_launch::AppID::find("inkscape").empty()); | ||
4000 | 562 | |||
4001 | 563 | auto id = ubuntu::app_launch::AppID::parse("com.ubuntu.test_test_123"); | ||
4002 | 564 | |||
4003 | 565 | ASSERT_FALSE(id.empty()); | ||
4004 | 566 | EXPECT_EQ("com.ubuntu.test", id.package.value()); | ||
4005 | 567 | EXPECT_EQ("test", id.appname.value()); | ||
4006 | 568 | EXPECT_EQ("123", id.version.value()); | ||
4007 | 569 | |||
4008 | 570 | return; | ||
4009 | 571 | } | ||
4010 | 572 | |||
4011 | 573 | TEST_F(LibUAL, DISABLED_ApplicationList) | ||
4012 | 574 | { | ||
4013 | 575 | auto apps = ubuntu::app_launch::Registry::runningApps(registry); | ||
4014 | 576 | |||
4015 | 577 | ASSERT_EQ(2, apps.size()); | ||
4016 | 578 | |||
4017 | 579 | apps.sort([](const std::shared_ptr<ubuntu::app_launch::Application>& a, | ||
4018 | 580 | const std::shared_ptr<ubuntu::app_launch::Application>& b) | ||
4019 | 581 | { | ||
4020 | 582 | std::string sa = a->appId(); | ||
4021 | 583 | std::string sb = b->appId(); | ||
4022 | 584 | |||
4023 | 585 | return sa < sb; | ||
4024 | 586 | }); | ||
4025 | 587 | |||
4026 | 588 | EXPECT_EQ("com.test.good_application_1.2.3", (std::string)apps.front()->appId()); | ||
4027 | 589 | EXPECT_EQ("multiple", (std::string)apps.back()->appId()); | ||
4028 | 590 | } | ||
4029 | 591 | |||
4030 | 592 | typedef struct | ||
4031 | 593 | { | ||
4032 | 594 | unsigned int count; | ||
4033 | 595 | const gchar* name; | ||
4034 | 596 | } observer_data_t; | ||
4035 | 597 | |||
4036 | 598 | static void observer_cb(const gchar* appid, gpointer user_data) | ||
4037 | 599 | { | ||
4038 | 600 | observer_data_t* data = (observer_data_t*)user_data; | ||
4039 | 601 | |||
4040 | 602 | if (data->name == NULL) | ||
4041 | 603 | { | ||
4042 | 604 | data->count++; | ||
4043 | 605 | } | ||
4044 | 606 | else if (g_strcmp0(data->name, appid) == 0) | ||
4045 | 607 | { | ||
4046 | 608 | data->count++; | ||
4047 | 609 | } | ||
4048 | 610 | } | ||
4049 | 611 | |||
4050 | 612 | TEST_F(LibUAL, StartStopObserver) | ||
4051 | 613 | { | ||
4052 | 614 | observer_data_t start_data = {.count = 0, .name = nullptr}; | ||
4053 | 615 | observer_data_t stop_data = {.count = 0, .name = nullptr}; | ||
4054 | 616 | |||
4055 | 617 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_started(observer_cb, &start_data)); | ||
4056 | 618 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_stop(observer_cb, &stop_data)); | ||
4057 | 619 | |||
4058 | 620 | DbusTestDbusMockObject* obj = | ||
4059 | 621 | dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); | ||
4060 | 622 | |||
4061 | 623 | /* Basic start */ | ||
4062 | 624 | dbus_test_dbus_mock_object_emit_signal( | ||
4063 | 625 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4064 | 626 | g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), | ||
4065 | 627 | NULL); | ||
4066 | 628 | |||
4067 | 629 | g_usleep(100000); | ||
4068 | 630 | while (g_main_pending()) | ||
4069 | 631 | { | ||
4070 | 632 | g_main_iteration(TRUE); | ||
4071 | 633 | } | ||
4072 | 634 | |||
4073 | 635 | ASSERT_EQ(start_data.count, 1); | ||
4074 | 636 | |||
4075 | 637 | /* Basic stop */ | ||
4076 | 638 | dbus_test_dbus_mock_object_emit_signal( | ||
4077 | 639 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4078 | 640 | g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), | ||
4079 | 641 | NULL); | ||
4080 | 642 | |||
4081 | 643 | g_usleep(100000); | ||
4082 | 644 | while (g_main_pending()) | ||
4083 | 645 | { | ||
4084 | 646 | g_main_iteration(TRUE); | ||
4085 | 647 | } | ||
4086 | 648 | |||
4087 | 649 | ASSERT_EQ(stop_data.count, 1); | ||
4088 | 650 | |||
4089 | 651 | /* Start legacy */ | ||
4090 | 652 | start_data.count = 0; | ||
4091 | 653 | start_data.name = "multiple"; | ||
4092 | 654 | |||
4093 | 655 | dbus_test_dbus_mock_object_emit_signal( | ||
4094 | 656 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4095 | 657 | g_variant_new_parsed("('started', ['JOB=application-legacy', 'INSTANCE=multiple-234235'])"), NULL); | ||
4096 | 658 | |||
4097 | 659 | g_usleep(100000); | ||
4098 | 660 | while (g_main_pending()) | ||
4099 | 661 | { | ||
4100 | 662 | g_main_iteration(TRUE); | ||
4101 | 663 | } | ||
4102 | 664 | |||
4103 | 665 | ASSERT_EQ(start_data.count, 1); | ||
4104 | 666 | |||
4105 | 667 | /* Legacy stop */ | ||
4106 | 668 | stop_data.count = 0; | ||
4107 | 669 | stop_data.name = "bar"; | ||
4108 | 670 | |||
4109 | 671 | dbus_test_dbus_mock_object_emit_signal( | ||
4110 | 672 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4111 | 673 | g_variant_new_parsed("('stopped', ['JOB=application-legacy', 'INSTANCE=bar-9344321'])"), NULL); | ||
4112 | 674 | |||
4113 | 675 | g_usleep(100000); | ||
4114 | 676 | while (g_main_pending()) | ||
4115 | 677 | { | ||
4116 | 678 | g_main_iteration(TRUE); | ||
4117 | 679 | } | ||
4118 | 680 | |||
4119 | 681 | ASSERT_EQ(stop_data.count, 1); | ||
4120 | 682 | |||
4121 | 683 | /* Test Noise Start */ | ||
4122 | 684 | start_data.count = 0; | ||
4123 | 685 | start_data.name = "com.test.good_application_1.2.3"; | ||
4124 | 686 | stop_data.count = 0; | ||
4125 | 687 | stop_data.name = "com.test.good_application_1.2.3"; | ||
4126 | 688 | |||
4127 | 689 | /* A full lifecycle */ | ||
4128 | 690 | dbus_test_dbus_mock_object_emit_signal( | ||
4129 | 691 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4130 | 692 | g_variant_new_parsed("('starting', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), | ||
4131 | 693 | NULL); | ||
4132 | 694 | dbus_test_dbus_mock_object_emit_signal( | ||
4133 | 695 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4134 | 696 | g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), | ||
4135 | 697 | NULL); | ||
4136 | 698 | dbus_test_dbus_mock_object_emit_signal( | ||
4137 | 699 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4138 | 700 | g_variant_new_parsed("('stopping', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), | ||
4139 | 701 | NULL); | ||
4140 | 702 | dbus_test_dbus_mock_object_emit_signal( | ||
4141 | 703 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4142 | 704 | g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), | ||
4143 | 705 | NULL); | ||
4144 | 706 | |||
4145 | 707 | g_usleep(100000); | ||
4146 | 708 | while (g_main_pending()) | ||
4147 | 709 | { | ||
4148 | 710 | g_main_iteration(TRUE); | ||
4149 | 711 | } | ||
4150 | 712 | |||
4151 | 713 | /* Ensure we just signaled once for each */ | ||
4152 | 714 | ASSERT_EQ(start_data.count, 1); | ||
4153 | 715 | ASSERT_EQ(stop_data.count, 1); | ||
4154 | 716 | |||
4155 | 717 | /* Remove */ | ||
4156 | 718 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_started(observer_cb, &start_data)); | ||
4157 | 719 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_stop(observer_cb, &stop_data)); | ||
4158 | 720 | } | ||
4159 | 721 | |||
4160 | 722 | static GDBusMessage* filter_starting(GDBusConnection* conn, | ||
4161 | 723 | GDBusMessage* message, | ||
4162 | 724 | gboolean incomming, | ||
4163 | 725 | gpointer user_data) | ||
4164 | 726 | { | ||
4165 | 727 | if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingSignal") == 0) | ||
4166 | 728 | { | ||
4167 | 729 | unsigned int* count = static_cast<unsigned int*>(user_data); | ||
4168 | 730 | (*count)++; | ||
4169 | 731 | g_object_unref(message); | ||
4170 | 732 | return NULL; | ||
4171 | 733 | } | ||
4172 | 734 | |||
4173 | 735 | return message; | ||
4174 | 736 | } | ||
4175 | 737 | |||
4176 | 738 | static void starting_observer(const gchar* appid, gpointer user_data) | ||
4177 | 739 | { | ||
4178 | 740 | std::string* last = static_cast<std::string*>(user_data); | ||
4179 | 741 | *last = appid; | ||
4180 | 742 | return; | ||
4181 | 743 | } | ||
4182 | 744 | |||
4183 | 745 | TEST_F(LibUAL, StartingResponses) | ||
4184 | 746 | { | ||
4185 | 747 | std::string last_observer; | ||
4186 | 748 | unsigned int starting_count = 0; | ||
4187 | 749 | GDBusConnection* session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); | ||
4188 | 750 | guint filter = g_dbus_connection_add_filter(session, filter_starting, &starting_count, NULL); | ||
4189 | 751 | |||
4190 | 752 | EXPECT_TRUE(ubuntu_app_launch_observer_add_app_starting(starting_observer, &last_observer)); | ||
4191 | 753 | |||
4192 | 754 | g_dbus_connection_emit_signal(session, NULL, /* destination */ | ||
4193 | 755 | "/", /* path */ | ||
4194 | 756 | "com.canonical.UbuntuAppLaunch", /* interface */ | ||
4195 | 757 | "UnityStartingBroadcast", /* signal */ | ||
4196 | 758 | g_variant_new("(s)", "com.test.good_application_1.2.3"), /* params, the same */ | ||
4197 | 759 | NULL); | ||
4198 | 760 | |||
4199 | 761 | pause(100); | ||
4200 | 762 | |||
4201 | 763 | EXPECT_EQ("com.test.good_application_1.2.3", last_observer); | ||
4202 | 764 | EXPECT_EQ(1, starting_count); | ||
4203 | 765 | |||
4204 | 766 | EXPECT_TRUE(ubuntu_app_launch_observer_delete_app_starting(starting_observer, &last_observer)); | ||
4205 | 767 | |||
4206 | 768 | g_dbus_connection_remove_filter(session, filter); | ||
4207 | 769 | g_object_unref(session); | ||
4208 | 770 | } | ||
4209 | 771 | |||
4210 | 772 | TEST_F(LibUAL, AppIdTest) | ||
4211 | 773 | { | ||
4212 | 774 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
4213 | 775 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
4214 | 776 | app->launch(); | ||
4215 | 777 | |||
4216 | 778 | pause(50); /* Ensure all the events come through */ | ||
4217 | 779 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); | ||
4218 | 780 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); | ||
4219 | 781 | } | ||
4220 | 782 | |||
4221 | 783 | GDBusMessage* filter_func_good(GDBusConnection* conn, GDBusMessage* message, gboolean incomming, gpointer user_data) | ||
4222 | 784 | { | ||
4223 | 785 | if (!incomming) | ||
4224 | 786 | { | ||
4225 | 787 | return message; | ||
4226 | 788 | } | ||
4227 | 789 | |||
4228 | 790 | if (g_strcmp0(g_dbus_message_get_path(message), (gchar*)user_data) == 0) | ||
4229 | 791 | { | ||
4230 | 792 | GDBusMessage* reply = g_dbus_message_new_method_reply(message); | ||
4231 | 793 | g_dbus_connection_send_message(conn, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); | ||
4232 | 794 | g_object_unref(message); | ||
4233 | 795 | return NULL; | ||
4234 | 796 | } | ||
4235 | 797 | |||
4236 | 798 | return message; | ||
4237 | 799 | } | ||
4238 | 800 | |||
4239 | 801 | TEST_F(LibUAL, UrlSendTest) | ||
4240 | 802 | { | ||
4241 | 803 | GDBusConnection* session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); | ||
4242 | 804 | guint filter = g_dbus_connection_add_filter(session, filter_func_good, | ||
4243 | 805 | (gpointer) "/com_2etest_2egood_5fapplication_5f1_2e2_2e3", NULL); | ||
4244 | 806 | |||
4245 | 807 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
4246 | 808 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
4247 | 809 | std::vector<ubuntu::app_launch::Application::URL> uris = { | ||
4248 | 810 | ubuntu::app_launch::Application::URL::from_raw("http://www.test.com")}; | ||
4249 | 811 | |||
4250 | 812 | app->launch(uris); | ||
4251 | 813 | |||
4252 | 814 | pause(100); /* Ensure all the events come through */ | ||
4253 | 815 | |||
4254 | 816 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); | ||
4255 | 817 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); | ||
4256 | 818 | |||
4257 | 819 | g_dbus_connection_remove_filter(session, filter); | ||
4258 | 820 | |||
4259 | 821 | /* Send multiple resume responses to ensure we unsubscribe */ | ||
4260 | 822 | /* Multiple to increase our chance of hitting a bad free in the middle, | ||
4261 | 823 | fun with async! */ | ||
4262 | 824 | int i; | ||
4263 | 825 | for (i = 0; i < 5; i++) | ||
4264 | 826 | { | ||
4265 | 827 | g_dbus_connection_emit_signal(session, NULL, /* destination */ | ||
4266 | 828 | "/", /* path */ | ||
4267 | 829 | "com.canonical.UbuntuAppLaunch", /* interface */ | ||
4268 | 830 | "UnityResumeResponse", /* signal */ | ||
4269 | 831 | g_variant_new("(s)", "com.test.good_application_1.2.3"), /* params, the same */ | ||
4270 | 832 | NULL); | ||
4271 | 833 | |||
4272 | 834 | pause(50); /* Ensure all the events come through */ | ||
4273 | 835 | } | ||
4274 | 836 | |||
4275 | 837 | g_object_unref(session); | ||
4276 | 838 | } | ||
4277 | 839 | |||
4278 | 840 | TEST_F(LibUAL, UrlSendNoObjectTest) | ||
4279 | 841 | { | ||
4280 | 842 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
4281 | 843 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
4282 | 844 | std::vector<ubuntu::app_launch::Application::URL> uris = { | ||
4283 | 845 | ubuntu::app_launch::Application::URL::from_raw("http://www.test.com")}; | ||
4284 | 846 | |||
4285 | 847 | app->launch(uris); | ||
4286 | 848 | |||
4287 | 849 | pause(100); /* Ensure all the events come through */ | ||
4288 | 850 | |||
4289 | 851 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); | ||
4290 | 852 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); | ||
4291 | 853 | } | ||
4292 | 854 | |||
4293 | 855 | TEST_F(LibUAL, UnityTimeoutTest) | ||
4294 | 856 | { | ||
4295 | 857 | this->resume_timeout = 100; | ||
4296 | 858 | |||
4297 | 859 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
4298 | 860 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
4299 | 861 | |||
4300 | 862 | app->launch(); | ||
4301 | 863 | |||
4302 | 864 | pause(1000); /* Ensure all the events come through */ | ||
4303 | 865 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); | ||
4304 | 866 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); | ||
4305 | 867 | } | ||
4306 | 868 | |||
4307 | 869 | TEST_F(LibUAL, UnityTimeoutUriTest) | ||
4308 | 870 | { | ||
4309 | 871 | this->resume_timeout = 200; | ||
4310 | 872 | |||
4311 | 873 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
4312 | 874 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
4313 | 875 | std::vector<ubuntu::app_launch::Application::URL> uris = { | ||
4314 | 876 | ubuntu::app_launch::Application::URL::from_raw("http://www.test.com")}; | ||
4315 | 877 | |||
4316 | 878 | app->launch(uris); | ||
4317 | 879 | |||
4318 | 880 | pause(1000); /* Ensure all the events come through */ | ||
4319 | 881 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); | ||
4320 | 882 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); | ||
4321 | 883 | } | ||
4322 | 884 | |||
4323 | 885 | GDBusMessage* filter_respawn(GDBusConnection* conn, GDBusMessage* message, gboolean incomming, gpointer user_data) | ||
4324 | 886 | { | ||
4325 | 887 | if (g_strcmp0(g_dbus_message_get_member(message), "UnityResumeResponse") == 0) | ||
4326 | 888 | { | ||
4327 | 889 | g_object_unref(message); | ||
4328 | 890 | return NULL; | ||
4329 | 891 | } | ||
4330 | 892 | |||
4331 | 893 | return message; | ||
4332 | 894 | } | ||
4333 | 895 | |||
4334 | 896 | TEST_F(LibUAL, UnityLostTest) | ||
4335 | 897 | { | ||
4336 | 898 | GDBusConnection* session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); | ||
4337 | 899 | guint filter = g_dbus_connection_add_filter(session, filter_respawn, NULL, NULL); | ||
4338 | 900 | |||
4339 | 901 | guint start = g_get_monotonic_time(); | ||
4340 | 902 | |||
4341 | 903 | auto appid = ubuntu::app_launch::AppID::parse("com.test.good_application_1.2.3"); | ||
4342 | 904 | auto app = ubuntu::app_launch::Application::create(appid, registry); | ||
4343 | 905 | std::vector<ubuntu::app_launch::Application::URL> uris = { | ||
4344 | 906 | ubuntu::app_launch::Application::URL::from_raw("http://www.test.com")}; | ||
4345 | 907 | |||
4346 | 908 | app->launch(uris); | ||
4347 | 909 | |||
4348 | 910 | guint end = g_get_monotonic_time(); | ||
4349 | 911 | |||
4350 | 912 | g_debug("Start call time: %d ms", (end - start) / 1000); | ||
4351 | 913 | EXPECT_LT(end - start, 2000 * 1000); | ||
4352 | 914 | |||
4353 | 915 | pause(1000); /* Ensure all the events come through */ | ||
4354 | 916 | |||
4355 | 917 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); | ||
4356 | 918 | EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); | ||
4357 | 919 | |||
4358 | 920 | g_dbus_connection_remove_filter(session, filter); | ||
4359 | 921 | g_object_unref(session); | ||
4360 | 922 | } | ||
4361 | 923 | |||
4362 | 924 | TEST_F(LibUAL, LegacySingleInstance) | ||
4363 | 925 | { | ||
4364 | 926 | DbusTestDbusMockObject* obj = | ||
4365 | 927 | dbus_test_dbus_mock_get_object(mock, "/com/test/application_legacy", "com.ubuntu.Upstart0_6.Job", NULL); | ||
4366 | 928 | |||
4367 | 929 | /* Check for a single-instance app */ | ||
4368 | 930 | auto singleappid = ubuntu::app_launch::AppID::find("single"); | ||
4369 | 931 | auto singleapp = ubuntu::app_launch::Application::create(singleappid, registry); | ||
4370 | 932 | |||
4371 | 933 | singleapp->launch(); | ||
4372 | 934 | |||
4373 | 935 | guint len = 0; | ||
4374 | 936 | const DbusTestDbusMockCall* calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
4375 | 937 | EXPECT_NE(nullptr, calls); | ||
4376 | 938 | EXPECT_EQ(1, len); | ||
4377 | 939 | |||
4378 | 940 | EXPECT_STREQ("Start", calls->name); | ||
4379 | 941 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
4380 | 942 | |||
4381 | 943 | GVariant* block = g_variant_get_child_value(calls->params, 1); | ||
4382 | 944 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
4383 | 945 | g_variant_unref(block); | ||
4384 | 946 | |||
4385 | 947 | GVariant* env = g_variant_get_child_value(calls->params, 0); | ||
4386 | 948 | EXPECT_TRUE(check_env(env, "APP_ID", "single")); | ||
4387 | 949 | EXPECT_TRUE(check_env(env, "INSTANCE_ID", "")); | ||
4388 | 950 | g_variant_unref(env); | ||
4389 | 951 | |||
4390 | 952 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4391 | 953 | |||
4392 | 954 | /* Check for a multi-instance app */ | ||
4393 | 955 | auto multipleappid = ubuntu::app_launch::AppID::find("multiple"); | ||
4394 | 956 | auto multipleapp = ubuntu::app_launch::Application::create(multipleappid, registry); | ||
4395 | 957 | |||
4396 | 958 | multipleapp->launch(); | ||
4397 | 959 | |||
4398 | 960 | len = 0; | ||
4399 | 961 | calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
4400 | 962 | EXPECT_NE(nullptr, calls); | ||
4401 | 963 | EXPECT_EQ(1, len); | ||
4402 | 964 | |||
4403 | 965 | EXPECT_STREQ("Start", calls->name); | ||
4404 | 966 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
4405 | 967 | |||
4406 | 968 | block = g_variant_get_child_value(calls->params, 1); | ||
4407 | 969 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
4408 | 970 | g_variant_unref(block); | ||
4409 | 971 | |||
4410 | 972 | env = g_variant_get_child_value(calls->params, 0); | ||
4411 | 973 | EXPECT_TRUE(check_env(env, "APP_ID", "multiple")); | ||
4412 | 974 | EXPECT_FALSE(check_env(env, "INSTANCE_ID", "")); | ||
4413 | 975 | g_variant_unref(env); | ||
4414 | 976 | } | ||
4415 | 977 | |||
4416 | 978 | static void failed_observer(const gchar* appid, UbuntuAppLaunchAppFailed reason, gpointer user_data) | ||
4417 | 979 | { | ||
4418 | 980 | if (reason == UBUNTU_APP_LAUNCH_APP_FAILED_CRASH) | ||
4419 | 981 | { | ||
4420 | 982 | std::string* last = static_cast<std::string*>(user_data); | ||
4421 | 983 | *last = appid; | ||
4422 | 984 | } | ||
4423 | 985 | return; | ||
4424 | 986 | } | ||
4425 | 987 | |||
4426 | 988 | TEST_F(LibUAL, FailingObserver) | ||
4427 | 989 | { | ||
4428 | 990 | std::string last_observer; | ||
4429 | 991 | GDBusConnection* session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); | ||
4430 | 992 | |||
4431 | 993 | EXPECT_TRUE(ubuntu_app_launch_observer_add_app_failed(failed_observer, &last_observer)); | ||
4432 | 994 | |||
4433 | 995 | g_dbus_connection_emit_signal( | ||
4434 | 996 | session, NULL, /* destination */ | ||
4435 | 997 | "/", /* path */ | ||
4436 | 998 | "com.canonical.UbuntuAppLaunch", /* interface */ | ||
4437 | 999 | "ApplicationFailed", /* signal */ | ||
4438 | 1000 | g_variant_new("(ss)", "com.test.good_application_1.2.3", "crash"), /* params, the same */ | ||
4439 | 1001 | NULL); | ||
4440 | 1002 | |||
4441 | 1003 | pause(100); | ||
4442 | 1004 | |||
4443 | 1005 | EXPECT_EQ("com.test.good_application_1.2.3", last_observer); | ||
4444 | 1006 | |||
4445 | 1007 | last_observer.clear(); | ||
4446 | 1008 | |||
4447 | 1009 | g_dbus_connection_emit_signal( | ||
4448 | 1010 | session, NULL, /* destination */ | ||
4449 | 1011 | "/", /* path */ | ||
4450 | 1012 | "com.canonical.UbuntuAppLaunch", /* interface */ | ||
4451 | 1013 | "ApplicationFailed", /* signal */ | ||
4452 | 1014 | g_variant_new("(ss)", "com.test.good_application_1.2.3", "blahblah"), /* params, the same */ | ||
4453 | 1015 | NULL); | ||
4454 | 1016 | |||
4455 | 1017 | pause(100); | ||
4456 | 1018 | |||
4457 | 1019 | EXPECT_EQ("com.test.good_application_1.2.3", last_observer); | ||
4458 | 1020 | |||
4459 | 1021 | last_observer.clear(); | ||
4460 | 1022 | |||
4461 | 1023 | g_dbus_connection_emit_signal( | ||
4462 | 1024 | session, NULL, /* destination */ | ||
4463 | 1025 | "/", /* path */ | ||
4464 | 1026 | "com.canonical.UbuntuAppLaunch", /* interface */ | ||
4465 | 1027 | "ApplicationFailed", /* signal */ | ||
4466 | 1028 | g_variant_new("(ss)", "com.test.good_application_1.2.3", "start-failure"), /* params, the same */ | ||
4467 | 1029 | NULL); | ||
4468 | 1030 | |||
4469 | 1031 | pause(100); | ||
4470 | 1032 | |||
4471 | 1033 | EXPECT_TRUE(last_observer.empty()); | ||
4472 | 1034 | |||
4473 | 1035 | EXPECT_TRUE(ubuntu_app_launch_observer_delete_app_failed(failed_observer, &last_observer)); | ||
4474 | 1036 | |||
4475 | 1037 | g_object_unref(session); | ||
4476 | 1038 | } | ||
4477 | 1039 | |||
4478 | 1040 | TEST_F(LibUAL, StartHelper) | ||
4479 | 1041 | { | ||
4480 | 1042 | DbusTestDbusMockObject* obj = | ||
4481 | 1043 | dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); | ||
4482 | 1044 | |||
4483 | 1045 | auto untrusted = ubuntu::app_launch::Helper::Type::from_raw("untrusted-type"); | ||
4484 | 1046 | |||
4485 | 1047 | /* Basic make sure we can send the event */ | ||
4486 | 1048 | auto appid = ubuntu::app_launch::AppID::parse("com.test.multiple_first_1.2.3"); | ||
4487 | 1049 | auto helper = ubuntu::app_launch::Helper::create(untrusted, appid, registry); | ||
4488 | 1050 | |||
4489 | 1051 | helper->launch(); | ||
4490 | 1052 | |||
4491 | 1053 | EXPECT_EQ(1, dbus_test_dbus_mock_object_check_method_call(mock, obj, "Start", NULL, NULL)); | ||
4492 | 1054 | |||
4493 | 1055 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4494 | 1056 | |||
4495 | 1057 | /* Now check a multi out */ | ||
4496 | 1058 | helper->launch(); | ||
4497 | 1059 | |||
4498 | 1060 | guint len = 0; | ||
4499 | 1061 | auto calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
4500 | 1062 | EXPECT_NE(nullptr, calls); | ||
4501 | 1063 | EXPECT_EQ(1, len); | ||
4502 | 1064 | |||
4503 | 1065 | EXPECT_STREQ("Start", calls->name); | ||
4504 | 1066 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
4505 | 1067 | |||
4506 | 1068 | auto block = g_variant_get_child_value(calls->params, 1); | ||
4507 | 1069 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
4508 | 1070 | g_variant_unref(block); | ||
4509 | 1071 | |||
4510 | 1072 | auto env = g_variant_get_child_value(calls->params, 0); | ||
4511 | 1073 | EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); | ||
4512 | 1074 | EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); | ||
4513 | 1075 | g_variant_unref(env); | ||
4514 | 1076 | |||
4515 | 1077 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4516 | 1078 | |||
4517 | 1079 | /* Let's pass some URLs */ | ||
4518 | 1080 | std::vector<ubuntu::app_launch::Helper::URL> urls = { | ||
4519 | 1081 | ubuntu::app_launch::Helper::URL::from_raw("http://ubuntu.com/"), | ||
4520 | 1082 | ubuntu::app_launch::Helper::URL::from_raw("https://ubuntu.com/"), | ||
4521 | 1083 | ubuntu::app_launch::Helper::URL::from_raw("file:///home/phablet/test.txt")}; | ||
4522 | 1084 | helper->launch(urls); | ||
4523 | 1085 | |||
4524 | 1086 | len = 0; | ||
4525 | 1087 | calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
4526 | 1088 | EXPECT_NE(nullptr, calls); | ||
4527 | 1089 | EXPECT_EQ(1, len); | ||
4528 | 1090 | |||
4529 | 1091 | env = g_variant_get_child_value(calls->params, 0); | ||
4530 | 1092 | EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); | ||
4531 | 1093 | EXPECT_TRUE( | ||
4532 | 1094 | check_env(env, "APP_URIS", "'http://ubuntu.com/' 'https://ubuntu.com/' 'file:///home/phablet/test.txt'")); | ||
4533 | 1095 | EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); | ||
4534 | 1096 | EXPECT_FALSE(check_env(env, "INSTANCE_ID", NULL)); | ||
4535 | 1097 | g_variant_unref(env); | ||
4536 | 1098 | |||
4537 | 1099 | return; | ||
4538 | 1100 | } | ||
4539 | 1101 | |||
4540 | 1102 | TEST_F(LibUAL, StopHelper) | ||
4541 | 1103 | { | ||
4542 | 1104 | DbusTestDbusMockObject* obj = | ||
4543 | 1105 | dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); | ||
4544 | 1106 | |||
4545 | 1107 | /* Multi helper */ | ||
4546 | 1108 | auto untrusted = ubuntu::app_launch::Helper::Type::from_raw("untrusted-type"); | ||
4547 | 1109 | |||
4548 | 1110 | auto appid = ubuntu::app_launch::AppID::parse("com.bar_foo_8432.13.1"); | ||
4549 | 1111 | auto helper = ubuntu::app_launch::Helper::create(untrusted, appid, registry); | ||
4550 | 1112 | |||
4551 | 1113 | ASSERT_TRUE(helper->hasInstances()); | ||
4552 | 1114 | |||
4553 | 1115 | auto instances = helper->instances(); | ||
4554 | 1116 | |||
4555 | 1117 | EXPECT_EQ(1, instances.size()); | ||
4556 | 1118 | |||
4557 | 1119 | instances[0]->stop(); | ||
4558 | 1120 | |||
4559 | 1121 | ASSERT_EQ(dbus_test_dbus_mock_object_check_method_call(mock, obj, "Stop", NULL, NULL), 1); | ||
4560 | 1122 | |||
4561 | 1123 | guint len = 0; | ||
4562 | 1124 | auto calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Stop", &len, NULL); | ||
4563 | 1125 | EXPECT_NE(nullptr, calls); | ||
4564 | 1126 | EXPECT_EQ(1, len); | ||
4565 | 1127 | |||
4566 | 1128 | EXPECT_STREQ("Stop", calls->name); | ||
4567 | 1129 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
4568 | 1130 | |||
4569 | 1131 | auto block = g_variant_get_child_value(calls->params, 1); | ||
4570 | 1132 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
4571 | 1133 | g_variant_unref(block); | ||
4572 | 1134 | |||
4573 | 1135 | auto env = g_variant_get_child_value(calls->params, 0); | ||
4574 | 1136 | EXPECT_TRUE(check_env(env, "APP_ID", "com.bar_foo_8432.13.1")); | ||
4575 | 1137 | EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); | ||
4576 | 1138 | EXPECT_TRUE(check_env(env, "INSTANCE_ID", "24034582324132")); | ||
4577 | 1139 | g_variant_unref(env); | ||
4578 | 1140 | |||
4579 | 1141 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4580 | 1142 | |||
4581 | 1143 | return; | ||
4582 | 1144 | } | ||
4583 | 1145 | |||
4584 | 1146 | TEST_F(LibUAL, HelperList) | ||
4585 | 1147 | { | ||
4586 | 1148 | auto nothelper = ubuntu::app_launch::Helper::Type::from_raw("not-a-type"); | ||
4587 | 1149 | auto notlist = ubuntu::app_launch::Registry::runningHelpers(nothelper, registry); | ||
4588 | 1150 | |||
4589 | 1151 | EXPECT_EQ(0, notlist.size()); | ||
4590 | 1152 | |||
4591 | 1153 | auto goodhelper = ubuntu::app_launch::Helper::Type::from_raw("untrusted-type"); | ||
4592 | 1154 | auto goodlist = ubuntu::app_launch::Registry::runningHelpers(goodhelper, registry); | ||
4593 | 1155 | |||
4594 | 1156 | EXPECT_EQ(2, goodlist.size()); | ||
4595 | 1157 | |||
4596 | 1158 | goodlist.sort( | ||
4597 | 1159 | [](const std::shared_ptr<ubuntu::app_launch::Helper>& a, const std::shared_ptr<ubuntu::app_launch::Helper>& b) | ||
4598 | 1160 | { | ||
4599 | 1161 | std::string sa = a->appId(); | ||
4600 | 1162 | std::string sb = b->appId(); | ||
4601 | 1163 | |||
4602 | 1164 | return sa < sb; | ||
4603 | 1165 | }); | ||
4604 | 1166 | |||
4605 | 1167 | EXPECT_EQ("com.bar_foo_8432.13.1", (std::string)goodlist.front()->appId()); | ||
4606 | 1168 | EXPECT_EQ("com.foo_bar_43.23.12", (std::string)goodlist.back()->appId()); | ||
4607 | 1169 | |||
4608 | 1170 | EXPECT_TRUE(goodlist.front()->hasInstances()); | ||
4609 | 1171 | EXPECT_TRUE(goodlist.back()->hasInstances()); | ||
4610 | 1172 | |||
4611 | 1173 | EXPECT_EQ(1, goodlist.front()->instances().size()); | ||
4612 | 1174 | EXPECT_EQ(1, goodlist.back()->instances().size()); | ||
4613 | 1175 | |||
4614 | 1176 | EXPECT_TRUE(goodlist.front()->instances()[0]->isRunning()); | ||
4615 | 1177 | EXPECT_TRUE(goodlist.back()->instances()[0]->isRunning()); | ||
4616 | 1178 | } | ||
4617 | 1179 | |||
4618 | 1180 | typedef struct | ||
4619 | 1181 | { | ||
4620 | 1182 | unsigned int count; | ||
4621 | 1183 | const gchar* appid; | ||
4622 | 1184 | const gchar* type; | ||
4623 | 1185 | const gchar* instance; | ||
4624 | 1186 | } helper_observer_data_t; | ||
4625 | 1187 | |||
4626 | 1188 | static void helper_observer_cb(const gchar* appid, const gchar* instance, const gchar* type, gpointer user_data) | ||
4627 | 1189 | { | ||
4628 | 1190 | helper_observer_data_t* data = (helper_observer_data_t*)user_data; | ||
4629 | 1191 | |||
4630 | 1192 | if (g_strcmp0(data->appid, appid) == 0 && g_strcmp0(data->type, type) == 0 && | ||
4631 | 1193 | g_strcmp0(data->instance, instance) == 0) | ||
4632 | 1194 | { | ||
4633 | 1195 | data->count++; | ||
4634 | 1196 | } | ||
4635 | 1197 | } | ||
4636 | 1198 | |||
4637 | 1199 | TEST_F(LibUAL, StartStopHelperObserver) | ||
4638 | 1200 | { | ||
4639 | 1201 | helper_observer_data_t start_data = { | ||
4640 | 1202 | .count = 0, .appid = "com.foo_foo_1.2.3", .type = "my-type-is-scorpio", .instance = nullptr}; | ||
4641 | 1203 | helper_observer_data_t stop_data = { | ||
4642 | 1204 | .count = 0, .appid = "com.bar_bar_44.32", .type = "my-type-is-libra", .instance = "1234"}; | ||
4643 | 1205 | |||
4644 | 1206 | ASSERT_TRUE(ubuntu_app_launch_observer_add_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data)); | ||
4645 | 1207 | ASSERT_TRUE(ubuntu_app_launch_observer_add_helper_stop(helper_observer_cb, "my-type-is-libra", &stop_data)); | ||
4646 | 1208 | |||
4647 | 1209 | DbusTestDbusMockObject* obj = | ||
4648 | 1210 | dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); | ||
4649 | 1211 | |||
4650 | 1212 | /* Basic start */ | ||
4651 | 1213 | dbus_test_dbus_mock_object_emit_signal( | ||
4652 | 1214 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4653 | 1215 | g_variant_new_parsed("('started', ['JOB=untrusted-helper', 'INSTANCE=my-type-is-scorpio::com.foo_foo_1.2.3'])"), | ||
4654 | 1216 | NULL); | ||
4655 | 1217 | |||
4656 | 1218 | g_usleep(100000); | ||
4657 | 1219 | while (g_main_pending()) | ||
4658 | 1220 | { | ||
4659 | 1221 | g_main_iteration(TRUE); | ||
4660 | 1222 | } | ||
4661 | 1223 | |||
4662 | 1224 | ASSERT_EQ(start_data.count, 1); | ||
4663 | 1225 | |||
4664 | 1226 | /* Basic stop */ | ||
4665 | 1227 | dbus_test_dbus_mock_object_emit_signal( | ||
4666 | 1228 | mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), | ||
4667 | 1229 | g_variant_new_parsed( | ||
4668 | 1230 | "('stopped', ['JOB=untrusted-helper', 'INSTANCE=my-type-is-libra:1234:com.bar_bar_44.32'])"), | ||
4669 | 1231 | NULL); | ||
4670 | 1232 | |||
4671 | 1233 | g_usleep(100000); | ||
4672 | 1234 | while (g_main_pending()) | ||
4673 | 1235 | { | ||
4674 | 1236 | g_main_iteration(TRUE); | ||
4675 | 1237 | } | ||
4676 | 1238 | |||
4677 | 1239 | ASSERT_EQ(stop_data.count, 1); | ||
4678 | 1240 | |||
4679 | 1241 | /* Remove */ | ||
4680 | 1242 | ASSERT_TRUE( | ||
4681 | 1243 | ubuntu_app_launch_observer_delete_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data)); | ||
4682 | 1244 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_helper_stop(helper_observer_cb, "my-type-is-libra", &stop_data)); | ||
4683 | 1245 | } | ||
4684 | 1246 | |||
4685 | 1247 | gboolean datain(GIOChannel* source, GIOCondition cond, gpointer data) | ||
4686 | 1248 | { | ||
4687 | 1249 | gsize* datacnt = static_cast<gsize*>(data); | ||
4688 | 1250 | gchar* str = NULL; | ||
4689 | 1251 | gsize len = 0; | ||
4690 | 1252 | GError* error = NULL; | ||
4691 | 1253 | |||
4692 | 1254 | g_io_channel_read_line(source, &str, &len, NULL, &error); | ||
4693 | 1255 | g_free(str); | ||
4694 | 1256 | |||
4695 | 1257 | if (error != NULL) | ||
4696 | 1258 | { | ||
4697 | 1259 | g_warning("Unable to read from channel: %s", error->message); | ||
4698 | 1260 | g_error_free(error); | ||
4699 | 1261 | } | ||
4700 | 1262 | |||
4701 | 1263 | *datacnt += len; | ||
4702 | 1264 | |||
4703 | 1265 | return TRUE; | ||
4704 | 1266 | } | ||
4705 | 1267 | |||
4706 | 1268 | static void signal_increment(GDBusConnection* connection, | ||
4707 | 1269 | const gchar* sender, | ||
4708 | 1270 | const gchar* path, | ||
4709 | 1271 | const gchar* interface, | ||
4710 | 1272 | const gchar* signal, | ||
4711 | 1273 | GVariant* params, | ||
4712 | 1274 | gpointer user_data) | ||
4713 | 1275 | { | ||
4714 | 1276 | guint* count = (guint*)user_data; | ||
4715 | 1277 | g_debug("Count incremented to: %d", *count + 1); | ||
4716 | 1278 | *count = *count + 1; | ||
4717 | 1279 | } | ||
4718 | 1280 | |||
4719 | 1281 | TEST_F(LibUAL, PauseResume) | ||
4720 | 1282 | { | ||
4721 | 1283 | g_setenv("UBUNTU_APP_LAUNCH_OOM_PROC_PATH", CMAKE_BINARY_DIR "/libual-proc", 1); | ||
4722 | 1284 | |||
4723 | 1285 | /* Setup some spew */ | ||
4724 | 1286 | GPid spewpid = 0; | ||
4725 | 1287 | gint spewstdout = 0; | ||
4726 | 1288 | const gchar* spewline[] = {SPEW_UTILITY, NULL}; | ||
4727 | 1289 | ASSERT_TRUE(g_spawn_async_with_pipes(NULL, (gchar**)spewline, NULL, /* environment */ | ||
4728 | 1290 | G_SPAWN_DEFAULT, NULL, NULL, /* child setup */ | ||
4729 | 1291 | &spewpid, NULL, /* stdin */ | ||
4730 | 1292 | &spewstdout, NULL, /* stderr */ | ||
4731 | 1293 | NULL)); /* error */ | ||
4732 | 1294 | |||
4733 | 1295 | gsize datacnt = 0; | ||
4734 | 1296 | GIOChannel* spewoutchan = g_io_channel_unix_new(spewstdout); | ||
4735 | 1297 | g_io_channel_set_flags(spewoutchan, G_IO_FLAG_NONBLOCK, NULL); | ||
4736 | 1298 | g_io_add_watch(spewoutchan, G_IO_IN, datain, &datacnt); | ||
4737 | 1299 | |||
4738 | 1300 | /* Setup our OOM adjust file */ | ||
4739 | 1301 | gchar* procdir = g_strdup_printf(CMAKE_BINARY_DIR "/libual-proc/%d", spewpid); | ||
4740 | 1302 | ASSERT_EQ(0, g_mkdir_with_parents(procdir, 0700)); | ||
4741 | 1303 | gchar* oomadjfile = g_strdup_printf("%s/oom_score_adj", procdir); | ||
4742 | 1304 | g_free(procdir); | ||
4743 | 1305 | ASSERT_TRUE(g_file_set_contents(oomadjfile, "0", -1, NULL)); | ||
4744 | 1306 | |||
4745 | 1307 | /* Setup the cgroup */ | ||
4746 | 1308 | g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock2", TRUE); | ||
4747 | 1309 | DbusTestDbusMock* cgmock2 = dbus_test_dbus_mock_new("org.test.cgmock2"); | ||
4748 | 1310 | DbusTestDbusMockObject* cgobject = dbus_test_dbus_mock_get_object(cgmock2, "/org/linuxcontainers/cgmanager", | ||
4749 | 1311 | "org.linuxcontainers.cgmanager0_0", NULL); | ||
4750 | 1312 | gchar* pypids = g_strdup_printf("ret = [%d]", spewpid); | ||
4751 | 1313 | dbus_test_dbus_mock_object_add_method(cgmock, cgobject, "GetTasksRecursive", G_VARIANT_TYPE("(ss)"), | ||
4752 | 1314 | G_VARIANT_TYPE("ai"), pypids, NULL); | ||
4753 | 1315 | g_free(pypids); | ||
4754 | 1316 | |||
4755 | 1317 | dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock2)); | ||
4756 | 1318 | dbus_test_task_run(DBUS_TEST_TASK(cgmock2)); | ||
4757 | 1319 | g_object_unref(G_OBJECT(cgmock2)); | ||
4758 | 1320 | |||
4759 | 1321 | /* Setup ZG Mock */ | ||
4760 | 1322 | DbusTestDbusMock* zgmock = dbus_test_dbus_mock_new("org.gnome.zeitgeist.Engine"); | ||
4761 | 1323 | DbusTestDbusMockObject* zgobj = | ||
4762 | 1324 | dbus_test_dbus_mock_get_object(zgmock, "/org/gnome/zeitgeist/log/activity", "org.gnome.zeitgeist.Log", NULL); | ||
4763 | 1325 | |||
4764 | 1326 | dbus_test_dbus_mock_object_add_method(zgmock, zgobj, "InsertEvents", G_VARIANT_TYPE("a(asaasay)"), | ||
4765 | 1327 | G_VARIANT_TYPE("au"), "ret = [ 0 ]", NULL); | ||
4766 | 1328 | |||
4767 | 1329 | dbus_test_service_add_task(service, DBUS_TEST_TASK(zgmock)); | ||
4768 | 1330 | dbus_test_task_run(DBUS_TEST_TASK(zgmock)); | ||
4769 | 1331 | g_object_unref(G_OBJECT(zgmock)); | ||
4770 | 1332 | |||
4771 | 1333 | /* Give things a chance to start */ | ||
4772 | 1334 | do | ||
4773 | 1335 | { | ||
4774 | 1336 | g_debug("Giving mocks a chance to start"); | ||
4775 | 1337 | pause(200); | ||
4776 | 1338 | } while (dbus_test_task_get_state(DBUS_TEST_TASK(cgmock2)) != DBUS_TEST_TASK_STATE_RUNNING && | ||
4777 | 1339 | dbus_test_task_get_state(DBUS_TEST_TASK(zgmock)) != DBUS_TEST_TASK_STATE_RUNNING); | ||
4778 | 1340 | |||
4779 | 1341 | /* Setup signal handling */ | ||
4780 | 1342 | guint paused_count = 0; | ||
4781 | 1343 | guint resumed_count = 0; | ||
4782 | 1344 | guint paused_signal = | ||
4783 | 1345 | g_dbus_connection_signal_subscribe(bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationPaused", "/", | ||
4784 | 1346 | nullptr, G_DBUS_SIGNAL_FLAGS_NONE, signal_increment, &paused_count, nullptr); | ||
4785 | 1347 | guint resumed_signal = g_dbus_connection_signal_subscribe( | ||
4786 | 1348 | bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationResumed", "/", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, | ||
4787 | 1349 | signal_increment, &resumed_count, nullptr); | ||
4788 | 1350 | |||
4789 | 1351 | /* Test it */ | ||
4790 | 1352 | EXPECT_NE(0, datacnt); | ||
4791 | 1353 | paused_count = 0; | ||
4792 | 1354 | |||
4793 | 1355 | /* Pause the app */ | ||
4794 | 1356 | EXPECT_TRUE(ubuntu_app_launch_pause_application("com.test.good_application_1.2.3")); | ||
4795 | 1357 | |||
4796 | 1358 | pause(0); /* Flush queued events */ | ||
4797 | 1359 | datacnt = 0; /* clear it */ | ||
4798 | 1360 | |||
4799 | 1361 | pause(200); | ||
4800 | 1362 | |||
4801 | 1363 | /* Check data coming out */ | ||
4802 | 1364 | EXPECT_EQ(1, paused_count); | ||
4803 | 1365 | EXPECT_EQ(0, datacnt); | ||
4804 | 1366 | |||
4805 | 1367 | /* Check to make sure we sent the event to ZG */ | ||
4806 | 1368 | guint numcalls = 0; | ||
4807 | 1369 | const DbusTestDbusMockCall* calls = | ||
4808 | 1370 | dbus_test_dbus_mock_object_get_method_calls(zgmock, zgobj, "InsertEvents", &numcalls, NULL); | ||
4809 | 1371 | |||
4810 | 1372 | EXPECT_NE(nullptr, calls); | ||
4811 | 1373 | EXPECT_EQ(1, numcalls); | ||
4812 | 1374 | |||
4813 | 1375 | dbus_test_dbus_mock_object_clear_method_calls(zgmock, zgobj, NULL); | ||
4814 | 1376 | |||
4815 | 1377 | /* Check to ensure we set the OOM score */ | ||
4816 | 1378 | gchar* pauseoomscore = NULL; | ||
4817 | 1379 | ASSERT_TRUE(g_file_get_contents(oomadjfile, &pauseoomscore, NULL, NULL)); | ||
4818 | 1380 | EXPECT_STREQ("900", pauseoomscore); | ||
4819 | 1381 | g_free(pauseoomscore); | ||
4820 | 1382 | resumed_count = 0; | ||
4821 | 1383 | |||
4822 | 1384 | /* Now Resume the App */ | ||
4823 | 1385 | EXPECT_TRUE(ubuntu_app_launch_resume_application("com.test.good_application_1.2.3")); | ||
4824 | 1386 | |||
4825 | 1387 | pause(200); | ||
4826 | 1388 | |||
4827 | 1389 | EXPECT_NE(0, datacnt); | ||
4828 | 1390 | EXPECT_EQ(1, resumed_count); | ||
4829 | 1391 | |||
4830 | 1392 | /* Check to make sure we sent the event to ZG */ | ||
4831 | 1393 | numcalls = 0; | ||
4832 | 1394 | calls = dbus_test_dbus_mock_object_get_method_calls(zgmock, zgobj, "InsertEvents", &numcalls, NULL); | ||
4833 | 1395 | |||
4834 | 1396 | EXPECT_NE(nullptr, calls); | ||
4835 | 1397 | EXPECT_EQ(1, numcalls); | ||
4836 | 1398 | |||
4837 | 1399 | /* Check to ensure we set the OOM score */ | ||
4838 | 1400 | gchar* resumeoomscore = NULL; | ||
4839 | 1401 | ASSERT_TRUE(g_file_get_contents(oomadjfile, &resumeoomscore, NULL, NULL)); | ||
4840 | 1402 | EXPECT_STREQ("100", resumeoomscore); | ||
4841 | 1403 | g_free(resumeoomscore); | ||
4842 | 1404 | |||
4843 | 1405 | /* Clean up */ | ||
4844 | 1406 | gchar* killstr = g_strdup_printf("kill -9 %d", spewpid); | ||
4845 | 1407 | ASSERT_TRUE(g_spawn_command_line_sync(killstr, NULL, NULL, NULL, NULL)); | ||
4846 | 1408 | g_free(killstr); | ||
4847 | 1409 | |||
4848 | 1410 | g_io_channel_unref(spewoutchan); | ||
4849 | 1411 | |||
4850 | 1412 | g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL); | ||
4851 | 1413 | |||
4852 | 1414 | g_dbus_connection_signal_unsubscribe(bus, paused_signal); | ||
4853 | 1415 | g_dbus_connection_signal_unsubscribe(bus, resumed_signal); | ||
4854 | 1416 | |||
4855 | 1417 | /* Kill ZG default instance :-( */ | ||
4856 | 1418 | ZeitgeistLog* log = zeitgeist_log_get_default(); | ||
4857 | 1419 | g_object_unref(log); | ||
4858 | 1420 | g_object_unref(log); | ||
4859 | 1421 | |||
4860 | 1422 | g_free(oomadjfile); | ||
4861 | 1423 | } | ||
4862 | 1424 | |||
4863 | 1425 | TEST_F(LibUAL, StartSessionHelper) | ||
4864 | 1426 | { | ||
4865 | 1427 | DbusTestDbusMockObject* obj = | ||
4866 | 1428 | dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); | ||
4867 | 1429 | MirConnection* conn = mir_connect_sync("libual-test", "start-session-helper"); // Mocked, doesn't need cleaning up | ||
4868 | 1430 | MirPromptSession* msession = mir_connection_create_prompt_session_sync(conn, 5, nullptr, nullptr); | ||
4869 | 1431 | |||
4870 | 1432 | /* Building a temporary file and making an FD for it */ | ||
4871 | 1433 | const char* filedata = "This is some data that we should get on the other side\n"; | ||
4872 | 1434 | ASSERT_TRUE(g_file_set_contents(SESSION_TEMP_FILE, filedata, strlen(filedata), nullptr) == TRUE); | ||
4873 | 1435 | int mirfd = open(SESSION_TEMP_FILE, 0); | ||
4874 | 1436 | mir_mock_set_trusted_fd(mirfd); | ||
4875 | 1437 | |||
4876 | 1438 | /* Basic make sure we can send the event */ | ||
4877 | 1439 | auto untrusted = ubuntu::app_launch::Helper::Type::from_raw("untrusted-type"); | ||
4878 | 1440 | auto appid = ubuntu::app_launch::AppID::parse("com.test.multiple_first_1.2.3"); | ||
4879 | 1441 | auto helper = ubuntu::app_launch::Helper::create(untrusted, appid, registry); | ||
4880 | 1442 | |||
4881 | 1443 | helper->launch(msession); | ||
4882 | 1444 | |||
4883 | 1445 | guint len = 0; | ||
4884 | 1446 | const DbusTestDbusMockCall* calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); | ||
4885 | 1447 | EXPECT_NE(nullptr, calls); | ||
4886 | 1448 | EXPECT_EQ(1, len); | ||
4887 | 1449 | |||
4888 | 1450 | EXPECT_STREQ("Start", calls->name); | ||
4889 | 1451 | EXPECT_EQ(2, g_variant_n_children(calls->params)); | ||
4890 | 1452 | |||
4891 | 1453 | GVariant* block = g_variant_get_child_value(calls->params, 1); | ||
4892 | 1454 | EXPECT_TRUE(g_variant_get_boolean(block)); | ||
4893 | 1455 | g_variant_unref(block); | ||
4894 | 1456 | |||
4895 | 1457 | /* Check the environment */ | ||
4896 | 1458 | GVariant* env = g_variant_get_child_value(calls->params, 0); | ||
4897 | 1459 | EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); | ||
4898 | 1460 | EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); | ||
4899 | 1461 | |||
4900 | 1462 | GVariant* mnamev = find_env(env, "UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); | ||
4901 | 1463 | ASSERT_NE(nullptr, mnamev); /* Have to assert because, eh, GVariant */ | ||
4902 | 1464 | EXPECT_STREQ(g_dbus_connection_get_unique_name(bus), | ||
4903 | 1465 | g_variant_get_string(mnamev, nullptr) + strlen("UBUNTU_APP_LAUNCH_DEMANGLE_NAME=")); | ||
4904 | 1466 | GVariant* mpathv = find_env(env, "UBUNTU_APP_LAUNCH_DEMANGLE_PATH"); | ||
4905 | 1467 | ASSERT_NE(nullptr, mpathv); /* Have to assert because, eh, GVariant */ | ||
4906 | 1468 | |||
4907 | 1469 | g_variant_unref(env); | ||
4908 | 1470 | |||
4909 | 1471 | /* Setup environment for call */ | ||
4910 | 1472 | const gchar* mname = g_variant_get_string(mnamev, nullptr); | ||
4911 | 1473 | mname += strlen("UBUNTU_APP_LAUNCH_DEMANGLE_NAME="); | ||
4912 | 1474 | g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME", mname, TRUE); | ||
4913 | 1475 | g_variant_unref(mnamev); | ||
4914 | 1476 | |||
4915 | 1477 | const gchar* mpath = g_variant_get_string(mpathv, nullptr); | ||
4916 | 1478 | mpath += strlen("UBUNTU_APP_LAUNCH_DEMANGLE_PATH="); | ||
4917 | 1479 | g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_PATH", mpath, TRUE); | ||
4918 | 1480 | g_variant_unref(mpathv); | ||
4919 | 1481 | |||
4920 | 1482 | /* Exec our tool */ | ||
4921 | 1483 | std::promise<std::string> outputpromise; | ||
4922 | 1484 | std::thread t( | ||
4923 | 1485 | [&outputpromise]() | ||
4924 | 1486 | { | ||
4925 | 1487 | gchar* socketstdout = nullptr; | ||
4926 | 1488 | GError* error = nullptr; | ||
4927 | 1489 | g_unsetenv("G_MESSAGES_DEBUG"); | ||
4928 | 1490 | |||
4929 | 1491 | g_spawn_command_line_sync(SOCKET_DEMANGLER " " SOCKET_TOOL, &socketstdout, nullptr, nullptr, &error); | ||
4930 | 1492 | |||
4931 | 1493 | if (error != nullptr) | ||
4932 | 1494 | { | ||
4933 | 1495 | fprintf(stderr, "Unable to spawn '" SOCKET_DEMANGLER " " SOCKET_TOOL "': %s\n", error->message); | ||
4934 | 1496 | g_error_free(error); | ||
4935 | 1497 | outputpromise.set_value(std::string("")); | ||
4936 | 1498 | } | ||
4937 | 1499 | else | ||
4938 | 1500 | { | ||
4939 | 1501 | outputpromise.set_value(std::string(socketstdout)); | ||
4940 | 1502 | g_free(socketstdout); | ||
4941 | 1503 | } | ||
4942 | 1504 | }); | ||
4943 | 1505 | t.detach(); | ||
4944 | 1506 | |||
4945 | 1507 | auto outputfuture = outputpromise.get_future(); | ||
4946 | 1508 | while (outputfuture.wait_for(std::chrono::milliseconds{1}) != std::future_status::ready) | ||
4947 | 1509 | { | ||
4948 | 1510 | pause(); | ||
4949 | 1511 | } | ||
4950 | 1512 | |||
4951 | 1513 | ASSERT_STREQ(filedata, outputfuture.get().c_str()); | ||
4952 | 1514 | |||
4953 | 1515 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4954 | 1516 | |||
4955 | 1517 | return; | ||
4956 | 1518 | } | ||
4957 | 1519 | |||
4958 | 1520 | TEST_F(LibUAL, SetExec) | ||
4959 | 1521 | { | ||
4960 | 1522 | DbusTestDbusMockObject* obj = | ||
4961 | 1523 | dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); | ||
4962 | 1524 | |||
4963 | 1525 | const char* exec = "lets exec this"; | ||
4964 | 1526 | |||
4965 | 1527 | g_setenv("UPSTART_JOB", "fubar", TRUE); | ||
4966 | 1528 | g_unsetenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); | ||
4967 | 1529 | EXPECT_TRUE(ubuntu_app_launch_helper_set_exec(exec, NULL)); | ||
4968 | 1530 | |||
4969 | 1531 | guint len = 0; | ||
4970 | 1532 | const DbusTestDbusMockCall* calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL); | ||
4971 | 1533 | ASSERT_NE(nullptr, calls); | ||
4972 | 1534 | EXPECT_EQ(1, len); | ||
4973 | 1535 | |||
4974 | 1536 | gchar* appexecstr = g_strdup_printf("APP_EXEC=%s", exec); | ||
4975 | 1537 | GVariant* appexecenv = g_variant_get_child_value(calls[0].params, 1); | ||
4976 | 1538 | EXPECT_STREQ(appexecstr, g_variant_get_string(appexecenv, nullptr)); | ||
4977 | 1539 | g_variant_unref(appexecenv); | ||
4978 | 1540 | g_free(appexecstr); | ||
4979 | 1541 | |||
4980 | 1542 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4981 | 1543 | |||
4982 | 1544 | /* Now check for the demangler */ | ||
4983 | 1545 | g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME", g_dbus_connection_get_unique_name(bus), TRUE); | ||
4984 | 1546 | EXPECT_TRUE(ubuntu_app_launch_helper_set_exec(exec, NULL)); | ||
4985 | 1547 | |||
4986 | 1548 | calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL); | ||
4987 | 1549 | ASSERT_NE(nullptr, calls); | ||
4988 | 1550 | EXPECT_EQ(1, len); | ||
4989 | 1551 | |||
4990 | 1552 | gchar* demangleexecstr = g_strdup_printf("APP_EXEC=%s %s", SOCKET_DEMANGLER_INSTALL, exec); | ||
4991 | 1553 | appexecenv = g_variant_get_child_value(calls[0].params, 1); | ||
4992 | 1554 | EXPECT_STREQ(demangleexecstr, g_variant_get_string(appexecenv, nullptr)); | ||
4993 | 1555 | g_variant_unref(appexecenv); | ||
4994 | 1556 | g_free(demangleexecstr); | ||
4995 | 1557 | |||
4996 | 1558 | ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); | ||
4997 | 1559 | |||
4998 | 1560 | /* Now check for the directory */ | ||
4999 | 1561 | g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME", g_dbus_connection_get_unique_name(bus), TRUE); | ||
5000 | 1562 | EXPECT_TRUE(ubuntu_app_launch_helper_set_exec(exec, "/not/a/real/directory")); |