mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 13:43:49 +02:00
repairs to new Qt'ed DataServer and DataServerClient
This commit is contained in:
parent
657589fa64
commit
cf40fb0ef8
6 changed files with 27 additions and 26 deletions
|
@ -66,7 +66,8 @@ void DataServer::readPendingDatagrams() {
|
|||
int readBytes = numBytesForPacketHeader(packetData);
|
||||
|
||||
// pull the sequence number used for this packet
|
||||
quint16 sequenceNumber = *reinterpret_cast<quint16>(packetData + readBytes);
|
||||
quint8 sequenceNumber = 0;
|
||||
memcpy(&sequenceNumber, packetData + readBytes, sizeof(sequenceNumber));
|
||||
readBytes += sizeof(sequenceNumber);
|
||||
|
||||
// pull the UUID that we will need as part of the key
|
||||
|
@ -77,9 +78,8 @@ void DataServer::readPendingDatagrams() {
|
|||
// we failed to parse a UUID, this means the user has sent us a username
|
||||
|
||||
QString username(reinterpret_cast<char*>(packetData + readBytes));
|
||||
readBytes += sizeof(username) + sizeof('\0');
|
||||
|
||||
|
||||
readBytes += username.size() + sizeof('\0');
|
||||
|
||||
// ask redis for the UUID for this user
|
||||
redisReply* reply = (redisReply*) redisCommand(_redis, "GET user:%s", qPrintable(username));
|
||||
|
||||
|
@ -113,7 +113,7 @@ void DataServer::readPendingDatagrams() {
|
|||
QString dataValue(reinterpret_cast<char*>(packetData + readBytes));
|
||||
readBytes += dataValue.size() + sizeof('\0');
|
||||
|
||||
qDebug("Sending command to redis: SET uuid:%s:%s %s\n",
|
||||
qDebug("Sending command to redis: SET uuid:%s:%s %s",
|
||||
qPrintable(uuidStringWithoutCurlyBraces(parsedUUID)),
|
||||
qPrintable(dataKey), qPrintable(dataValue));
|
||||
|
||||
|
@ -133,19 +133,15 @@ void DataServer::readPendingDatagrams() {
|
|||
} else {
|
||||
// setup a send packet with the returned data
|
||||
// leverage the packetData sent by overwriting and appending
|
||||
int numSendPacketBytes = 0;
|
||||
int numSendPacketBytes = receivedBytes;
|
||||
|
||||
numSendPacketBytes += populateTypeAndVersion(packetData, PACKET_TYPE_DATA_SERVER_SEND);
|
||||
|
||||
memcpy(packetData + numSendPacketBytes, &sequenceNumber, sizeof(sequenceNumber));
|
||||
numSendPacketBytes += sizeof(sequenceNumber);
|
||||
packetData[0] = PACKET_TYPE_DATA_SERVER_SEND;
|
||||
|
||||
const char MULTI_KEY_VALUE_SEPARATOR = '|';
|
||||
|
||||
if (strcmp((char*) packetData + readBytes, "uuid") != 0) {
|
||||
|
||||
// the user has sent one or more keys - make the associated requests
|
||||
|
||||
for (int j = 0; j < numKeys; j++) {
|
||||
|
||||
// pull the key that specifies the data the user is putting/getting, null terminate it
|
||||
|
@ -160,7 +156,7 @@ void DataServer::readPendingDatagrams() {
|
|||
QString dataKey(QByteArray(reinterpret_cast<char*>(packetData + readBytes), numDataKeyBytes));
|
||||
readBytes += dataKey.size() + sizeof('\0');
|
||||
|
||||
qDebug("Sending command to redis: GET uuid:%s:%s\n",
|
||||
qDebug("Sending command to redis: GET uuid:%s:%s",
|
||||
qPrintable(uuidStringWithoutCurlyBraces(parsedUUID)),
|
||||
qPrintable(dataKey));
|
||||
redisReply* reply = (redisReply*) redisCommand(_redis, "GET uuid:%s:%s",
|
||||
|
@ -182,16 +178,21 @@ void DataServer::readPendingDatagrams() {
|
|||
|
||||
freeReplyObject(reply);
|
||||
}
|
||||
|
||||
// null terminate the packet we're sending back (erases the trailing separator)
|
||||
packetData[(numSendPacketBytes - 1)] = '\0';
|
||||
} else {
|
||||
// user is asking for a UUID matching username, copy the UUID we found
|
||||
QString uuidString = uuidStringWithoutCurlyBraces(parsedUUID);
|
||||
memcpy(packetData + numSendPacketBytes, uuidString.constData(), uuidString.size() + sizeof('\0'));
|
||||
numSendPacketBytes = uuidString.size() + sizeof('\0');
|
||||
numSendPacketBytes += uuidString.size() + sizeof('\0');
|
||||
}
|
||||
|
||||
// reply back with the send packet
|
||||
_socket.writeDatagram(reinterpret_cast<char*>(packetData), numSendPacketBytes,
|
||||
senderAddress, senderPort);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,16 @@
|
|||
|
||||
#include "DataServer.h"
|
||||
|
||||
const char DATA_SERVER_LOGGING_TARGET_NAME[] = "data-server";
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
||||
|
||||
Logging::setTargetName(DATA_SERVER_LOGGING_TARGET_NAME);
|
||||
|
||||
DataServer dataServer(argc, argv);
|
||||
|
||||
return dataServer.exec();
|
||||
|
|
|
@ -24,7 +24,7 @@ quint8 DataServerClient::_sequenceNumber = 0;
|
|||
|
||||
const char MULTI_KEY_VALUE_SEPARATOR = '|';
|
||||
|
||||
const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io";
|
||||
const char DATA_SERVER_HOSTNAME[] = "localhost";
|
||||
const unsigned short DATA_SERVER_PORT = 3282;
|
||||
|
||||
const HifiSockAddr& DataServerClient::dataServerSockAddr() {
|
||||
|
@ -35,7 +35,7 @@ const HifiSockAddr& DataServerClient::dataServerSockAddr() {
|
|||
void DataServerClient::putValueForKey(const QString& key, const char* value) {
|
||||
if (!_clientIdentifier.isEmpty()) {
|
||||
|
||||
static unsigned char putPacket[MAX_PACKET_SIZE];
|
||||
unsigned char putPacket[MAX_PACKET_SIZE];
|
||||
|
||||
// setup the header for this packet
|
||||
int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
|
||||
|
@ -88,7 +88,7 @@ void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QU
|
|||
void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString,
|
||||
DataServerCallbackObject* callbackObject) {
|
||||
if (!userString.isEmpty() && keys.size() <= UCHAR_MAX) {
|
||||
static unsigned char getPacket[MAX_PACKET_SIZE];
|
||||
unsigned char getPacket[MAX_PACKET_SIZE];
|
||||
|
||||
// setup the header for this packet
|
||||
int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
|
||||
|
@ -146,19 +146,15 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int
|
|||
DataServerCallbackObject* callbackObject = _callbackObjects.take(_sequenceNumber);
|
||||
|
||||
char* userStringPosition = (char*) packetData + numHeaderBytes + sizeof(_sequenceNumber);
|
||||
QString userString(userStringPosition);
|
||||
|
||||
QString userString(QByteArray(userStringPosition, strlen(userStringPosition)));
|
||||
|
||||
QUuid userUUID(userString);
|
||||
|
||||
char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition)
|
||||
+ sizeof('\0') + sizeof(unsigned char);
|
||||
char* keysPosition = userStringPosition + userString.size() + sizeof('\0') + sizeof(unsigned char);
|
||||
char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0');
|
||||
|
||||
QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR);
|
||||
QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR);
|
||||
|
||||
callbackObject->processDataServerResponse(userUUID, keyList, valueList);
|
||||
callbackObject->processDataServerResponse(userString, keyList, valueList);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
class DataServerCallbackObject {
|
||||
public:
|
||||
virtual void processDataServerResponse(const QUuid& userUUID, const QStringList& keyList, const QStringList& valueList) = 0;
|
||||
virtual void processDataServerResponse(const QString& userString, const QStringList& keyList, const QStringList& valueList) = 0;
|
||||
};
|
||||
|
||||
class DataServerClient {
|
||||
|
|
|
@ -146,7 +146,7 @@ void Profile::loadData(QSettings* settings) {
|
|||
settings->endGroup();
|
||||
}
|
||||
|
||||
void Profile::processDataServerResponse(const QUuid& userUUID, const QStringList& keyList, const QStringList& valueList) {
|
||||
void Profile::processDataServerResponse(const QString& userString, const QStringList& keyList, const QStringList& valueList) {
|
||||
qDebug() << "Called with" << keyList << valueList;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
void saveData(QSettings* settings);
|
||||
void loadData(QSettings* settings);
|
||||
|
||||
void processDataServerResponse(const QUuid& userUUID, const QStringList& keyList, const QStringList& valueList);
|
||||
void processDataServerResponse(const QString& userString, const QStringList& keyList, const QStringList& valueList);
|
||||
private:
|
||||
|
||||
void setUsername(const QString& username);
|
||||
|
|
Loading…
Reference in a new issue