//.h
struct struct_ClientSocket
{
int nPort;
};
private:
QList<struct_ClientSocket> m_lst_pClientSockets;
private slots:
void SetIncomingSocket();
void OnSocketDisconnected();
void ReadInputData();
//.cpp
void CKeyboardLogAdmin::SetIncomingSocket()
{
QTcpSocket *tempSocket
= pTcpServer
->nextPendingConnection
();
struct_ClientSocket temp_struct_ClientSocket;
temp_struct_ClientSocket.pClientSocket = tempSocket;
temp_struct_ClientSocket.str_ClientAddress = tempSocket->peerAddress().toString();
temp_struct_ClientSocket.nPort = tempSocket->peerPort();
connect(tempSocket, SIGNAL(disconnected()), tempSocket, SLOT(deleteLater()));
connect(tempSocket, SIGNAL(disconnected()), this, SLOT(OnSocketDisconnected()));
connect(tempSocket, SIGNAL(readyRead()), this, SLOT(ReadInputData()));
m_lst_pClientSockets.append(temp_struct_ClientSocket);
}
void CKeyboardLogAdmin::OnSocketDisconnected()
{
struct_ClientSocket tempSocket;
for (int nSock = 0; nSock < m_lst_pClientSockets.size(); nSock++)
{
if (m_lst_pClientSockets
[nSock
].
pClientSocket->state
() == QAbstractSocket::UnconnectedState || m_lst_pClientSockets
[nSock
].
pClientSocket->state
() == QAbstractSocket::ClosingState) {
m_lst_pClientSockets.removeAt(nSock);
break;
}
}
}
void CKeyboardLogAdmin::ReadInputData()
{
m_str_ReadData.clear();
int nSocket;
if (m_lst_pClientSockets.size() > 0)
{
for (nSocket = 0; nSocket < m_lst_pClientSockets.size(); nSocket++)
{
if (m_lst_pClientSockets[nSocket].pClientSocket->bytesAvailable() > 0)
{
break;
}
}
if (nSocket < m_lst_pClientSockets.size())
{
while (m_lst_pClientSockets[nSocket].pClientSocket->bytesAvailable() > 0)
{
ba_ByteData = m_lst_pClientSockets[nSocket].pClientSocket->readAll();
}
const char* ch_Data = ba_ByteData.data();
QStringList str_lst_ReadData
= m_str_ReadData.
split("\t");
if (!str_lst_ReadData.isEmpty())
{
if (str_lst_ReadData.first().compare(tr("LoginUser")) == 0)
{
ProcessLoginUserData(str_lst_ReadData);
}
if (str_lst_ReadData.first().compare(tr("LoginGuests")) == 0)
{
ProcessLoginGuests(str_lst_ReadData);
}
else if (str_lst_ReadData.first().compare(tr("Logout")) == 0)
{
ProcessLogoutData(str_lst_ReadData);
}
else if (str_lst_ReadData.first().compare(tr("ScreenLock")) == 0)
{
ProcessScreenLockData((str_lst_ReadData));
}
else if (str_lst_ReadData.first().compare(tr("ScreenUnlock")) == 0)
{
ProcessScreenUnlockData(str_lst_ReadData);
}
else if (str_lst_ReadData.first().compare(tr("AccountLogout")) == 0)
{
ProcessComputerUserAccountLogoutData(str_lst_ReadData);
}
else if (str_lst_ReadData.first().compare(tr("ValidatePin")) == 0)
{
ProcessValidatePinData(str_lst_ReadData);
}
else if (str_lst_ReadData.first().compare(tr("SessionLogoff")) == 0)
{
ProcessSessionLogoff(str_lst_ReadData);
}
}
}
}
}
Bookmarks