diff --git a/src/avahidevicelocator.cpp b/src/avahidevicelocator.cpp index a59bbdb7f..2460da8de 100644 --- a/src/avahidevicelocator.cpp +++ b/src/avahidevicelocator.cpp @@ -43,7 +43,13 @@ DeviceLink* AvahiDeviceLocator::link(QString id) { Device* d = visibleDevices[id]; const DNSSD::RemoteService::Ptr& rs = deviceRoutes[d]; - DeviceLink* dl = new UdpDeviceLink(QHostAddress(rs->hostName()),rs->port()); + DeviceLink* dl = new UdpDeviceLink(d, QHostAddress(rs->hostName()),rs->port()); + + qDebug() << "Sending pair request to device " + id; + NetworkPackage np(12345); + //TODO: Package contents + dl->sendPackage(np); + linkedDevices.append(dl); //Store the ref to be able to delete the memory later return dl; diff --git a/src/daemon.cpp b/src/daemon.cpp index aa189b01a..c1b6dd268 100644 --- a/src/daemon.cpp +++ b/src/daemon.cpp @@ -80,9 +80,11 @@ Daemon::Daemon(QObject *parent, const QList&) deviceLocators.insert(new FakeDeviceLocator()); //TODO: Read paired devices from config - pairedDevices.push_back(new Device("MyAndroid","MyAndroid")); + //pairedDevices.push_back(new Device("MyAndroid","MyAndroid")); //At boot time, try to link to all paired devices + //FIXME: This should be done for every new visible device, not only at boot + //TODO: Add a way to notify discovered/lost devices Q_FOREACH (Device* device, pairedDevices) { linkTo(device->id()); } @@ -122,7 +124,7 @@ bool Daemon::linkDevice(QString id) } -QString Daemon::listLinkedDevices(long int id) +QString Daemon::listLinkedDevices() { QString ret; @@ -137,6 +139,5 @@ QString Daemon::listLinkedDevices(long int id) Daemon::~Daemon() { qDebug() << "SAYONARA BABY"; - } diff --git a/src/daemon.h b/src/daemon.h index cda4a42dc..dcfab7d1e 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -61,15 +61,15 @@ public Q_SLOTS: Q_SCRIPTABLE bool linkDevice(QString id); /* - Q_SCRIPTABLE bool pairDevice(long id); + Q_SCRIPTABLE bool pairDevice(QString id); - Q_SCRIPTABLE QString listPairedDevices(long id); + Q_SCRIPTABLE QString listPairedDevices(QString id); Q_SCRIPTABLE bool linkAllPairedDevices(); */ - Q_SCRIPTABLE QString listLinkedDevices(long id); + Q_SCRIPTABLE QString listLinkedDevices(); private: diff --git a/src/devicelink.cpp b/src/devicelink.cpp index 8d00c081c..f48ac039e 100644 --- a/src/devicelink.cpp +++ b/src/devicelink.cpp @@ -20,6 +20,8 @@ #include "devicelink.h" -DeviceLink::DeviceLink() { +DeviceLink::DeviceLink(Device* d) + : mDevice(d) +{ //gcc complains if we don't add something to compile on a class with virtual functions } \ No newline at end of file diff --git a/src/devicelink.h b/src/devicelink.h index 303063b22..c6959cdbc 100644 --- a/src/devicelink.h +++ b/src/devicelink.h @@ -33,7 +33,7 @@ class DeviceLink Q_OBJECT public: - DeviceLink(Device* d) : mDevice(d) { }; + DeviceLink(Device* d); Device* device() { return mDevice; } diff --git a/src/devicelocator.h b/src/devicelocator.h index 9c5f38add..d9708130f 100644 --- a/src/devicelocator.h +++ b/src/devicelocator.h @@ -50,6 +50,12 @@ public: virtual bool pair(Device* d) = 0; virtual QList discover() = 0; +signals: + + //TODO: Emit this to be able to see if it is a known device + //void deviceDiscovered(Device* d); + //void deviceLost(QString id); + }; #endif // DEVICELOCATOR_H diff --git a/src/echodevicelink.h b/src/echodevicelink.h index 6f832b026..756ec2f51 100644 --- a/src/echodevicelink.h +++ b/src/echodevicelink.h @@ -25,8 +25,9 @@ class EchoDeviceLink : public DeviceLink { - public: + EchoDeviceLink(Device* d) : DeviceLink(d) { } + void sendPackage(const NetworkPackage& np) { emit receivedPackage(np); } diff --git a/src/fakedevicelocator.cpp b/src/fakedevicelocator.cpp index 460ca403b..246938373 100644 --- a/src/fakedevicelocator.cpp +++ b/src/fakedevicelocator.cpp @@ -24,7 +24,7 @@ FakeDeviceLocator::FakeDeviceLocator() { fakeDevice = new Device("fake","Fake device"); - echoDeviceLink = new EchoDeviceLink(); + echoDeviceLink = new EchoDeviceLink(fakeDevice); } bool FakeDeviceLocator::canLink(QString id) { diff --git a/src/udpdevicelink.cpp b/src/udpdevicelink.cpp index 5bdc67242..f73f88c49 100644 --- a/src/udpdevicelink.cpp +++ b/src/udpdevicelink.cpp @@ -21,7 +21,8 @@ #include "udpdevicelink.h" -UdpDeviceLink::UdpDeviceLink(QHostAddress ip, quint16 port) +UdpDeviceLink::UdpDeviceLink(Device* d, QHostAddress ip, quint16 port) + : DeviceLink(d) { mIp = ip; diff --git a/src/udpdevicelink.h b/src/udpdevicelink.h index 0e6da8617..56bd9bb92 100644 --- a/src/udpdevicelink.h +++ b/src/udpdevicelink.h @@ -33,7 +33,7 @@ class UdpDeviceLink Q_OBJECT public: - UdpDeviceLink(QHostAddress ip, quint16 port); + UdpDeviceLink(Device* d, QHostAddress ip, quint16 port); void sendPackage(const NetworkPackage& np) { mUdpSocket->writeDatagram(np.toString(), mIp, mPort);