Merge lp:~sergiusens/nuntium/uploads into lp:nuntium

Proposed by Sergio Schvezov
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 49
Merged at revision: 46
Proposed branch: lp:~sergiusens/nuntium/uploads
Merge into: lp:nuntium
Prerequisite: lp:~sergiusens/nuntium/telepathy_switch
Diff against target: 730 lines (+64/-574)
5 files modified
debian/control (+2/-1)
mediator.go (+17/-16)
mms/download.go (+37/-4)
ofono/modem.go (+8/-1)
udm/udm.go (+0/-552)
To merge this branch: bzr merge lp:~sergiusens/nuntium/uploads
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Review via email: mp+225144@code.launchpad.net

Commit message

Upload support while moving udm to it's new package namespace

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2014-05-13 17:06:46 +0000
+++ debian/control 2014-07-01 12:18:20 +0000
@@ -10,6 +10,7 @@
10 golang-go-dbus-dev,10 golang-go-dbus-dev,
11 golang-go-xdg-dev,11 golang-go-xdg-dev,
12 golang-gocheck-dev,12 golang-gocheck-dev,
13 golang-udm-dev,
13Standards-Version: 3.9.514Standards-Version: 3.9.5
14Homepage: https://launchpad.net/nuntium15Homepage: https://launchpad.net/nuntium
15Vcs-Browser: http://bazaar.launchpad.net/~phablet-team/nuntium/trunk/files16Vcs-Browser: http://bazaar.launchpad.net/~phablet-team/nuntium/trunk/files
@@ -17,7 +18,7 @@
1718
18Package: nuntium19Package: nuntium
19Architecture: any20Architecture: any
20Depends: ofono, ubuntu-download-manager, ${misc:Depends}, ${shlibs:Depends}21Depends: ofono, ubuntu-download-manager, ubuntu-upload-manager, ${misc:Depends}, ${shlibs:Depends}
21Built-Using: ${misc:Built-Using}22Built-Using: ${misc:Built-Using}
22Recommends: telepathy-ofono23Recommends: telepathy-ofono
23Conflicts: mmsd24Conflicts: mmsd
2425
=== modified file 'mediator.go'
--- mediator.go 2014-05-12 13:47:34 +0000
+++ mediator.go 2014-07-01 12:18:20 +0000
@@ -190,7 +190,9 @@
190 }190 }
191 mediator.NewMRetrieveConf <- mRetrieveConf191 mediator.NewMRetrieveConf <- mRetrieveConf
192 if mediator.telepathyService != nil {192 if mediator.telepathyService != nil {
193 mediator.telepathyService.MessageAdded(mRetrieveConf)193 if err := mediator.telepathyService.MessageAdded(mRetrieveConf); err != nil {
194 log.Println("Cannot notify telepathy-ofono about new message", err)
195 }
194 } else {196 } else {
195 log.Print("Not sending recently retrieved message")197 log.Print("Not sending recently retrieved message")
196 }198 }
@@ -226,23 +228,22 @@
226func (mediator *Mediator) sendMNotifyRespInd(mNotifyRespIndFile string) {228func (mediator *Mediator) sendMNotifyRespInd(mNotifyRespIndFile string) {
227 defer os.Remove(mNotifyRespIndFile)229 defer os.Remove(mNotifyRespIndFile)
228 if err := mediator.uploadFile(mNotifyRespIndFile); err != nil {230 if err := mediator.uploadFile(mNotifyRespIndFile); err != nil {
229 log.Printf("Cannot upload m-notifyresp.ind encoded file %s to message center", mNotifyRespIndFile)231 log.Printf("Cannot upload m-notifyresp.ind encoded file %s to message center: %s", mNotifyRespIndFile, err)
230 }232 }
231}233}
232234
233func (mediator *Mediator) uploadFile(filePath string) error {235func (mediator *Mediator) uploadFile(filePath string) error {
234 // TODO Upload file part236 mmsContext, err := mediator.modem.ActivateMMSContext()
235 /*237 if err != nil {
236 mmsContext, err := mediator.modem.ActivateMMSContext()238 return err
237 if err != nil {239 }
238 log.Print("Cannot activate ofono context: ", err)240 proxy, err := mmsContext.GetProxy()
239 return241 if err != nil {
240 }242 return err
241 proxy, err := mmsContext.GetProxy()243 }
242 if err != nil {244 msc, err := mmsContext.GetMessageCenter()
243 log.Print("Error retrieving proxy: ", err)245 if err != nil {
244 return246 return err
245 }247 }
246 */248 return mms.Upload(filePath, msc, proxy.Host, int32(proxy.Port))
247 return nil
248}249}
249250
=== modified file 'mms/download.go'
--- mms/download.go 2014-04-30 14:24:26 +0000
+++ mms/download.go 2014-07-01 12:18:20 +0000
@@ -22,26 +22,27 @@
22package mms22package mms
2323
24import (24import (
25 "errors"
25 "fmt"26 "fmt"
26 "log"27 "log"
27 "time"28 "time"
2829
29 "launchpad.net/nuntium/udm"30 "launchpad.net/udm"
30)31)
3132
32func (pdu *MNotificationInd) DownloadContent(proxyHostname string, proxyPort int32) (string, error) {33func (pdu *MNotificationInd) DownloadContent(proxyHost string, proxyPort int32) (string, error) {
33 downloadManager, err := udm.NewDownloadManager()34 downloadManager, err := udm.NewDownloadManager()
34 if err != nil {35 if err != nil {
35 return "", err36 return "", err
36 }37 }
37 download, err := downloadManager.CreateMmsDownload(pdu.ContentLocation, proxyHostname, proxyPort)38 download, err := downloadManager.CreateMmsDownload(pdu.ContentLocation, proxyHost, proxyPort)
38 if err != nil {39 if err != nil {
39 return "", err40 return "", err
40 }41 }
41 f := download.Finished()42 f := download.Finished()
42 p := download.DownloadProgress()43 p := download.DownloadProgress()
43 e := download.Error()44 e := download.Error()
44 log.Print("Starting download")45 log.Print("Starting download of ", pdu.ContentLocation, " with proxy ", proxyHost, ":", proxyPort)
45 download.Start()46 download.Start()
46 for {47 for {
47 select {48 select {
@@ -57,3 +58,35 @@
57 }58 }
58 }59 }
59}60}
61
62func Upload(file, msc, proxyHost string, proxyPort int32) error {
63 udm, err := udm.NewUploadManager()
64 if err != nil {
65 return err
66 }
67 upload, err := udm.CreateMmsUpload(msc, file, proxyHost, proxyPort)
68 if err != nil {
69 return err
70 }
71 f := upload.Finished()
72 p := upload.UploadProgress()
73 e := upload.Error()
74 log.Print("Starting upload of ", file, " to ", msc, " with proxy ", proxyHost, ":", proxyPort)
75 if err := upload.Start(); err != nil {
76 return err
77 }
78
79 for {
80 select {
81 case progress := <-p:
82 log.Print("Progress:", progress.Total, progress.Received)
83 case f := <-f:
84 log.Print("File ", f, " uploaded")
85 return nil
86 case <-time.After(10 * time.Minute):
87 return errors.New("upload timeout")
88 case err := <-e:
89 return err
90 }
91 }
92}
6093
=== modified file 'ofono/modem.go'
--- ofono/modem.go 2014-05-13 11:29:13 +0000
+++ ofono/modem.go 2014-07-01 12:18:20 +0000
@@ -244,6 +244,14 @@
244 return reflect.ValueOf(oContext.Properties["Active"].Value).Bool()244 return reflect.ValueOf(oContext.Properties["Active"].Value).Bool()
245}245}
246246
247func (oContext OfonoContext) GetMessageCenter() (string, error) {
248 if msc := reflect.ValueOf(oContext.Properties["MessageCenter"].Value).String(); msc != "" {
249 return msc, nil
250 } else {
251 return "", errors.New("context setting for the Message Center value is empty")
252 }
253}
254
247func (oContext OfonoContext) GetProxy() (proxyInfo ProxyInfo, err error) {255func (oContext OfonoContext) GetProxy() (proxyInfo ProxyInfo, err error) {
248 proxy := reflect.ValueOf(oContext.Properties["MessageProxy"].Value).String()256 proxy := reflect.ValueOf(oContext.Properties["MessageProxy"].Value).String()
249 if strings.HasPrefix(proxy, "http://") {257 if strings.HasPrefix(proxy, "http://") {
@@ -254,7 +262,6 @@
254 if err != nil {262 if err != nil {
255 proxyInfo.Host = proxy263 proxyInfo.Host = proxy
256 proxyInfo.Port = 80264 proxyInfo.Port = 80
257 fmt.Println("Setting proxy to:", proxyInfo)
258 return proxyInfo, nil265 return proxyInfo, nil
259 }266 }
260 proxyInfo.Port, err = strconv.ParseUint(portString, 0, 64)267 proxyInfo.Port, err = strconv.ParseUint(portString, 0, 64)
261268
=== removed directory 'udm'
=== removed file 'udm/udm.go'
--- udm/udm.go 2014-04-24 21:33:38 +0000
+++ udm/udm.go 1970-01-01 00:00:00 +0000
@@ -1,552 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * ubuntu-download-manager is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22// Package udm provides a go interface to work with the ubuntu download manager
23package udm
24
25import (
26 "errors"
27 "runtime"
28
29 "launchpad.net/go-dbus/v1"
30)
31
32const (
33 DOWNLOAD_SERVICE = "com.canonical.applications.Downloader"
34 DOWNLOAD_INTERFACE = "com.canonical.applications.Download"
35 DOWNLOAD_MANAGER_INTERFACE = "com.canonical.applications.DownloadManager"
36)
37
38type hashType string
39
40const (
41 MD5 hashType = "md5"
42 SHA1 hashType = "sha1"
43 SHA224 hashType = "sha224"
44 SHA256 hashType = "sha256"
45 SHA384 hashType = "sha384"
46 SHA512 hashType = "sha512"
47)
48
49const (
50 LOCAL_PATH = "local-path"
51 OBJECT_PATH = "objectpath"
52 POST_DOWNLOAD_COMMAND = "post-download-command"
53)
54
55// Progress provides how much progress has been performed in a download that was
56// already started.
57type Progress struct {
58 Received uint64
59 Total uint64
60}
61
62// Download is the common interface of a download. It provides all the required
63// methods to interact with a download created by udm.
64type Download interface {
65 TotalSize() (uint64, error)
66 Progress() (uint64, error)
67 Metadata() (map[string]string, error)
68 SetThrottle(uint64) error
69 Throttle() (uint64, error)
70 AllowMobileDownload(bool) error
71 IsMobileDownload() (bool, error)
72 Start() error
73 Pause() error
74 Resume() error
75 Cancel() error
76 Started() chan bool
77 Paused() chan bool
78 DownloadProgress() chan Progress
79 Resumed() chan bool
80 Canceled() chan bool
81 Finished() chan string
82 Error() chan error
83}
84
85// Manager is the single point of entry of the API. Allows to interact with the
86// general setting of udm as well as to create downloads at will.
87type Manager interface {
88 CreateDownload(string, string, string, map[string]interface{}, map[string]string) (Download, error)
89 CreateMmsDownload(string, string, int, string, string) (Download, error)
90}
91
92// FileDownload represents a single file being downloaded by udm.
93type FileDownload struct {
94 conn *dbus.Connection
95 proxy *dbus.ObjectProxy
96 path dbus.ObjectPath
97 started chan bool
98 started_w *dbus.SignalWatch
99 paused chan bool
100 paused_w *dbus.SignalWatch
101 resumed chan bool
102 resumed_w *dbus.SignalWatch
103 canceled chan bool
104 canceled_w *dbus.SignalWatch
105 finished chan string
106 finished_w *dbus.SignalWatch
107 errors chan error
108 error_w *dbus.SignalWatch
109 progress chan Progress
110 progress_w *dbus.SignalWatch
111}
112
113func connectToSignal(conn *dbus.Connection, path dbus.ObjectPath, signal string) (*dbus.SignalWatch, error) {
114 w, err := conn.WatchSignal(&dbus.MatchRule{
115 Type: dbus.TypeSignal,
116 Sender: DOWNLOAD_SERVICE,
117 Interface: DOWNLOAD_INTERFACE,
118 Member: signal,
119 Path: path})
120 return w, err
121}
122
123func (down *FileDownload) free() {
124 // cancel all watches so that goroutines are done and close the
125 // channels
126 down.started_w.Cancel()
127 down.paused_w.Cancel()
128 down.resumed_w.Cancel()
129 down.canceled_w.Cancel()
130 down.finished_w.Cancel()
131 down.error_w.Cancel()
132 down.progress_w.Cancel()
133}
134
135func cleanDownloadData(down *FileDownload) {
136 down.free()
137}
138
139func newFileDownload(conn *dbus.Connection, path dbus.ObjectPath) (*FileDownload, error) {
140 proxy := conn.Object(DOWNLOAD_SERVICE, path)
141 started_ch := make(chan bool)
142 started_w, err := connectToSignal(conn, path, "started")
143 if err != nil {
144 return nil, err
145 }
146
147 paused_ch := make(chan bool)
148 paused_w, err := connectToSignal(conn, path, "paused")
149 if err != nil {
150 return nil, err
151 }
152
153 resumed_ch := make(chan bool)
154 resumed_w, err := connectToSignal(conn, path, "resumed")
155 if err != nil {
156 return nil, err
157 }
158
159 canceled_ch := make(chan bool)
160 canceled_w, err := connectToSignal(conn, path, "canceled")
161 if err != nil {
162 return nil, err
163 }
164
165 finished_ch := make(chan string)
166 finished_w, err := connectToSignal(conn, path, "finished")
167 if err != nil {
168 return nil, err
169 }
170
171 errors_ch := make(chan error)
172 errors_w, err := connectToSignal(conn, path, "error")
173 if err != nil {
174 return nil, err
175 }
176
177 progress_ch := make(chan Progress)
178 progress_w, err := connectToSignal(conn, path, "progress")
179 if err != nil {
180 return nil, err
181 }
182
183 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}
184
185 // connect to the diff signals so that we have nice channels that do
186 // not expose dbus watchers
187 d.connectToStarted()
188 d.connectToPaused()
189 d.connectToResumed()
190 d.connectToCanceled()
191 d.connectToFinished()
192 d.connectToError()
193 d.connectToProgress()
194 runtime.SetFinalizer(&d, cleanDownloadData)
195 return &d, nil
196}
197
198// TotalSize returns the total size of the file being downloaded.
199func (down *FileDownload) TotalSize() (size uint64, err error) {
200 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "totalSize")
201 if err != nil || reply.Type == dbus.TypeError {
202 return 0, err
203 }
204 if err = reply.Args(&size); err != nil {
205 return 0, err
206 }
207 return size, nil
208}
209
210// Process returns the process so far in downloading the file.
211func (down *FileDownload) Progress() (progress uint64, err error) {
212 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "progress")
213 if err != nil || reply.Type == dbus.TypeError {
214 return 0, err
215 }
216 if err = reply.Args(&progress); err != nil {
217 return 0, err
218 }
219 return progress, nil
220}
221
222// Metadata returns the metadata that was provided at creating time to the download.
223func (down *FileDownload) Metadata() (metadata map[string]string, err error) {
224 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "metadata")
225 if err != nil || reply.Type == dbus.TypeError {
226 return nil, err
227 }
228 if err = reply.Args(&metadata); err != nil {
229 return nil, err
230 }
231 return metadata, nil
232}
233
234// SetThrottle sets the network throttle to be used in the download.
235func (down *FileDownload) SetThrottle(throttle uint64) (err error) {
236 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setThrottle", throttle)
237 if err != nil || reply.Type == dbus.TypeError {
238 return err
239 }
240 return nil
241}
242
243// Throttle returns the network throttle that is currently used in the download.
244func (down *FileDownload) Throttle() (throttle uint64, err error) {
245 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "throttle")
246 if err != nil || reply.Type == dbus.TypeError {
247 return 0, err
248 }
249 if err = reply.Args(&throttle); err != nil {
250 return 0, err
251 }
252 return throttle, nil
253}
254
255// AllowMobileDownload returns if the download is allow to use the mobile connect
256// connection.
257func (down *FileDownload) AllowMobileDownload(allowed bool) (err error) {
258 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "allowGSMDownload", allowed)
259 if err != nil || reply.Type == dbus.TypeError {
260 return err
261 }
262 return nil
263}
264
265// IsMobileDownload returns if the download will be performed over the mobile data.
266func (down *FileDownload) IsMobileDownload() (allowed bool, err error) {
267 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "isGSMDownloadAllowed", allowed)
268 if err != nil || reply.Type == dbus.TypeError {
269 return false, err
270 }
271 if err = reply.Args(&allowed); err != nil {
272 return false, err
273 }
274 return allowed, nil
275}
276
277// Start tells udm that the download is ready to be peformed and that the client is
278// ready to recieve signals. The following is a commong pattern to be used when
279// creating downloads in udm.
280//
281// man, err := udm.NewDownloadManager()
282// if err != nil {
283// }
284//
285// // variables used to create the download
286//
287// url := "http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz"
288// hash := "8af44d33ea3a1528fc56b3a362924500"
289// hashAlgo := MD5
290// var metadata map[string]interface{}
291// var headers map[string]string
292//
293// // create the download BUT do not start downloading just yet
294// down, err := man.CreateDownload(url, hash, hashAlgo, metadata, headers)
295//
296// // connect routines to the download channels so that we can get the
297// // information of the download the channel will not get any data until the
298// // Start is called.
299//
300// started_signal := down.Started()
301// go func() {
302// <-started_signal
303// fmt.Println("Download started")
304// }()
305// progress_signal := down.DownloadProgress()
306// go func() {
307// for progress := range p {
308// fmt.Printf("Recieved %d out of %d\n", progress.Received, progress.Total)
309// }
310// }()
311//
312// finished_signal := down.Finished()
313//
314// // start download
315// down.Start()
316//
317// // block until we are finished downloading
318// <- finished_signal
319func (down *FileDownload) Start() (err error) {
320 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "start")
321 if err != nil || reply.Type == dbus.TypeError {
322 return err
323 }
324 return nil
325}
326
327// Pause pauses a download that was started and if not nothing is done.
328func (down *FileDownload) Pause() (err error) {
329 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "pause")
330 if err != nil || reply.Type == dbus.TypeError {
331 return err
332 }
333 return nil
334}
335
336// Resumes a download that was paused or does nothing otherwise.
337func (down *FileDownload) Resume() (err error) {
338 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "resume")
339 if err != nil || reply.Type == dbus.TypeError {
340 return err
341 }
342 return nil
343}
344
345// Cancel cancels a download that was in process and deletes any local files
346// that were created.
347func (down *FileDownload) Cancel() (err error) {
348 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "cancel")
349 if err != nil || reply.Type == dbus.TypeError {
350 return err
351 }
352 return nil
353}
354
355func (down *FileDownload) connectToStarted() {
356 go func() {
357 for msg := range down.started_w.C {
358 var started bool
359 msg.Args(&started)
360 down.started <- started
361 }
362 close(down.started)
363 }()
364}
365
366// Started returns a channel that will be used to communicate the started signals.
367func (down *FileDownload) Started() chan bool {
368 return down.started
369}
370
371func (down *FileDownload) connectToPaused() {
372 go func() {
373 for msg := range down.paused_w.C {
374 var paused bool
375 msg.Args(&paused)
376 down.paused <- paused
377 }
378 close(down.paused)
379 }()
380}
381
382// Paused returns a channel that will be used to communicate the paused signals.
383func (down *FileDownload) Paused() chan bool {
384 return down.paused
385}
386
387func (down *FileDownload) connectToProgress() {
388 go func() {
389 for msg := range down.progress_w.C {
390 var received uint64
391 var total uint64
392 msg.Args(&received, &total)
393 down.progress <- Progress{received, total}
394 }
395 close(down.progress)
396 }()
397}
398
399// DownloadProgress returns a channel that will be used to communicate the progress
400// signals.
401func (down *FileDownload) DownloadProgress() chan Progress {
402 return down.progress
403}
404
405func (down *FileDownload) connectToResumed() {
406 go func() {
407 for msg := range down.resumed_w.C {
408 var resumed bool
409 msg.Args(&resumed)
410 down.resumed <- resumed
411 }
412 close(down.resumed)
413 }()
414}
415
416// Resumed returns a channel that will be used to communicate the paused signals.
417func (down *FileDownload) Resumed() chan bool {
418 return down.resumed
419}
420
421func (down *FileDownload) connectToCanceled() {
422 go func() {
423 for msg := range down.canceled_w.C {
424 var canceled bool
425 msg.Args(&canceled)
426 down.canceled <- canceled
427 }
428 close(down.canceled)
429 }()
430}
431
432// Canceled returns a channel that will be used to communicate the canceled signals.
433func (down *FileDownload) Canceled() chan bool {
434 return down.canceled
435}
436
437func (down *FileDownload) connectToFinished() {
438 go func() {
439 for msg := range down.finished_w.C {
440 var path string
441 msg.Args(&path)
442 down.finished <- path
443 }
444 close(down.finished)
445 }()
446}
447
448// Finished returns a channel that will ne used to communicate the finished signals.
449func (down *FileDownload) Finished() chan string {
450 return down.finished
451}
452
453func (down *FileDownload) connectToError() {
454 go func() {
455 for msg := range down.error_w.C {
456 var reason string
457 msg.Args(&reason)
458 down.errors <- errors.New(reason)
459 }
460 close(down.errors)
461 }()
462}
463
464// Error returns the channel that will be used to communicate the error signals.
465func (down *FileDownload) Error() chan error {
466 return down.errors
467}
468
469type DownloadManager struct {
470 conn *dbus.Connection
471 proxy *dbus.ObjectProxy
472}
473
474// NewDownloadManager creates a new manager that can be used to create download in the
475// udm daemon.
476func NewDownloadManager() (*DownloadManager, error) {
477 conn, err := dbus.Connect(dbus.SessionBus)
478 if err != nil {
479 return nil, err
480 }
481
482 if err != nil {
483 return nil, err
484 }
485
486 proxy := conn.Object(DOWNLOAD_SERVICE, "/")
487 d := DownloadManager{conn, proxy}
488 return &d, nil
489}
490
491// CreateDownload creates a new download in the udm daemon that can be used to get
492// a remote resource. Udm allows to pass a hash signature and method that will be
493// check once the download has been complited.
494//
495// The download hash can be one of the the following constants:
496//
497// MD5
498// SHA1
499// SHA224
500// SHA256
501// SHA384
502// SHA512
503//
504// The metadata attribute can be used to pass extra information to the udm daemon
505// that will just be considered if the caller is not a apparmor confined application.
506//
507// LOCAL_PATH => allows to provide the local path for the download.
508// OBJECT_PATH => allows to provide the object path to be used in the dbus daemon.
509// POST_DOWNLOAD_COMMAND => allows to provide a command that will be executed on the
510// download
511//
512// The headers attribute allows to provide extra headers to be used in the request used
513// to perform the download.
514func (man *DownloadManager) CreateDownload(url string, hash string, algo hashType, metadata map[string]interface{}, headers map[string]string) (down Download, err error) {
515 var t map[string]*dbus.Variant
516 for key, value := range metadata {
517 t[key] = &dbus.Variant{Value: value}
518 }
519 s := struct {
520 U string
521 H string
522 A string
523 M map[string]*dbus.Variant
524 HD map[string]string
525 }{url, hash, string(algo), t, headers}
526 var path dbus.ObjectPath
527 reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createDownload", s)
528 if err != nil || reply.Type == dbus.TypeError {
529 return nil, err
530 }
531 if err = reply.Args(&path); err != nil {
532 return nil, err
533 }
534 down, err = newFileDownload(man.conn, path)
535 return down, err
536}
537
538// CreateMmsDownload creates an mms download that will be performed right away. An
539// mms download only uses mobile that and an apn proxy to download a multime media
540// message.
541func (man *DownloadManager) CreateMmsDownload(url string, hostname string, port int32) (down Download, err error) {
542 var path dbus.ObjectPath
543 reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createMmsDownload", url, hostname, port)
544 if err != nil || reply.Type == dbus.TypeError {
545 return nil, err
546 }
547 if err = reply.Args(&path); err != nil {
548 return nil, err
549 }
550 down, err = newFileDownload(man.conn, path)
551 return down, err
552}

Subscribers

People subscribed via source and target branches