Skip to content

Commit 2c2740c

Browse files
authored
4.1.0 (#22)
# Analytics SDK for C++ - Version 4.1.0 ## ⚠️ Important Update - **Version 4.0.0 is deprecated**. A **mandatory update** to version 4.1.0 is required to ensure continued support, optimal performance, and access to future updates. ## 🚀 New Features - **Boot Time in Milliseconds**: Boot time now reported in milliseconds for precise performance metrics. ## 🐛 Bug Fixes - **Design Event Values**: Improved the consistency of design event value handling, ensuring more accurate data delivery. ## ✨ Enhancements - **Local Cache Path**: Refined the local cache path configuration to automatically use the default writable path, streamlining setup by making `configureWritablePath` optional.
1 parent d2c8629 commit 2c2740c

File tree

15 files changed

+90
-57
lines changed

15 files changed

+90
-57
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: cmake --build . --target cov_data
3535

3636
- name: Report code coverage
37-
uses: zgosalvez/github-actions-report-lcov@v3
37+
uses: zgosalvez/github-actions-report-lcov@v4
3838
with:
3939
coverage-files: build/cov.info.cleaned
4040
minimum-coverage: 30

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
Changelog
1+
# Changelog
2+
3+
## 4.1.0
4+
5+
### Added
6+
7+
- **Boot Time in Milliseconds**: Boot time now reported in milliseconds for precise performance metrics.
8+
9+
### Fixed
10+
11+
- **Design Event Values**: Improved the consistency of design event value handling, ensuring more accurate data delivery.
12+
- **Local Cache Path**: Refined the local cache path configuration to automatically use the default writable path, streamlining setup by making `configureWritablePath` optional.
13+
- **Verbose Logging**: more logs are not visible when verbose logging is enabled.
14+
215
---------
316

17+
## Older deprecated versions
18+
419
**4.0.0**
520

621
* updated to C++17

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,7 @@ if (ENABLE_COVERAGE)
273273
)
274274

275275
target_link_libraries(
276-
GameAnalytics
277-
PRIVATE
278-
--coverage
276+
GameAnalytics PRIVATE -fprofile-arcs -ftest-coverage
279277
)
280278

281279
set(covname cov)
@@ -289,13 +287,22 @@ if (ENABLE_COVERAGE)
289287
COMMAND GameAnalyticsUnitTests
290288

291289
# Capturing lcov counters and generating report
292-
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${covname}.info
290+
291+
COMMAND echo "Processing code coverage counters and generating report."
292+
293+
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${covname}.info --branch-coverage --rc geninfo_unexecuted_blocks=1 --rc no_exception_branch=1
294+
295+
COMMAND echo "Removing unwanted files from coverage report."
296+
293297
COMMAND ${LCOV_PATH} --remove ${covname}.info
294298
'${CMAKE_SOURCE_DIR}/source/dependencies/*'
295299
'${CMAKE_SOURCE_DIR}/test/*'
296300
'/usr/*'
297301
'/Applications/Xcode.app/*'
298302
--output-file ${covname}.info.cleaned
303+
--ignore-errors unused
304+
305+
COMMAND echo "Finished processing code coverage counters and generating report."
299306
)
300307

301308
if (GENHTML_PATH)

README.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,7 @@ Dependencies
2323
Changelog
2424
------------
2525

26-
**4.0.0**
27-
28-
* updated to C++17
29-
* public functions will now expect `std::string` instead of `const char*`
30-
* configureAvailableCustomDimensions, configureAvailableResourceCurrencies and configureAvailableItemTypes will now require a `std::vector<std::string>` as argument
31-
* removed duplicated public functions, replaced with default arguments
32-
* added argument for IRemoteConfigsListener callback
33-
* rewritten build scripts, now requires python3
34-
* changed user id logic to always use randomized id (except if custom id is set)
35-
* replaced usage of unsafe cstrings and functions with safer alternatives
36-
* refactored the internal codebase
37-
* rewritten threading logic
38-
* replaced RapidJson
39-
* removed Tizien support
40-
* added SDK init event
41-
* added health event
42-
* added external user id
43-
* safer handling of device properties retrieval
44-
* added exception handling
45-
* improved stability
46-
* various bug fixes
47-
* added sample app
26+
See the full [CHANGELOG](./CHANGELOG) for detailed version history.
4827

4928
How to build
5029
------------

sample/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include "GameAnalytics/GameAnalytics.h"
66

7-
constexpr const char* GAME_KEY = "bd624ee6f8e6efb32a054f8d7ba11618";
8-
constexpr const char* SECRET_KEY = "7f5c3f682cbd217841efba92e92ffb1b3b6612bc";
7+
constexpr const char* GAME_KEY = "INSERT_GAME_KEY";
8+
constexpr const char* SECRET_KEY = "INSERT_SECRET_KEY";
99

1010
struct RemoteConfigs:
1111
public gameanalytics::IRemoteConfigsListener

source/dependencies/crossguid/guid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ THE SOFTWARE.
3636
#include <string_view>
3737
#include <utility>
3838
#include <iomanip>
39+
#include <cinttypes>
3940

4041
#define BEGIN_XG_NAMESPACE namespace xg {
4142
#define END_XG_NAMESPACE }

source/gameanalytics/GACommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace gameanalytics
8585
class GAState;
8686
}
8787

88-
constexpr const char* GA_VERSION_STR = "cpp 4.0.0-alpha";
88+
constexpr const char* GA_VERSION_STR = "cpp 4.1.0";
8989

9090
constexpr int MAX_CUSTOM_FIELDS_COUNT = 50;
9191
constexpr int MAX_CUSTOM_FIELDS_KEY_LENGTH = 64;

source/gameanalytics/GALogger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "GAUtilities.h"
99
#include "GAState.h"
1010

11+
#define ZF_LOG_SRCLOC ZF_LOG_SRCLOC_NONE
1112
#define ZF_LOG_LEVEL ZF_LOG_VERBOSE
1213
#define ZF_LOG_BUF_SZ 2048
1314
#include "zf_log.h"

source/gameanalytics/GALogger.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include "GACommon.h"
99
#include "GAUtilities.h"
1010

11-
#define ZF_LOG_SRCLOC ZF_LOG_SRCLOC_NONE
12-
#include "zf_log.h"
11+
struct zf_log_message;
1312

1413
namespace gameanalytics
1514
{

source/gameanalytics/GAStore.cpp

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,32 +207,67 @@ namespace gameanalytics
207207
return sqlDatabase;
208208
}
209209

210-
bool GAStore::ensureDatabase(bool dropDatabase, std::string const& key)
210+
bool GAStore::fixOldDatabase()
211+
{
212+
std::filesystem::path oldPath = dbPath;
213+
std::filesystem::path filename = oldPath.filename();
214+
215+
oldPath = oldPath.parent_path() / ".." / filename;
216+
217+
if(std::filesystem::exists(oldPath) && !std::filesystem::exists(dbPath))
218+
{
219+
try
220+
{
221+
std::filesystem::rename(oldPath, dbPath);
222+
}
223+
catch(...)
224+
{
225+
return false;
226+
}
227+
228+
return true;
229+
}
230+
231+
return false;
232+
}
233+
234+
bool GAStore::initDatabaseLocation()
211235
{
212-
// lazy creation of db path
213-
if(getInstance().dbPath.empty())
236+
constexpr const char* DATABASE_NAME = "ga.sqlite3";
237+
238+
std::filesystem::path p = device::GADevice::getWritablePath();
239+
240+
p /= state::GAState::getGameKey();
241+
242+
dbPath = (p / DATABASE_NAME).string();
243+
if(!std::filesystem::exists(p))
214244
{
215-
std::string path = device::GADevice::getWritablePath();
216-
path += "/ga.sqlite3";
245+
if(!std::filesystem::create_directory(p))
246+
return false;
217247

218-
getInstance().dbPath = path;
248+
fixOldDatabase();
219249
}
220250

221-
const std::string dbPath = getInstance().dbPath;
251+
return true;
252+
}
222253

254+
bool GAStore::ensureDatabase(bool dropDatabase, std::string const& key)
255+
{
256+
getInstance().initDatabaseLocation();
257+
223258
// Open database
224-
if (sqlite3_open(dbPath.c_str(), &getInstance().sqlDatabase) != SQLITE_OK)
259+
if (sqlite3_open(getInstance().dbPath.c_str(), &getInstance().sqlDatabase) != SQLITE_OK)
225260
{
226261
getInstance().dbReady = false;
227-
logging::GALogger::w("Could not open database: %s", dbPath.c_str());
262+
logging::GALogger::w("Could not open database: %s", getInstance().dbPath.c_str());
228263
return false;
229264
}
230265
else
231266
{
232267
getInstance().dbReady = true;
233-
logging::GALogger::i("Database opened: %s", dbPath.c_str());
268+
logging::GALogger::i("Database opened: %s", getInstance().dbPath.c_str());
234269
}
235-
270+
236271
if (dropDatabase)
237272
{
238273
logging::GALogger::d("Drop tables");

source/gameanalytics/GAStore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ namespace gameanalytics
5050

5151
static GAStore& getInstance();
5252

53+
bool fixOldDatabase();
5354
bool trimEventTable();
55+
56+
bool initDatabaseLocation();
5457

5558
// set when calling "ensureDatabase"
5659
// using a "writablePath" that needs to be set into the C++ component before

source/gameanalytics/GameAnalytics.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ namespace gameanalytics
356356
{
357357
return;
358358
}
359-
360-
359+
361360
threading::GAThreading::performTaskOnGAThread([gameKey, gameSecret]()
362361
{
363362
if (isSdkReady(true, false))
@@ -517,7 +516,7 @@ namespace gameanalytics
517516
try
518517
{
519518
json fieldsJson = utilities::parseFields(fields);
520-
events::GAEvents::addDesignEvent(eventId, value, false, fieldsJson, mergeFields);
519+
events::GAEvents::addDesignEvent(eventId, value, true, fieldsJson, mergeFields);
521520
}
522521
catch(json::exception const& e)
523522
{
@@ -739,11 +738,6 @@ namespace gameanalytics
739738
});
740739
}
741740

742-
std::string GameAnalytics::getRemoteConfigsValueAsString(std::string const& key)
743-
{
744-
return getRemoteConfigsValueAsString(key, "");
745-
}
746-
747741
std::string GameAnalytics::getRemoteConfigsValueAsString(std::string const& key, std::string const& defaultValue)
748742
{
749743
return state::GAState::getRemoteConfigsStringValue(key, defaultValue);

source/gameanalytics/Platform/GADevicePlatform.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,3 @@ namespace gameanalytics
4949
return std::make_unique<GADevicePlatform>();
5050
}
5151
}
52-
53-

source/gameanalytics/Platform/GAMacOS.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ int64_t gameanalytics::GAPlatformMacOS::getBootTime() const
259259
struct timeval currentTime = {};
260260

261261
gettimeofday(&currentTime, NULL);
262-
263-
return currentTime.tv_sec - startTime.tv_sec;
262+
263+
int64_t remainingMs = static_cast<double>(currentTime.tv_usec - startTime.tv_usec) * 1e-3;
264+
return (currentTime.tv_sec - startTime.tv_sec) * 1000 + remainingMs;
264265
}
265266

266267
#endif

source/gameanalytics/Platform/GAWin32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int64_t GAPlatformWin32::getBootTime() const
332332

333333
// filetime is expressed in 100s of nanoseconds
334334
std::chrono::nanoseconds timeInNs = std::chrono::nanoseconds(value * 100);
335-
return std::chrono::duration_cast<std::chrono::seconds>(timeInNs).count();
335+
return std::chrono::duration_cast<std::chrono::milliseconds>(timeInNs).count();
336336
}
337337

338338
return 0ll;

0 commit comments

Comments
 (0)