add an assignment class and begin to hookup AS

This commit is contained in:
Stephen Birarda 2013-08-22 11:21:52 -07:00
parent 1591e11c77
commit f3e4196a81
3 changed files with 46 additions and 30 deletions

View file

@ -12,16 +12,13 @@
#include <QtCore/QString>
#include <Assignment.h>
#include <PacketHeaders.h>
#include <SharedUtil.h>
#include <UDPSocket.h>
const int MAX_PACKET_SIZE_BYTES = 1400;
struct Assignment {
QString scriptFilename;
};
int main(int argc, const char* argv[]) {
std::queue<Assignment> assignmentQueue;
@ -37,41 +34,20 @@ int main(int argc, const char* argv[]) {
while (true) {
if (serverSocket.receive((sockaddr*) &senderSocket, &senderData, &receivedBytes)) {
int numHeaderBytes = numBytesForPacketHeader(senderData);
if (senderData[0] == PACKET_TYPE_REQUEST_ASSIGNMENT) {
if (senderData[0] == PACKET_TYPE_REQUEST_ASSIGNMENT) {
qDebug() << "Assignment request received.\n";
// grab the FI assignment in the queue, if it exists
// grab the first assignment in the queue, if it exists
if (assignmentQueue.size() > 0) {
Assignment firstAssignment = assignmentQueue.front();
assignmentQueue.pop();
QString scriptURL = QString("http://base8-compute.s3.amazonaws.com/%1").arg(firstAssignment.scriptFilename);
qDebug() << "Sending assignment with URL" << scriptURL << "\n";
int scriptURLBytes = scriptURL.size();
memcpy(assignmentPacket + numSendHeaderBytes, scriptURL.toLocal8Bit().constData(), scriptURLBytes);
// send the assignment
serverSocket.send((sockaddr*) &senderSocket, assignmentPacket, numHeaderBytes + scriptURLBytes);
}
} else if (senderData[0] == PACKET_TYPE_SEND_ASSIGNMENT) {
Assignment newAssignment;
senderData[receivedBytes] = '\0';
newAssignment.scriptFilename = QString((const char*)senderData + numHeaderBytes);
qDebug() << "Added an assignment with script with filename" << newAssignment.scriptFilename << "\n";
} else if (senderData[0] == PACKET_TYPE_SEND_ASSIGNMENT && packetVersionMatch(senderData)) {
Assignment newAssignment(*(senderData + numBytesForPacketHeader(senderData));
// add this assignment to the queue
// we're not a queue right now, only keep one assignment
if (assignmentQueue.size() > 0) {
assignmentQueue.pop();
}
assignmentQueue.push(newAssignment);
}
}

View file

@ -0,0 +1,13 @@
//
// Assignment.cpp
// hifi
//
// Created by Stephen Birarda on 8/22/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#include "Assignment.h"
Assignment::Assignment(Assignment::Type type) : _type(type) {
}

View file

@ -0,0 +1,27 @@
//
// Assignment.h
// hifi
//
// Created by Stephen Birarda on 8/22/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#ifndef __hifi__Assignment__
#define __hifi__Assignment__
#include "NodeList.h"
class Assignment {
public:
enum Type {
AudioMixer
};
Assignment(Assignment::Type type);
private:
Assignment::Type _type;
};
#endif /* defined(__hifi__Assignment__) */