mirror of
https://github.com/lubosz/overte.git
synced 2025-04-14 14:46:55 +02:00
add notion of pool and direction to Assignment class
This commit is contained in:
parent
f485814a42
commit
29e5eda358
8 changed files with 34 additions and 26 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
const int ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
// create a NodeList as an unassigned client
|
||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
|
||||
|
@ -27,17 +27,19 @@ int main(int argc, const char* argv[]) {
|
|||
unsigned char packetData[MAX_PACKET_SIZE];
|
||||
ssize_t receivedBytes = 0;
|
||||
|
||||
Assignment requestAssignment(Assignment::Request, Assignment::All);
|
||||
|
||||
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();
|
||||
nodeList->sendAssignment(requestAssignment);
|
||||
}
|
||||
|
||||
while (nodeList->getNodeSocket()->receive(packetData, &receivedBytes)) {
|
||||
if (packetData[0] == PACKET_TYPE_SEND_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||
Assignment::Type assignmentType = (Assignment::Type) *(packetData + numBytesForPacketHeader(packetData));
|
||||
|
||||
qDebug() << "Received an assignment of type" << assignmentType << "\n";
|
||||
|
|
|
@ -30,7 +30,7 @@ int main(int argc, const char* argv[]) {
|
|||
UDPSocket serverSocket(ASSIGNMENT_SERVER_PORT);
|
||||
|
||||
unsigned char assignmentPacket[MAX_PACKET_SIZE_BYTES];
|
||||
int numSendHeaderBytes = populateTypeAndVersion(assignmentPacket, PACKET_TYPE_SEND_ASSIGNMENT);
|
||||
int numSendHeaderBytes = populateTypeAndVersion(assignmentPacket, PACKET_TYPE_CREATE_ASSIGNMENT);
|
||||
|
||||
while (true) {
|
||||
if (serverSocket.receive((sockaddr*) &senderSocket, &senderData, &receivedBytes)) {
|
||||
|
@ -48,16 +48,16 @@ int main(int argc, const char* argv[]) {
|
|||
// send the assignment
|
||||
serverSocket.send((sockaddr*) &senderSocket, assignmentPacket, numSendHeaderBytes + sizeof(unsigned char));
|
||||
}
|
||||
} else if (senderData[0] == PACKET_TYPE_SEND_ASSIGNMENT && packetVersionMatch(senderData)) {
|
||||
} else if (senderData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(senderData)) {
|
||||
// assignment server is on a public server
|
||||
// assume that the address we now have for the sender is the public address/port
|
||||
// and store that with the assignment so it can be given to the requestor later
|
||||
Assignment newAssignment((Assignment::Type) *(senderData + numBytesForPacketHeader(senderData)), senderSocket);
|
||||
// Assignment newAssignment((Assignment::Type) *(senderData + numBytesForPacketHeader(senderData)), senderSocket);
|
||||
|
||||
qDebug() << "Received assignment of type " << newAssignment.getType() << "\n";
|
||||
// qDebug() << "Received assignment of type " << newAssignment.getType() << "\n";
|
||||
|
||||
// add this assignment to the queue
|
||||
assignmentQueue.push(newAssignment);
|
||||
// assignmentQueue.push(newAssignment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ int main(int argc, const char * argv[])
|
|||
// we don't have an audio mixer, and we know we need one
|
||||
// so tell that to the assignment server
|
||||
|
||||
Assignment mixerAssignment(Assignment::AudioMixer);
|
||||
Assignment mixerAssignment(Assignment::Create, Assignment::AudioMixer);
|
||||
nodeList->sendAssignment(mixerAssignment);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,10 @@
|
|||
|
||||
#include "Assignment.h"
|
||||
|
||||
Assignment::Assignment(Assignment::Type type) : _type(type) {
|
||||
|
||||
}
|
||||
|
||||
Assignment::Assignment(Assignment::Type type, sockaddr_in& senderSocket) :
|
||||
Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool) :
|
||||
_direction(direction),
|
||||
_type(type),
|
||||
_senderSocket(senderSocket) {
|
||||
_pool(pool)
|
||||
{
|
||||
|
||||
}
|
|
@ -15,17 +15,25 @@ class Assignment {
|
|||
public:
|
||||
|
||||
enum Type {
|
||||
AudioMixer
|
||||
AudioMixer,
|
||||
All
|
||||
};
|
||||
|
||||
Assignment(Assignment::Type type);
|
||||
Assignment(Assignment::Type type, sockaddr_in& senderSocket);
|
||||
enum Direction {
|
||||
Create,
|
||||
Request
|
||||
};
|
||||
|
||||
Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool = NULL);
|
||||
|
||||
Assignment::Direction getDirection() const { return _direction; }
|
||||
Assignment::Type getType() const { return _type; }
|
||||
const char* getPool() const { return _pool; }
|
||||
|
||||
private:
|
||||
Assignment::Direction _direction;
|
||||
Assignment::Type _type;
|
||||
sockaddr_in _senderSocket;
|
||||
const char* _pool;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -371,13 +371,14 @@ const char ASSIGNMENT_SERVER_HOSTNAME[] = "localhost";
|
|||
const sockaddr_in assignmentServerSocket = socketForHostnameAndHostOrderPort(ASSIGNMENT_SERVER_HOSTNAME,
|
||||
ASSIGNMENT_SERVER_PORT);
|
||||
|
||||
void NodeList::requestAssignment() {
|
||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, &PACKET_TYPE_REQUEST_ASSIGNMENT, 1);
|
||||
}
|
||||
|
||||
void NodeList::sendAssignment(Assignment& assignment) {
|
||||
unsigned char assignmentPacket[MAX_PACKET_SIZE];
|
||||
int numHeaderBytes = populateTypeAndVersion(assignmentPacket, PACKET_TYPE_SEND_ASSIGNMENT);
|
||||
|
||||
PACKET_TYPE assignmentPacketType = assignment.getDirection() == Assignment::Create
|
||||
? PACKET_TYPE_CREATE_ASSIGNMENT
|
||||
: PACKET_TYPE_REQUEST_ASSIGNMENT;
|
||||
|
||||
int numHeaderBytes = populateTypeAndVersion(assignmentPacket, assignmentPacketType);
|
||||
*(assignmentPacket + numHeaderBytes) = assignment.getType();
|
||||
|
||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, assignmentPacket, numHeaderBytes + sizeof(unsigned char));
|
||||
|
|
|
@ -96,7 +96,6 @@ public:
|
|||
void sendDomainServerCheckIn();
|
||||
int processDomainServerList(unsigned char *packetData, size_t dataBytes);
|
||||
|
||||
void requestAssignment();
|
||||
void sendAssignment(Assignment& assignment);
|
||||
|
||||
Node* nodeWithAddress(sockaddr *senderAddress);
|
||||
|
|
|
@ -36,7 +36,7 @@ const PACKET_TYPE PACKET_TYPE_ENVIRONMENT_DATA = 'e';
|
|||
const PACKET_TYPE PACKET_TYPE_DOMAIN_LIST_REQUEST = 'L';
|
||||
const PACKET_TYPE PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY = 'C';
|
||||
const PACKET_TYPE PACKET_TYPE_REQUEST_ASSIGNMENT = 'r';
|
||||
const PACKET_TYPE PACKET_TYPE_SEND_ASSIGNMENT = 's';
|
||||
const PACKET_TYPE PACKET_TYPE_CREATE_ASSIGNMENT = 's';
|
||||
const PACKET_TYPE PACKET_TYPE_VOXEL_STATS = '#';
|
||||
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION = 'J';
|
||||
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION_REQUEST = 'j';
|
||||
|
|
Loading…
Reference in a new issue