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 // void disconnectCallbackHelper(void * object) {
12 // QClient * client = static_cast<QClient *>(object);
14 // client->disconnectCallbackHandler();
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());
26 xmmsc_unref(m_Connection
);
30 void QClient::disconnectCallbackHandler(void * instance
) {
31 QClient
* client
= static_cast<QClient
*>(instance
);
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
);
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
));