Browse files

listen on a random port for now

  • Loading branch information...
1 parent 76c75e8 commit 5438aa415ca0f062239205e69a910e5c6ef1e173 @RJ committed Feb 8, 2010
Showing with 85 additions and 67 deletions.
  1. +2 −2 src/library/library.cpp
  2. +39 −3 src/remotecollection.cpp
  3. +40 −57 src/remotecollection.h
  4. +4 −5 src/servent.cpp
View
4 src/library/library.cpp
@@ -6,7 +6,7 @@
./gen_schema.h.sh ./schema.sql library > library.sql.h
*/
#include "library/library.sql.h"
-#define CURRENT_SCHEMA_VERSION 1
+#define CURRENT_SCHEMA_VERSION 2
Library::Library(const QString &dbname, QObject *parent)
: QObject(parent)
@@ -398,7 +398,7 @@ QList<QVariantMap> Library::artists()
QList<QVariant> Library::allTracks()
{
QList<QVariant> tracks;
- QString sql = "SELECT file.id, artist.name, album.name, track.name, file.size, file.duration "
+ QString sql = "SELECT file.id, artist.name, album.name, track.name, file.size, file.duration, "
"file.bitrate "
"FROM file, file_join, artist, album, track "
"WHERE file.id = file_join.file AND "
View
42 src/remotecollection.cpp
@@ -1,9 +1,45 @@
#include "remotecollection.h"
-#include "httpd.h"
+//#include "httpd.h"
RemoteCollection::RemoteCollection(Servent * s, RemoteCollectionConnection * conn) :
QDaap::Collection(conn->name(), conn), m_servent(s), m_rcconn(conn)
{
- qDebug() << "CTOR RemoteCollection, listening on 8080";
- Httpd * h = new Httpd(this, 8080);
+ int port = (int)(qrand()*50000)/RAND_MAX;
+ qDebug() << "CTOR RemoteCollection, listening on " << port;
+ m_h = new Httpd(this, port);
+}
+
+RemoteCollection::~RemoteCollection()
+{
+ qDebug() << "DTOR RemoteCollection";
+ m_h->deleteLater();
+}
+
+
+QList<QDaap::Track> RemoteCollection::loadTracks()
+{
+ // wait till connection is ready...
+ qDebug() << "Is RemoteCollectionConnection ready?";
+ if(!m_rcconn->isReady())
+ {
+ qDebug() << "Waiting.....";
+ connect(m_rcconn, SIGNAL(ready()), this, SLOT(connReady()));
+ m_mut_ready.lock();
+ m_waitcond_ready.wait(&m_mut_ready);
+ m_mut_ready.unlock();
+ }
+ qDebug() << "It's ready!";
+
+ // request all tracks:
+ QByteArray msg("ALLTRACKSREQUEST");
+ m_rcconn->sendMsg(msg);
+
+ // wait till all tracks are loaded
+ connect(m_rcconn, SIGNAL(allTracks(QList<QDaap::Track>)),
+ this, SLOT(connAllTracks(QList<QDaap::Track>)));
+ m_mut_all.lock();
+ m_waitcond_all.wait(&m_mut_all);
+ m_mut_all.unlock();
+ qDebug() << "all tracks received";
+ return m_tmp_tracks;
}
View
97 src/remotecollection.h
@@ -9,6 +9,44 @@
#include "servent.h"
#include "library/library.h"
#include "conjist.h"
+#include "httpd.h"
+class RemoteCollectionConnection;
+class RemoteCollection : public QDaap::Collection
+{
+Q_OBJECT
+public:
+ explicit RemoteCollection(Servent * s, RemoteCollectionConnection * conn);
+ ~RemoteCollection();
+ virtual QList<QDaap::Track> loadTracks();
+
+signals:
+
+public slots:
+ void connReady()
+ {
+ m_waitcond_ready.wakeAll();
+ };
+
+ void connAllTracks(QList<QDaap::Track> tracks)
+ {
+ m_tmp_tracks = tracks;
+ m_waitcond_all.wakeAll();
+ };
+
+private:
+ Servent * m_servent;
+ RemoteCollectionConnection * m_rcconn;
+
+ QMutex m_mut_ready, m_mut_all;
+ QWaitCondition m_waitcond_ready, m_waitcond_all;
+
+ QList<QDaap::Track> m_tmp_tracks;
+
+ Httpd * m_h;
+};
+
+
+
class RemoteCollectionConnection : public Connection
{
@@ -31,6 +69,7 @@ class RemoteCollectionConnection : public Connection
void setup()
{
+ m_rc = new RemoteCollection(m_servent, this);
};
void handleMsg(QByteArray msg)
@@ -92,65 +131,9 @@ class RemoteCollectionConnection : public Connection
private:
Library * m_library;
QJson::Parser parser;
+ RemoteCollection * m_rc;
};
-class RemoteCollection : public QDaap::Collection
-{
-Q_OBJECT
-public:
- explicit RemoteCollection(Servent * s, RemoteCollectionConnection * conn);
-
- virtual QList<QDaap::Track> loadTracks()
- {
- // wait till connection is ready...
- qDebug() << "Is RemoteCollectionConnection ready?";
- if(!m_rcconn->isReady())
- {
- qDebug() << "Waiting.....";
- connect(m_rcconn, SIGNAL(ready()), this, SLOT(connReady()));
- m_mut_ready.lock();
- m_waitcond_ready.wait(&m_mut_ready);
- m_mut_ready.unlock();
- }
- qDebug() << "It's ready!";
-
- // request all tracks:
- QByteArray msg("ALLTRACKSREQUEST");
- m_rcconn->sendMsg(msg);
-
- // wait till all tracks are loaded
- connect(m_rcconn, SIGNAL(allTracks(QList<QDaap::Track>)),
- this, SLOT(connAllTracks(QList<QDaap::Track>)));
- m_mut_all.lock();
- m_waitcond_all.wait(&m_mut_all);
- m_mut_all.unlock();
- qDebug() << "all tracks received";
- return m_tmp_tracks;
- };
-
-signals:
-
-public slots:
- void connReady()
- {
- m_waitcond_ready.wakeAll();
- };
-
- void connAllTracks(QList<QDaap::Track> tracks)
- {
- m_tmp_tracks = tracks;
- m_waitcond_all.wakeAll();
- };
-
-private:
- Servent * m_servent;
- RemoteCollectionConnection * m_rcconn;
-
- QMutex m_mut_ready, m_mut_all;
- QWaitCondition m_waitcond_ready, m_waitcond_all;
-
- QList<QDaap::Track> m_tmp_tracks;
-};
#endif // REMOTECOLLECTION_H
View
9 src/servent.cpp
@@ -44,9 +44,9 @@ void Servent::registerControlConnection(ControlConnection * conn)
{
m_controlconnections.append(conn);
- //if(conn->outbound())
- //{
- qDebug() << "Sending invite for library sharing";
+ if(!conn->outbound())
+ {
+ qDebug() << "Sending invite for library sharing...";
QString key = uuid();
Library * lib = ((conjist*)QCoreApplication::instance())->library();
RemoteCollectionConnection * rcconn = new RemoteCollectionConnection(lib, this);
@@ -59,7 +59,7 @@ void Servent::registerControlConnection(ControlConnection * conn)
{
cc->sendMsg(msg);
}
- //}
+ }
/*
foreach(ProxyConnection * pc, m_proxyconnections)
@@ -340,7 +340,6 @@ void Servent::createRemoteCollection(ControlConnection * conn, QString key, QStr
Library * lib = ((conjist*)QCoreApplication::instance())->library();
RemoteCollectionConnection * rcconn = new RemoteCollectionConnection(lib, this);
createParallelConnection(conn, rcconn, key);
- RemoteCollection * rc = new RemoteCollection(this, rcconn);
//ProxyListener * pl = new ProxyListener(this, conn, key);
//BonjourRecord rec(QString("DAAP %1 via %2").arg(name).arg(""),//conn->name()),
// QLatin1String("_daap._tcp"), QString());

0 comments on commit 5438aa4

Please sign in to comment.