1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 17:43:59 +02:00

* Moved zeroconf cache back in place.

This commit is contained in:
Christian Muehlhaeuser
2011-03-02 07:52:45 +01:00
parent a9d99ebdfc
commit 78d3547343
4 changed files with 32 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ SipHandler::~SipHandler()
disconnectPlugins();
}
QList< SipPlugin* >
SipHandler::plugins() const
{

View File

@@ -61,10 +61,16 @@ public:
TomahawkZeroconf( int port, QObject* parent = 0 )
: QObject( parent ), m_sock( this ), m_port( port )
{
qDebug() << Q_FUNC_INFO;
m_sock.bind( ZCONF_PORT, QUdpSocket::ShareAddress );
connect( &m_sock, SIGNAL( readyRead() ), this, SLOT( readPacket() ) );
}
virtual ~TomahawkZeroconf()
{
qDebug() << Q_FUNC_INFO;
}
public slots:
void advertise()
{
@@ -107,8 +113,8 @@ private slots:
{
qDebug() << "ADVERT received:" << sender << port;
Node *n = new Node( sender.toString(), parts.at( 2 ), port );
connect( n, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
this, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ) );
connect( n, SIGNAL( tomahawkHostFound( QString, int, QString, QString ) ),
this, SIGNAL( tomahawkHostFound( QString, int, QString, QString ) ) );
n->resolve();
}
}

View File

@@ -25,12 +25,21 @@ ZeroconfPlugin::connectPlugin( bool /*startup*/ )
{
delete m_zeroconf;
m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this );
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) );
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( QString, int, QString, QString ) ),
SLOT( lanHostFound( QString, int, QString, QString ) ) );
m_zeroconf->advertise();
m_isOnline = true;
foreach( QStringList *currNode, m_cachedNodes )
{
QStringList nodeSet = *currNode;
if ( !Servent::instance()->connectedToSession( nodeSet[3] ) )
Servent::instance()->connectToPeer( nodeSet[0], nodeSet[1].toInt(), "whitelist", nodeSet[2], nodeSet[3] );
delete currNode;
}
return true;
}
@@ -39,8 +48,6 @@ ZeroconfPlugin::disconnectPlugin()
{
m_isOnline = false;
delete m_zeroconf;
m_zeroconf = 0;
}
@@ -53,6 +60,15 @@ ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name
qDebug() << "Found LAN host:" << host << port << nodeid;
if ( !m_isOnline )
{
qDebug() << "Not online, so not connecting.";
QStringList *nodeSet = new QStringList();
*nodeSet << host << QString::number( port ) << name << nodeid;
m_cachedNodes.insert( nodeSet );
return;
}
if ( !Servent::instance()->connectedToSession( nodeid ) )
Servent::instance()->connectToPeer( host, port, "whitelist", name, nodeid );
else

View File

@@ -17,6 +17,7 @@ public:
ZeroconfPlugin()
: m_zeroconf( 0 )
, m_isOnline( false )
, m_cachedNodes()
{
qDebug() << Q_FUNC_INFO;
}
@@ -54,6 +55,7 @@ private slots:
private:
TomahawkZeroconf* m_zeroconf;
bool m_isOnline;
QSet< QStringList* > m_cachedNodes;
};
#endif