[client] fixed ununsed var warning
[libxmms2client-qt.git] / client.cpp
blob32cd0afb6d7c705e83e94eedf183b7a6a7c36d07
1 //
2 // C++ Implementation: client
3 //
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
5 //
6 // Copyright: See COPYING file that comes with this distribution
7 //
8 #include "client.h"
10 namespace XmmsQt {
11 // void disconnectCallbackHelper(void * object) {
12 // QClient * client = static_cast<QClient *>(object);
13 // if (client)
14 // client->disconnectCallbackHandler();
15 // }
17 QClient::QClient(QString name, QObject * parent) : QObject(parent),
18 m_Name(name), m_Connected(false), m_Connection(NULL), m_ReadNotifier(NULL), m_WriteNotifier(NULL),
19 m_Playback(this), m_Playlist(this)
21 m_Connection = xmmsc_init(name.toAscii().data());
24 QClient::~QClient() {
25 if( m_Connection ) {
26 xmmsc_unref(m_Connection);
30 void QClient::disconnectCallbackHandler(void * instance) {
31 QClient * client = static_cast<QClient *>(instance);
32 if (client) {
33 xmmsc_unref(client->m_Connection);
34 client->m_Connection = 0;
35 emit client->connectionChanged(NULL); //TODO: check if this is possible
39 void QClient::outputCheck(int, void * instance) {
40 QClient * client = static_cast<QClient *>(instance);
41 if (client) {
42 if (xmmsc_io_want_out(client->m_Connection))
43 client->m_WriteNotifier->setEnabled(true);
44 else
45 client->m_WriteNotifier->setEnabled(false);
49 void QClient::handleIn(int) {
50 xmmsc_io_in_handle(m_Connection);
53 void QClient::handleOut(int) {
54 xmmsc_io_out_handle(m_Connection);
57 void QClient::connectToServer(QString ipcPath) {
58 if(!m_Connected) {
59 if(!m_Connection) {
60 m_Connection = xmmsc_init(m_Name.toAscii().data());
62 m_Connected = xmmsc_connect(m_Connection, (ipcPath.isEmpty()) ? NULL : ipcPath.toAscii().data());
64 if (!m_Connected)
65 return;
67 xmmsc_disconnect_callback_set(m_Connection, disconnectCallbackHandler, this);
68 xmmsc_io_need_out_callback_set(m_Connection, outputCheck, this);
70 //don't think we need a quit handler as we have a disconnect handler
71 //xmmsc_result_notifier_set();
73 //xmmsc_io_need_out_callback_set();
75 if (m_ReadNotifier)
76 delete m_ReadNotifier;
77 if (m_WriteNotifier)
78 delete m_WriteNotifier;
80 m_ReadNotifier = new QSocketNotifier(xmmsc_io_fd_get(m_Connection), QSocketNotifier::Read, this);
81 m_WriteNotifier = new QSocketNotifier(xmmsc_io_fd_get(m_Connection), QSocketNotifier::Write, this);
82 connect(m_ReadNotifier, SIGNAL(activated(int)), this, SLOT(handleIn(int)));
83 connect(m_WriteNotifier, SIGNAL(activated(int)), this, SLOT(handleOut(int)));
84 m_ReadNotifier->setEnabled(true);
85 m_WriteNotifier->setEnabled(false);
87 emit connectionChanged(m_Connection);
90 bool QClient::isConnectedToServer() const
92 return m_Connected;
95 void QClient::quitServer() {
96 if(m_Connected) {
97 xmmsc_result_t * result = xmmsc_quit(m_Connection);
98 xmmsc_result_unref(result);
99 m_Connected = false;
103 QString QClient::lastError() const {
104 return QString(xmmsc_get_last_error(m_Connection));