-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "pipeserver.h" | ||
|
||
#include <QtNetwork> | ||
#include <QSignalMapper> | ||
#include "ts_logging_qt.h" | ||
|
||
PipeServer::PipeServer(QObject *parent, QString name) : | ||
QObject(parent) | ||
{ | ||
m_SignalMapper = new QSignalMapper(this); | ||
|
||
m_PipeServer = new QLocalServer(this); | ||
if (!m_PipeServer->listen(name)) { //QString(ts3plugin_author()) + QString(ts3plugin_name())) | ||
TSLogging::Error(QString("Unable to start the server: %1.").arg(m_PipeServer->errorString())); | ||
return; | ||
} | ||
connect(m_PipeServer, SIGNAL(newConnection()), this, SLOT(onNewConnection())); | ||
connect(m_SignalMapper, SIGNAL(mapped(QString)), this, SLOT(onClientDisconnected(QString))); | ||
} | ||
|
||
void PipeServer::Send(QString message) | ||
{ | ||
if (m_Clients.isEmpty()) | ||
return; | ||
|
||
foreach (QLocalSocket* clientConnection, m_Clients) | ||
clientConnection->write(message.toLocal8Bit().constData()); | ||
} | ||
|
||
void PipeServer::onNewConnection() | ||
{ | ||
QLocalSocket *clientConnection = m_PipeServer->nextPendingConnection(); | ||
qintptr desc = clientConnection->socketDescriptor(); | ||
QString descStr = QString("%1").arg(desc); | ||
m_Clients.insert(descStr, clientConnection); | ||
connect(clientConnection, SIGNAL(disconnected()), m_SignalMapper, SLOT(map())); | ||
m_SignalMapper->setMapping(clientConnection, descStr); | ||
} | ||
|
||
void PipeServer::onClientDisconnected(QString descStr) | ||
{ | ||
QLocalSocket *clientConnection = m_Clients.take(descStr); | ||
clientConnection->deleteLater(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef PIPESERVER_H | ||
#define PIPESERVER_H | ||
|
||
#include <QObject> | ||
#include <QLocalSocket> | ||
|
||
class QLocalServer; | ||
class QSignalMapper; | ||
|
||
class PipeServer : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit PipeServer(QObject *parent = 0, QString name = "ThorweCtPipeServer"); | ||
|
||
signals: | ||
|
||
public slots: | ||
void Send(QString message); | ||
|
||
private slots: | ||
void onNewConnection(); | ||
void onClientDisconnected(QString descStr); | ||
|
||
private: | ||
QLocalServer *m_PipeServer; | ||
QMap<QString, QLocalSocket*> m_Clients; | ||
QSignalMapper *m_SignalMapper; | ||
}; | ||
|
||
#endif // PIPESERVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters