MoSync 3.3
MAUtil::ImageDownloader Class Reference

The ImageDownloader class. Use it to simplify asynchronous downloading of images to image resources. More...

#include <MAUtil/Downloader.h>

Inheritance diagram for MAUtil::ImageDownloader:
MAUtil::Downloader MAUtil::HttpConnectionListener MAUtil::ConnectionListener

List of all members.

Public Member Functions

 ImageDownloader ()
virtual ~ImageDownloader ()
int beginDownloading (const char *url, MAHandle placeholder=0)
void addDownloadListener (DownloadListener *dl)
void removeDownloadListener (DownloadListener *dl)
void setDownloadController (DownloadController *dc)
virtual int cancelDownloading ()
bool isDownloading () const
virtual void connectFinished (Connection *conn, int result) __attribute__((noreturn))
virtual void connWriteFinished (Connection *conn, int result) __attribute__((noreturn))
virtual void connReadFinished (Connection *conn, int result) __attribute__((noreturn))

Protected Member Functions

virtual MAHandle getHandle ()
virtual void closeConnection (int cleanup)
MAHandle getDataPlaceholder ()
void fireNotifyProgress (int dataOffset, int contentLength)
void fireFinishedDownloading (MAHandle data)
void fireError (int code)
void deleteReader ()
void doRedirect (HttpConnection *http)
virtual void httpFinished (HttpConnection *http, int result)
void connRecvFinished (Connection *conn, int result)

Protected Attributes

bool mIsImagePlaceholderSystemAllocated
bool mIsImageCreated
MAHandle mImagePlaceholder
HttpConnectionmConn
bool mIsDownloading
bool mIsDataPlaceholderSystemAllocated
MAHandle mDataPlaceholder
Vector< DownloadListener * > mDownloadListeners
DownloaderReadermReader
DownloadControllermController
int mRedirectionCounter

Detailed Description

The ImageDownloader class. Use it to simplify asynchronous downloading of images to image resources.


Constructor & Destructor Documentation


Member Function Documentation

int MAUtil::ImageDownloader::beginDownloading ( const char *  url,
MAHandle  placeholder = 0 
) [virtual]
virtual MAHandle MAUtil::ImageDownloader::getHandle ( ) [protected, virtual]

Return the image handle of the downloader. The caller of this method should fire an error to listeners.

Returns:
The image handle (> 0) if successful, 0 if there is an error (out of memory).

Reimplemented from MAUtil::Downloader.

virtual void MAUtil::ImageDownloader::closeConnection ( int  cleanup) [protected, virtual]

Close the connection used by the downloader. This is part of the normal finishing of the download, and is also done on errors and on cancelling the download.

Parameters:
cleanupif 1 free downloaded resources, if 0 do not do free downloaded resources. Cleanup is done on errors and on cancelling a download.

Reimplemented from MAUtil::Downloader.

Function to register a DownloadListener, to which all events for this Downloader is distributed.

Parameters:
dlPointer to the DownloadListener instance.

Remove a DownloadListener.

Parameters:
dlPointer to the DownloadListener instance.

Sets the controller for this Downloader.

By default, a Downloader has no controller. See DownloadController for info on default behavior.

Parameters:
dcPointer to a DownloadController instance, or NULL to remove any existing controller.
virtual int MAUtil::Downloader::cancelDownloading ( ) [virtual, inherited]

Function to cancel the current download. Do cleanup and send downloadCancelled to listeners.

Returns:
>0 on success, or CONNERR code if there is no active download.
bool MAUtil::Downloader::isDownloading ( ) const [inline, inherited]

Function to retrieve if the Downloader is currently downloading something.

Returns:
a boolean value, if true the function is currently downloading otherwise it isn't.

References MAUtil::Downloader::mIsDownloading.

Helper method to get the data handle. Used by friend classes.

void MAUtil::Downloader::fireNotifyProgress ( int  dataOffset,
int  contentLength 
) [protected, inherited]

Send notifyProgress to listeners.

void MAUtil::Downloader::fireFinishedDownloading ( MAHandle  data) [protected, inherited]

Close connection and send finishedDownloading to listeners.

void MAUtil::Downloader::fireError ( int  code) [protected, inherited]

Do cleanup and send error to listeners.

void MAUtil::Downloader::deleteReader ( ) [protected, inherited]

Delete the reader object (this is the object that performs the download).

void MAUtil::Downloader::doRedirect ( HttpConnection http) [protected, inherited]

Performs url redirection if not blocked by the Downloader user (via DownloadController).

Parameters:
httpA http connection that needs redirection.
virtual void MAUtil::Downloader::httpFinished ( HttpConnection http,
int  result 
) [protected, virtual, inherited]

Callback method in HttpConnectionListener.

Implements MAUtil::HttpConnectionListener.

Reimplemented in MAUtil::AudioDownloader.

void MAUtil::Downloader::connRecvFinished ( Connection conn,
int  result 
) [protected, virtual, inherited]

Callback method.

Reimplemented from MAUtil::ConnectionListener.

virtual void MAUtil::ConnectionListener::connectFinished ( Connection conn,
int  result 
) [virtual, inherited]

Called when a connect operation finishes.

Parameters:
connThe Connection that ran the operation.
result> 0 on success, or a CONNERR code < 0 on failure.
virtual void MAUtil::ConnectionListener::connWriteFinished ( Connection conn,
int  result 
) [virtual, inherited]

Called when a write operation finishes.

Parameters:
connThe Connection that ran the operation.
result> 0 on success, or a CONNERR code < 0 on failure.

Reimplemented in Wormhole::HighLevelHttpConnection.

virtual void MAUtil::ConnectionListener::connReadFinished ( Connection conn,
int  result 
) [virtual, inherited]

Called when a read operation finishes.

Parameters:
connThe Connection that ran the operation.
result> 0 on success, or a CONNERR code < 0 on failure.

Reimplemented in Wormhole::HighLevelHttpConnection.


Member Data Documentation

HttpConnection* MAUtil::Downloader::mConn [protected, inherited]
bool MAUtil::Downloader::mIsDownloading [protected, inherited]

Object that performs the actual download. A downloader is configured with different readers depending on the how the server sends the data to the client.

int MAUtil::Downloader::mRedirectionCounter [protected, inherited]

A counter representing the number of redirection attemps.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines