Merge pull request #300 from birarda/master

add a PairingHandler to send pair requests from the Qt menu
This commit is contained in:
ZappoMan 2013-05-13 18:17:28 -07:00
commit 46a9715dcb
4 changed files with 71 additions and 6 deletions

View file

@ -7,6 +7,7 @@
#include <QMenuBar>
#include <QtDebug>
#include <PairingHandler.h>
#include "Application.h"
@ -14,9 +15,10 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) {
// simple menu bar (will only appear on OS X, for now)
QMenuBar* menuBar = new QMenuBar();
QMenu* fileMenu = menuBar->addMenu("File");
fileMenu->addAction("Test", this, SLOT(testSlot()));
fileMenu->addAction("Pair", this, SLOT(pair()));
}
void Application::testSlot() {
qDebug() << "Hello world.";
void Application::pair() {
PairingHandler::sendPairRequest();
}

View file

@ -15,12 +15,10 @@ class Application : public QApplication {
Q_OBJECT
public:
Application(int& argc, char** argv);
public slots:
void testSlot();
void pair();
};
#endif /* defined(__interface__Application__) */

View file

@ -0,0 +1,46 @@
//
// PairingHandler.cpp
// hifi
//
// Created by Stephen Birarda on 5/13/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include <arpa/inet.h>
#include <AgentList.h>
#include "PairingHandler.h"
const char PAIRING_SERVER_HOSTNAME[] = "pairing.highfidelity.io";
const int PAIRING_SERVER_PORT = 7247;
void PairingHandler::sendPairRequest() {
// grab the agent socket from the AgentList singleton
UDPSocket *agentSocket = &AgentList::getInstance()->getAgentSocket();
// prepare the pairing request packet
// use the getLocalAddress helper to get this client's listening address
int localAddress = getLocalAddress();
char pairPacket[24] = {};
sprintf(pairPacket, "Find %d.%d.%d.%d:%d",
localAddress & 0xFF,
(localAddress >> 8) & 0xFF,
(localAddress >> 16) & 0xFF,
(localAddress >> 24) & 0xFF,
AGENT_SOCKET_LISTEN_PORT);
sockaddr_in pairingServerSocket;
pairingServerSocket.sin_family = AF_INET;
// lookup the pairing server IP by the hostname
struct hostent* hostInfo = gethostbyname(PAIRING_SERVER_HOSTNAME);
memcpy(&pairingServerSocket.sin_addr, hostInfo->h_addr_list[0], hostInfo->h_length);
pairingServerSocket.sin_port = htons(PAIRING_SERVER_PORT);
// send the pair request to the pairing server
agentSocket->send((sockaddr*) &pairingServerSocket, pairPacket, strlen(pairPacket));
}

View file

@ -0,0 +1,19 @@
//
// PairingHandler.h
// hifi
//
// Created by Stephen Birarda on 5/13/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef __hifi__PairingHandler__
#define __hifi__PairingHandler__
#include <iostream>
class PairingHandler {
public:
static void sendPairRequest();
};
#endif /* defined(__hifi__PairingHandler__) */