From 16dbc8048fc26ad78b101de7967104ef5bb70a73 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 20 Jan 2015 15:40:34 -0800 Subject: [PATCH] inital connection of android client to domain --- gvr-interface/src/Client.cpp | 68 ++++++++++++++++++++++++ gvr-interface/src/{client.h => Client.h} | 6 +++ gvr-interface/src/client.cpp | 24 --------- 3 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 gvr-interface/src/Client.cpp rename gvr-interface/src/{client.h => Client.h} (82%) delete mode 100644 gvr-interface/src/client.cpp diff --git a/gvr-interface/src/Client.cpp b/gvr-interface/src/Client.cpp new file mode 100644 index 0000000000..fe7c3afc2d --- /dev/null +++ b/gvr-interface/src/Client.cpp @@ -0,0 +1,68 @@ +// +// Client.cpp +// gvr-interface/src +// +// Created by Stephen Birarda on 1/20/15. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include +#include +#include + +#include "Client.h" + +Client::Client(QObject* parent) : + QObject(parent) +{ + // we need to make sure that required dependencies are created + DependencyManager::set(); + + setupNetworking(); +} + +void Client::setupNetworking() { + // setup the NodeList for this client + auto nodeList = DependencyManager::set(NodeType::Agent, 0); + + // while datagram processing remains simple for targets using Client, we'll handle datagrams + connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &Client::processDatagrams); + + // every second, ask the NodeList to check in with the domain server + QTimer* domainCheckInTimer = new QTimer(this); + domainCheckInTimer->setInterval(DOMAIN_SERVER_CHECK_IN_MSECS); + connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn); + + // TODO: once the Client knows its Address on start-up we should be able to immediately send a check in here + domainCheckInTimer->start(); +} + +void Client::processDatagrams() { + HifiSockAddr senderSockAddr; + + static QByteArray incomingPacket; + + auto nodeList = DependencyManager::get(); + + while (DependencyManager::get()->getNodeSocket().hasPendingDatagrams()) { + incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize()); + nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), + senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + + if (nodeList->packetVersionAndHashMatch(incomingPacket)) { + + PacketType incomingType = packetTypeForPacket(incomingPacket); + // only process this packet if we have a match on the packet version + switch (incomingType) { + default: + nodeList->processNodeData(senderSockAddr, incomingPacket); + break; + } + } + } +} \ No newline at end of file diff --git a/gvr-interface/src/client.h b/gvr-interface/src/Client.h similarity index 82% rename from gvr-interface/src/client.h rename to gvr-interface/src/Client.h index 8ab14b8964..1c828dbc5d 100644 --- a/gvr-interface/src/client.h +++ b/gvr-interface/src/Client.h @@ -14,10 +14,16 @@ #include +class QThread; + class Client : public QObject { Q_OBJECT public: Client(QObject* parent = 0); +private slots: + void processDatagrams(); +private: + void setupNetworking(); }; #endif // hifi_Client_h diff --git a/gvr-interface/src/client.cpp b/gvr-interface/src/client.cpp deleted file mode 100644 index 61de226741..0000000000 --- a/gvr-interface/src/client.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// -// Client.cpp -// gvr-interface/src -// -// Created by Stephen Birarda on 1/20/15. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include - -#include "Client.h" - -Client::Client(QObject* parent) : - QObject(parent) -{ - DependencyManager::set(); - - // setup the NodeList for this client - auto nodeList = DependencyManager::set(NodeType::Agent, 0); -}