History

add API for Profile userString and multiple value requests

Stephen Birarda committed 13 years ago

Commit 32317761 parent d66137e4 files · +46 −31Browse files

Showing the changes to interface/src/DataServerClient.cpp (1 of 4 files). Show all

Unified · Split

interface/src/DataServerClient.cpp+31−30
@@ -26,11 +26,7 @@ const unsigned short DATA_SERVER_PORT = 3282; · 25 unmodified lines
2626 const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
2727
2828 void DataServerClient::putValueForKey(const char* key, const char* value) {
29− Profile* userProfile = Application::getInstance()->getProfile();
30− QString clientString = userProfile->getUUID().isNull()
31− ? userProfile->getUsername()
32− : uuidStringWithoutCurlyBraces(userProfile->getUUID().toString());
33−
29+ QString clientString = Application::getInstance()->getProfile()->getUserString();
3430 if (!clientString.isEmpty()) {
3531
3632 unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
@@ -62,40 +58,45 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 25 unmodified lines
6258 }
6359
6460 void DataServerClient::getValueForKeyAndUUID(const char* key, const QUuid &uuid) {
61+ getValuesForKeysAndUUID(QStringList(QString(key)), uuid);
62+}
63+
64+void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QUuid& uuid) {
6565 if (!uuid.isNull()) {
66− getValueForKeyAndUserString(key, uuidStringWithoutCurlyBraces(uuid));
66+ getValuesForKeysAndUserString(keys, uuidStringWithoutCurlyBraces(uuid));
6767 }
6868 }
6969
70−void DataServerClient::getValueForKeyAndUserString(const char* key, const QString& userString) {
71− unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE];
72−
73− // setup the header for this packet
74− int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
75−
76− // pack the user string (could be username or UUID string), null-terminate
77− memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
78− numPacketBytes += userString.toLocal8Bit().size();
79− getPacket[numPacketBytes++] = '\0';
80−
81− // pack the key, null terminated
82− strcpy((char*) getPacket + numPacketBytes, key);
83− int numKeyBytes = strlen(key);
84−
85− if (numKeyBytes > 0) {
86− numPacketBytes += numKeyBytes;
70+void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString) {
71+ if (!userString.isEmpty()) {
72+ unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE];
73+
74+ // setup the header for this packet
75+ int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
76+
77+ // pack the user string (could be username or UUID string), null-terminate
78+ memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
79+ numPacketBytes += userString.toLocal8Bit().size();
8780 getPacket[numPacketBytes++] = '\0';
81+
82+ for (int i = 0; i < keys.size(); ++i) {
83+ // pack the keys, null terminated
84+ strcpy((char*) getPacket + numPacketBytes, keys[i].toLocal8Bit().constData());
85+
86+ numPacketBytes += keys[i].size();
87+ getPacket[numPacketBytes++] = '\0';
88+ }
89+
90+ // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver
91+ _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));
92+
93+ // send the get to the data server
94+ NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);
8895 }
89−
90− // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver
91− _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));
92−
93− // send the get to the data server
94− NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes);
9596 }
9697
9798 void DataServerClient::getClientValueForKey(const char* key) {
98− getValueForKeyAndUserString(key, Application::getInstance()->getProfile()->getUsername());
99+ getValuesForKeysAndUserString(QStringList(QString(key)), Application::getInstance()->getProfile()->getUserString());
99100 }
100101
101102 void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {