downloader.h File Reference

Image downloader. More...

Go to the source code of this file.


int create_downloader (struct interface *job, struct image *image)
 Instantiate a downloader. More...

Detailed Description

Image downloader.

Definition in file downloader.h.

Function Documentation



◆ create_downloader()

int create_downloader ( struct interface job,
struct image image 

Instantiate a downloader.

jobJob control interface
imageImage to fill with downloaded file
Return values
rcReturn status code

Instantiates a downloader object to download the content of the specified image from its URI.

Definition at line 258 of file downloader.c.

258  {
259  struct downloader *downloader;
260  int rc;
262  /* Allocate and initialise structure */
263  downloader = zalloc ( sizeof ( *downloader ) );
264  if ( ! downloader )
265  return -ENOMEM;
268  &downloader->refcnt );
270  &downloader->refcnt );
274  /* Instantiate child objects and attach to our interfaces */
275  if ( ( rc = xfer_open_uri ( &downloader->xfer, image->uri ) ) != 0 )
276  goto err;
278  /* Attach parent interface, mortalise self, and return */
280  ref_put ( &downloader->refcnt );
281  return 0;
283  err:
285  ref_put ( &downloader->refcnt );
286  return rc;
287 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
struct image * image
Image to contain downloaded file.
Definition: downloader.c:56
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
int xfer_open_uri(struct interface *intf, struct uri *uri)
Open URI.
Definition: open.c:67
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:218
static struct interface_descriptor downloader_xfer_desc
Downloader data transfer interface descriptor.
Definition: downloader.c:223
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
An executable image.
Definition: image.h:24
struct interface job
Job control interface.
Definition: downloader.c:51
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void downloader_finished(struct downloader *downloader, int rc)
Terminate download.
Definition: downloader.c:80
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
A downloader.
Definition: downloader.c:46
struct uri * uri
URI of image.
Definition: image.h:32
struct interface xfer
Data transfer interface.
Definition: downloader.c:53
static void xferbuf_umalloc_init(struct xfer_buffer *xferbuf, userptr_t *data)
Initialise umalloc()-based data transfer buffer.
Definition: xferbuf.h:87
struct refcnt refcnt
Reference count for this object.
Definition: downloader.c:48
struct xfer_buffer buffer
Data transfer buffer.
Definition: downloader.c:58
static struct interface_descriptor downloader_job_desc
Downloader job control interface descriptor.
Definition: downloader.c:239
static void downloader_free(struct refcnt *refcnt)
Free downloader object.
Definition: downloader.c:66
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References downloader::buffer, image::data, downloader_finished(), downloader_free(), downloader_job_desc, downloader_xfer_desc, ENOMEM, downloader::image, image_get(), intf_init(), intf_plug_plug(), downloader::job, rc, ref_init, ref_put, downloader::refcnt, image::uri, downloader::xfer, xfer_open_uri(), xferbuf_umalloc_init(), and zalloc().

Referenced by imgdownload().