mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 05:17:24 +02:00
remove the pairing-server target
This commit is contained in:
parent
00b4cd799e
commit
f72a87a47e
3 changed files with 0 additions and 153 deletions
|
@ -37,6 +37,5 @@ endif (NOT WIN32)
|
||||||
add_subdirectory(assignment-client)
|
add_subdirectory(assignment-client)
|
||||||
add_subdirectory(domain-server)
|
add_subdirectory(domain-server)
|
||||||
add_subdirectory(interface)
|
add_subdirectory(interface)
|
||||||
add_subdirectory(pairing-server)
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
add_subdirectory(voxel-edit)
|
add_subdirectory(voxel-edit)
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
cmake_minimum_required(VERSION 2.8)
|
|
||||||
|
|
||||||
set(ROOT_DIR ..)
|
|
||||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
|
||||||
|
|
||||||
set(TARGET_NAME pairing-server)
|
|
||||||
|
|
||||||
find_package(Qt5Network REQUIRED)
|
|
||||||
|
|
||||||
include(${MACRO_DIR}/SetupHifiProject.cmake)
|
|
||||||
setup_hifi_project(${TARGET_NAME} TRUE)
|
|
||||||
|
|
||||||
qt5_use_modules(${TARGET_NAME} Network)
|
|
||||||
|
|
||||||
# link the shared hifi library
|
|
||||||
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
|
||||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
|
|
@ -1,135 +0,0 @@
|
||||||
//
|
|
||||||
// main.cpp
|
|
||||||
// pairing-server
|
|
||||||
//
|
|
||||||
// Created by Stephen Birarda on 5/1/13.
|
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <arpa/inet.h> // not available on windows
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const int INET_ADDR_STRLEN = 16;
|
|
||||||
|
|
||||||
#include <QtNetwork/QUdpSocket>
|
|
||||||
|
|
||||||
#include <HifiSockAddr.h>
|
|
||||||
|
|
||||||
const int PAIRING_SERVER_LISTEN_PORT = 7247;
|
|
||||||
const int MAX_PACKET_SIZE_BYTES = 1400;
|
|
||||||
|
|
||||||
struct PairableDevice {
|
|
||||||
char identifier[64];
|
|
||||||
char name[64];
|
|
||||||
HifiSockAddr sendingSocket;
|
|
||||||
HifiSockAddr localSocket;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RequestingClient {
|
|
||||||
char address[INET_ADDR_STRLEN];
|
|
||||||
int port;
|
|
||||||
};
|
|
||||||
|
|
||||||
QUdpSocket serverSocket;
|
|
||||||
PairableDevice* lastDevice = NULL;
|
|
||||||
RequestingClient* lastClient = NULL;
|
|
||||||
|
|
||||||
int indexOfFirstOccurenceOfCharacter(char* haystack, char needle) {
|
|
||||||
int currentIndex = 0;
|
|
||||||
|
|
||||||
while (haystack[currentIndex] != '\0' && haystack[currentIndex] != needle) {
|
|
||||||
currentIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendLastClientToLastDevice() {
|
|
||||||
char pairData[INET_ADDR_STRLEN + 6] = {};
|
|
||||||
int bytesWritten = sprintf(pairData, "%s:%d", ::lastClient->address, ::lastClient->port);
|
|
||||||
|
|
||||||
::serverSocket.writeDatagram(pairData, bytesWritten,
|
|
||||||
::lastDevice->sendingSocket.getAddress(), ::lastDevice->sendingSocket.getPort());
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
|
||||||
|
|
||||||
serverSocket.bind(QHostAddress::LocalHost, PAIRING_SERVER_LISTEN_PORT);
|
|
||||||
|
|
||||||
HifiSockAddr senderSockAddr;
|
|
||||||
char senderData[MAX_PACKET_SIZE_BYTES] = {};
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (::serverSocket.hasPendingDatagrams()
|
|
||||||
&& ::serverSocket.readDatagram(senderData, MAX_PACKET_SIZE_BYTES,
|
|
||||||
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer())) {
|
|
||||||
if (senderData[0] == 'A') {
|
|
||||||
// this is a device reporting itself as available
|
|
||||||
|
|
||||||
PairableDevice tempDevice = {};
|
|
||||||
|
|
||||||
char deviceAddress[INET_ADDR_STRLEN] = {};
|
|
||||||
int socketPort = 0;
|
|
||||||
|
|
||||||
int numMatches = sscanf(senderData, "Available %s %[^:]:%d %s",
|
|
||||||
tempDevice.identifier,
|
|
||||||
deviceAddress,
|
|
||||||
&socketPort,
|
|
||||||
tempDevice.name);
|
|
||||||
|
|
||||||
if (numMatches >= 3) {
|
|
||||||
// if we have fewer than 3 matches the packet wasn't properly formatted
|
|
||||||
|
|
||||||
// setup the localSocket for the pairing device
|
|
||||||
tempDevice.localSocket.setAddress(QHostAddress(deviceAddress));
|
|
||||||
tempDevice.localSocket.setPort(socketPort);
|
|
||||||
|
|
||||||
// store this device's sending socket so we can talk back to it
|
|
||||||
tempDevice.sendingSocket = senderSockAddr;
|
|
||||||
|
|
||||||
// push this new device into the vector
|
|
||||||
printf("New last device is %s (%s) at %s:%d\n",
|
|
||||||
tempDevice.identifier,
|
|
||||||
tempDevice.name,
|
|
||||||
deviceAddress,
|
|
||||||
socketPort);
|
|
||||||
|
|
||||||
// copy the tempDevice to the persisting lastDevice
|
|
||||||
::lastDevice = new PairableDevice(tempDevice);
|
|
||||||
|
|
||||||
if (::lastClient) {
|
|
||||||
sendLastClientToLastDevice();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (senderData[0] == 'F') {
|
|
||||||
// this is a client looking to pair with a device
|
|
||||||
// send the most recent device this address so it can attempt to pair
|
|
||||||
|
|
||||||
RequestingClient tempClient = {};
|
|
||||||
|
|
||||||
int requestorMatches = sscanf(senderData, "Find %[^:]:%d",
|
|
||||||
tempClient.address,
|
|
||||||
&tempClient.port);
|
|
||||||
|
|
||||||
if (requestorMatches == 2) {
|
|
||||||
// good data, copy the tempClient to the persisting lastInterfaceClient
|
|
||||||
::lastClient = new RequestingClient(tempClient);
|
|
||||||
|
|
||||||
printf("New last client is at %s:%d\n",
|
|
||||||
::lastClient->address,
|
|
||||||
::lastClient->port);
|
|
||||||
|
|
||||||
if (::lastDevice) {
|
|
||||||
sendLastClientToLastDevice();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue