initial stub of data server client code in Interface

This commit is contained in:
Stephen Birarda 2013-10-07 09:55:08 -07:00
parent 825d397e21
commit 4cc9f29c83
3 changed files with 100 additions and 0 deletions

View file

@ -0,0 +1,70 @@
//
// DataServerClient.cpp
// hifi
//
// Created by Stephen Birarda on 10/7/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#include <NodeList.h>
#include <PacketHeaders.h>
#include <UDPSocket.h>
#include "DataServerClient.h"
const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io";
const unsigned short DATA_SERVER_PORT = 3282;
const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
void DataServerClient::putValueForKey(const char* key, const char* value) {
unsigned char putPacket[MAX_PACKET_SIZE];
// setup the header for this packet
int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
// pack the client UUID
QByteArray rfcUUID = _clientUUID.toRfc4122();
memcpy(putPacket + numPacketBytes, rfcUUID.constData(), rfcUUID.size());
numPacketBytes += rfcUUID.size();
// pack the key, null terminated
strcpy((char*) putPacket + numPacketBytes, key);
numPacketBytes += strlen(key);
putPacket[numPacketBytes++] = '\0';
// pack the value, null terminated
strcpy((char*) putPacket + numPacketBytes, value);
numPacketBytes += strlen(value);
putPacket[numPacketBytes++] = '\0';
// send this put request to the data server
NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
}
void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) {
unsigned char getPacket[MAX_PACKET_SIZE];
// setup the header for this packet
int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
// pack the UUID we're asking for data for
QByteArray rfcUUID = uuid.toRfc4122();
memcpy(getPacket + numPacketBytes, rfcUUID, rfcUUID.size());
numPacketBytes += rfcUUID.size();
// pack the key, null terminated
strcpy((char*) getPacket + numPacketBytes, key);
numPacketBytes += strlen(key);
getPacket[numPacketBytes++] = '\0';
// send the get to the data server
NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);
}
void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
}
void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) {
}

View file

@ -0,0 +1,28 @@
//
// DataServerClient.h
// hifi
//
// Created by Stephen Birarda on 10/7/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#ifndef __hifi__DataServerClient__
#define __hifi__DataServerClient__
#include <QtCore/QUuid>
class DataServerClient {
public:
static void putValueForKey(const char* key, const char* value);
static void getValueForKeyAndUUID(const char* key, QUuid& uuid);
static void getClientValueForKey(const char* key) { getValueForKeyAndUUID(key, _clientUUID); }
static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes);
static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes);
static void setClientUUID(QUuid& clientUUID) { _clientUUID = clientUUID; }
static QUuid& getClientUUID() { return _clientUUID; }
private:
static QUuid _clientUUID;
};
#endif /* defined(__hifi__DataServerClient__) */

View file

@ -41,6 +41,8 @@ const PACKET_TYPE PACKET_TYPE_DEPLOY_ASSIGNMENT = 'd';
const PACKET_TYPE PACKET_TYPE_VOXEL_STATS = '#';
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION = 'J';
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION_REQUEST = 'j';
const PACKET_TYPE PACKET_TYPE_DATA_SERVER_PUT = 'p';
const PACKET_TYPE PACKET_TYPE_DATA_SERVER_GET = 'g';
typedef char PACKET_VERSION;