mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-25 10:00:21 -04:00 
			
		
		
		
	TCPSrc channel: process connexion/deconnnexion through messages
This commit is contained in:
		
							parent
							
								
									10783906cb
								
							
						
					
					
						commit
						ffebc53586
					
				| @ -252,6 +252,19 @@ bool TCPSrc::handleMessage(const Message& cmd) | |||||||
| 
 | 
 | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
|  | 	else if (MsgTCPConnection::match(cmd)) | ||||||
|  | 	{ | ||||||
|  | 		MsgTCPConnection& con = (MsgTCPConnection&) cmd; | ||||||
|  | 
 | ||||||
|  | 		if (con.getConnect()) | ||||||
|  | 		{ | ||||||
|  | 			processNewConnection(); | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			processDeconnection(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		if(m_spectrum != 0) | 		if(m_spectrum != 0) | ||||||
| @ -275,13 +288,21 @@ void TCPSrc::closeAllSockets(Sockets* sockets) | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| void TCPSrc::onNewConnection() | void TCPSrc::onNewConnection() | ||||||
| { | { | ||||||
| 	qDebug("TCPSrc::onNewConnection"); | 	qDebug("TCPSrc::onNewConnection"); | ||||||
|  | 	MsgTCPConnection *cmd = MsgTCPConnection::create(true); | ||||||
|  | 	getInputMessageQueue()->push(cmd); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void TCPSrc::processNewConnection() | ||||||
|  | { | ||||||
|  | 	qDebug("TCPSrc::processNewConnection"); | ||||||
| 
 | 
 | ||||||
| 	while(m_tcpServer->hasPendingConnections()) | 	while(m_tcpServer->hasPendingConnections()) | ||||||
| 	{ | 	{ | ||||||
| 		qDebug("TCPSrc::onNewConnection: has a pending connection"); | 		qDebug("TCPSrc::processNewConnection: has a pending connection"); | ||||||
| 		QTcpSocket* connection = m_tcpServer->nextPendingConnection(); | 		QTcpSocket* connection = m_tcpServer->nextPendingConnection(); | ||||||
| 		connection->setSocketOption(QAbstractSocket:: KeepAliveOption, 1); | 		connection->setSocketOption(QAbstractSocket:: KeepAliveOption, 1); | ||||||
| 		connect(connection, SIGNAL(disconnected()), this, SLOT(onDisconnected())); | 		connect(connection, SIGNAL(disconnected()), this, SLOT(onDisconnected())); | ||||||
| @ -301,7 +322,7 @@ void TCPSrc::onNewConnection() | |||||||
| 
 | 
 | ||||||
| 			case FormatS16LE: | 			case FormatS16LE: | ||||||
| 			{ | 			{ | ||||||
| 				qDebug("TCPSrc::onNewConnection: establish new S16LE connection"); | 				qDebug("TCPSrc::processNewConnection: establish new S16LE connection"); | ||||||
| 				quint32 id = (FormatS16LE << 24) | m_nextS16leId; | 				quint32 id = (FormatS16LE << 24) | m_nextS16leId; | ||||||
| 				MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort()); | 				MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort()); | ||||||
| 				m_nextS16leId = (m_nextS16leId + 1) & 0xffffff; | 				m_nextS16leId = (m_nextS16leId + 1) & 0xffffff; | ||||||
| @ -318,11 +339,18 @@ void TCPSrc::onNewConnection() | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void TCPSrc::onDisconnected() | void TCPSrc::onDisconnected() | ||||||
|  | { | ||||||
|  | 	qDebug("TCPSrc::onDisconnected"); | ||||||
|  | 	MsgTCPConnection *cmd = MsgTCPConnection::create(false); | ||||||
|  | 	getInputMessageQueue()->push(cmd); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void TCPSrc::processDeconnection() | ||||||
| { | { | ||||||
| 	quint32 id; | 	quint32 id; | ||||||
| 	QTcpSocket* socket = 0; | 	QTcpSocket* socket = 0; | ||||||
| 
 | 
 | ||||||
| 	qDebug("TCPSrc::onDisconnected"); | 	qDebug("TCPSrc::processDeconnection"); | ||||||
| 
 | 
 | ||||||
| 	for(int i = 0; i < m_ssbSockets.count(); i++) | 	for(int i = 0; i < m_ssbSockets.count(); i++) | ||||||
| 	{ | 	{ | ||||||
| @ -342,7 +370,7 @@ void TCPSrc::onDisconnected() | |||||||
| 		{ | 		{ | ||||||
| 			if(m_s16leSockets[i].socket == sender()) | 			if(m_s16leSockets[i].socket == sender()) | ||||||
| 			{ | 			{ | ||||||
| 				qDebug("TCPSrc::onDisconnected: remove S16LE socket #%d", i); | 				qDebug("TCPSrc::processDeconnection: remove S16LE socket #%d", i); | ||||||
| 
 | 
 | ||||||
| 				id = m_s16leSockets[i].id; | 				id = m_s16leSockets[i].id; | ||||||
| 				socket = m_s16leSockets[i].socket; | 				socket = m_s16leSockets[i].socket; | ||||||
|  | |||||||
| @ -118,6 +118,25 @@ protected: | |||||||
| 			m_enabled(enabled) | 			m_enabled(enabled) | ||||||
| 		{ } | 		{ } | ||||||
| 	}; | 	}; | ||||||
|  | 	class MsgTCPConnection : public Message { | ||||||
|  | 		MESSAGE_CLASS_DECLARATION | ||||||
|  | 
 | ||||||
|  | 	public: | ||||||
|  | 		bool getConnect() const { return m_connect; } | ||||||
|  | 
 | ||||||
|  | 		static MsgTCPConnection* create(bool connect) | ||||||
|  | 		{ | ||||||
|  | 			return new MsgTCPConnection(connect); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 	private: | ||||||
|  | 		bool m_connect; | ||||||
|  | 
 | ||||||
|  | 		MsgTCPConnection(bool connect) : | ||||||
|  | 			Message(), | ||||||
|  | 			m_connect(connect) | ||||||
|  | 		{ } | ||||||
|  | 	}; | ||||||
| 
 | 
 | ||||||
| 	MessageQueue* m_uiMessageQueue; | 	MessageQueue* m_uiMessageQueue; | ||||||
| 	TCPSrcGUI* m_tcpSrcGUI; | 	TCPSrcGUI* m_tcpSrcGUI; | ||||||
| @ -162,6 +181,8 @@ protected: | |||||||
| 	QMutex m_settingsMutex; | 	QMutex m_settingsMutex; | ||||||
| 
 | 
 | ||||||
| 	void closeAllSockets(Sockets* sockets); | 	void closeAllSockets(Sockets* sockets); | ||||||
|  | 	void processNewConnection(); | ||||||
|  | 	void processDeconnection(); | ||||||
| 
 | 
 | ||||||
| protected slots: | protected slots: | ||||||
| 	void onNewConnection(); | 	void onNewConnection(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user