Showing the changes to interface/src/DataServerClient.cpp (1 of 3 files). Show all
Unified · Split
| @@ -0,0 +1,70 @@ | ||
| 1 | +// | |
| 2 | +// DataServerClient.cpp | |
| 3 | +// hifi | |
| 4 | +// | |
| 5 | +// Created by Stephen Birarda on 10/7/13. | |
| 6 | +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#include <NodeList.h> | |
| 10 | +#include <PacketHeaders.h> | |
| 11 | +#include <UDPSocket.h> | |
| 12 | + | |
| 13 | +#include "DataServerClient.h" | |
| 14 | + | |
| 15 | +const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; | |
| 16 | +const unsigned short DATA_SERVER_PORT = 3282; | |
| 17 | +const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); | |
| 18 | + | |
| 19 | +void DataServerClient::putValueForKey(const char* key, const char* value) { | |
| 20 | + unsigned char putPacket[MAX_PACKET_SIZE]; | |
| 21 | + | |
| 22 | + // setup the header for this packet | |
| 23 | + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); | |
| 24 | + | |
| 25 | + // pack the client UUID | |
| 26 | + QByteArray rfcUUID = _clientUUID.toRfc4122(); | |
| 27 | + memcpy(putPacket + numPacketBytes, rfcUUID.constData(), rfcUUID.size()); | |
| 28 | + numPacketBytes += rfcUUID.size(); | |
| 29 | + | |
| 30 | + // pack the key, null terminated | |
| 31 | + strcpy((char*) putPacket + numPacketBytes, key); | |
| 32 | + numPacketBytes += strlen(key); | |
| 33 | + putPacket[numPacketBytes++] = '\0'; | |
| 34 | + | |
| 35 | + // pack the value, null terminated | |
| 36 | + strcpy((char*) putPacket + numPacketBytes, value); | |
| 37 | + numPacketBytes += strlen(value); | |
| 38 | + putPacket[numPacketBytes++] = '\0'; | |
| 39 | + | |
| 40 | + // send this put request to the data server | |
| 41 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); | |
| 42 | +} | |
| 43 | + | |
| 44 | +void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { | |
| 45 | + unsigned char getPacket[MAX_PACKET_SIZE]; | |
| 46 | + | |
| 47 | + // setup the header for this packet | |
| 48 | + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 49 | + | |
| 50 | + // pack the UUID we're asking for data for | |
| 51 | + QByteArray rfcUUID = uuid.toRfc4122(); | |
| 52 | + memcpy(getPacket + numPacketBytes, rfcUUID, rfcUUID.size()); | |
| 53 | + numPacketBytes += rfcUUID.size(); | |
| 54 | + | |
| 55 | + // pack the key, null terminated | |
| 56 | + strcpy((char*) getPacket + numPacketBytes, key); | |
| 57 | + numPacketBytes += strlen(key); | |
| 58 | + getPacket[numPacketBytes++] = '\0'; | |
| 59 | + | |
| 60 | + // send the get to the data server | |
| 61 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 62 | +} | |
| 63 | + | |
| 64 | +void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { | |
| 65 | + | |
| 66 | +} | |
| 67 | + | |
| 68 | +void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { | |
| 69 | + | |
| 70 | +} | |