diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp new file mode 100644 index 0000000000..57789fa8d3 --- /dev/null +++ b/interface/src/DataServerClient.cpp @@ -0,0 +1,70 @@ +// +// DataServerClient.cpp +// hifi +// +// Created by Stephen Birarda on 10/7/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#include +#include +#include + +#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) { + +} diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h new file mode 100644 index 0000000000..08d828ed49 --- /dev/null +++ b/interface/src/DataServerClient.h @@ -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 + +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__) */ diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index 6d20eac078..c41bc83e03 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -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;