Merge lp:~mandel/ubuntu-download-manager/remove-username-password-update into lp:ubuntu-download-manager
- remove-username-password-update
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~mandel/ubuntu-download-manager/remove-username-password-update |
Merge into: | lp:ubuntu-download-manager |
Prerequisite: | lp:~mandel/ubuntu-download-manager/upload-go-bindings |
Diff against target: |
1835 lines (+11/-1702) 13 files modified
bindings/golang/common.go (+0/-78) bindings/golang/common_test.go (+0/-83) bindings/golang/downloader.go (+0/-600) bindings/golang/downloader_test.go (+0/-306) bindings/golang/uploader.go (+0/-396) bindings/golang/uploader_test.go (+0/-215) docs/com.canonical.applications.upload_manager.xml (+0/-2) src/uploads/priv/ubuntu/uploads/factory.cpp (+2/-4) src/uploads/priv/ubuntu/uploads/factory.h (+1/-3) src/uploads/priv/ubuntu/uploads/manager.cpp (+4/-7) src/uploads/priv/ubuntu/uploads/manager.h (+1/-3) src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp (+2/-2) src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h (+1/-3) |
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/remove-username-password-update |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Ubuntu One hackers | Pending | ||
Review via email: mp+217258@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-05-21.
Commit message
Remove the username and password from mms uploads.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
- 262. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:262
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 263. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update. - 264. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:264
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 265. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:265
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 266. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:266
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 267. By Manuel de la Peña
-
Fix merge issues due to the removal of go.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:267
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Unmerged revisions
Preview Diff
1 | === removed directory 'bindings' | |||
2 | === removed directory 'bindings/golang' | |||
3 | === removed file 'bindings/golang/common.go' | |||
4 | --- bindings/golang/common.go 2014-05-13 08:50:46 +0000 | |||
5 | +++ bindings/golang/common.go 1970-01-01 00:00:00 +0000 | |||
6 | @@ -1,78 +0,0 @@ | |||
7 | 1 | /* | ||
8 | 2 | * Copyright 2014 Canonical Ltd. | ||
9 | 3 | * | ||
10 | 4 | * Authors: | ||
11 | 5 | * Manuel de la Pena: manuel.delapena@canonical.com | ||
12 | 6 | * | ||
13 | 7 | * This file is part of ubuntu-download-manager. | ||
14 | 8 | * | ||
15 | 9 | * ubuntu-download-manager is free software; you can redistribute it and/or modify | ||
16 | 10 | * it under the terms of the GNU General Public License as published by | ||
17 | 11 | * the Free Software Foundation; version 3. | ||
18 | 12 | * | ||
19 | 13 | * ubuntu-download-manager is distributed in the hope that it will be useful, | ||
20 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | 16 | * GNU General Public License for more details. | ||
23 | 17 | * | ||
24 | 18 | * You should have received a copy of the GNU General Public License | ||
25 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
26 | 20 | */ | ||
27 | 21 | |||
28 | 22 | // Package udm provides a go interface to work with the ubuntu download manager | ||
29 | 23 | package udm | ||
30 | 24 | |||
31 | 25 | import ( | ||
32 | 26 | "launchpad.net/go-dbus/v1" | ||
33 | 27 | ) | ||
34 | 28 | |||
35 | 29 | // Progress provides how much progress has been performed in a download that was | ||
36 | 30 | // already started. | ||
37 | 31 | type Progress struct { | ||
38 | 32 | Received uint64 | ||
39 | 33 | Total uint64 | ||
40 | 34 | } | ||
41 | 35 | |||
42 | 36 | // internal interface used to simplify testing | ||
43 | 37 | type watch interface { | ||
44 | 38 | Cancel() error | ||
45 | 39 | Chanel() chan *dbus.Message | ||
46 | 40 | } | ||
47 | 41 | |||
48 | 42 | // small wrapper used to simplify testing by using the watch interface | ||
49 | 43 | type watchWrapper struct { | ||
50 | 44 | watch *dbus.SignalWatch | ||
51 | 45 | } | ||
52 | 46 | |||
53 | 47 | func newWatchWrapper(sw *dbus.SignalWatch) *watchWrapper { | ||
54 | 48 | w := watchWrapper{} | ||
55 | 49 | return &w | ||
56 | 50 | } | ||
57 | 51 | |||
58 | 52 | func (w *watchWrapper) Cancel() error { | ||
59 | 53 | return w.watch.Cancel() | ||
60 | 54 | } | ||
61 | 55 | |||
62 | 56 | func (w *watchWrapper) Chanel() chan *dbus.Message { | ||
63 | 57 | return w.watch.C | ||
64 | 58 | } | ||
65 | 59 | |||
66 | 60 | // interface added to simplify testing | ||
67 | 61 | type proxy interface { | ||
68 | 62 | Call(iface, method string, args ...interface{}) (*dbus.Message, error) | ||
69 | 63 | } | ||
70 | 64 | |||
71 | 65 | var readArgs = func(msg *dbus.Message, args ...interface{}) error { | ||
72 | 66 | return msg.Args(args) | ||
73 | 67 | } | ||
74 | 68 | |||
75 | 69 | func connectToSignal(conn *dbus.Connection, path dbus.ObjectPath, signal string) (watch, error) { | ||
76 | 70 | sw, err := conn.WatchSignal(&dbus.MatchRule{ | ||
77 | 71 | Type: dbus.TypeSignal, | ||
78 | 72 | Sender: DOWNLOAD_SERVICE, | ||
79 | 73 | Interface: DOWNLOAD_INTERFACE, | ||
80 | 74 | Member: signal, | ||
81 | 75 | Path: path}) | ||
82 | 76 | w := newWatchWrapper(sw) | ||
83 | 77 | return w, err | ||
84 | 78 | } | ||
85 | 79 | 0 | ||
86 | === removed file 'bindings/golang/common_test.go' | |||
87 | --- bindings/golang/common_test.go 2014-05-13 08:50:46 +0000 | |||
88 | +++ bindings/golang/common_test.go 1970-01-01 00:00:00 +0000 | |||
89 | @@ -1,83 +0,0 @@ | |||
90 | 1 | /* | ||
91 | 2 | * Copyright 2014 Canonical Ltd. | ||
92 | 3 | * | ||
93 | 4 | * Authors: | ||
94 | 5 | * Manuel de la Pena: manuel.delapena@canonical.com | ||
95 | 6 | * | ||
96 | 7 | * This file is part of ubuntu-download-manager. | ||
97 | 8 | * | ||
98 | 9 | * ubuntu-download-manager is free software; you can redistribute it and/or modify | ||
99 | 10 | * it under the terms of the GNU General Public License as published by | ||
100 | 11 | * the Free Software Foundation; version 3. | ||
101 | 12 | * | ||
102 | 13 | * ubuntu-download-manager is distributed in the hope that it will be useful, | ||
103 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
104 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
105 | 16 | * GNU General Public License for more details. | ||
106 | 17 | * | ||
107 | 18 | * You should have received a copy of the GNU General Public License | ||
108 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
109 | 20 | */ | ||
110 | 21 | |||
111 | 22 | package udm | ||
112 | 23 | |||
113 | 24 | import ( | ||
114 | 25 | . "gopkg.in/check.v1" | ||
115 | 26 | "launchpad.net/go-dbus/v1" | ||
116 | 27 | "testing" | ||
117 | 28 | ) | ||
118 | 29 | |||
119 | 30 | func Test(t *testing.T) { TestingT(t) } | ||
120 | 31 | |||
121 | 32 | type fakeProxy struct { | ||
122 | 33 | Interface string | ||
123 | 34 | MethodName string | ||
124 | 35 | Args []interface{} | ||
125 | 36 | Err error | ||
126 | 37 | Result *dbus.Message | ||
127 | 38 | } | ||
128 | 39 | |||
129 | 40 | func (f *fakeProxy) Call(iface, method string, args ...interface{}) (*dbus.Message, error) { | ||
130 | 41 | // store the called method and return Result | ||
131 | 42 | f.Interface = iface | ||
132 | 43 | f.MethodName = method | ||
133 | 44 | f.Args = args | ||
134 | 45 | if f.Err == nil { | ||
135 | 46 | return f.Result, nil | ||
136 | 47 | } | ||
137 | 48 | return nil, f.Err | ||
138 | 49 | } | ||
139 | 50 | |||
140 | 51 | type FakeWatch struct { | ||
141 | 52 | Canceled bool | ||
142 | 53 | Ch chan *dbus.Message | ||
143 | 54 | } | ||
144 | 55 | |||
145 | 56 | func newFakeWatch() *FakeWatch { | ||
146 | 57 | ch := make(chan *dbus.Message) | ||
147 | 58 | fw := FakeWatch{false, ch} | ||
148 | 59 | return &fw | ||
149 | 60 | } | ||
150 | 61 | |||
151 | 62 | func (w *FakeWatch) Cancel() error { | ||
152 | 63 | w.Canceled = true | ||
153 | 64 | return nil | ||
154 | 65 | } | ||
155 | 66 | |||
156 | 67 | func (w *FakeWatch) Chanel() chan *dbus.Message { | ||
157 | 68 | return w.Ch | ||
158 | 69 | } | ||
159 | 70 | |||
160 | 71 | // returns a new error that can be used in the tests | ||
161 | 72 | func newDBusError() *dbus.Message { | ||
162 | 73 | msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method") | ||
163 | 74 | msg.Type = dbus.TypeError | ||
164 | 75 | msg.ErrorName = "com.testing.udm" | ||
165 | 76 | return msg | ||
166 | 77 | } | ||
167 | 78 | |||
168 | 79 | func newDBusReturn() *dbus.Message { | ||
169 | 80 | msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method") | ||
170 | 81 | msg.Type = dbus.TypeMethodReturn | ||
171 | 82 | return msg | ||
172 | 83 | } | ||
173 | 84 | 0 | ||
174 | === removed file 'bindings/golang/downloader.go' | |||
175 | --- bindings/golang/downloader.go 2014-05-13 08:50:46 +0000 | |||
176 | +++ bindings/golang/downloader.go 1970-01-01 00:00:00 +0000 | |||
177 | @@ -1,600 +0,0 @@ | |||
178 | 1 | /* | ||
179 | 2 | * Copyright 2014 Canonical Ltd. | ||
180 | 3 | * | ||
181 | 4 | * Authors: | ||
182 | 5 | * Manuel de la Pena: manuel.delapena@canonical.com | ||
183 | 6 | * | ||
184 | 7 | * This file is part of ubuntu-download-manager. | ||
185 | 8 | * | ||
186 | 9 | * ubuntu-download-manager is free software; you can redistribute it and/or modify | ||
187 | 10 | * it under the terms of the GNU General Public License as published by | ||
188 | 11 | * the Free Software Foundation; version 3. | ||
189 | 12 | * | ||
190 | 13 | * ubuntu-download-manager is distributed in the hope that it will be useful, | ||
191 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
192 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
193 | 16 | * GNU General Public License for more details. | ||
194 | 17 | * | ||
195 | 18 | * You should have received a copy of the GNU General Public License | ||
196 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
197 | 20 | */ | ||
198 | 21 | |||
199 | 22 | // Package udm provides a go interface to work with the ubuntu download manager | ||
200 | 23 | package udm | ||
201 | 24 | |||
202 | 25 | import ( | ||
203 | 26 | "errors" | ||
204 | 27 | "fmt" | ||
205 | 28 | "launchpad.net/go-dbus/v1" | ||
206 | 29 | "runtime" | ||
207 | 30 | ) | ||
208 | 31 | |||
209 | 32 | const ( | ||
210 | 33 | DOWNLOAD_SERVICE = "com.canonical.applications.Downloader" | ||
211 | 34 | DOWNLOAD_INTERFACE = "com.canonical.applications.Download" | ||
212 | 35 | DOWNLOAD_MANAGER_INTERFACE = "com.canonical.applications.DownloadManager" | ||
213 | 36 | ) | ||
214 | 37 | |||
215 | 38 | type hashType string | ||
216 | 39 | |||
217 | 40 | const ( | ||
218 | 41 | MD5 hashType = "md5" | ||
219 | 42 | SHA1 hashType = "sha1" | ||
220 | 43 | SHA224 hashType = "sha224" | ||
221 | 44 | SHA256 hashType = "sha256" | ||
222 | 45 | SHA384 hashType = "sha384" | ||
223 | 46 | SHA512 hashType = "sha512" | ||
224 | 47 | ) | ||
225 | 48 | |||
226 | 49 | const ( | ||
227 | 50 | LOCAL_PATH = "local-path" | ||
228 | 51 | OBJECT_PATH = "objectpath" | ||
229 | 52 | POST_DOWNLOAD_COMMAND = "post-download-command" | ||
230 | 53 | ) | ||
231 | 54 | |||
232 | 55 | // Download is the common interface of a download. It provides all the required | ||
233 | 56 | // methods to interact with a download created by udm. | ||
234 | 57 | type Download interface { | ||
235 | 58 | TotalSize() (uint64, error) | ||
236 | 59 | Progress() (uint64, error) | ||
237 | 60 | Metadata() (map[string]string, error) | ||
238 | 61 | SetThrottle(uint64) error | ||
239 | 62 | Throttle() (uint64, error) | ||
240 | 63 | AllowMobileDownload(bool) error | ||
241 | 64 | SetDestinationDir(string) error | ||
242 | 65 | IsMobileDownload() (bool, error) | ||
243 | 66 | Start() error | ||
244 | 67 | Pause() error | ||
245 | 68 | Resume() error | ||
246 | 69 | Cancel() error | ||
247 | 70 | Started() chan bool | ||
248 | 71 | Paused() chan bool | ||
249 | 72 | DownloadProgress() chan Progress | ||
250 | 73 | Resumed() chan bool | ||
251 | 74 | Canceled() chan bool | ||
252 | 75 | Finished() chan string | ||
253 | 76 | Error() chan error | ||
254 | 77 | } | ||
255 | 78 | |||
256 | 79 | // FileDownload represents a single file being downloaded by udm. | ||
257 | 80 | type FileDownload struct { | ||
258 | 81 | conn *dbus.Connection | ||
259 | 82 | proxy proxy | ||
260 | 83 | path dbus.ObjectPath | ||
261 | 84 | started chan bool | ||
262 | 85 | started_w watch | ||
263 | 86 | paused chan bool | ||
264 | 87 | paused_w watch | ||
265 | 88 | resumed chan bool | ||
266 | 89 | resumed_w watch | ||
267 | 90 | canceled chan bool | ||
268 | 91 | canceled_w watch | ||
269 | 92 | finished chan string | ||
270 | 93 | finished_w watch | ||
271 | 94 | errors chan error | ||
272 | 95 | error_w watch | ||
273 | 96 | progress chan Progress | ||
274 | 97 | progress_w watch | ||
275 | 98 | } | ||
276 | 99 | |||
277 | 100 | func (down *FileDownload) free() { | ||
278 | 101 | // cancel all watches so that goroutines are done and close the | ||
279 | 102 | // channels | ||
280 | 103 | down.started_w.Cancel() | ||
281 | 104 | down.paused_w.Cancel() | ||
282 | 105 | down.resumed_w.Cancel() | ||
283 | 106 | down.canceled_w.Cancel() | ||
284 | 107 | down.finished_w.Cancel() | ||
285 | 108 | down.error_w.Cancel() | ||
286 | 109 | down.progress_w.Cancel() | ||
287 | 110 | } | ||
288 | 111 | |||
289 | 112 | func cleanDownloadData(down *FileDownload) { | ||
290 | 113 | down.free() | ||
291 | 114 | } | ||
292 | 115 | |||
293 | 116 | func newFileDownload(conn *dbus.Connection, path dbus.ObjectPath) (*FileDownload, error) { | ||
294 | 117 | proxy := conn.Object(DOWNLOAD_SERVICE, path) | ||
295 | 118 | started_ch := make(chan bool) | ||
296 | 119 | started_w, err := connectToSignal(conn, path, "started") | ||
297 | 120 | if err != nil { | ||
298 | 121 | return nil, err | ||
299 | 122 | } | ||
300 | 123 | |||
301 | 124 | paused_ch := make(chan bool) | ||
302 | 125 | paused_w, err := connectToSignal(conn, path, "paused") | ||
303 | 126 | if err != nil { | ||
304 | 127 | return nil, err | ||
305 | 128 | } | ||
306 | 129 | |||
307 | 130 | resumed_ch := make(chan bool) | ||
308 | 131 | resumed_w, err := connectToSignal(conn, path, "resumed") | ||
309 | 132 | if err != nil { | ||
310 | 133 | return nil, err | ||
311 | 134 | } | ||
312 | 135 | |||
313 | 136 | canceled_ch := make(chan bool) | ||
314 | 137 | canceled_w, err := connectToSignal(conn, path, "canceled") | ||
315 | 138 | if err != nil { | ||
316 | 139 | return nil, err | ||
317 | 140 | } | ||
318 | 141 | |||
319 | 142 | finished_ch := make(chan string) | ||
320 | 143 | finished_w, err := connectToSignal(conn, path, "finished") | ||
321 | 144 | if err != nil { | ||
322 | 145 | return nil, err | ||
323 | 146 | } | ||
324 | 147 | |||
325 | 148 | errors_ch := make(chan error) | ||
326 | 149 | errors_w, err := connectToSignal(conn, path, "error") | ||
327 | 150 | if err != nil { | ||
328 | 151 | return nil, err | ||
329 | 152 | } | ||
330 | 153 | |||
331 | 154 | progress_ch := make(chan Progress) | ||
332 | 155 | progress_w, err := connectToSignal(conn, path, "progress") | ||
333 | 156 | if err != nil { | ||
334 | 157 | return nil, err | ||
335 | 158 | } | ||
336 | 159 | |||
337 | 160 | d := FileDownload{conn, proxy, path, started_ch, started_w, paused_ch, paused_w, resumed_ch, resumed_w, canceled_ch, canceled_w, finished_ch, finished_w, errors_ch, errors_w, progress_ch, progress_w} | ||
338 | 161 | |||
339 | 162 | // connect to the diff signals so that we have nice channels that do | ||
340 | 163 | // not expose dbus watchers | ||
341 | 164 | d.connectToStarted() | ||
342 | 165 | d.connectToPaused() | ||
343 | 166 | d.connectToResumed() | ||
344 | 167 | d.connectToCanceled() | ||
345 | 168 | d.connectToFinished() | ||
346 | 169 | d.connectToError() | ||
347 | 170 | d.connectToProgress() | ||
348 | 171 | runtime.SetFinalizer(&d, cleanDownloadData) | ||
349 | 172 | return &d, nil | ||
350 | 173 | } | ||
351 | 174 | |||
352 | 175 | // TotalSize returns the total size of the file being downloaded. | ||
353 | 176 | func (down *FileDownload) TotalSize() (size uint64, err error) { | ||
354 | 177 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "totalSize") | ||
355 | 178 | if err != nil { | ||
356 | 179 | return 0, err | ||
357 | 180 | } | ||
358 | 181 | |||
359 | 182 | if reply.Type == dbus.TypeError { | ||
360 | 183 | return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
361 | 184 | } | ||
362 | 185 | |||
363 | 186 | if err = readArgs(reply, &size); err != nil { | ||
364 | 187 | return 0, err | ||
365 | 188 | } | ||
366 | 189 | return size, nil | ||
367 | 190 | } | ||
368 | 191 | |||
369 | 192 | // Process returns the process so far in downloading the file. | ||
370 | 193 | func (down *FileDownload) Progress() (progress uint64, err error) { | ||
371 | 194 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "progress") | ||
372 | 195 | if err != nil { | ||
373 | 196 | return 0, err | ||
374 | 197 | } | ||
375 | 198 | |||
376 | 199 | if reply.Type == dbus.TypeError { | ||
377 | 200 | return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
378 | 201 | } | ||
379 | 202 | |||
380 | 203 | if err = readArgs(reply, &progress); err != nil { | ||
381 | 204 | return 0, err | ||
382 | 205 | } | ||
383 | 206 | return progress, nil | ||
384 | 207 | } | ||
385 | 208 | |||
386 | 209 | // Metadata returns the metadata that was provided at creating time to the download. | ||
387 | 210 | func (down *FileDownload) Metadata() (metadata map[string]string, err error) { | ||
388 | 211 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "metadata") | ||
389 | 212 | if err != nil { | ||
390 | 213 | return nil, err | ||
391 | 214 | } | ||
392 | 215 | |||
393 | 216 | if reply.Type == dbus.TypeError { | ||
394 | 217 | return nil, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
395 | 218 | } | ||
396 | 219 | |||
397 | 220 | if err = readArgs(reply, &metadata); err != nil { | ||
398 | 221 | return nil, err | ||
399 | 222 | } | ||
400 | 223 | return metadata, nil | ||
401 | 224 | } | ||
402 | 225 | |||
403 | 226 | // SetThrottle sets the network throttle to be used in the download. | ||
404 | 227 | func (down *FileDownload) SetThrottle(throttle uint64) (err error) { | ||
405 | 228 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setThrottle", throttle) | ||
406 | 229 | if err != nil { | ||
407 | 230 | return err | ||
408 | 231 | } | ||
409 | 232 | |||
410 | 233 | if reply.Type == dbus.TypeError { | ||
411 | 234 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
412 | 235 | } | ||
413 | 236 | |||
414 | 237 | return nil | ||
415 | 238 | } | ||
416 | 239 | |||
417 | 240 | // Throttle returns the network throttle that is currently used in the download. | ||
418 | 241 | func (down *FileDownload) Throttle() (throttle uint64, err error) { | ||
419 | 242 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "throttle") | ||
420 | 243 | if err != nil { | ||
421 | 244 | return 0, err | ||
422 | 245 | } | ||
423 | 246 | |||
424 | 247 | if reply.Type == dbus.TypeError { | ||
425 | 248 | return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
426 | 249 | } | ||
427 | 250 | |||
428 | 251 | if err = readArgs(reply, &throttle); err != nil { | ||
429 | 252 | return 0, err | ||
430 | 253 | } | ||
431 | 254 | return throttle, nil | ||
432 | 255 | } | ||
433 | 256 | |||
434 | 257 | // AllowMobileDownload returns if the download is allow to use the mobile connect | ||
435 | 258 | // connection. | ||
436 | 259 | func (down *FileDownload) AllowMobileDownload(allowed bool) (err error) { | ||
437 | 260 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "allowGSMDownload", allowed) | ||
438 | 261 | if err != nil { | ||
439 | 262 | return err | ||
440 | 263 | } | ||
441 | 264 | |||
442 | 265 | if reply.Type == dbus.TypeError { | ||
443 | 266 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
444 | 267 | } | ||
445 | 268 | |||
446 | 269 | return nil | ||
447 | 270 | } | ||
448 | 271 | |||
449 | 272 | // SetDestinationDir permits unconfined applications to set the destination | ||
450 | 273 | // directory of the download. This method must be called BEFORE the download | ||
451 | 274 | // is started else an error will be returned. | ||
452 | 275 | func (down *FileDownload) SetDestinationDir(path string) (err error) { | ||
453 | 276 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setDestinationDir", path) | ||
454 | 277 | if err != nil { | ||
455 | 278 | return err | ||
456 | 279 | } | ||
457 | 280 | |||
458 | 281 | if reply.Type == dbus.TypeError { | ||
459 | 282 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
460 | 283 | } | ||
461 | 284 | |||
462 | 285 | return nil | ||
463 | 286 | } | ||
464 | 287 | |||
465 | 288 | // IsMobileDownload returns if the download will be performed over the mobile data. | ||
466 | 289 | func (down *FileDownload) IsMobileDownload() (allowed bool, err error) { | ||
467 | 290 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "isGSMDownloadAllowed", allowed) | ||
468 | 291 | if err != nil { | ||
469 | 292 | return false, err | ||
470 | 293 | } | ||
471 | 294 | |||
472 | 295 | if reply.Type == dbus.TypeError { | ||
473 | 296 | return false, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
474 | 297 | } | ||
475 | 298 | |||
476 | 299 | if err = readArgs(reply, &allowed); err != nil { | ||
477 | 300 | return false, err | ||
478 | 301 | } | ||
479 | 302 | return allowed, nil | ||
480 | 303 | } | ||
481 | 304 | |||
482 | 305 | // Start tells udm that the download is ready to be peformed and that the client is | ||
483 | 306 | // ready to recieve signals. The following is a common pattern to be used when | ||
484 | 307 | // creating downloads in udm. | ||
485 | 308 | // | ||
486 | 309 | // man, err := udm.NewDownloadManager() | ||
487 | 310 | // if err != nil { | ||
488 | 311 | // } | ||
489 | 312 | // | ||
490 | 313 | // // variables used to create the download | ||
491 | 314 | // | ||
492 | 315 | // url := "http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz" | ||
493 | 316 | // hash := "8af44d33ea3a1528fc56b3a362924500" | ||
494 | 317 | // hashAlgo := MD5 | ||
495 | 318 | // var metadata map[string]interface{} | ||
496 | 319 | // var headers map[string]string | ||
497 | 320 | // | ||
498 | 321 | // // create the download BUT do not start downloading just yet | ||
499 | 322 | // down, err := man.CreateDownload(url, hash, hashAlgo, metadata, headers) | ||
500 | 323 | // | ||
501 | 324 | // // connect routines to the download channels so that we can get the | ||
502 | 325 | // // information of the download the channel will not get any data until the | ||
503 | 326 | // // Start is called. | ||
504 | 327 | // | ||
505 | 328 | // started_signal := down.Started() | ||
506 | 329 | // go func() { | ||
507 | 330 | // <-started_signal | ||
508 | 331 | // fmt.Println("Download started") | ||
509 | 332 | // }() | ||
510 | 333 | // progress_signal := down.DownloadProgress() | ||
511 | 334 | // go func() { | ||
512 | 335 | // for progress := range p { | ||
513 | 336 | // fmt.Printf("Recieved %d out of %d\n", progress.Received, progress.Total) | ||
514 | 337 | // } | ||
515 | 338 | // }() | ||
516 | 339 | // | ||
517 | 340 | // finished_signal := down.Finished() | ||
518 | 341 | // | ||
519 | 342 | // // start download | ||
520 | 343 | // down.Start() | ||
521 | 344 | // | ||
522 | 345 | // // block until we are finished downloading | ||
523 | 346 | // <- finished_signal | ||
524 | 347 | func (down *FileDownload) Start() (err error) { | ||
525 | 348 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "start") | ||
526 | 349 | if err != nil { | ||
527 | 350 | return err | ||
528 | 351 | } | ||
529 | 352 | |||
530 | 353 | if reply.Type == dbus.TypeError { | ||
531 | 354 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
532 | 355 | } | ||
533 | 356 | |||
534 | 357 | return nil | ||
535 | 358 | } | ||
536 | 359 | |||
537 | 360 | // Pause pauses a download that was started and if not nothing is done. | ||
538 | 361 | func (down *FileDownload) Pause() (err error) { | ||
539 | 362 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "pause") | ||
540 | 363 | if err != nil { | ||
541 | 364 | return err | ||
542 | 365 | } | ||
543 | 366 | |||
544 | 367 | if reply.Type == dbus.TypeError { | ||
545 | 368 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
546 | 369 | } | ||
547 | 370 | |||
548 | 371 | return nil | ||
549 | 372 | } | ||
550 | 373 | |||
551 | 374 | // Resumes a download that was paused or does nothing otherwise. | ||
552 | 375 | func (down *FileDownload) Resume() (err error) { | ||
553 | 376 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "resume") | ||
554 | 377 | if err != nil { | ||
555 | 378 | return err | ||
556 | 379 | } | ||
557 | 380 | |||
558 | 381 | if reply.Type == dbus.TypeError { | ||
559 | 382 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
560 | 383 | } | ||
561 | 384 | |||
562 | 385 | return nil | ||
563 | 386 | } | ||
564 | 387 | |||
565 | 388 | // Cancel cancels a download that was in process and deletes any local files | ||
566 | 389 | // that were created. | ||
567 | 390 | func (down *FileDownload) Cancel() (err error) { | ||
568 | 391 | reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "cancel") | ||
569 | 392 | if err != nil { | ||
570 | 393 | return err | ||
571 | 394 | } | ||
572 | 395 | |||
573 | 396 | if reply.Type == dbus.TypeError { | ||
574 | 397 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
575 | 398 | } | ||
576 | 399 | |||
577 | 400 | return nil | ||
578 | 401 | } | ||
579 | 402 | |||
580 | 403 | func (down *FileDownload) connectToStarted() { | ||
581 | 404 | go func() { | ||
582 | 405 | for msg := range down.started_w.Chanel() { | ||
583 | 406 | var started bool | ||
584 | 407 | readArgs(msg, &started) | ||
585 | 408 | down.started <- started | ||
586 | 409 | } | ||
587 | 410 | close(down.started) | ||
588 | 411 | }() | ||
589 | 412 | } | ||
590 | 413 | |||
591 | 414 | // Started returns a channel that will be used to communicate the started signals. | ||
592 | 415 | func (down *FileDownload) Started() chan bool { | ||
593 | 416 | return down.started | ||
594 | 417 | } | ||
595 | 418 | |||
596 | 419 | func (down *FileDownload) connectToPaused() { | ||
597 | 420 | go func() { | ||
598 | 421 | for msg := range down.paused_w.Chanel() { | ||
599 | 422 | var paused bool | ||
600 | 423 | readArgs(msg, &paused) | ||
601 | 424 | down.paused <- paused | ||
602 | 425 | } | ||
603 | 426 | close(down.paused) | ||
604 | 427 | }() | ||
605 | 428 | } | ||
606 | 429 | |||
607 | 430 | // Paused returns a channel that will be used to communicate the paused signals. | ||
608 | 431 | func (down *FileDownload) Paused() chan bool { | ||
609 | 432 | return down.paused | ||
610 | 433 | } | ||
611 | 434 | |||
612 | 435 | func (down *FileDownload) connectToProgress() { | ||
613 | 436 | go func() { | ||
614 | 437 | for msg := range down.progress_w.Chanel() { | ||
615 | 438 | var received uint64 | ||
616 | 439 | var total uint64 | ||
617 | 440 | readArgs(msg, &received, &total) | ||
618 | 441 | down.progress <- Progress{received, total} | ||
619 | 442 | } | ||
620 | 443 | close(down.progress) | ||
621 | 444 | }() | ||
622 | 445 | } | ||
623 | 446 | |||
624 | 447 | // DownloadProgress returns a channel that will be used to communicate the progress | ||
625 | 448 | // signals. | ||
626 | 449 | func (down *FileDownload) DownloadProgress() chan Progress { | ||
627 | 450 | return down.progress | ||
628 | 451 | } | ||
629 | 452 | |||
630 | 453 | func (down *FileDownload) connectToResumed() { | ||
631 | 454 | go func() { | ||
632 | 455 | for msg := range down.resumed_w.Chanel() { | ||
633 | 456 | var resumed bool | ||
634 | 457 | readArgs(msg, &resumed) | ||
635 | 458 | down.resumed <- resumed | ||
636 | 459 | } | ||
637 | 460 | close(down.resumed) | ||
638 | 461 | }() | ||
639 | 462 | } | ||
640 | 463 | |||
641 | 464 | // Resumed returns a channel that will be used to communicate the paused signals. | ||
642 | 465 | func (down *FileDownload) Resumed() chan bool { | ||
643 | 466 | return down.resumed | ||
644 | 467 | } | ||
645 | 468 | |||
646 | 469 | func (down *FileDownload) connectToCanceled() { | ||
647 | 470 | go func() { | ||
648 | 471 | for msg := range down.canceled_w.Chanel() { | ||
649 | 472 | var canceled bool | ||
650 | 473 | readArgs(msg, &canceled) | ||
651 | 474 | down.canceled <- canceled | ||
652 | 475 | } | ||
653 | 476 | close(down.canceled) | ||
654 | 477 | }() | ||
655 | 478 | } | ||
656 | 479 | |||
657 | 480 | // Canceled returns a channel that will be used to communicate the canceled signals. | ||
658 | 481 | func (down *FileDownload) Canceled() chan bool { | ||
659 | 482 | return down.canceled | ||
660 | 483 | } | ||
661 | 484 | |||
662 | 485 | func (down *FileDownload) connectToFinished() { | ||
663 | 486 | go func() { | ||
664 | 487 | for msg := range down.finished_w.Chanel() { | ||
665 | 488 | var path string | ||
666 | 489 | readArgs(msg, &path) | ||
667 | 490 | down.finished <- path | ||
668 | 491 | } | ||
669 | 492 | close(down.finished) | ||
670 | 493 | }() | ||
671 | 494 | } | ||
672 | 495 | |||
673 | 496 | // Finished returns a channel that will ne used to communicate the finished signals. | ||
674 | 497 | func (down *FileDownload) Finished() chan string { | ||
675 | 498 | return down.finished | ||
676 | 499 | } | ||
677 | 500 | |||
678 | 501 | func (down *FileDownload) connectToError() { | ||
679 | 502 | go func() { | ||
680 | 503 | for msg := range down.error_w.Chanel() { | ||
681 | 504 | var reason string | ||
682 | 505 | readArgs(msg, &reason) | ||
683 | 506 | down.errors <- errors.New(reason) | ||
684 | 507 | } | ||
685 | 508 | close(down.errors) | ||
686 | 509 | }() | ||
687 | 510 | } | ||
688 | 511 | |||
689 | 512 | // Error returns the channel that will be used to communicate the error signals. | ||
690 | 513 | func (down *FileDownload) Error() chan error { | ||
691 | 514 | return down.errors | ||
692 | 515 | } | ||
693 | 516 | |||
694 | 517 | type DownloadManager struct { | ||
695 | 518 | conn *dbus.Connection | ||
696 | 519 | proxy *dbus.ObjectProxy | ||
697 | 520 | } | ||
698 | 521 | |||
699 | 522 | // NewDownloadManager creates a new manager that can be used to create download in the | ||
700 | 523 | // udm daemon. | ||
701 | 524 | func NewDownloadManager() (*DownloadManager, error) { | ||
702 | 525 | conn, err := dbus.Connect(dbus.SessionBus) | ||
703 | 526 | if err != nil { | ||
704 | 527 | return nil, err | ||
705 | 528 | } | ||
706 | 529 | |||
707 | 530 | if err != nil { | ||
708 | 531 | return nil, err | ||
709 | 532 | } | ||
710 | 533 | |||
711 | 534 | proxy := conn.Object(DOWNLOAD_SERVICE, "/") | ||
712 | 535 | d := DownloadManager{conn, proxy} | ||
713 | 536 | return &d, nil | ||
714 | 537 | } | ||
715 | 538 | |||
716 | 539 | // CreateDownload creates a new download in the udm daemon that can be used to get | ||
717 | 540 | // a remote resource. Udm allows to pass a hash signature and method that will be | ||
718 | 541 | // check once the download has been complited. | ||
719 | 542 | // | ||
720 | 543 | // The download hash can be one of the the following constants: | ||
721 | 544 | // | ||
722 | 545 | // MD5 | ||
723 | 546 | // SHA1 | ||
724 | 547 | // SHA224 | ||
725 | 548 | // SHA256 | ||
726 | 549 | // SHA384 | ||
727 | 550 | // SHA512 | ||
728 | 551 | // | ||
729 | 552 | // The metadata attribute can be used to pass extra information to the udm daemon | ||
730 | 553 | // that will just be considered if the caller is not a apparmor confined application. | ||
731 | 554 | // | ||
732 | 555 | // LOCAL_PATH => allows to provide the local path for the download. | ||
733 | 556 | // OBJECT_PATH => allows to provide the object path to be used in the dbus daemon. | ||
734 | 557 | // POST_DOWNLOAD_COMMAND => allows to provide a command that will be executed on the | ||
735 | 558 | // download | ||
736 | 559 | // | ||
737 | 560 | // The headers attribute allows to provide extra headers to be used in the request used | ||
738 | 561 | // to perform the download. | ||
739 | 562 | func (man *DownloadManager) CreateDownload(url string, hash string, algo hashType, metadata map[string]interface{}, headers map[string]string) (down Download, err error) { | ||
740 | 563 | var t map[string]*dbus.Variant | ||
741 | 564 | for key, value := range metadata { | ||
742 | 565 | t[key] = &dbus.Variant{Value: value} | ||
743 | 566 | } | ||
744 | 567 | s := struct { | ||
745 | 568 | U string | ||
746 | 569 | H string | ||
747 | 570 | A string | ||
748 | 571 | M map[string]*dbus.Variant | ||
749 | 572 | HD map[string]string | ||
750 | 573 | }{url, hash, string(algo), t, headers} | ||
751 | 574 | var path dbus.ObjectPath | ||
752 | 575 | reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createDownload", s) | ||
753 | 576 | if err != nil || reply.Type == dbus.TypeError { | ||
754 | 577 | return nil, err | ||
755 | 578 | } | ||
756 | 579 | if err = readArgs(reply, &path); err != nil { | ||
757 | 580 | return nil, err | ||
758 | 581 | } | ||
759 | 582 | down, err = newFileDownload(man.conn, path) | ||
760 | 583 | return down, err | ||
761 | 584 | } | ||
762 | 585 | |||
763 | 586 | // CreateMmsDownload creates an mms download that will be performed right away. An | ||
764 | 587 | // mms download only uses mobile that and an apn proxy to download a multime media | ||
765 | 588 | // message. | ||
766 | 589 | func (man *DownloadManager) CreateMmsDownload(url string, hostname string, port int32) (down Download, err error) { | ||
767 | 590 | var path dbus.ObjectPath | ||
768 | 591 | reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createMmsDownload", url, hostname, port) | ||
769 | 592 | if err != nil || reply.Type == dbus.TypeError { | ||
770 | 593 | return nil, err | ||
771 | 594 | } | ||
772 | 595 | if err = readArgs(reply, &path); err != nil { | ||
773 | 596 | return nil, err | ||
774 | 597 | } | ||
775 | 598 | down, err = newFileDownload(man.conn, path) | ||
776 | 599 | return down, err | ||
777 | 600 | } | ||
778 | 601 | 0 | ||
779 | === removed file 'bindings/golang/downloader_test.go' | |||
780 | --- bindings/golang/downloader_test.go 2014-05-13 08:50:46 +0000 | |||
781 | +++ bindings/golang/downloader_test.go 1970-01-01 00:00:00 +0000 | |||
782 | @@ -1,306 +0,0 @@ | |||
783 | 1 | /* | ||
784 | 2 | * Copyright 2014 Canonical Ltd. | ||
785 | 3 | * | ||
786 | 4 | * Authors: | ||
787 | 5 | * Manuel de la Pena: manuel.delapena@canonical.com | ||
788 | 6 | * | ||
789 | 7 | * This file is part of ubuntu-download-manager. | ||
790 | 8 | * | ||
791 | 9 | * ubuntu-download-manager is free software; you can redistribute it and/or modify | ||
792 | 10 | * it under the terms of the GNU General Public License as published by | ||
793 | 11 | * the Free Software Foundation; version 3. | ||
794 | 12 | * | ||
795 | 13 | * ubuntu-download-manager is distributed in the hope that it will be useful, | ||
796 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
797 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
798 | 16 | * GNU General Public License for more details. | ||
799 | 17 | * | ||
800 | 18 | * You should have received a copy of the GNU General Public License | ||
801 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
802 | 20 | */ | ||
803 | 21 | |||
804 | 22 | package udm | ||
805 | 23 | |||
806 | 24 | import ( | ||
807 | 25 | "errors" | ||
808 | 26 | . "gopkg.in/check.v1" | ||
809 | 27 | "launchpad.net/go-dbus/v1" | ||
810 | 28 | "reflect" | ||
811 | 29 | ) | ||
812 | 30 | |||
813 | 31 | type DownloadSuite struct { | ||
814 | 32 | proxy *fakeProxy | ||
815 | 33 | download *FileDownload | ||
816 | 34 | msg_args []interface{} | ||
817 | 35 | msg_args_err error | ||
818 | 36 | started_ch chan bool | ||
819 | 37 | started_w watch | ||
820 | 38 | paused_ch chan bool | ||
821 | 39 | paused_w watch | ||
822 | 40 | resumed_ch chan bool | ||
823 | 41 | resumed_w watch | ||
824 | 42 | canceled_ch chan bool | ||
825 | 43 | canceled_w watch | ||
826 | 44 | finished_ch chan string | ||
827 | 45 | finished_w watch | ||
828 | 46 | errors_ch chan error | ||
829 | 47 | errors_w watch | ||
830 | 48 | progress_ch chan Progress | ||
831 | 49 | progress_w watch | ||
832 | 50 | } | ||
833 | 51 | |||
834 | 52 | var _ = Suite(&DownloadSuite{}) | ||
835 | 53 | |||
836 | 54 | func (s *DownloadSuite) SetUpTest(c *C) { | ||
837 | 55 | s.proxy = &fakeProxy{} | ||
838 | 56 | s.started_ch = make(chan bool) | ||
839 | 57 | s.started_w = newFakeWatch() | ||
840 | 58 | s.paused_ch = make(chan bool) | ||
841 | 59 | s.paused_w = newFakeWatch() | ||
842 | 60 | s.resumed_ch = make(chan bool) | ||
843 | 61 | s.resumed_w = newFakeWatch() | ||
844 | 62 | s.canceled_ch = make(chan bool) | ||
845 | 63 | s.canceled_w = newFakeWatch() | ||
846 | 64 | s.finished_ch = make(chan string) | ||
847 | 65 | s.finished_w = newFakeWatch() | ||
848 | 66 | s.errors_ch = make(chan error) | ||
849 | 67 | s.errors_w = newFakeWatch() | ||
850 | 68 | s.progress_ch = make(chan Progress) | ||
851 | 69 | s.progress_w = newFakeWatch() | ||
852 | 70 | s.download = &FileDownload{nil, s.proxy, "", s.started_ch, s.started_w, s.paused_ch, s.paused_w, s.resumed_ch, s.resumed_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w} | ||
853 | 71 | |||
854 | 72 | readArgs = func(msg *dbus.Message, args ...interface{}) error { | ||
855 | 73 | for i, arg := range args { | ||
856 | 74 | v := reflect.ValueOf(arg) | ||
857 | 75 | e := v.Elem() | ||
858 | 76 | switch s.msg_args[i].(type) { | ||
859 | 77 | default: | ||
860 | 78 | return errors.New("unexpected type") | ||
861 | 79 | case bool: | ||
862 | 80 | e.SetBool(s.msg_args[i].(bool)) | ||
863 | 81 | case uint64: | ||
864 | 82 | e.SetUint(s.msg_args[i].(uint64)) | ||
865 | 83 | } | ||
866 | 84 | } | ||
867 | 85 | return s.msg_args_err | ||
868 | 86 | } | ||
869 | 87 | } | ||
870 | 88 | |||
871 | 89 | func (s *DownloadSuite) TestTotalSizeError(c *C) { | ||
872 | 90 | s.proxy.Result = newDBusError() | ||
873 | 91 | size, err := s.download.TotalSize() | ||
874 | 92 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
875 | 93 | c.Assert(s.proxy.MethodName, Equals, "totalSize") | ||
876 | 94 | c.Assert(size, Equals, uint64(0)) | ||
877 | 95 | c.Assert(err, NotNil) | ||
878 | 96 | } | ||
879 | 97 | |||
880 | 98 | func (s *DownloadSuite) TestTotalSize(c *C) { | ||
881 | 99 | expected_size := uint64(98) | ||
882 | 100 | s.proxy.Result = newDBusReturn() | ||
883 | 101 | s.msg_args = make([]interface{}, 1) | ||
884 | 102 | s.msg_args[0] = expected_size | ||
885 | 103 | s.msg_args_err = nil | ||
886 | 104 | size, err := s.download.TotalSize() | ||
887 | 105 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
888 | 106 | c.Assert(s.proxy.MethodName, Equals, "totalSize") | ||
889 | 107 | c.Assert(err, IsNil) | ||
890 | 108 | c.Assert(size, Equals, expected_size) | ||
891 | 109 | } | ||
892 | 110 | |||
893 | 111 | func (s *DownloadSuite) TestProgressError(c *C) { | ||
894 | 112 | s.proxy.Result = newDBusError() | ||
895 | 113 | progress, err := s.download.Progress() | ||
896 | 114 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
897 | 115 | c.Assert(s.proxy.MethodName, Equals, "progress") | ||
898 | 116 | c.Assert(progress, Equals, uint64(0)) | ||
899 | 117 | c.Assert(err, NotNil) | ||
900 | 118 | } | ||
901 | 119 | |||
902 | 120 | func (s *DownloadSuite) TestProgress(c *C) { | ||
903 | 121 | expected_progress := uint64(98) | ||
904 | 122 | s.proxy.Result = newDBusReturn() | ||
905 | 123 | s.msg_args = make([]interface{}, 1) | ||
906 | 124 | s.msg_args[0] = expected_progress | ||
907 | 125 | s.msg_args_err = nil | ||
908 | 126 | progress, err := s.download.Progress() | ||
909 | 127 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
910 | 128 | c.Assert(s.proxy.MethodName, Equals, "progress") | ||
911 | 129 | c.Assert(err, IsNil) | ||
912 | 130 | c.Assert(progress, Equals, expected_progress) | ||
913 | 131 | } | ||
914 | 132 | |||
915 | 133 | func (s *DownloadSuite) TestMetadataError(c *C) { | ||
916 | 134 | s.proxy.Result = newDBusError() | ||
917 | 135 | metadata, err := s.download.Metadata() | ||
918 | 136 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
919 | 137 | c.Assert(s.proxy.MethodName, Equals, "metadata") | ||
920 | 138 | c.Assert(metadata, IsNil) | ||
921 | 139 | c.Assert(err, NotNil) | ||
922 | 140 | } | ||
923 | 141 | |||
924 | 142 | func (s *DownloadSuite) TestSetThrotthleError(c *C) { | ||
925 | 143 | throttle := uint64(9) | ||
926 | 144 | s.proxy.Result = newDBusError() | ||
927 | 145 | err := s.download.SetThrottle(throttle) | ||
928 | 146 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
929 | 147 | c.Assert(s.proxy.MethodName, Equals, "setThrottle") | ||
930 | 148 | c.Assert(err, NotNil) | ||
931 | 149 | c.Assert(s.proxy.Args[0], Equals, throttle) | ||
932 | 150 | } | ||
933 | 151 | |||
934 | 152 | func (s *DownloadSuite) TestSetThrottle(c *C) { | ||
935 | 153 | s.proxy.Result = newDBusReturn() | ||
936 | 154 | err := s.download.SetThrottle(uint64(9)) | ||
937 | 155 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
938 | 156 | c.Assert(s.proxy.MethodName, Equals, "setThrottle") | ||
939 | 157 | c.Assert(err, IsNil) | ||
940 | 158 | } | ||
941 | 159 | |||
942 | 160 | func (s *DownloadSuite) TestThrottleError(c *C) { | ||
943 | 161 | s.proxy.Result = newDBusError() | ||
944 | 162 | size, err := s.download.Throttle() | ||
945 | 163 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
946 | 164 | c.Assert(s.proxy.MethodName, Equals, "throttle") | ||
947 | 165 | c.Assert(size, Equals, uint64(0)) | ||
948 | 166 | c.Assert(err, NotNil) | ||
949 | 167 | } | ||
950 | 168 | |||
951 | 169 | func (s *DownloadSuite) TestThrottle(c *C) { | ||
952 | 170 | expected_throttle := uint64(98) | ||
953 | 171 | s.proxy.Result = newDBusReturn() | ||
954 | 172 | s.msg_args = make([]interface{}, 1) | ||
955 | 173 | s.msg_args[0] = expected_throttle | ||
956 | 174 | s.msg_args_err = nil | ||
957 | 175 | throttle, err := s.download.Throttle() | ||
958 | 176 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
959 | 177 | c.Assert(s.proxy.MethodName, Equals, "throttle") | ||
960 | 178 | c.Assert(err, IsNil) | ||
961 | 179 | c.Assert(throttle, Equals, expected_throttle) | ||
962 | 180 | } | ||
963 | 181 | |||
964 | 182 | func (s *DownloadSuite) TestAllowMobileDownloadError(c *C) { | ||
965 | 183 | s.proxy.Result = newDBusError() | ||
966 | 184 | err := s.download.AllowMobileDownload(true) | ||
967 | 185 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
968 | 186 | c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload") | ||
969 | 187 | c.Assert(err, NotNil) | ||
970 | 188 | } | ||
971 | 189 | |||
972 | 190 | func (s *DownloadSuite) TestAllowMobileDownload(c *C) { | ||
973 | 191 | expected_allowed := true | ||
974 | 192 | s.proxy.Result = newDBusReturn() | ||
975 | 193 | err := s.download.AllowMobileDownload(expected_allowed) | ||
976 | 194 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
977 | 195 | c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload") | ||
978 | 196 | c.Assert(err, IsNil) | ||
979 | 197 | c.Assert(s.proxy.Args[0], Equals, expected_allowed) | ||
980 | 198 | } | ||
981 | 199 | |||
982 | 200 | func (s *DownloadSuite) TestSetDestinationDirError(c *C) { | ||
983 | 201 | s.proxy.Result = newDBusError() | ||
984 | 202 | err := s.download.SetDestinationDir("/new/path") | ||
985 | 203 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
986 | 204 | c.Assert(s.proxy.MethodName, Equals, "setDestinationDir") | ||
987 | 205 | c.Assert(err, NotNil) | ||
988 | 206 | } | ||
989 | 207 | |||
990 | 208 | func (s *DownloadSuite) TestSetDestinationDir(c *C) { | ||
991 | 209 | expected_dir := "/path/to/use" | ||
992 | 210 | s.proxy.Result = newDBusReturn() | ||
993 | 211 | err := s.download.SetDestinationDir(expected_dir) | ||
994 | 212 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
995 | 213 | c.Assert(s.proxy.MethodName, Equals, "setDestinationDir") | ||
996 | 214 | c.Assert(err, IsNil) | ||
997 | 215 | c.Assert(s.proxy.Args[0], Equals, expected_dir) | ||
998 | 216 | } | ||
999 | 217 | |||
1000 | 218 | func (s *DownloadSuite) TestIsMobileDownloadError(c *C) { | ||
1001 | 219 | s.proxy.Result = newDBusError() | ||
1002 | 220 | allowed, err := s.download.IsMobileDownload() | ||
1003 | 221 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1004 | 222 | c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed") | ||
1005 | 223 | c.Assert(allowed, Equals, false) | ||
1006 | 224 | c.Assert(err, NotNil) | ||
1007 | 225 | } | ||
1008 | 226 | |||
1009 | 227 | func (s *DownloadSuite) TestIsMobileDownload(c *C) { | ||
1010 | 228 | expected_allowed := true | ||
1011 | 229 | s.proxy.Result = newDBusReturn() | ||
1012 | 230 | s.msg_args = make([]interface{}, 1) | ||
1013 | 231 | s.msg_args[0] = expected_allowed | ||
1014 | 232 | s.msg_args_err = nil | ||
1015 | 233 | allowed, err := s.download.IsMobileDownload() | ||
1016 | 234 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1017 | 235 | c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed") | ||
1018 | 236 | c.Assert(err, IsNil) | ||
1019 | 237 | c.Assert(allowed, Equals, expected_allowed) | ||
1020 | 238 | } | ||
1021 | 239 | |||
1022 | 240 | func (s *DownloadSuite) TestStartDBusError(c *C) { | ||
1023 | 241 | s.proxy.Result = newDBusError() | ||
1024 | 242 | err := s.download.Start() | ||
1025 | 243 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1026 | 244 | c.Assert(s.proxy.MethodName, Equals, "start") | ||
1027 | 245 | c.Assert(err, NotNil) | ||
1028 | 246 | } | ||
1029 | 247 | |||
1030 | 248 | func (s *DownloadSuite) TestStartError(c *C) { | ||
1031 | 249 | s.proxy.Result = newDBusReturn() | ||
1032 | 250 | s.proxy.Err = errors.New("Fake error") | ||
1033 | 251 | err := s.download.Start() | ||
1034 | 252 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1035 | 253 | c.Assert(s.proxy.MethodName, Equals, "start") | ||
1036 | 254 | c.Assert(err, NotNil) | ||
1037 | 255 | } | ||
1038 | 256 | |||
1039 | 257 | func (s *DownloadSuite) TestPauseDBusError(c *C) { | ||
1040 | 258 | s.proxy.Result = newDBusError() | ||
1041 | 259 | err := s.download.Pause() | ||
1042 | 260 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1043 | 261 | c.Assert(s.proxy.MethodName, Equals, "pause") | ||
1044 | 262 | c.Assert(err, NotNil) | ||
1045 | 263 | } | ||
1046 | 264 | |||
1047 | 265 | func (s *DownloadSuite) TestPauseError(c *C) { | ||
1048 | 266 | s.proxy.Result = newDBusReturn() | ||
1049 | 267 | s.proxy.Err = errors.New("Fake error") | ||
1050 | 268 | err := s.download.Pause() | ||
1051 | 269 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1052 | 270 | c.Assert(s.proxy.MethodName, Equals, "pause") | ||
1053 | 271 | c.Assert(err, NotNil) | ||
1054 | 272 | } | ||
1055 | 273 | |||
1056 | 274 | func (s *DownloadSuite) TestResumeDBusError(c *C) { | ||
1057 | 275 | s.proxy.Result = newDBusError() | ||
1058 | 276 | err := s.download.Resume() | ||
1059 | 277 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1060 | 278 | c.Assert(s.proxy.MethodName, Equals, "resume") | ||
1061 | 279 | c.Assert(err, NotNil) | ||
1062 | 280 | } | ||
1063 | 281 | |||
1064 | 282 | func (s *DownloadSuite) TestResumeError(c *C) { | ||
1065 | 283 | s.proxy.Result = newDBusReturn() | ||
1066 | 284 | s.proxy.Err = errors.New("Fake error") | ||
1067 | 285 | err := s.download.Resume() | ||
1068 | 286 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1069 | 287 | c.Assert(s.proxy.MethodName, Equals, "resume") | ||
1070 | 288 | c.Assert(err, NotNil) | ||
1071 | 289 | } | ||
1072 | 290 | |||
1073 | 291 | func (s *DownloadSuite) TestCancelDBusError(c *C) { | ||
1074 | 292 | s.proxy.Result = newDBusError() | ||
1075 | 293 | err := s.download.Cancel() | ||
1076 | 294 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1077 | 295 | c.Assert(s.proxy.MethodName, Equals, "cancel") | ||
1078 | 296 | c.Assert(err, NotNil) | ||
1079 | 297 | } | ||
1080 | 298 | |||
1081 | 299 | func (s *DownloadSuite) TestCancelError(c *C) { | ||
1082 | 300 | s.proxy.Result = newDBusReturn() | ||
1083 | 301 | s.proxy.Err = errors.New("Fake error") | ||
1084 | 302 | err := s.download.Cancel() | ||
1085 | 303 | c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) | ||
1086 | 304 | c.Assert(s.proxy.MethodName, Equals, "cancel") | ||
1087 | 305 | c.Assert(err, NotNil) | ||
1088 | 306 | } | ||
1089 | 307 | 0 | ||
1090 | === removed file 'bindings/golang/uploader.go' | |||
1091 | --- bindings/golang/uploader.go 2014-05-13 08:50:46 +0000 | |||
1092 | +++ bindings/golang/uploader.go 1970-01-01 00:00:00 +0000 | |||
1093 | @@ -1,396 +0,0 @@ | |||
1094 | 1 | /* | ||
1095 | 2 | * Copyright 2014 Canonical Ltd. | ||
1096 | 3 | * | ||
1097 | 4 | * Authors: | ||
1098 | 5 | * Manuel de la Pena: manuel.delapena@canonical.com | ||
1099 | 6 | * | ||
1100 | 7 | * This file is part of ubuntu-download-manager. | ||
1101 | 8 | * | ||
1102 | 9 | * ubuntu-download-manager is free software; you can redistribute it and/or modify | ||
1103 | 10 | * it under the terms of the GNU General Public License as published by | ||
1104 | 11 | * the Free Software Foundation; version 3. | ||
1105 | 12 | * | ||
1106 | 13 | * ubuntu-download-manager is distributed in the hope that it will be useful, | ||
1107 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1108 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1109 | 16 | * GNU General Public License for more details. | ||
1110 | 17 | * | ||
1111 | 18 | * You should have received a copy of the GNU General Public License | ||
1112 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1113 | 20 | */ | ||
1114 | 21 | |||
1115 | 22 | // Package udm provides a go interface to work with the ubuntu download manager | ||
1116 | 23 | package udm | ||
1117 | 24 | |||
1118 | 25 | import ( | ||
1119 | 26 | "errors" | ||
1120 | 27 | "fmt" | ||
1121 | 28 | "launchpad.net/go-dbus/v1" | ||
1122 | 29 | "runtime" | ||
1123 | 30 | ) | ||
1124 | 31 | |||
1125 | 32 | const ( | ||
1126 | 33 | UPLOAD_SERVICE = "com.canonical.applications.Uploader" | ||
1127 | 34 | UPLOAD_INTERFACE = "com.canonical.applications.Upload" | ||
1128 | 35 | UPLOAD_MANAGER_INTERFACE = "com.canonical.applications.UploadManager" | ||
1129 | 36 | ) | ||
1130 | 37 | |||
1131 | 38 | // Upload is the common interface of an upload. It provides all the required | ||
1132 | 39 | // methods to interact with an upload created by udm. | ||
1133 | 40 | type Upload interface { | ||
1134 | 41 | Progress() (uint64, error) | ||
1135 | 42 | Metadata() (map[string]string, error) | ||
1136 | 43 | SetThrottle(uint64) error | ||
1137 | 44 | Throttle() (uint64, error) | ||
1138 | 45 | AllowMobileUpload(bool) error | ||
1139 | 46 | IsMobileUpload() (bool, error) | ||
1140 | 47 | Start() error | ||
1141 | 48 | Cancel() error | ||
1142 | 49 | Started() chan bool | ||
1143 | 50 | UploadProgress() chan Progress | ||
1144 | 51 | Canceled() chan bool | ||
1145 | 52 | Finished() chan string | ||
1146 | 53 | Error() chan error | ||
1147 | 54 | } | ||
1148 | 55 | |||
1149 | 56 | // FileUpload represents a single file being uploaded by udm. | ||
1150 | 57 | type FileUpload struct { | ||
1151 | 58 | conn *dbus.Connection | ||
1152 | 59 | proxy proxy | ||
1153 | 60 | path dbus.ObjectPath | ||
1154 | 61 | started chan bool | ||
1155 | 62 | started_w watch | ||
1156 | 63 | canceled chan bool | ||
1157 | 64 | canceled_w watch | ||
1158 | 65 | finished chan string | ||
1159 | 66 | finished_w watch | ||
1160 | 67 | errors chan error | ||
1161 | 68 | error_w watch | ||
1162 | 69 | progress chan Progress | ||
1163 | 70 | progress_w watch | ||
1164 | 71 | } | ||
1165 | 72 | |||
1166 | 73 | func (upload *FileUpload) free() { | ||
1167 | 74 | // cancel all watches so that goroutines are done and close the | ||
1168 | 75 | // channels | ||
1169 | 76 | upload.started_w.Cancel() | ||
1170 | 77 | upload.canceled_w.Cancel() | ||
1171 | 78 | upload.finished_w.Cancel() | ||
1172 | 79 | upload.error_w.Cancel() | ||
1173 | 80 | upload.progress_w.Cancel() | ||
1174 | 81 | } | ||
1175 | 82 | |||
1176 | 83 | func cleanUploadData(upload *FileUpload) { | ||
1177 | 84 | upload.free() | ||
1178 | 85 | } | ||
1179 | 86 | |||
1180 | 87 | func newFileUpload(conn *dbus.Connection, path dbus.ObjectPath) (*FileUpload, error) { | ||
1181 | 88 | proxy := conn.Object(DOWNLOAD_SERVICE, path) | ||
1182 | 89 | started_ch := make(chan bool) | ||
1183 | 90 | started_w, err := connectToSignal(conn, path, "started") | ||
1184 | 91 | if err != nil { | ||
1185 | 92 | return nil, err | ||
1186 | 93 | } | ||
1187 | 94 | |||
1188 | 95 | canceled_ch := make(chan bool) | ||
1189 | 96 | canceled_w, err := connectToSignal(conn, path, "canceled") | ||
1190 | 97 | if err != nil { | ||
1191 | 98 | return nil, err | ||
1192 | 99 | } | ||
1193 | 100 | |||
1194 | 101 | finished_ch := make(chan string) | ||
1195 | 102 | finished_w, err := connectToSignal(conn, path, "finished") | ||
1196 | 103 | if err != nil { | ||
1197 | 104 | return nil, err | ||
1198 | 105 | } | ||
1199 | 106 | |||
1200 | 107 | errors_ch := make(chan error) | ||
1201 | 108 | errors_w, err := connectToSignal(conn, path, "error") | ||
1202 | 109 | if err != nil { | ||
1203 | 110 | return nil, err | ||
1204 | 111 | } | ||
1205 | 112 | |||
1206 | 113 | progress_ch := make(chan Progress) | ||
1207 | 114 | progress_w, err := connectToSignal(conn, path, "progress") | ||
1208 | 115 | if err != nil { | ||
1209 | 116 | return nil, err | ||
1210 | 117 | } | ||
1211 | 118 | |||
1212 | 119 | u := FileUpload{conn, proxy, path, started_ch, started_w, canceled_ch, canceled_w, finished_ch, finished_w, errors_ch, errors_w, progress_ch, progress_w} | ||
1213 | 120 | |||
1214 | 121 | // connect to the diff signals so that we have nice channels that do | ||
1215 | 122 | // not expose dbus watchers | ||
1216 | 123 | u.connectToStarted() | ||
1217 | 124 | u.connectToCanceled() | ||
1218 | 125 | u.connectToFinished() | ||
1219 | 126 | u.connectToError() | ||
1220 | 127 | u.connectToProgress() | ||
1221 | 128 | runtime.SetFinalizer(&u, cleanDownloadData) | ||
1222 | 129 | return &u, nil | ||
1223 | 130 | } | ||
1224 | 131 | |||
1225 | 132 | // Process returns the process so far in uploading the file. | ||
1226 | 133 | func (upload *FileUpload) Progress() (progress uint64, err error) { | ||
1227 | 134 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "progress") | ||
1228 | 135 | if err != nil { | ||
1229 | 136 | return 0, err | ||
1230 | 137 | } | ||
1231 | 138 | |||
1232 | 139 | if reply.Type == dbus.TypeError { | ||
1233 | 140 | return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1234 | 141 | } | ||
1235 | 142 | |||
1236 | 143 | if err = readArgs(reply, &progress); err != nil { | ||
1237 | 144 | return 0, err | ||
1238 | 145 | } | ||
1239 | 146 | return progress, nil | ||
1240 | 147 | } | ||
1241 | 148 | |||
1242 | 149 | // Metadata returns the metadata that was provided at creating time to the upload. | ||
1243 | 150 | func (upload *FileUpload) Metadata() (metadata map[string]string, err error) { | ||
1244 | 151 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "metadata") | ||
1245 | 152 | if err != nil { | ||
1246 | 153 | return nil, err | ||
1247 | 154 | } | ||
1248 | 155 | |||
1249 | 156 | if reply.Type == dbus.TypeError { | ||
1250 | 157 | return nil, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1251 | 158 | } | ||
1252 | 159 | |||
1253 | 160 | if err = readArgs(reply, &metadata); err != nil { | ||
1254 | 161 | return nil, err | ||
1255 | 162 | } | ||
1256 | 163 | return metadata, nil | ||
1257 | 164 | } | ||
1258 | 165 | |||
1259 | 166 | // SetThrottle sets the network throttle to be used in the upload. | ||
1260 | 167 | func (upload *FileUpload) SetThrottle(throttle uint64) (err error) { | ||
1261 | 168 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "setThrottle", throttle) | ||
1262 | 169 | if err != nil { | ||
1263 | 170 | return err | ||
1264 | 171 | } | ||
1265 | 172 | |||
1266 | 173 | if reply.Type == dbus.TypeError { | ||
1267 | 174 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1268 | 175 | } | ||
1269 | 176 | |||
1270 | 177 | return nil | ||
1271 | 178 | } | ||
1272 | 179 | |||
1273 | 180 | // Throttle returns the network throttle that is currently used in the upload. | ||
1274 | 181 | func (upload *FileUpload) Throttle() (throttle uint64, err error) { | ||
1275 | 182 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "throttle") | ||
1276 | 183 | if err != nil { | ||
1277 | 184 | return 0, err | ||
1278 | 185 | } | ||
1279 | 186 | |||
1280 | 187 | if reply.Type == dbus.TypeError { | ||
1281 | 188 | return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1282 | 189 | } | ||
1283 | 190 | |||
1284 | 191 | if err = readArgs(reply, &throttle); err != nil { | ||
1285 | 192 | return 0, err | ||
1286 | 193 | } | ||
1287 | 194 | return throttle, nil | ||
1288 | 195 | } | ||
1289 | 196 | |||
1290 | 197 | // AllowMobileUpload returns if the download is allow to use the mobile connect | ||
1291 | 198 | // connection. | ||
1292 | 199 | func (upload *FileUpload) AllowMobileUpload(allowed bool) (err error) { | ||
1293 | 200 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "allowMobileUpload", allowed) | ||
1294 | 201 | if err != nil { | ||
1295 | 202 | return err | ||
1296 | 203 | } | ||
1297 | 204 | |||
1298 | 205 | if reply.Type == dbus.TypeError { | ||
1299 | 206 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1300 | 207 | } | ||
1301 | 208 | |||
1302 | 209 | return nil | ||
1303 | 210 | } | ||
1304 | 211 | |||
1305 | 212 | // IsMobileUpload returns if the download will be performed over the mobile data. | ||
1306 | 213 | func (upload *FileUpload) IsMobileUpload() (allowed bool, err error) { | ||
1307 | 214 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "isMobileUploadAllowed", allowed) | ||
1308 | 215 | if err != nil { | ||
1309 | 216 | return false, err | ||
1310 | 217 | } | ||
1311 | 218 | |||
1312 | 219 | if reply.Type == dbus.TypeError { | ||
1313 | 220 | return false, fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1314 | 221 | } | ||
1315 | 222 | |||
1316 | 223 | if err = readArgs(reply, &allowed); err != nil { | ||
1317 | 224 | return false, err | ||
1318 | 225 | } | ||
1319 | 226 | return allowed, nil | ||
1320 | 227 | } | ||
1321 | 228 | |||
1322 | 229 | func (upload *FileUpload) Start() (err error) { | ||
1323 | 230 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "start") | ||
1324 | 231 | if err != nil { | ||
1325 | 232 | return err | ||
1326 | 233 | } | ||
1327 | 234 | |||
1328 | 235 | if reply.Type == dbus.TypeError { | ||
1329 | 236 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1330 | 237 | } | ||
1331 | 238 | |||
1332 | 239 | return nil | ||
1333 | 240 | } | ||
1334 | 241 | |||
1335 | 242 | // Cancel cancels an upload that was in process and deletes any local files | ||
1336 | 243 | // that were created. | ||
1337 | 244 | func (upload *FileUpload) Cancel() (err error) { | ||
1338 | 245 | reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "cancel") | ||
1339 | 246 | if err != nil { | ||
1340 | 247 | return err | ||
1341 | 248 | } | ||
1342 | 249 | |||
1343 | 250 | if reply.Type == dbus.TypeError { | ||
1344 | 251 | return fmt.Errorf("DBus Error: %", reply.ErrorName) | ||
1345 | 252 | } | ||
1346 | 253 | |||
1347 | 254 | return nil | ||
1348 | 255 | } | ||
1349 | 256 | |||
1350 | 257 | func (upload *FileUpload) connectToStarted() { | ||
1351 | 258 | |||
1352 | 259 | go func() { | ||
1353 | 260 | for msg := range upload.started_w.Chanel() { | ||
1354 | 261 | var started bool | ||
1355 | 262 | readArgs(msg, &started) | ||
1356 | 263 | upload.started <- started | ||
1357 | 264 | } | ||
1358 | 265 | close(upload.started) | ||
1359 | 266 | }() | ||
1360 | 267 | } | ||
1361 | 268 | |||
1362 | 269 | // Started returns a channel that will be used to communicate the started signals. | ||
1363 | 270 | func (upload *FileUpload) Started() chan bool { | ||
1364 | 271 | return upload.started | ||
1365 | 272 | } | ||
1366 | 273 | |||
1367 | 274 | func (upload *FileUpload) connectToCanceled() { | ||
1368 | 275 | go func() { | ||
1369 | 276 | for msg := range upload.canceled_w.Chanel() { | ||
1370 | 277 | var canceled bool | ||
1371 | 278 | readArgs(msg, &canceled) | ||
1372 | 279 | upload.canceled <- canceled | ||
1373 | 280 | } | ||
1374 | 281 | close(upload.canceled) | ||
1375 | 282 | }() | ||
1376 | 283 | } | ||
1377 | 284 | |||
1378 | 285 | // Canceled returns a channel that will be used to communicate the canceled signals. | ||
1379 | 286 | func (upload *FileUpload) Canceled() chan bool { | ||
1380 | 287 | return upload.canceled | ||
1381 | 288 | } | ||
1382 | 289 | |||
1383 | 290 | func (upload *FileUpload) connectToFinished() { | ||
1384 | 291 | go func() { | ||
1385 | 292 | for msg := range upload.finished_w.Chanel() { | ||
1386 | 293 | var path string | ||
1387 | 294 | readArgs(msg, &path) | ||
1388 | 295 | upload.finished <- path | ||
1389 | 296 | } | ||
1390 | 297 | close(upload.finished) | ||
1391 | 298 | }() | ||
1392 | 299 | } | ||
1393 | 300 | |||
1394 | 301 | // Finished returns a channel that will ne used to communicate the finished signals. | ||
1395 | 302 | func (upload *FileUpload) Finished() chan string { | ||
1396 | 303 | return upload.finished | ||
1397 | 304 | } | ||
1398 | 305 | |||
1399 | 306 | func (upload *FileUpload) connectToError() { | ||
1400 | 307 | go func() { | ||
1401 | 308 | for msg := range upload.error_w.Chanel() { | ||
1402 | 309 | var reason string | ||
1403 | 310 | readArgs(msg, &reason) | ||
1404 | 311 | upload.errors <- errors.New(reason) | ||
1405 | 312 | } | ||
1406 | 313 | close(upload.errors) | ||
1407 | 314 | }() | ||
1408 | 315 | } | ||
1409 | 316 | |||
1410 | 317 | // Error returns the channel that will be used to communicate the error signals. | ||
1411 | 318 | func (upload *FileUpload) Error() chan error { | ||
1412 | 319 | return upload.errors | ||
1413 | 320 | } | ||
1414 | 321 | |||
1415 | 322 | func (upload *FileUpload) connectToProgress() { | ||
1416 | 323 | go func() { | ||
1417 | 324 | for msg := range upload.progress_w.Chanel() { | ||
1418 | 325 | var received uint64 | ||
1419 | 326 | var total uint64 | ||
1420 | 327 | readArgs(msg, &received, &total) | ||
1421 | 328 | upload.progress <- Progress{received, total} | ||
1422 | 329 | } | ||
1423 | 330 | close(upload.progress) | ||
1424 | 331 | }() | ||
1425 | 332 | } | ||
1426 | 333 | |||
1427 | 334 | // UploadProgress returns a channel that will be used to communicate the progress | ||
1428 | 335 | // signals. | ||
1429 | 336 | func (upload *FileUpload) UploadProgress() chan Progress { | ||
1430 | 337 | return upload.progress | ||
1431 | 338 | } | ||
1432 | 339 | |||
1433 | 340 | type UploadManager struct { | ||
1434 | 341 | conn *dbus.Connection | ||
1435 | 342 | proxy *dbus.ObjectProxy | ||
1436 | 343 | } | ||
1437 | 344 | |||
1438 | 345 | // NewUploadManager creates a new manager that can be used to create download in the | ||
1439 | 346 | // udm daemon. | ||
1440 | 347 | func NewUploadManager() (*UploadManager, error) { | ||
1441 | 348 | conn, err := dbus.Connect(dbus.SessionBus) | ||
1442 | 349 | if err != nil { | ||
1443 | 350 | return nil, err | ||
1444 | 351 | } | ||
1445 | 352 | |||
1446 | 353 | if err != nil { | ||
1447 | 354 | return nil, err | ||
1448 | 355 | } | ||
1449 | 356 | |||
1450 | 357 | proxy := conn.Object(UPLOAD_SERVICE, "/") | ||
1451 | 358 | d := UploadManager{conn, proxy} | ||
1452 | 359 | return &d, nil | ||
1453 | 360 | } | ||
1454 | 361 | |||
1455 | 362 | func (man *UploadManager) CreateUpload(url string, file string, metadata map[string]interface{}, headers map[string]string) (upload Upload, err error) { | ||
1456 | 363 | var t map[string]*dbus.Variant | ||
1457 | 364 | for key, value := range metadata { | ||
1458 | 365 | t[key] = &dbus.Variant{Value: value} | ||
1459 | 366 | } | ||
1460 | 367 | s := struct { | ||
1461 | 368 | U string | ||
1462 | 369 | F string | ||
1463 | 370 | M map[string]*dbus.Variant | ||
1464 | 371 | HD map[string]string | ||
1465 | 372 | }{url, file, t, headers} | ||
1466 | 373 | var path dbus.ObjectPath | ||
1467 | 374 | reply, err := man.proxy.Call(UPLOAD_MANAGER_INTERFACE, "createUpload", s) | ||
1468 | 375 | if err != nil || reply.Type == dbus.TypeError { | ||
1469 | 376 | return nil, err | ||
1470 | 377 | } | ||
1471 | 378 | if err = readArgs(reply, &path); err != nil { | ||
1472 | 379 | return nil, err | ||
1473 | 380 | } | ||
1474 | 381 | upload, err = newFileUpload(man.conn, path) | ||
1475 | 382 | return upload, err | ||
1476 | 383 | } | ||
1477 | 384 | |||
1478 | 385 | func (man *UploadManager) CreateMmsUpload(url string, file string, hostname string, port int32) (upload Upload, err error) { | ||
1479 | 386 | var path dbus.ObjectPath | ||
1480 | 387 | reply, err := man.proxy.Call(UPLOAD_MANAGER_INTERFACE, "createMmsUpload", url, file, hostname, port) | ||
1481 | 388 | if err != nil || reply.Type == dbus.TypeError { | ||
1482 | 389 | return nil, err | ||
1483 | 390 | } | ||
1484 | 391 | if err = readArgs(reply, &path); err != nil { | ||
1485 | 392 | return nil, err | ||
1486 | 393 | } | ||
1487 | 394 | upload, err = newFileUpload(man.conn, path) | ||
1488 | 395 | return upload, err | ||
1489 | 396 | } | ||
1490 | 397 | 0 | ||
1491 | === removed file 'bindings/golang/uploader_test.go' | |||
1492 | --- bindings/golang/uploader_test.go 2014-05-13 08:50:46 +0000 | |||
1493 | +++ bindings/golang/uploader_test.go 1970-01-01 00:00:00 +0000 | |||
1494 | @@ -1,215 +0,0 @@ | |||
1495 | 1 | /* | ||
1496 | 2 | * Copyright 2014 Canonical Ltd. | ||
1497 | 3 | * | ||
1498 | 4 | * Authors: | ||
1499 | 5 | * Manuel de la Pena: manuel.delapena@canonical.com | ||
1500 | 6 | * | ||
1501 | 7 | * This file is part of ubuntu-download-manager. | ||
1502 | 8 | * | ||
1503 | 9 | * ubuntu-download-manager is free software; you can redistribute it and/or modify | ||
1504 | 10 | * it under the terms of the GNU General Public License as published by | ||
1505 | 11 | * the Free Software Foundation; version 3. | ||
1506 | 12 | * | ||
1507 | 13 | * ubuntu-download-manager is distributed in the hope that it will be useful, | ||
1508 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1509 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1510 | 16 | * GNU General Public License for more details. | ||
1511 | 17 | * | ||
1512 | 18 | * You should have received a copy of the GNU General Public License | ||
1513 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1514 | 20 | */ | ||
1515 | 21 | |||
1516 | 22 | package udm | ||
1517 | 23 | |||
1518 | 24 | import ( | ||
1519 | 25 | "errors" | ||
1520 | 26 | . "gopkg.in/check.v1" | ||
1521 | 27 | "launchpad.net/go-dbus/v1" | ||
1522 | 28 | "reflect" | ||
1523 | 29 | ) | ||
1524 | 30 | |||
1525 | 31 | type UploadSuite struct { | ||
1526 | 32 | proxy *fakeProxy | ||
1527 | 33 | upload *FileUpload | ||
1528 | 34 | msg_args []interface{} | ||
1529 | 35 | msg_args_err error | ||
1530 | 36 | started_ch chan bool | ||
1531 | 37 | started_w watch | ||
1532 | 38 | canceled_ch chan bool | ||
1533 | 39 | canceled_w watch | ||
1534 | 40 | finished_ch chan string | ||
1535 | 41 | finished_w watch | ||
1536 | 42 | errors_ch chan error | ||
1537 | 43 | errors_w watch | ||
1538 | 44 | progress_ch chan Progress | ||
1539 | 45 | progress_w watch | ||
1540 | 46 | } | ||
1541 | 47 | |||
1542 | 48 | var _ = Suite(&UploadSuite{}) | ||
1543 | 49 | |||
1544 | 50 | func (s *UploadSuite) SetUpTest(c *C) { | ||
1545 | 51 | s.proxy = &fakeProxy{} | ||
1546 | 52 | s.started_ch = make(chan bool) | ||
1547 | 53 | s.started_w = newFakeWatch() | ||
1548 | 54 | s.canceled_ch = make(chan bool) | ||
1549 | 55 | s.canceled_w = newFakeWatch() | ||
1550 | 56 | s.finished_ch = make(chan string) | ||
1551 | 57 | s.finished_w = newFakeWatch() | ||
1552 | 58 | s.errors_ch = make(chan error) | ||
1553 | 59 | s.errors_w = newFakeWatch() | ||
1554 | 60 | s.progress_ch = make(chan Progress) | ||
1555 | 61 | s.progress_w = newFakeWatch() | ||
1556 | 62 | s.upload = &FileUpload{nil, s.proxy, "", s.started_ch, s.started_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w} | ||
1557 | 63 | |||
1558 | 64 | readArgs = func(msg *dbus.Message, args ...interface{}) error { | ||
1559 | 65 | for i, arg := range args { | ||
1560 | 66 | v := reflect.ValueOf(arg) | ||
1561 | 67 | e := v.Elem() | ||
1562 | 68 | switch s.msg_args[i].(type) { | ||
1563 | 69 | default: | ||
1564 | 70 | return errors.New("unexpected type") | ||
1565 | 71 | case bool: | ||
1566 | 72 | e.SetBool(s.msg_args[i].(bool)) | ||
1567 | 73 | case uint64: | ||
1568 | 74 | e.SetUint(s.msg_args[i].(uint64)) | ||
1569 | 75 | } | ||
1570 | 76 | } | ||
1571 | 77 | return s.msg_args_err | ||
1572 | 78 | } | ||
1573 | 79 | } | ||
1574 | 80 | |||
1575 | 81 | func (s *UploadSuite) TestProgressError(c *C) { | ||
1576 | 82 | s.proxy.Result = newDBusError() | ||
1577 | 83 | progress, err := s.upload.Progress() | ||
1578 | 84 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1579 | 85 | c.Assert(s.proxy.MethodName, Equals, "progress") | ||
1580 | 86 | c.Assert(progress, Equals, uint64(0)) | ||
1581 | 87 | c.Assert(err, NotNil) | ||
1582 | 88 | } | ||
1583 | 89 | |||
1584 | 90 | func (s *UploadSuite) TestProgress(c *C) { | ||
1585 | 91 | expected_progress := uint64(98) | ||
1586 | 92 | s.proxy.Result = newDBusReturn() | ||
1587 | 93 | s.msg_args = make([]interface{}, 1) | ||
1588 | 94 | s.msg_args[0] = expected_progress | ||
1589 | 95 | s.msg_args_err = nil | ||
1590 | 96 | progress, err := s.upload.Progress() | ||
1591 | 97 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1592 | 98 | c.Assert(s.proxy.MethodName, Equals, "progress") | ||
1593 | 99 | c.Assert(err, IsNil) | ||
1594 | 100 | c.Assert(progress, Equals, expected_progress) | ||
1595 | 101 | } | ||
1596 | 102 | |||
1597 | 103 | func (s *UploadSuite) TestMetadataError(c *C) { | ||
1598 | 104 | s.proxy.Result = newDBusError() | ||
1599 | 105 | metadata, err := s.upload.Metadata() | ||
1600 | 106 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1601 | 107 | c.Assert(s.proxy.MethodName, Equals, "metadata") | ||
1602 | 108 | c.Assert(metadata, IsNil) | ||
1603 | 109 | c.Assert(err, NotNil) | ||
1604 | 110 | } | ||
1605 | 111 | |||
1606 | 112 | func (s *UploadSuite) TestSetThrotthleError(c *C) { | ||
1607 | 113 | throttle := uint64(9) | ||
1608 | 114 | s.proxy.Result = newDBusError() | ||
1609 | 115 | err := s.upload.SetThrottle(throttle) | ||
1610 | 116 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1611 | 117 | c.Assert(s.proxy.MethodName, Equals, "setThrottle") | ||
1612 | 118 | c.Assert(err, NotNil) | ||
1613 | 119 | c.Assert(s.proxy.Args[0], Equals, throttle) | ||
1614 | 120 | } | ||
1615 | 121 | |||
1616 | 122 | func (s *UploadSuite) TestSetThrottle(c *C) { | ||
1617 | 123 | s.proxy.Result = newDBusReturn() | ||
1618 | 124 | err := s.upload.SetThrottle(uint64(9)) | ||
1619 | 125 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1620 | 126 | c.Assert(s.proxy.MethodName, Equals, "setThrottle") | ||
1621 | 127 | c.Assert(err, IsNil) | ||
1622 | 128 | } | ||
1623 | 129 | |||
1624 | 130 | func (s *UploadSuite) TestThrottle(c *C) { | ||
1625 | 131 | expected_throttle := uint64(98) | ||
1626 | 132 | s.proxy.Result = newDBusReturn() | ||
1627 | 133 | s.msg_args = make([]interface{}, 1) | ||
1628 | 134 | s.msg_args[0] = expected_throttle | ||
1629 | 135 | s.msg_args_err = nil | ||
1630 | 136 | throttle, err := s.upload.Throttle() | ||
1631 | 137 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1632 | 138 | c.Assert(s.proxy.MethodName, Equals, "throttle") | ||
1633 | 139 | c.Assert(err, IsNil) | ||
1634 | 140 | c.Assert(throttle, Equals, expected_throttle) | ||
1635 | 141 | } | ||
1636 | 142 | |||
1637 | 143 | func (s *UploadSuite) TestAllowMobileUploadError(c *C) { | ||
1638 | 144 | s.proxy.Result = newDBusError() | ||
1639 | 145 | err := s.upload.AllowMobileUpload(true) | ||
1640 | 146 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1641 | 147 | c.Assert(s.proxy.MethodName, Equals, "allowMobileUpload") | ||
1642 | 148 | c.Assert(err, NotNil) | ||
1643 | 149 | } | ||
1644 | 150 | |||
1645 | 151 | func (s *UploadSuite) TestAllowMobileUpload(c *C) { | ||
1646 | 152 | expected_allowed := true | ||
1647 | 153 | s.proxy.Result = newDBusReturn() | ||
1648 | 154 | err := s.upload.AllowMobileUpload(expected_allowed) | ||
1649 | 155 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1650 | 156 | c.Assert(s.proxy.MethodName, Equals, "allowMobileUpload") | ||
1651 | 157 | c.Assert(err, IsNil) | ||
1652 | 158 | c.Assert(s.proxy.Args[0], Equals, expected_allowed) | ||
1653 | 159 | } | ||
1654 | 160 | |||
1655 | 161 | func (s *UploadSuite) TestIsMobileUploadError(c *C) { | ||
1656 | 162 | s.proxy.Result = newDBusError() | ||
1657 | 163 | allowed, err := s.upload.IsMobileUpload() | ||
1658 | 164 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1659 | 165 | c.Assert(s.proxy.MethodName, Equals, "isMobileUploadAllowed") | ||
1660 | 166 | c.Assert(allowed, Equals, false) | ||
1661 | 167 | c.Assert(err, NotNil) | ||
1662 | 168 | } | ||
1663 | 169 | |||
1664 | 170 | func (s *UploadSuite) TestIsMobileUpload(c *C) { | ||
1665 | 171 | expected_allowed := true | ||
1666 | 172 | s.proxy.Result = newDBusReturn() | ||
1667 | 173 | s.msg_args = make([]interface{}, 1) | ||
1668 | 174 | s.msg_args[0] = expected_allowed | ||
1669 | 175 | s.msg_args_err = nil | ||
1670 | 176 | allowed, err := s.upload.IsMobileUpload() | ||
1671 | 177 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1672 | 178 | c.Assert(s.proxy.MethodName, Equals, "isMobileUploadAllowed") | ||
1673 | 179 | c.Assert(err, IsNil) | ||
1674 | 180 | c.Assert(allowed, Equals, expected_allowed) | ||
1675 | 181 | } | ||
1676 | 182 | |||
1677 | 183 | func (s *UploadSuite) TestStartDBusError(c *C) { | ||
1678 | 184 | s.proxy.Result = newDBusError() | ||
1679 | 185 | err := s.upload.Start() | ||
1680 | 186 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1681 | 187 | c.Assert(s.proxy.MethodName, Equals, "start") | ||
1682 | 188 | c.Assert(err, NotNil) | ||
1683 | 189 | } | ||
1684 | 190 | |||
1685 | 191 | func (s *UploadSuite) TestStartError(c *C) { | ||
1686 | 192 | s.proxy.Result = newDBusReturn() | ||
1687 | 193 | s.proxy.Err = errors.New("Fake error") | ||
1688 | 194 | err := s.upload.Start() | ||
1689 | 195 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1690 | 196 | c.Assert(s.proxy.MethodName, Equals, "start") | ||
1691 | 197 | c.Assert(err, NotNil) | ||
1692 | 198 | } | ||
1693 | 199 | |||
1694 | 200 | func (s *UploadSuite) TestCancelDBusError(c *C) { | ||
1695 | 201 | s.proxy.Result = newDBusError() | ||
1696 | 202 | err := s.upload.Cancel() | ||
1697 | 203 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1698 | 204 | c.Assert(s.proxy.MethodName, Equals, "cancel") | ||
1699 | 205 | c.Assert(err, NotNil) | ||
1700 | 206 | } | ||
1701 | 207 | |||
1702 | 208 | func (s *UploadSuite) TestCancelError(c *C) { | ||
1703 | 209 | s.proxy.Result = newDBusReturn() | ||
1704 | 210 | s.proxy.Err = errors.New("Fake error") | ||
1705 | 211 | err := s.upload.Cancel() | ||
1706 | 212 | c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) | ||
1707 | 213 | c.Assert(s.proxy.MethodName, Equals, "cancel") | ||
1708 | 214 | c.Assert(err, NotNil) | ||
1709 | 215 | } | ||
1710 | 216 | 0 | ||
1711 | === modified file 'docs/com.canonical.applications.upload_manager.xml' | |||
1712 | --- docs/com.canonical.applications.upload_manager.xml 2014-02-21 11:56:12 +0000 | |||
1713 | +++ docs/com.canonical.applications.upload_manager.xml 2014-05-13 08:50:47 +0000 | |||
1714 | @@ -11,8 +11,6 @@ | |||
1715 | 11 | <arg name="file" type="s" direction="in" /> | 11 | <arg name="file" type="s" direction="in" /> |
1716 | 12 | <arg name="hostname" type="s" direction="in" /> | 12 | <arg name="hostname" type="s" direction="in" /> |
1717 | 13 | <arg name="port" type="i" direction="in" /> | 13 | <arg name="port" type="i" direction="in" /> |
1718 | 14 | <arg name="username" type="s" direction="in" /> | ||
1719 | 15 | <arg name="password" type="s" direction="in" /> | ||
1720 | 16 | <arg name="uploadPath" type="o" direction="out" /> | 14 | <arg name="uploadPath" type="o" direction="out" /> |
1721 | 17 | </method> | 15 | </method> |
1722 | 18 | 16 | ||
1723 | 19 | 17 | ||
1724 | === modified file 'src/uploads/priv/ubuntu/uploads/factory.cpp' | |||
1725 | --- src/uploads/priv/ubuntu/uploads/factory.cpp 2014-05-13 08:50:46 +0000 | |||
1726 | +++ src/uploads/priv/ubuntu/uploads/factory.cpp 2014-05-13 08:50:47 +0000 | |||
1727 | @@ -89,11 +89,9 @@ | |||
1728 | 89 | const QUrl& url, | 89 | const QUrl& url, |
1729 | 90 | const QString& filePath, | 90 | const QString& filePath, |
1730 | 91 | const QString& hostname, | 91 | const QString& hostname, |
1734 | 92 | int port, | 92 | int port) { |
1732 | 93 | const QString& username, | ||
1733 | 94 | const QString& password) { | ||
1735 | 95 | QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname, | 93 | QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname, |
1737 | 96 | port, username, password); | 94 | port); |
1738 | 97 | QVariantMap metadata; | 95 | QVariantMap metadata; |
1739 | 98 | QMap<QString, QString> headers; | 96 | QMap<QString, QString> headers; |
1740 | 99 | QScopedPointer<SecurityDetails> details( | 97 | QScopedPointer<SecurityDetails> details( |
1741 | 100 | 98 | ||
1742 | === modified file 'src/uploads/priv/ubuntu/uploads/factory.h' | |||
1743 | --- src/uploads/priv/ubuntu/uploads/factory.h 2014-03-26 10:00:28 +0000 | |||
1744 | +++ src/uploads/priv/ubuntu/uploads/factory.h 2014-05-13 08:50:47 +0000 | |||
1745 | @@ -51,9 +51,7 @@ | |||
1746 | 51 | const QUrl& url, | 51 | const QUrl& url, |
1747 | 52 | const QString& filePath, | 52 | const QString& filePath, |
1748 | 53 | const QString& hostname, | 53 | const QString& hostname, |
1752 | 54 | int port, | 54 | int port); |
1750 | 55 | const QString& username, | ||
1751 | 56 | const QString& password); | ||
1753 | 57 | 55 | ||
1754 | 58 | // mainly for testing purposes | 56 | // mainly for testing purposes |
1755 | 59 | virtual QList<QSslCertificate> acceptedCertificates(); | 57 | virtual QList<QSslCertificate> acceptedCertificates(); |
1756 | 60 | 58 | ||
1757 | === modified file 'src/uploads/priv/ubuntu/uploads/manager.cpp' | |||
1758 | --- src/uploads/priv/ubuntu/uploads/manager.cpp 2014-03-04 13:17:09 +0000 | |||
1759 | +++ src/uploads/priv/ubuntu/uploads/manager.cpp 2014-05-13 08:50:47 +0000 | |||
1760 | @@ -128,16 +128,13 @@ | |||
1761 | 128 | UploadManager::createMmsUpload(const QString& url, | 128 | UploadManager::createMmsUpload(const QString& url, |
1762 | 129 | const QString& file, | 129 | const QString& file, |
1763 | 130 | const QString& hostname, | 130 | const QString& hostname, |
1767 | 131 | int port, | 131 | int port) { |
1765 | 132 | const QString& username, | ||
1766 | 133 | const QString& password) { | ||
1768 | 134 | LOG(INFO) << "Create MMS upload == {url:" << url << " filePath: " | 132 | LOG(INFO) << "Create MMS upload == {url:" << url << " filePath: " |
1771 | 135 | << file << " hostname:" << hostname << " port:" | 133 | << file << " hostname:" << hostname << " port:" << port << "}"; |
1770 | 136 | << port << " username:" << username << " pwd: " << password << "}"; | ||
1772 | 137 | UploadCreationFunc createUploadFunc = | 134 | UploadCreationFunc createUploadFunc = |
1774 | 138 | [this, url, file, hostname, port, username, password](QString owner) { | 135 | [this, url, file, hostname, port](QString owner) { |
1775 | 139 | auto upload = _factory->createMmsUpload(owner, url, file, hostname, | 136 | auto upload = _factory->createMmsUpload(owner, url, file, hostname, |
1777 | 140 | port, username, password); | 137 | port); |
1778 | 141 | return upload; | 138 | return upload; |
1779 | 142 | }; | 139 | }; |
1780 | 143 | return createUpload(createUploadFunc); | 140 | return createUpload(createUploadFunc); |
1781 | 144 | 141 | ||
1782 | === modified file 'src/uploads/priv/ubuntu/uploads/manager.h' | |||
1783 | --- src/uploads/priv/ubuntu/uploads/manager.h 2014-03-03 23:28:01 +0000 | |||
1784 | +++ src/uploads/priv/ubuntu/uploads/manager.h 2014-05-13 08:50:47 +0000 | |||
1785 | @@ -64,9 +64,7 @@ | |||
1786 | 64 | QDBusObjectPath createMmsUpload(const QString& url, | 64 | QDBusObjectPath createMmsUpload(const QString& url, |
1787 | 65 | const QString& file, | 65 | const QString& file, |
1788 | 66 | const QString& hostname, | 66 | const QString& hostname, |
1792 | 67 | int port, | 67 | int port); |
1790 | 68 | const QString& username, | ||
1791 | 69 | const QString& password); | ||
1793 | 70 | QDBusObjectPath createUpload(const QString& url, | 68 | QDBusObjectPath createUpload(const QString& url, |
1794 | 71 | const QString& filePath, | 69 | const QString& filePath, |
1795 | 72 | const QVariantMap& metadata, | 70 | const QVariantMap& metadata, |
1796 | 73 | 71 | ||
1797 | === modified file 'src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp' | |||
1798 | --- src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp 2014-02-26 19:54:31 +0000 | |||
1799 | +++ src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp 2014-05-13 08:50:47 +0000 | |||
1800 | @@ -44,11 +44,11 @@ | |||
1801 | 44 | QMetaObject::invokeMethod(parent(), "allowMobileUpload", Q_ARG(bool, allowed)); | 44 | QMetaObject::invokeMethod(parent(), "allowMobileUpload", Q_ARG(bool, allowed)); |
1802 | 45 | } | 45 | } |
1803 | 46 | 46 | ||
1805 | 47 | QDBusObjectPath UploadManagerAdaptor::createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port, const QString &username, const QString &password) | 47 | QDBusObjectPath UploadManagerAdaptor::createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port) |
1806 | 48 | { | 48 | { |
1807 | 49 | // handle method call com.canonical.applications.UploadManager.createMmsUpload | 49 | // handle method call com.canonical.applications.UploadManager.createMmsUpload |
1808 | 50 | QDBusObjectPath uploadPath; | 50 | QDBusObjectPath uploadPath; |
1810 | 51 | QMetaObject::invokeMethod(parent(), "createMmsUpload", Q_RETURN_ARG(QDBusObjectPath, uploadPath), Q_ARG(QString, url), Q_ARG(QString, file), Q_ARG(QString, hostname), Q_ARG(int, port), Q_ARG(QString, username), Q_ARG(QString, password)); | 51 | QMetaObject::invokeMethod(parent(), "createMmsUpload", Q_RETURN_ARG(QDBusObjectPath, uploadPath), Q_ARG(QString, url), Q_ARG(QString, file), Q_ARG(QString, hostname), Q_ARG(int, port)); |
1811 | 52 | return uploadPath; | 52 | return uploadPath; |
1812 | 53 | } | 53 | } |
1813 | 54 | 54 | ||
1814 | 55 | 55 | ||
1815 | === modified file 'src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h' | |||
1816 | --- src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h 2014-02-26 19:54:31 +0000 | |||
1817 | +++ src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h 2014-05-13 08:50:47 +0000 | |||
1818 | @@ -50,8 +50,6 @@ | |||
1819 | 50 | " <arg direction=\"in\" type=\"s\" name=\"file\"/>\n" | 50 | " <arg direction=\"in\" type=\"s\" name=\"file\"/>\n" |
1820 | 51 | " <arg direction=\"in\" type=\"s\" name=\"hostname\"/>\n" | 51 | " <arg direction=\"in\" type=\"s\" name=\"hostname\"/>\n" |
1821 | 52 | " <arg direction=\"in\" type=\"i\" name=\"port\"/>\n" | 52 | " <arg direction=\"in\" type=\"i\" name=\"port\"/>\n" |
1822 | 53 | " <arg direction=\"in\" type=\"s\" name=\"username\"/>\n" | ||
1823 | 54 | " <arg direction=\"in\" type=\"s\" name=\"password\"/>\n" | ||
1824 | 55 | " <arg direction=\"out\" type=\"o\" name=\"uploadPath\"/>\n" | 53 | " <arg direction=\"out\" type=\"o\" name=\"uploadPath\"/>\n" |
1825 | 56 | " </method>\n" | 54 | " </method>\n" |
1826 | 57 | " <method name=\"getAllUploads\">\n" | 55 | " <method name=\"getAllUploads\">\n" |
1827 | @@ -87,7 +85,7 @@ | |||
1828 | 87 | public: // PROPERTIES | 85 | public: // PROPERTIES |
1829 | 88 | public Q_SLOTS: // METHODS | 86 | public Q_SLOTS: // METHODS |
1830 | 89 | void allowMobileUpload(bool allowed); | 87 | void allowMobileUpload(bool allowed); |
1832 | 90 | QDBusObjectPath createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port, const QString &username, const QString &password); | 88 | QDBusObjectPath createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port); |
1833 | 91 | QDBusObjectPath createUpload(UploadStruct upload); | 89 | QDBusObjectPath createUpload(UploadStruct upload); |
1834 | 92 | qulonglong defaultThrottle(); | 90 | qulonglong defaultThrottle(); |
1835 | 93 | void exit(); | 91 | void exit(); |
PASSED: Continuous integration, rev:261 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/634/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- amd64-ci/ 524 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- armhf-ci/ 523
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/ubuntu- download- manager- ci/634/ rebuild
http://