Skip to content

Commit 7d65eaa

Browse files
committed
fixes for win32
1 parent 5577e70 commit 7d65eaa

22 files changed

+206
-195
lines changed

source/gameanalytics/GACommon.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
#include "GAConstants.h"
44

5+
#if IS_MAC
6+
#include <sys/sysctl.h>
7+
#elif IS_WIN32
8+
#include <winsock2.h>
9+
#include <windows.h>
10+
#elif IS_UWP
11+
#include <winsock2.h>
12+
#include <windows.h>
13+
#elif IS_LINUX
14+
#include <sys/utsname.h>
15+
#include <sys/types.h>
16+
#include <sys/stat.h>
17+
#endif
18+
19+
520
#include <string>
621
#include <vector>
722
#include <cinttypes>
@@ -25,28 +40,20 @@
2540

2641
#include "nlohmann/json.hpp"
2742

28-
#if IS_MAC
29-
#include <sys/sysctl.h>
30-
#elif IS_LINUX
31-
#include <sys/utsname.h>
32-
#include <sys/types.h>
33-
#include <sys/stat.h>
34-
#endif
35-
3643
namespace gameanalytics
3744
{
38-
using nlohmann::json;
45+
using nlohmann::json;
3946
using StringVector = std::vector<std::string>;
4047

4148
using LogHandler = std::function<void(std::string const&, EGALoggerMessageType)>;
4249
using FPSTracker = std::function<float()>;
4350

44-
namespace state
45-
{
46-
class GAState;
47-
}
51+
namespace state
52+
{
53+
class GAState;
54+
}
4855

49-
struct IRemoteConfigsListener
56+
struct IRemoteConfigsListener
5057
{
5158
virtual void onRemoteConfigsUpdated(std::string const& remoteConfigs) = 0;
5259
};

source/gameanalytics/GADevice.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ namespace gameanalytics
3939
if(getInstance()._platform)
4040
{
4141
getInstance()._platform->onInit();
42-
4342
if(state::GAState::useErrorReporting())
4443
{
4544
getInstance()._platform->setupUncaughtExceptionHandler();

source/gameanalytics/GAEvents.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ namespace gameanalytics
802802
const std::string jsonString = ev.dump();
803803

804804
// output if VERBOSE LOG enabled
805-
logging::GALogger::ii("Event added to queue: %s", jsonString.c_str());
805+
logging::GALogger::v("Event added to queue: %s", jsonString.c_str());
806806

807807
// Add to store
808808
std::string const clientTS = std::to_string(ev["client_ts"].get<int64_t>());

source/gameanalytics/GAHTTPApi.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,11 @@ namespace gameanalytics
1616
{
1717
size_t writefunc(void *ptr, size_t size, size_t nmemb, ResponseData *s)
1818
{
19-
const size_t new_len = s->len + size*nmemb;
19+
const size_t new_len = s->packet.size() + size * nmemb + 1;
20+
s->packet.reserve(new_len);
2021

21-
if (s->ptr)
22-
{
23-
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(new_len);
24-
25-
if (!buffer) // maybe just return instead?
26-
throw std::runtime_error("Failed to allocate buffer!");
27-
28-
std::memcpy(buffer.get(), s->ptr.get(), s->len);
29-
s->ptr = std::move(buffer);
30-
}
31-
else
32-
{
33-
s->ptr = std::make_unique<char[]>(new_len);
34-
}
35-
36-
std::memcpy(s->ptr.get() + s->len, ptr, size * nmemb);
37-
s->ptr[new_len] = '\0';
38-
s->len = new_len;
22+
s->packet.insert(s->packet.end(), reinterpret_cast<char*>(ptr), reinterpret_cast<char*>(ptr) + size * nmemb);
23+
s->packet.push_back('\0');
3924

4025
return size*nmemb;
4126
}
@@ -83,7 +68,7 @@ namespace gameanalytics
8368
std::string jsonString = initAnnotations.dump();
8469
if (jsonString.empty())
8570
{
86-
return; JsonEncodeFailed;
71+
return JsonEncodeFailed;
8772
}
8873

8974
std::vector<uint8_t> payloadData = createPayloadData(jsonString, useGzip);
@@ -121,7 +106,7 @@ namespace gameanalytics
121106

122107
json requestJsonDict = json::parse(s.toString());
123108

124-
EGAHTTPApiResponse requestResponseEnum = processRequestResponse(response_code, s.ptr.get(), "Init");
109+
EGAHTTPApiResponse requestResponseEnum = processRequestResponse(response_code, s.packet.data(), "Init");
125110

126111
// if not 200 result
127112
if (requestResponseEnum != Ok && requestResponseEnum != Created && requestResponseEnum != BadRequest)
@@ -224,7 +209,7 @@ namespace gameanalytics
224209

225210
logging::GALogger::d("body: %s", s.toString().c_str());
226211

227-
EGAHTTPApiResponse requestResponseEnum = processRequestResponse(response_code, s.ptr.get(), "Events");
212+
EGAHTTPApiResponse requestResponseEnum = processRequestResponse(response_code, s.packet.data(), "Events");
228213

229214
// if not 200 result
230215
if (requestResponseEnum != Ok && requestResponseEnum != Created && requestResponseEnum != BadRequest)
@@ -477,13 +462,7 @@ namespace gameanalytics
477462

478463
std::string ResponseData::toString() const
479464
{
480-
std::string str;
481-
if (ptr && len)
482-
{
483-
str = std::string(ptr.get(), len);
484-
}
485-
486-
return str;
465+
return std::string(packet.begin(), packet.end());
487466
}
488467
}
489468
}

source/gameanalytics/GAHTTPApi.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#pragma once
77

8-
8+
#include "GACommon.h"
9+
#include <curl/curl.h>
910

1011
#include <vector>
1112
#include <map>
12-
#include <curl/curl.h>
1313
#include <mutex>
1414
#include <cstdlib>
1515
#include <tuple>
@@ -104,9 +104,7 @@ namespace gameanalytics
104104

105105
struct ResponseData
106106
{
107-
std::unique_ptr<char[]> ptr;
108-
std::size_t len = 0;
109-
107+
std::vector<char> packet;
110108
std::string toString() const;
111109
};
112110

@@ -132,17 +130,9 @@ namespace gameanalytics
132130

133131
static GAHTTPApi& getInstance();
134132

135-
#if USE_UWP
136-
concurrency::task<std::pair<EGAHTTPApiResponse, std::string>> requestInitReturningDict(const char* configsHash);
137-
concurrency::task<std::pair<EGAHTTPApiResponse, std::string>> sendEventsInArray(const rapidjson::Value& eventArray);
138-
void sendSdkErrorEvent(EGASdkErrorCategory category, EGASdkErrorArea area, EGASdkErrorAction action, EGASdkErrorParameter parameter, std::string reason, std::string gameKey, std::string secretKey);
139-
#else
140133
EGAHTTPApiResponse requestInitReturningDict(json& json_out, std::string const& configsHash);
141134
EGAHTTPApiResponse sendEventsInArray(json& json_out, const json& eventArray);
142-
void sendSdkErrorEvent(EGASdkErrorCategory category, EGASdkErrorArea area, EGASdkErrorAction action, EGASdkErrorParameter parameter, std::string const& reason, std::string const& gameKey, std::string const& secretKey);
143-
#endif
144-
145-
135+
void sendSdkErrorEvent(EGASdkErrorCategory category, EGASdkErrorArea area, EGASdkErrorAction action, EGASdkErrorParameter parameter, std::string const& reason, std::string const& gameKey, std::string const& secretKey);
146136

147137
private:
148138

@@ -152,14 +142,9 @@ namespace gameanalytics
152142
GAHTTPApi& operator=(const GAHTTPApi&) = delete;
153143
std::vector<uint8_t> createPayloadData(std::string const& payload, bool gzip);
154144

155-
#if USE_UWP && defined(USE_UWP_HTTPAPI)
156-
std::vector<char> createRequest(Windows::Web::Http::HttpRequestMessage^ message, const std::string& url, const std::vector<char>& payloadData, bool gzip);
157-
EGAHTTPApiResponse processRequestResponse(Windows::Web::Http::HttpResponseMessage^ response, const std::string& requestId);
158-
concurrency::task<Windows::Storage::Streams::InMemoryRandomAccessStream^> createStream(std::string data);
159-
#else
160145
std::vector<uint8_t> createRequest(CURL *curl, std::string const& url, const std::vector<uint8_t>& payloadData, bool gzip);
161146
EGAHTTPApiResponse processRequestResponse(long statusCode, const char* body, const char* requestId);
162-
#endif
147+
163148
std::string protocol = PROTOCOL;
164149
std::string hostName = HOST_NAME;
165150
std::string version = VERSION;

source/gameanalytics/GALogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace gameanalytics
9696
}
9797

9898
template<typename ...args_t>
99-
static void ii(std::string const& fmt, args_t&&... args)
99+
static void v(std::string const& fmt, args_t&&... args)
100100
{
101101
sendMessage(LogVerbose, fmt, std::forward<args_t>(args)...);
102102
}

source/gameanalytics/GAState.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ namespace gameanalytics
197197

198198
json& GAState::getSdkConfig()
199199
{
200-
201200
if (getInstance()._sdkConfig.is_object())
202201
{
203202
return _sdkConfig;
@@ -505,14 +504,6 @@ namespace gameanalytics
505504
{
506505
_identifier = _userId;
507506
}
508-
else if(!device::GADevice::getAdvertisingId().empty() && _enableIdTracking)
509-
{
510-
_identifier = device::GADevice::getAdvertisingId();
511-
}
512-
else if (!device::GADevice::getDeviceId().empty() && _enableIdTracking)
513-
{
514-
_identifier = device::GADevice::getDeviceId();
515-
}
516507
else
517508
{
518509
_identifier = _defaultUserId;
@@ -526,7 +517,7 @@ namespace gameanalytics
526517
{
527518
if (!value.empty())
528519
{
529-
store::GAStore::setState(key.c_str(), value.c_str());
520+
store::GAStore::setState(key, value);
530521
return value;
531522
}
532523
else if(dict.contains(key) && dict[key].is_string())

source/gameanalytics/GAStore.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ namespace gameanalytics
5959
// local pointer to database
6060
sqlite3* sqlDatabase = nullptr;
6161

62-
// 10 MB limit for database. Will initiate trim logic when exceeded.
63-
// long maxDbSizeBytes = 10485760;
64-
6562
// ??
6663
bool dbReady = false;
64+
6765
// bool to determine if tables are ensured ready
6866
bool tableReady = false;
6967
};

source/gameanalytics/GAUtilities.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
#include <climits>
1414
#include <cctype>
1515

16-
#if USE_UWP
17-
#include <Objbase.h>
18-
#else
19-
#include <hmac_sha2.h>
20-
#include <guid.h>
21-
#endif
16+
#include <hmac_sha2.h>
17+
#include <guid.h>
2218

2319
#include "GAConstants.h"
2420
#include "stacktrace/call_stack.hpp"
@@ -330,30 +326,10 @@ namespace gameanalytics
330326

331327
std::string GAUtilities::generateUUID()
332328
{
333-
char out[UUID_STR_LENGTH] = "";
334-
335-
#if USE_UWP
336-
GUID result;
337-
CoCreateGuid(&result);
338-
339-
//if (SUCCEEDED(hr))
340-
{
341-
// Generate new GUID.
342-
Platform::Guid guid(result);
343-
auto guidString = std::wstring(guid.ToString()->Data());
344-
345-
// Remove curly brackets.
346-
auto sessionId = guidString.substr(1, guidString.length() - 2);
347-
std::string result = ws2s(sessionId);
348-
snprintf(out, result.size() + 1, "%s", result.c_str());
349-
}
350-
#else
351-
GuidGenerator generator;
352-
auto myGuid = generator.newGuid();
353-
myGuid.to_string(out);
354-
#endif
355-
356-
return out;
329+
xg::Guid guid = xg::newGuid();
330+
std::stringstream stream;
331+
stream << guid;
332+
return stream.str();
357333
}
358334

359335
// TODO(nikolaj): explain function

source/gameanalytics/GAUtilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#pragma once
77

8-
#include <vector>
98
#include "GACommon.h"
9+
#include <vector>
1010
#include <string>
1111
#include <locale>
1212
#include <codecvt>

0 commit comments

Comments
 (0)