MoSync 3.0.1
MAUtil::AudioDownloader Class Reference

The AudioDownloader class. Use it to simplify asynchronous downloading of audio to audio resources. Note that for AudioDownloader to work, the server must return a content-length header in the HTTP response. More...

#include <MAUtil/Downloader.h>

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

List of all members.

Public Member Functions

int beginDownloading (const char *url, MAHandle placeholder=0, const char *mimeType=NULL, bool forceMime=false)
virtual int beginDownloading (const char *url, MAHandle placeholder)
void addDownloadListener (DownloadListener *dl)
void removeDownloadListener (DownloadListener *dl)
virtual void 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 void httpFinished (HttpConnection *http, int result)
virtual MAHandle getHandle ()
MAHandle getDataPlaceholder ()
void fireNotifyProgress (int dataOffset, int contentLength)
void fireFinishedDownloading (MAHandle data)
void fireError (int code)
virtual void closeConnection (int cleanup)
void deleteReader ()
void connRecvFinished (Connection *conn, int result)

Protected Attributes

String mMimeType
bool mForceMimeType
HttpConnectionmConn
bool mIsDownloading
bool mIsDataPlaceholderSystemAllocated
MAHandle mDataPlaceholder
Vector< DownloadListener * > mDownloadListeners
DownloaderReadermReader

Detailed Description

The AudioDownloader class. Use it to simplify asynchronous downloading of audio to audio resources. Note that for AudioDownloader to work, the server must return a content-length header in the HTTP response.


Member Function Documentation

int MAUtil::AudioDownloader::beginDownloading ( const char *  url,
MAHandle  placeholder = 0,
const char *  mimeType = NULL,
bool  forceMime = false 
)

Same as Downloader::beginDownloading() with an additional optional parameter to specify mime type of the downloaded file. If neither the server or you provide a mime type, CONNERR_NOHEADER will be thrown. If both the server and you provide a mime type, by default the server's will be picked, but you can force use of your mime type.

virtual int MAUtil::AudioDownloader::beginDownloading ( const char *  url,
MAHandle  placeholder 
) [virtual]

Function to begin downloading a file.

Parameters:
urlC string containing a null terminated url to the file.
placeholderOptional argument to specify a placeholder to use for the binary resource of the downloaded data.
Returns:
>0 on success, or a CONNERR code < 0 on failure.

Reimplemented from MAUtil::Downloader.

virtual void MAUtil::AudioDownloader::httpFinished ( HttpConnection http,
int  result 
) [protected, virtual]

Callback method in HttpConnectionListener.

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.
virtual void MAUtil::Downloader::cancelDownloading ( ) [virtual, inherited]

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

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.

virtual MAHandle MAUtil::Downloader::getHandle ( ) [protected, virtual, inherited]

Should return a handle to the final product of the download. May return zero if a handle could not be obtained. Do NOT call explicitly. Use the handle provided in finishedDownloading.

Reimplemented in MAUtil::ImageDownloader.

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.

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

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 in MAUtil::ImageDownloader.

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

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

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.
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.

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.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines