2 // C++ Implementation: client
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
6 // Copyright: See COPYING file that comes with this distribution
11 QClient::QClient(QString name
, QObject
* parent
) : QObject(parent
),
12 m_Name(name
), m_Connected(false), m_Connection(NULL
), m_ReadNotifier(NULL
), m_WriteNotifier(NULL
)
13 // m_Playback(this), m_Playlist(this)
15 m_Connection
= xmmsc_init(name
.toAscii().data());
20 xmmsc_unref(m_Connection
);
24 void QClient::disconnectCallbackHandler(void * instance
) {
26 QClient
* client
= static_cast<QClient
*>(instance
);
27 xmmsc_unref(client
->m_Connection
);
28 client
->m_Connection
= 0;
30 if (client
->m_ReadNotifier
)
31 delete client
->m_ReadNotifier
;
32 if (client
->m_WriteNotifier
)
33 delete client
->m_WriteNotifier
;
35 emit client
->connectionChanged(NULL
); //TODO: check if this is possible
39 void QClient::outputCheck(int, void * instance
) {
41 QClient
* client
= static_cast<QClient
*>(instance
);
42 if (xmmsc_io_want_out(client
->m_Connection
))
43 client
->m_WriteNotifier
->setEnabled(true);
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
) {
60 m_Connection
= xmmsc_init(m_Name
.toAscii().data());
62 m_Connected
= xmmsc_connect(m_Connection
, (ipcPath
.isEmpty()) ? NULL
: ipcPath
.toAscii().data());
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();
76 delete m_ReadNotifier
;
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
95 void QClient::quitServer() {
97 xmmsc_result_t
* result
= xmmsc_quit(m_Connection
);
98 xmmsc_result_unref(result
);
103 QString
QClient::lastError() const {
104 return QString(xmmsc_get_last_error(m_Connection
));