mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-07 13:12:39 +02:00
add a stubbed assignment client to request assignments
This commit is contained in:
parent
ef7e7ae4c5
commit
97bee1eb82
5 changed files with 69 additions and 1 deletions
|
@ -13,6 +13,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_subdirectory(animation-server)
|
||||
add_subdirectory(assignment-client)
|
||||
add_subdirectory(assignment-server)
|
||||
add_subdirectory(avatar-mixer)
|
||||
add_subdirectory(audio-mixer)
|
||||
|
|
13
assignment-client/CMakeLists.txt
Normal file
13
assignment-client/CMakeLists.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(TARGET_NAME assignment-client)
|
||||
|
||||
set(ROOT_DIR ..)
|
||||
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||
|
||||
include(${MACRO_DIR}/SetupHifiProject.cmake)
|
||||
setup_hifi_project(${TARGET_NAME} TRUE)
|
||||
|
||||
# link in the shared library
|
||||
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
50
assignment-client/src/main.cpp
Normal file
50
assignment-client/src/main.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// main.cpp
|
||||
// assignment-client
|
||||
//
|
||||
// Created by Stephen Birarda on 8/22/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <Assignment.h>
|
||||
#include <NodeList.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
const int ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
// create a NodeList as an unassigned client
|
||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
|
||||
nodeList->getNodeSocket()->setBlocking(false);
|
||||
|
||||
timeval lastRequest = {};
|
||||
|
||||
unsigned char packetData[MAX_PACKET_SIZE];
|
||||
ssize_t receivedBytes = 0;
|
||||
|
||||
while (true) {
|
||||
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
|
||||
gettimeofday(&lastRequest, NULL);
|
||||
|
||||
// send an assignment request to the Nodelist
|
||||
qDebug("Sending assignment request.\n");
|
||||
nodeList->requestAssignment();
|
||||
}
|
||||
|
||||
while (nodeList->getNodeSocket()->receive(packetData, &receivedBytes)) {
|
||||
if (packetData[0] == PACKET_TYPE_SEND_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||
Assignment::Type assignmentType = (Assignment::Type) *(packetData + numBytesForPacketHeader(packetData));
|
||||
|
||||
qDebug() << "Received an assignment of type" << assignmentType << "\n";
|
||||
|
||||
// reset our NodeList by switching back to unassigned and clearing the list
|
||||
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
|
||||
nodeList->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,7 +42,11 @@ int main(int argc, const char* argv[]) {
|
|||
Assignment firstAssignment = assignmentQueue.front();
|
||||
assignmentQueue.pop();
|
||||
|
||||
*(assignmentPacket + numSendHeaderBytes) = firstAssignment.getType();
|
||||
|
||||
|
||||
// send the assignment
|
||||
serverSocket.send((sockaddr*) &senderSocket, assignmentPacket, numSendHeaderBytes + sizeof(unsigned char));
|
||||
}
|
||||
} else if (senderData[0] == PACKET_TYPE_SEND_ASSIGNMENT && packetVersionMatch(senderData)) {
|
||||
// assignment server is on a public server
|
||||
|
|
|
@ -371,7 +371,7 @@ const char ASSIGNMENT_SERVER_HOSTNAME[] = "localhost";
|
|||
const sockaddr_in assignmentServerSocket = socketForHostnameAndHostOrderPort(ASSIGNMENT_SERVER_HOSTNAME,
|
||||
ASSIGNMENT_SERVER_PORT);
|
||||
|
||||
void NodeList::requestAssignment() {
|
||||
void NodeList::requestAssignment() {
|
||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, &PACKET_TYPE_REQUEST_ASSIGNMENT, 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue