1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

升级QQtProtocol

升级QQtProtocolManager
This commit is contained in:
tianduanrui 2018-07-01 13:24:21 +08:00
parent 255aacb3b6
commit cad81495c5
13 changed files with 67 additions and 3 deletions

View File

@ -49,6 +49,7 @@ void QQtBluetoothClient::installProtocol ( QQtProtocol* stack )
connect ( m_protocol, SIGNAL ( write ( const QByteArray& ) ),
this, SLOT ( slotWriteData ( const QByteArray& ) ) );
m_protocol->attach();
m_protocol->initializer();
}
void QQtBluetoothClient::uninstallProtocol ( QQtProtocol* stack )

View File

@ -45,6 +45,7 @@ void QQtBluetoothServer::clientSocketDisConnected()
clientSocket->uninstallProtocol ( protocol );
clientSocket->deleteLater();
m_clientList.removeOne ( clientSocket );
m_protocolManager->deleteProtocol ( protocol );
}
void QQtBluetoothServer::installProtocolManager ( QQtProtocolManager* stackGroup )

View File

@ -21,6 +21,7 @@ void QQtNfcClient::installProtocol ( QQtProtocol* stack )
connect ( m_protocol, SIGNAL ( write ( const QByteArray& ) ),
this, SLOT ( slotWriteData ( const QByteArray& ) ) );
m_protocol->attach();
m_protocol->initializer();
}
void QQtNfcClient::uninstallProtocol ( QQtProtocol* stack )

View File

@ -71,6 +71,7 @@ void QQtNfcServer::hasTargetLosted ( QNearFieldTarget* target )
clientSocket->uninstallProtocol ( protocol );
clientSocket->deleteLater();
m_clientList.removeOne ( clientSocket );
m_protocolManager->deleteProtocol ( protocol );
}
QQtNfcClient* QQtNfcServer::findInstanceByUid ( QByteArray uid )

View File

@ -83,14 +83,14 @@ signals:
/**
* Socket和这个Protocol关联
* Protocol初始化和清理override
* 使
*/
public:
virtual void detach() {
inline virtual void detach() {
mIsDetached = true;
statusChanged ( 0 );
}
virtual void attach() {
inline virtual void attach() {
mIsDetached = false;
statusChanged ( 1 );
}
@ -99,6 +99,15 @@ public:
protected:
bool mIsDetached;
/**
* 使
* optional
* reset函数 = clear = clean = init函数
* Protocol句柄进行初始化成员变量
* 使
*/
public:
inline virtual void initializer() {}
/*
*
*/

View File

@ -28,8 +28,33 @@ QQtProtocol* QQtProtocolManager::createProtocol()
return p0;
}
void QQtProtocolManager::deleteProtocol ( QQtProtocol* stack )
{
//决定不删除句柄
return;
if ( m_protocol_list.isEmpty() )
return;
QQtProtocol* p0 = stack;
if ( !p0 )
return;
disconnect ( p0, SIGNAL ( notifyToProtocolManager ( const QQtProtocol*, const QQtMessage* ) ),
this, SIGNAL ( notifyToBusinessLevel ( const QQtProtocol*, const QQtMessage* ) ) );
m_protocol_list.removeOne ( p0 );
p0->deleteLater();
return;
}
QQtProtocol* QQtProtocolManager::findDetachedInstance()
{
//但凡attached就是在使用的。createProtocol,attach.
//但凡deattached的都是准备删除的。deattach,deleteProtocol.
//初始deattached的呢不会删除。删除操作发生在deattached阶段。
QListIterator<QQtProtocol*> itor0 ( m_protocol_list );
int index = 0;
while ( itor0.hasNext() )
@ -39,6 +64,7 @@ QQtProtocol* QQtProtocolManager::findDetachedInstance()
index++;
}
emit remanentProtocolChanged ( index );
emit remainingProtocolChanged ( index );
QListIterator<QQtProtocol*> itor ( m_protocol_list );
while ( itor.hasNext() )

View File

@ -88,6 +88,7 @@ signals:
//内部每次协议句柄列表发生变动都会发射这个信号。
//剩余的可用句柄数目
void remanentProtocolChanged ( int num );
void remainingProtocolChanged ( int num );
/**
*
@ -95,12 +96,30 @@ signals:
public:
/**
* @brief createProtocol
* Protocol句柄使
*
* QQtSocketServer用的
*
*
* @param protocolTypeName
* @return
*/
QQtProtocol* createProtocol ();
/**
* 使
*
* Protocol的deattach和这个功能不同使使
* deleteProtocol表示
* deattachattach以后reset了吗reset了
* resetattach的时候调用delete掉
*
* 使使
* QQtProtocol句柄的时候override init函数初始化句柄
* Protocol的init函数
*
* QList加锁movetothread里用
*/
void deleteProtocol ( QQtProtocol* stack );
protected:
QQtProtocol* findDetachedInstance();
private:

View File

@ -53,6 +53,7 @@ void QQtTcpClient::installProtocol ( QQtProtocol* stack )
connect ( m_protocol, SIGNAL ( write ( const QByteArray& ) ),
this, SLOT ( slotWriteData ( const QByteArray& ) ) );
m_protocol->attach();
m_protocol->initializer();
}
void QQtTcpClient::uninstallProtocol ( QQtProtocol* stack )

View File

@ -42,6 +42,7 @@ void QQtTcpServer::clientSocketDisConnected()
clientSocket->uninstallProtocol ( protocol );
clientSocket->deleteLater();
m_clientList.removeOne ( clientSocket );
m_protocolManager->deleteProtocol ( protocol );
}
void QQtTcpServer::comingNewConnection()

View File

@ -34,6 +34,7 @@ void QQtUdpClient::installProtocol ( QQtProtocol* stack )
connect ( m_protocol, SIGNAL ( write ( const QByteArray& ) ),
this, SLOT ( slotWriteData ( const QByteArray& ) ) );
m_protocol->attach();
m_protocol->initializer();
}
void QQtUdpClient::uninstallProtocol ( QQtProtocol* stack )

View File

@ -37,6 +37,7 @@ void QQtUdpServer::clientSocketDisConnected()
clientSocket->uninstallProtocol ( protocol );
clientSocket->deleteLater();
m_clientList.removeOne ( clientSocket );
m_protocolManager->deleteProtocol ( protocol );
}
QQtUdpClient* QQtUdpServer::findClientByProtocolInstance ( QQtProtocol* protocol )

View File

@ -16,6 +16,7 @@ void QQtWebSocketClient::installProtocol ( QQtProtocol* stack )
connect ( m_protocol, SIGNAL ( write ( const QByteArray& ) ),
this, SLOT ( slotWriteData ( const QByteArray& ) ) );
m_protocol->attach();
m_protocol->initializer();
}
void QQtWebSocketClient::uninstallProtocol ( QQtProtocol* stack )

View File

@ -86,6 +86,7 @@ void QQtWebSocketServer::clientSocketDisConnected()
clientSocket->uninstallProtocol ( protocol );
clientSocket->deleteLater();
m_clientList.removeOne ( clientSocket );
m_protocolManager->deleteProtocol ( protocol );
}
QQtProtocolManager* QQtWebSocketServer::installedProtocolManager()