3#include "ServiceTigerVNC.h"
4#include "RabbitCommonTools.h"
5#include "network/Socket.h"
8#include "ParameterServiceTigerVNC.h"
10#include "PluginService.h"
14#include "FrmParameterTigerVNC.h"
19 #include "ICE/ChannelIce.h"
22Q_DECLARE_LOGGING_CATEGORY(TigerVNC)
26 check = connect(&m_Lister, SIGNAL(newConnection()),
27 this, SLOT(slotNewConnection()));
33CServiceTigerVNC::~CServiceTigerVNC()
35 qDebug(TigerVNC) <<
"CServiceTigerVNC::~CServiceTigerVNC";
39QWidget* CServiceTigerVNC::GetParameterWidget(QWidget* parent)
69 check = connect(m_Signal.data(), SIGNAL(sigOffer(
const QString&,
74 this, SLOT(slotSignalOffer(
const QString&,
80 qInfo(TigerVNC) <<
"Connect ICE signal";
85 if(p->GetEnableSocket())
87 if(!m_Lister.listen(QHostAddress::Any, p->getPort()))
89 qCritical(TigerVNC,
"Lister fail: Port [%d]; %s",
90 GetParameters()->getPort(),
91 m_Lister.errorString().toStdString().c_str());
94 qInfo(TigerVNC) <<
"Lister at:" << p->getPort();
109 m_Signal->disconnect(
this);
114 m_lstConnection.clear();
118void CServiceTigerVNC::slotNewConnection()
120 if(!m_Lister.hasPendingConnections())
122 QTcpSocket* pSocket = m_Lister.nextPendingConnection();
124 qInfo(TigerVNC) <<
"New connection:"
125 << pSocket->peerAddress() <<
":" << pSocket->peerPort();
127 QSharedPointer<CChannel> channel(
new CChannel(pSocket), &QObject::deleteLater);
128 if(!channel->isOpen())
129 if(!channel->open(QIODevice::ReadWrite))
131 qCritical(TigerVNC) <<
"Don't open channel";
132 throw std::runtime_error(
"Don't open channel");
134 QSharedPointer<CConnection> c(
new CConnection(channel,
136 &QObject::deleteLater);
137 m_lstConnection.push_back(c);
138 bool check = connect(c.data(), SIGNAL(sigDisconnected()),
139 this, SLOT(slotDisconnected()));
141 check = connect(c.data(), SIGNAL(sigError(
int, QString)),
142 this, SLOT(slotError(
int, QString)));
145 emit channel->sigConnected();
146 }
catch (std::exception e) {
147 qCritical(TigerVNC) <<
"New connection exception" << e.what();
149 qCritical(TigerVNC) <<
"New connection exception";
153void CServiceTigerVNC::slotDisconnected()
156 pConnect->close(tr(
"Exit").toStdString().c_str());
157 foreach(
auto c, m_lstConnection)
159 m_lstConnection.removeOne(c);
162void CServiceTigerVNC::slotError(
int nErr, QString szErr)
168void CServiceTigerVNC::slotSignalConnected()
172 qInfo(TigerVNC,
"Connected to signal server: %s:%d; user:%s",
173 p->getSignalServer().toStdString().c_str(),
175 p->getSignalUser().toStdString().c_str());
178void CServiceTigerVNC::slotSignalDisConnected()
182 qInfo(TigerVNC,
"Disconnect signal server: %s:%d; user:%s",
183 p->getSignalServer().toStdString().c_str(),
185 p->getSignalUser().toStdString().c_str());
188void CServiceTigerVNC::slotSignalError(
int nErr,
const QString& szErr)
192 qCritical(TigerVNC,
"signal: %s:%d; user:%s; error: %d: %s",
193 p->getSignalServer().toStdString().c_str(),
195 p->getSignalUser().toStdString().c_str(),
196 nErr, szErr.toStdString().c_str());
199void CServiceTigerVNC::slotSignalOffer(
const QString& fromUser,
200 const QString& toUser,
201 const QString& channelId,
207 "New connection: from:%s; to:%s; channelId:%s",
208 fromUser.toStdString().c_str(),
209 toUser.toStdString().c_str(),
210 channelId.toStdString().c_str());
213 QSharedPointer<CChannelIce> channel(
new CChannelIce(m_Signal.data()),
214 &QObject::deleteLater);
215 if(!channel->isOpen())
217 rtc::IceServer stun(p->getStunServer().toStdString().c_str(),
219 rtc::IceServer turn(p->getTurnServer().toStdString().c_str(),
221 p->getTurnUser().toStdString().c_str(),
222 p->getTurnPassword().toStdString().c_str());
223 rtc::Configuration config;
224 config.iceServers.push_back(stun);
225 config.iceServers.push_back(turn);
226 channel->SetConfigure(config);
227 if(!channel->open(fromUser, toUser, channelId, type, sdp))
229 qCritical(TigerVNC) <<
"Don't open channel";
230 throw std::runtime_error(
"Don't open channel");
233 QSharedPointer<CConnection> c(
new CConnection(channel,
235 &QObject::deleteLater);
236 m_lstConnection.push_back(c);
237 bool check = connect(c.data(), SIGNAL(sigDisconnected()),
238 this, SLOT(slotDisconnected()));
240 check = connect(c.data(), SIGNAL(sigError(
int, QString)),
241 this, SLOT(slotError(
int, QString)));
243 }
catch (std::exception e) {
244 qCritical(TigerVNC) <<
"New connection exception" << e.what();
246 qCritical(TigerVNC) <<
"New connection exception";
The ICE channel interface class.
The channel interface class.
static CICE * Instance()
Single instance.
ICE parameter helper class.
The service plugin interface.
virtual int OnInit() override
Init service.
virtual int OnClean() override
Clean service.