Rationale

The DownloadManager represents the entry point for the DBus API provided by the ubuntu download service. An application can use the DownloadManager to create downloads that will be performed by the daemon and in this way ensure that the downloads will be completed even if the application is paused or killed by the operating system.

Interface

The following defines the public interface exposed by the DownloadManager.

Methods

createDownload(IN Download download, OUT ObjectPath path)

createDownloadGroup(IN Arra<GroupDownload> group, IN String algorithm, IN Bool allowGSM, IN Dict<String, Variant> metadata, IN Dict<String, String> headers)

getAllDownloads(OUT Array<ObjectPath> paths)

getAllDownloadsWithMetadata(IN String name, IN String value, OUT Array<ObjectPath> paths )

setDefaultThrottle(IN UInt64 value)

defaultThrottle(OUT UInt64 value)

allowGSMDownload(IN Bool isAllowed)

isGSMDownloadAllowed(OUT Bool isAllowed)

Signals

downloadCreated(OUT ObjectPath path)

DBus API XML Definition

The following is an XML definition of the DBus interface that can be used to generate adapters in different languages:

   1 <node>
   2   <interface name="com.canonical.applications.DownloaderManager">
   3     <method name="createDownload">
   4         <arg name="download" type="(sssa{sv}a{ss})" direction="in" />
   5         <arg name="downloadPath" type="o" direction="out" />
   6     </method>
   7 
   8     <method name="createDownloadGroup">
   9         <arg name="downloads" type="a(sss)" direction="in"/>
  10         <arg name="algorithm" type="s" direction="in"/>
  11         <arg name="allowed3G" type="b" direction="in"/>
  12         <arg name="metadata" type="a{sv}" direction="in"/>
  13         <arg name="headers" type="a{ss}" direction="in"/>
  14         <arg name="download" type="o" direction="out" />
  15     </method>
  16 
  17     <method name="getAllDownloads">
  18         <arg name="downloads" type="ao" direction="out" />
  19     </method>
  20 
  21     <method name="getAllDownloadsWithMetadata">
  22         <arg name="name" type="s" direction="in"/>
  23         <arg name="value" type="s" direction="in"/>
  24         <arg name="downloads" type="ao" direction="out" />
  25     </method>
  26 
  27     <method name="setDefaultThrottle">
  28         <arg name="speed" type="t" direction="in"/>
  29     </method>
  30 
  31     <method name="defaultThrottle">
  32         <arg name="speed" type="t" direction="out"/>
  33     </method>
  34 
  35     <method name="allowGSMDownload">
  36         <arg name="allowed" type="b" direction="in"/>
  37     </method>
  38 
  39     <method name="isGSMDownloadAllowed">
  40         <arg name="allowed" type="b" direction="out"/>
  41     </method>
  42 
  43     <signal name="downloadCreated">
  44         <arg name="path" type="o" direction="out"/>
  45     </signal>
  46 
  47  </interface>
  48 </node>

Code Examples

Python

Small script that shows how to use the DownloadManager to create a single download, track its process and finish the script.

   1 #!/usr/bin/python3
   2 
   3 from gi.repository import GLib
   4 import dbus
   5 from dbus.mainloop.glib import DBusGMainLoop
   6 
   7 DBusGMainLoop(set_as_default=True)
   8 
   9 MANAGER_PATH = '/'
  10 MANAGER_IFACE = 'com.canonical.applications.DownloadManager'
  11 DOWNLOAD_IFACE = 'com.canonical.applications.Download'
  12 IMAGE_FILE = 'http://i.imgur.com/y51njgu.jpg'
  13 
  14 
  15 def download_created(path):
  16     """Deal with the download created signal."""
  17     print('Download created in %s' % path)
  18 
  19 
  20 def finished_callback(path, loop):
  21     """Deal with the finis signal."""
  22     print('Download performed in "%s"' % path)
  23     loop.quit()
  24 
  25 
  26 def progress_callback(total, progress):
  27     """Deal with the progress signals."""
  28     print('Progress is %s/%s' % (progress, total))
  29 
  30 if __name__ == '__main__':
  31 
  32     bus = dbus.SessionBus()
  33     loop = GLib.MainLoop()
  34     manager = bus.get_object('com.canonical.applications.Downloader',
  35             MANAGER_PATH)
  36     manager_dev_iface = dbus.Interface(manager, dbus_interface=MANAGER_IFACE)
  37 
  38     # ensure that download created works
  39     manager_dev_iface.connect_to_signal('downloadCreated', download_created)
  40 
  41     down_path1 = manager_dev_iface.createDownload((IMAGE_FILE, "", "",
  42         dbus.Dictionary({}, signature="sv"),
  43         dbus.Dictionary({}, signature="ss")))
  44     down_path2 = manager_dev_iface.createDownload((IMAGE_FILE, "", "",
  45         dbus.Dictionary({}, signature="sv"),
  46         dbus.Dictionary({}, signature="ss")))
  47     down_path3 = manager_dev_iface.createDownload((IMAGE_FILE, "", "",
  48         dbus.Dictionary({}, signature="sv"),
  49         dbus.Dictionary({}, signature="ss")))
  50 
  51     download1 = bus.get_object('com.canonical.applications.Downloader',
  52             down_path1)
  53     download2 = bus.get_object('com.canonical.applications.Downloader',
  54             down_path2)
  55     download3 = bus.get_object('com.canonical.applications.Downloader',
  56             down_path3)
  57 
  58     download_dev_iface1 = dbus.Interface(download1, dbus_interface=DOWNLOAD_IFACE)
  59     download_dev_iface2 = dbus.Interface(download2, dbus_interface=DOWNLOAD_IFACE)
  60     download_dev_iface3 = dbus.Interface(download3, dbus_interface=DOWNLOAD_IFACE)
  61 
  62     # connect to signals
  63     download_dev_iface1.connect_to_signal('progress', progress_callback)
  64     download_dev_iface2.connect_to_signal('progress', progress_callback)
  65     download_dev_iface3.connect_to_signal('progress', progress_callback)
  66     download_dev_iface3.connect_to_signal('finished',
  67             lambda path: finished_callback(path, loop))
  68 
  69     download_dev_iface1.start()
  70     download_dev_iface2.start()
  71     download_dev_iface3.start()
  72 
  73     loop.run()

DownloadService/DownloadManager (last edited 2014-06-18 14:48:19 by ip68-12-7-251)