improve logging
[scrobby.git] / src / mpdpp.h
blob5917dac89baeb0097d51941e31cb777fc0a78145
1 /***************************************************************************
2 * Copyright (C) 2008 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef _MPDPP_H
22 #define _MPDPP_H
24 #include <string>
25 #include "libmpdclient.h"
27 namespace MPD
29 enum State { psUnknown, psStop, psPlay, psPause };
31 struct StatusChanges
33 bool SongID;
34 bool ElapsedTime;
35 bool State;
38 class Connection
40 typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
41 typedef void (*ErrorHandler) (Connection *, int, std::string, void *);
43 public:
44 Connection();
45 ~Connection();
47 bool Connect();
48 bool Connected() const;
49 void Disconnect();
51 const std::string & GetHostname() { return itsHost; }
52 int GetPort() { return itsPort; }
54 void SetHostname(const std::string &);
55 void SetPort(int port) { itsPort = port; }
56 void SetTimeout(int timeout) { itsTimeout = timeout; }
57 void SetPassword(const std::string &password) { itsPassword = password; }
58 void SendPassword() const;
60 void SetStatusUpdater(StatusUpdater, void *);
61 void SetErrorHandler(ErrorHandler, void *);
62 void UpdateStatus();
64 State GetState() const { return isConnected && itsCurrentStatus ? (State)itsCurrentStatus->state : psUnknown; }
65 int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
67 const std::string & GetErrorMessage() const { return itsErrorMessage; }
68 int GetErrorCode() const { return itsErrorCode; }
70 mpd_Song * CurrentSong() const;
72 private:
73 int CheckForErrors();
75 StatusChanges itsChanges;
77 mpd_Connection *itsConnection;
78 bool isConnected;
80 std::string itsErrorMessage;
81 int itsErrorCode;
83 std::string itsHost;
84 std::string itsPassword;
85 int itsPort;
86 int itsTimeout;
88 mpd_Status *itsCurrentStatus;
89 mpd_Status *itsOldStatus;
91 StatusUpdater itsUpdater;
92 void *itsStatusUpdaterUserdata;
93 ErrorHandler itsErrorHandler;
94 void *itsErrorHandlerUserdata;
98 #endif