1
#ifndef __CLIENTSTUB_H_
2
#define __CLIENTSTUB_H_
6
#include "clientstubbase.h"
14
using std::stringstream;
15
using std::ostringstream;
19
template <typename Ops>
20
class IMMSClient : public IMMSClientStub, protected GIOSocket
23
IMMSClient() : connected(false) { }
26
int fd = socket_connect(get_imms_root("socket"));
30
return connected = true;
32
cerr << "Connection failed: " << strerror(errno) << endl;
35
virtual void write_command(const string &line)
36
{ if (isok()) GIOSocket::write(line + "\n"); }
37
virtual void process_line(const string &line)
42
#if defined(DEBUG) && 1
43
std::cout << "< " << line << endl;
49
if (command == "ResetSelection")
51
Ops::reset_selection();
54
if (command == "TryAgain")
56
write_command("SelectNext");
59
if (command == "EnqueueNext")
66
if (command == "PlaylistChanged")
68
IMMSClientStub::playlist_changed(Ops::get_length());
71
if (command == "GetPlaylistItem")
75
send_item("PlaylistItem", i);
78
if (command == "GetEntirePlaylist")
80
for (int i = 0; i < Ops::get_length(); ++i)
81
send_item("Playlist", i);
82
write_command("PlaylistEnd");
86
cerr << "IMMS: Unknown command: " << command << endl;
88
virtual void connection_lost() { connected = false; }
90
bool check_connection()
100
bool isok() { return connected; }
104
void send_item(const char *command, int i)
107
osstr << command << " " << i << " " << Ops::get_item(i);
108
write_command(osstr.str());