mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 15:59:49 +02:00
add a PairingHandler to send pair requests to the pairing server
This commit is contained in:
parent
8689a3f352
commit
b6925edbe8
4 changed files with 73 additions and 6 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
#include <PairingHandler.h>
|
||||||
|
|
||||||
#include "Application.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)
|
// simple menu bar (will only appear on OS X, for now)
|
||||||
QMenuBar* menuBar = new QMenuBar();
|
QMenuBar* menuBar = new QMenuBar();
|
||||||
QMenu* fileMenu = menuBar->addMenu("File");
|
QMenu* fileMenu = menuBar->addMenu("File");
|
||||||
fileMenu->addAction("Test", this, SLOT(testSlot()));
|
|
||||||
|
fileMenu->addAction("Pair", this, SLOT(pair()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::testSlot() {
|
void Application::pair() {
|
||||||
qDebug() << "Hello world.";
|
PairingHandler::sendPairRequest();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,10 @@ class Application : public QApplication {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Application(int& argc, char** argv);
|
Application(int& argc, char** argv);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void pair();
|
||||||
void testSlot();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__Application__) */
|
#endif /* defined(__interface__Application__) */
|
||||||
|
|
48
interface/src/PairingHandler.cpp
Normal file
48
interface/src/PairingHandler.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
printf("Sending a pair request to %s on port %d\n", inet_ntoa(pairingServerSocket.sin_addr), ntohs(pairingServerSocket.sin_port));
|
||||||
|
|
||||||
|
// send the pair request to the pairing server
|
||||||
|
agentSocket->send((sockaddr*) &pairingServerSocket, pairPacket, strlen(pairPacket));
|
||||||
|
}
|
19
interface/src/PairingHandler.h
Normal file
19
interface/src/PairingHandler.h
Normal 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__) */
|
Loading…
Reference in a new issue