From f3e4196a81bfb97ea315f97d2095524c86d5deed Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 22 Aug 2013 11:21:52 -0700 Subject: [PATCH] add an assignment class and begin to hookup AS --- assignment-server/src/main.cpp | 36 +++++------------------------ libraries/shared/src/Assignment.cpp | 13 +++++++++++ libraries/shared/src/Assignment.h | 27 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 libraries/shared/src/Assignment.cpp create mode 100644 libraries/shared/src/Assignment.h diff --git a/assignment-server/src/main.cpp b/assignment-server/src/main.cpp index be902ed5b0..90d8c1754c 100644 --- a/assignment-server/src/main.cpp +++ b/assignment-server/src/main.cpp @@ -12,16 +12,13 @@ #include +#include #include #include #include const int MAX_PACKET_SIZE_BYTES = 1400; -struct Assignment { - QString scriptFilename; -}; - int main(int argc, const char* argv[]) { std::queue 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); } } diff --git a/libraries/shared/src/Assignment.cpp b/libraries/shared/src/Assignment.cpp new file mode 100644 index 0000000000..a87a75935d --- /dev/null +++ b/libraries/shared/src/Assignment.cpp @@ -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) { + +} \ No newline at end of file diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h new file mode 100644 index 0000000000..341f2fed5b --- /dev/null +++ b/libraries/shared/src/Assignment.h @@ -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__) */