Commit f123ca7d by NitefullWind

Merge branch 'dev' of https://git.oschina.net/kong__mo/FMVip into dev

parents add9535d 59e0488a
......@@ -10,6 +10,8 @@
#include <QApplication>
#include <QMessageBox>
#include <QMenu>
#include <QTimer>
#include <winsock2.h>
FMVipDispatcher::FMVipDispatcher(QObject *parent)
: QObject(parent),
......@@ -17,14 +19,17 @@ FMVipDispatcher::FMVipDispatcher(QObject *parent)
_vindow(0),
isLastOne(true),
_windowReturn(0),
_posSocket(new QTcpSocket(this)),
_posSocketTimer(new QTimer(this)),
_sysIcon(new QSystemTrayIcon)
{
connect(this, SIGNAL(requested(QJsonObject)), SLOT(onRequest(QJsonObject)));
connect(this, SIGNAL(responded(QByteArray)), SLOT(onResponse(QByteArray)));
connect(FMVipForward::instance(), SIGNAL(serverResponsed(QJsonObject)), SLOT(onServerResponsed(QJsonObject)));
connect(this, SIGNAL(initSocket()),this, SLOT(onInitSocket()));
_posSocketTimer->setInterval(5000);
connect(_posSocketTimer, SIGNAL(timeout()), SLOT(onCheckSocket()));
connect(this, SIGNAL(stopSocketTimer()), _posSocketTimer, SLOT(stop()));
connect(this, SIGNAL(startSocketTimer()), _posSocketTimer, SLOT(start()));
QIcon icon = QIcon(":/img_logo.png");
_sysIcon->setIcon(icon);
......@@ -50,9 +55,9 @@ FMVipDispatcher::~FMVipDispatcher()
_sysIcon = NULL;
}
if(_posSocket != nullptr) {
delete _posSocket;
_posSocket = nullptr;
if(_posSocketTimer != nullptr) {
delete _posSocketTimer;
_posSocketTimer = nullptr;
}
}
......@@ -91,16 +96,13 @@ INT FMVipDispatcher::_ParseRequest(LPSTR data)
// 唤起客户端界面
emit requested(_posReqObj);
return FM_API_SUCCESS;
}
BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len)
{
emit startSocketTimer();
mutex.lock();
emit initSocket();
if(_serverRspData.isEmpty())
{
// 服务器还未返回则一直阻塞
......@@ -112,6 +114,8 @@ BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len)
qDebug() << "发给POS:" << rsp;
emit stopSocketTimer();
return 1;
}
......@@ -334,10 +338,31 @@ BOOL FMVipDispatcher::isLogined()
return account != "";
}
void FMVipDispatcher::onInitSocket()
void FMVipDispatcher::onCheckSocket()
{
_posSocket->setSocketDescriptor(_socket);
connect(_posSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onDisconnected()), Qt::UniqueConnection);
if(_socket <=0 ) {
emit stopSocketTimer();
return;
}
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
WSAStartup(wVersionRequested, &wsaData);
HANDLE closeEvent = WSACreateEvent();
WSAEventSelect(_socket, closeEvent, FD_CLOSE);
DWORD dwRet = WaitForSingleObject(closeEvent, 0);
if(dwRet == WSA_WAIT_EVENT_0) {
onDisconnected();
}
WSACloseEvent(closeEvent);
WSACleanup();
}
void FMVipDispatcher::onDisconnected()
......
......@@ -41,8 +41,8 @@ protected:
signals:
void requested(const QJsonObject &);
void responded(const QByteArray &);
void initSocket();
void startSocketTimer();
void stopSocketTimer();
private slots:
void onRequest(const QJsonObject &jsonObj);
......@@ -53,7 +53,7 @@ private slots:
void onDoPost();
void onInitSocket();
void onCheckSocket();
void onDisconnected();
void onActiveSysTrayIcon(QSystemTrayIcon::ActivationReason);
......@@ -68,7 +68,7 @@ private:
QSystemTrayIcon *_sysIcon;
QTcpSocket *_posSocket;
QTimer *_posSocketTimer;
QMutex mutex;
QWaitCondition serverIsBusy;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment