put mpd connection related things into namespace
This commit is contained in:
315
src/mpdpp.h
315
src/mpdpp.h
@@ -18,190 +18,195 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef HAVE_MPDPP_H
|
||||
#define HAVE_MPDPP_H
|
||||
#ifndef _MPDPP_H
|
||||
#define _MPDPP_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "libmpdclient.h"
|
||||
#include "ncmpcpp.h"
|
||||
#include "song.h"
|
||||
|
||||
enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist };
|
||||
enum ItemType { itDirectory, itSong, itPlaylist };
|
||||
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
||||
|
||||
struct MPDStatusChanges
|
||||
namespace MPD
|
||||
{
|
||||
MPDStatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), PlayerState(0) { }
|
||||
bool Playlist;
|
||||
bool SongID;
|
||||
bool Database;
|
||||
bool DBUpdating;
|
||||
bool Volume;
|
||||
bool ElapsedTime;
|
||||
bool Crossfade;
|
||||
bool Random;
|
||||
bool Repeat;
|
||||
bool PlayerState;
|
||||
};
|
||||
enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist };
|
||||
enum ItemType { itDirectory, itSong, itPlaylist };
|
||||
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
||||
|
||||
struct QueueCommand
|
||||
{
|
||||
QueueCommand() : id(0), id2(0) { }
|
||||
QueueCommandType type;
|
||||
string playlist_path;
|
||||
string item_path;
|
||||
int id;
|
||||
int id2;
|
||||
};
|
||||
|
||||
struct Item
|
||||
{
|
||||
Item() : song(0) { }
|
||||
Song *song;
|
||||
ItemType type;
|
||||
string name;
|
||||
};
|
||||
|
||||
typedef std::vector<Item> ItemList;
|
||||
typedef std::vector<Song *> SongList;
|
||||
typedef std::vector<string> TagList;
|
||||
|
||||
void FreeSongList(SongList &);
|
||||
void FreeItemList(ItemList &);
|
||||
|
||||
class MPDConnection
|
||||
{
|
||||
typedef void (*StatusUpdater) (MPDConnection *, MPDStatusChanges, void *);
|
||||
typedef void (*ErrorHandler) (MPDConnection *, int, string, void *);
|
||||
struct Item
|
||||
{
|
||||
Item() : song(0) { }
|
||||
Song *song;
|
||||
ItemType type;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
public:
|
||||
MPDConnection();
|
||||
~MPDConnection();
|
||||
struct StatusChanges
|
||||
{
|
||||
bool Playlist:1;
|
||||
bool SongID:1;
|
||||
bool Database:1;
|
||||
bool DBUpdating:1;
|
||||
bool Volume:1;
|
||||
bool ElapsedTime:1;
|
||||
bool Crossfade:1;
|
||||
bool Random:1;
|
||||
bool Repeat:1;
|
||||
bool PlayerState:1;
|
||||
};
|
||||
|
||||
typedef std::vector<Item> ItemList;
|
||||
typedef std::vector<Song *> SongList;
|
||||
typedef std::vector<std::string> TagList;
|
||||
|
||||
void FreeSongList(SongList &);
|
||||
void FreeItemList(ItemList &);
|
||||
|
||||
class Connection
|
||||
{
|
||||
struct QueueCommand
|
||||
{
|
||||
QueueCommand() : id(0), id2(0) { }
|
||||
QueueCommandType type;
|
||||
std::string playlist_path;
|
||||
std::string item_path;
|
||||
int id;
|
||||
int id2;
|
||||
};
|
||||
|
||||
bool Connect();
|
||||
bool Connected() const;
|
||||
void Disconnect();
|
||||
typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
|
||||
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
|
||||
|
||||
const string & GetHostname() { return MPD_HOST; }
|
||||
int GetPort() { return MPD_PORT; }
|
||||
public:
|
||||
Connection();
|
||||
~Connection();
|
||||
|
||||
void SetHostname(const string &);
|
||||
void SetPort(int port) { MPD_PORT = port; }
|
||||
void SetTimeout(int timeout) { MPD_TIMEOUT = timeout; }
|
||||
void SetPassword(const string &password) { MPD_PASSWORD = password; }
|
||||
void SendPassword() const;
|
||||
bool Connect();
|
||||
bool Connected() const;
|
||||
void Disconnect();
|
||||
|
||||
void SetStatusUpdater(StatusUpdater, void *);
|
||||
void SetErrorHandler(ErrorHandler, void *);
|
||||
void UpdateStatus();
|
||||
void UpdateDirectory(const string &) const;
|
||||
const std::string & GetHostname() { return itsHost; }
|
||||
int GetPort() { return itsPort; }
|
||||
|
||||
void Execute(const string &) const;
|
||||
void SetHostname(const std::string &);
|
||||
void SetPort(int port) { itsPort = port; }
|
||||
void SetTimeout(int timeout) { itsTimeout = timeout; }
|
||||
void SetPassword(const std::string &password) { itsPassword = password; }
|
||||
void SendPassword() const;
|
||||
|
||||
void Play() const;
|
||||
void Play(int) const;
|
||||
void PlayID(int) const;
|
||||
void Pause() const;
|
||||
void Stop() const;
|
||||
void Next() const;
|
||||
void Prev() const;
|
||||
void Move(int, int) const;
|
||||
void Seek(int) const;
|
||||
void Shuffle() const;
|
||||
void ClearPlaylist() const;
|
||||
void SetStatusUpdater(StatusUpdater, void *);
|
||||
void SetErrorHandler(ErrorHandler, void *);
|
||||
void UpdateStatus();
|
||||
void UpdateDirectory(const std::string &) const;
|
||||
|
||||
PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; }
|
||||
bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; }
|
||||
bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; }
|
||||
bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; }
|
||||
int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : -1; }
|
||||
int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : -1; }
|
||||
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; }
|
||||
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; }
|
||||
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
|
||||
void Execute(const std::string &) const;
|
||||
|
||||
unsigned int GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }
|
||||
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
|
||||
void GetPlaylistChanges(long long, SongList &) const;
|
||||
void Play() const;
|
||||
void Play(int) const;
|
||||
void PlayID(int) const;
|
||||
void Pause() const;
|
||||
void Stop() const;
|
||||
void Next() const;
|
||||
void Prev() const;
|
||||
void Move(int, int) const;
|
||||
void Seek(int) const;
|
||||
void Shuffle() const;
|
||||
void ClearPlaylist() const;
|
||||
|
||||
const string & GetErrorMessage() const { return itsErrorMessage; }
|
||||
int GetErrorCode() const { return itsErrorCode; }
|
||||
PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; }
|
||||
bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; }
|
||||
bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; }
|
||||
bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; }
|
||||
int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : -1; }
|
||||
int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : -1; }
|
||||
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; }
|
||||
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; }
|
||||
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
|
||||
|
||||
Song GetCurrentSong() const;
|
||||
int GetCurrentSongPos() const;
|
||||
Song GetSong(const string &) const;
|
||||
void GetPlaylistContent(const string &, SongList &) const;
|
||||
unsigned int GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }
|
||||
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
|
||||
void GetPlaylistChanges(long long, SongList &) const;
|
||||
|
||||
void SetRepeat(bool) const;
|
||||
void SetRandom(bool) const;
|
||||
void SetVolume(int) const;
|
||||
void SetCrossfade(int) const;
|
||||
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
||||
int GetErrorCode() const { return itsErrorCode; }
|
||||
|
||||
int AddSong(const string &); // returns id of added song
|
||||
int AddSong(const Song &); // returns id of added song
|
||||
void QueueAddSong(const string &);
|
||||
void QueueAddSong(const Song &);
|
||||
void QueueAddToPlaylist(const string &, const string &);
|
||||
void QueueAddToPlaylist(const string &, const Song &);
|
||||
void QueueDeleteSong(int);
|
||||
void QueueDeleteSongId(int);
|
||||
void QueueMove(int, int);
|
||||
void QueueMove(const string &, int, int);
|
||||
void QueueDeleteFromPlaylist(const string &, int);
|
||||
bool CommitQueue();
|
||||
Song GetCurrentSong() const;
|
||||
int GetCurrentSongPos() const;
|
||||
Song GetSong(const std::string &) const;
|
||||
void GetPlaylistContent(const std::string &, SongList &) const;
|
||||
|
||||
void DeletePlaylist(const string &) const;
|
||||
bool SavePlaylist(const string &) const;
|
||||
void ClearPlaylist(const string &) const;
|
||||
void AddToPlaylist(const string &, const Song &) const;
|
||||
void AddToPlaylist(const string &, const string &) const;
|
||||
void Move(const string &, int, int) const;
|
||||
void Rename(const string &, const string &) const;
|
||||
void SetRepeat(bool) const;
|
||||
void SetRandom(bool) const;
|
||||
void SetVolume(int) const;
|
||||
void SetCrossfade(int) const;
|
||||
|
||||
void StartSearch(bool) const;
|
||||
void StartFieldSearch(mpd_TagItems);
|
||||
void AddSearch(mpd_TagItems, const string &) const;
|
||||
void CommitSearch(SongList &) const;
|
||||
void CommitSearch(TagList &) const;
|
||||
int AddSong(const std::string &); // returns id of added song
|
||||
int AddSong(const Song &); // returns id of added song
|
||||
void QueueAddSong(const std::string &);
|
||||
void QueueAddSong(const Song &);
|
||||
void QueueAddToPlaylist(const std::string &, const std::string &);
|
||||
void QueueAddToPlaylist(const std::string &, const Song &);
|
||||
void QueueDeleteSong(int);
|
||||
void QueueDeleteSongId(int);
|
||||
void QueueMove(int, int);
|
||||
void QueueMove(const std::string &, int, int);
|
||||
void QueueDeleteFromPlaylist(const std::string &, int);
|
||||
bool CommitQueue();
|
||||
|
||||
void GetPlaylists(TagList &) const;
|
||||
void GetList(TagList &, mpd_TagItems) const;
|
||||
void GetArtists(TagList &) const;
|
||||
void GetAlbums(string, TagList &) const;
|
||||
void GetDirectory(const string &, ItemList &) const;
|
||||
void GetDirectoryRecursive(const string &, SongList &) const;
|
||||
void GetSongs(const string &, SongList &) const;
|
||||
void GetDirectories(const string &, TagList &) const;
|
||||
void DeletePlaylist(const std::string &) const;
|
||||
bool SavePlaylist(const std::string &) const;
|
||||
void ClearPlaylist(const std::string &) const;
|
||||
void AddToPlaylist(const std::string &, const Song &) const;
|
||||
void AddToPlaylist(const std::string &, const std::string &) const;
|
||||
void Move(const std::string &, int, int) const;
|
||||
void Rename(const std::string &, const std::string &) const;
|
||||
|
||||
private:
|
||||
void ClearQueue();
|
||||
int CheckForErrors();
|
||||
void StartSearch(bool) const;
|
||||
void StartFieldSearch(mpd_TagItems);
|
||||
void AddSearch(mpd_TagItems, const std::string &) const;
|
||||
void CommitSearch(SongList &) const;
|
||||
void CommitSearch(TagList &) const;
|
||||
|
||||
mpd_Connection *itsConnection;
|
||||
bool isConnected;
|
||||
void GetPlaylists(TagList &) const;
|
||||
void GetList(TagList &, mpd_TagItems) const;
|
||||
void GetArtists(TagList &) const;
|
||||
void GetAlbums(std::string, TagList &) const;
|
||||
void GetDirectory(const std::string &, ItemList &) const;
|
||||
void GetDirectoryRecursive(const std::string &, SongList &) const;
|
||||
void GetSongs(const std::string &, SongList &) const;
|
||||
void GetDirectories(const std::string &, TagList &) const;
|
||||
|
||||
string itsErrorMessage;
|
||||
int itsErrorCode;
|
||||
unsigned int itsMaxPlaylistLength;
|
||||
private:
|
||||
void ClearQueue();
|
||||
int CheckForErrors();
|
||||
|
||||
string MPD_HOST;
|
||||
int MPD_PORT;
|
||||
int MPD_TIMEOUT;
|
||||
string MPD_PASSWORD;
|
||||
mpd_Connection *itsConnection;
|
||||
bool isConnected;
|
||||
|
||||
mpd_Stats *itsOldStats;
|
||||
mpd_Stats *itsCurrentStats;
|
||||
mpd_Status *itsCurrentStatus;
|
||||
mpd_Status *itsOldStatus;
|
||||
std::string itsErrorMessage;
|
||||
int itsErrorCode;
|
||||
unsigned int itsMaxPlaylistLength;
|
||||
|
||||
StatusUpdater itsUpdater;
|
||||
void *itsStatusUpdaterUserdata;
|
||||
ErrorHandler itsErrorHandler;
|
||||
void *itsErrorHandlerUserdata;
|
||||
std::string itsHost;
|
||||
int itsPort;
|
||||
int itsTimeout;
|
||||
std::string itsPassword;
|
||||
|
||||
mpd_TagItems itsSearchedField;
|
||||
std::vector<QueueCommand *> itsQueue;
|
||||
};
|
||||
mpd_Stats *itsOldStats;
|
||||
mpd_Stats *itsCurrentStats;
|
||||
mpd_Status *itsCurrentStatus;
|
||||
mpd_Status *itsOldStatus;
|
||||
|
||||
StatusChanges itsChanges;
|
||||
|
||||
StatusUpdater itsUpdater;
|
||||
void *itsStatusUpdaterUserdata;
|
||||
ErrorHandler itsErrorHandler;
|
||||
void *itsErrorHandlerUserdata;
|
||||
|
||||
mpd_TagItems itsSearchedField;
|
||||
std::vector<QueueCommand *> itsQueue;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user