ScrobSubmitter Class Reference

#include <ScrobSubmitter.h>

List of all members.

Public Types

enum  Encoding { ISO_8859_1, UTF_8 }
typedef void(*) StatusCallback (int reqId, bool error, std::string msg, void *userData)

Public Member Functions

 ScrobSubmitter ()
virtual ~ScrobSubmitter ()
void Init (const std::string &pluginId, StatusCallback callback, void *userData)
void Term ()
int Start (std::string artist, std::string track, std::string album, std::string mbId, int length, std::string filename, Encoding encoding=UTF_8)
int Stop ()
int Pause ()
int Resume ()
std::string GetVersion ()

Static Public Member Functions

static std::string GetLogPath ()


Detailed Description

Class for submitting tracks to the Last.fm client. It communicates with the client via a local socket.

To use it, call Init on player startup passing the required parameters. This will launch the Last.fm client if it isn't already runnning and initialise the socket communication and worker thread.

Then simply call functions Start, Stop, Pause and Resume in response to player events to communicate these events to the Last.fm client. They all operate asynchronously, i.e. they will return straight away so as to prevent hanging the calling thread if an operation takes some time. This shouldn't normally be the case but if the client is not running, it might take some time to discover that the socket is not open. The functions will return a request ID uniquely identifying the command just sent. When the request is finished, the status callback will be called with the ID as a parameter and a message of either "OK" or a description of the error if one occurred.

It's important to call Term at shutdown to clean up all resources properly.


Member Typedef Documentation

typedef void(*) ScrobSubmitter::StatusCallback(int reqId, bool error, std::string msg, void *userData)

Callback function type for status reporting.

Parameters:
[in] reqId The request ID the message is in regards to.
[in] error True if an error occurred.
[in] msg Status message.
[in] userData The user data passed to Init.


Member Enumeration Documentation

enum ScrobSubmitter::Encoding

Text encoding used for track submissions.


Constructor & Destructor Documentation

ScrobSubmitter::ScrobSubmitter (  ) 

Constructor

ScrobSubmitter::~ScrobSubmitter (  )  [virtual]

Destructor


Member Function Documentation

void ScrobSubmitter::Init ( const std::string &  pluginId,
StatusCallback  callback,
void *  userData 
)

Call this to initialise the class. Must be called before any tracks are submitted or things won't work. This function will also launch Last.fm if it isn't running.

Parameters:
[in] pluginId Three-letter plugin code as assigned by Last.fm. Contact russ at last.fm to get one for your plugin.
[in] callback Function pointer for reporting result status of asynchronous operations.
[in] userData Pointer that will be passed back through the callback. Use for "this" pointer.

void ScrobSubmitter::Term (  ) 

Call this to terminate. Must be called in order for the socket thread to be shut down properly.

int ScrobSubmitter::Start ( std::string  artist,
std::string  track,
std::string  album,
std::string  mbId,
int  length,
std::string  filename,
Encoding  encoding = UTF_8 
)

Sends a START command to client. All parameter strings are treated as standard char strings.

Parameters:
[in] artist Name of artist.
[in] track Name of track.
[in] album Name of album.
[in] mbId Musicbrainz ID if present.
[in] length Length of track in seconds.
[in] filename Full path to the file on the disk.
[in] encoding Text encoding specifying how to interpret the characters in the strings passed in.
Returns:
A unique request ID.

int ScrobSubmitter::Stop (  ) 

Sends a STOP command to client. Call this both for stop and when a song plays to the end.

Returns:
A unique request ID.

int ScrobSubmitter::Pause (  ) 

Sends a PAUSE command to client. Use this only for pause.

Returns:
A unique request ID.

int ScrobSubmitter::Resume (  ) 

Sends a RESUME command to client. Should only be used following a preceding START-PAUSE sequence to resume a paused track.

Returns:
A unique request ID.

string ScrobSubmitter::GetVersion (  ) 

Get ScrobSub version.

Returns:
Version string.

string ScrobSubmitter::GetLogPath (  )  [static]

Returns a suitable directory for putting log files in. Normally "Documents and Settings/[user]/Local Settings/Application Data/ Last.fm/Client".

Returns:
Path to log folder.


The documentation for this class was generated from the following files:
Generated on Wed May 2 19:28:45 2007 by  doxygen 1.5.1