Skip to content

Commit 128896e

Browse files
authored
Fix: Update the log callback to use int32 instead of enum in dll (#1819)
* Fix: Update the log callback to use int32 instead of enum in dll The call to the dll will still leverage the enum. This should ensure ABI stability over time * fix formating * Replace the DLL with the signed version
1 parent 6dd384d commit 128896e

7 files changed

Lines changed: 103 additions & 42 deletions

File tree

analytics/src/analytics_desktop.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ LogLevel ConvertAnalyticsLogLevelToFirebaseLogLevel(
411411
}
412412
}
413413

414-
void GoogleAnalyticsWrapperLogCallback(GoogleAnalytics_LogLevel log_level,
415-
const char* message) {
414+
void GoogleAnalyticsWrapperLogCallback(int32_t log_level, const char* message) {
416415
LogCallback callback_to_call;
417416

418417
{
@@ -421,8 +420,8 @@ void GoogleAnalyticsWrapperLogCallback(GoogleAnalytics_LogLevel log_level,
421420
}
422421

423422
if (callback_to_call) {
424-
LogLevel firebase_log_level =
425-
ConvertAnalyticsLogLevelToFirebaseLogLevel(log_level);
423+
LogLevel firebase_log_level = ConvertAnalyticsLogLevelToFirebaseLogLevel(
424+
static_cast<GoogleAnalytics_LogLevel>(log_level));
426425
callback_to_call(firebase_log_level, message);
427426
}
428427
}

analytics/src/analytics_desktop_dynamic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ const char* FirebaseAnalytics_KnownWindowsDllHashes[] = {
3333
"c1b9ff6e9119c30bbeb7472326dcde418f45682e6b822e25eed922fe6e3cc698",
3434
"13ae5f9349b24186f1f3667b52832076e8d14ad9656c3546b1b7fca79ac8144b",
3535
"3f1fb1bb21bce0061c4b89bb674d3b6c94eaea2c8de98802198a35ea94c97900",
36-
"1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5"
36+
"1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5",
37+
"9127cffeb617f07197e13b40b09f756ae856f3a4f066115e6fc9d45d33293e7d"
3738
};
3839

3940
// Count of known Google Analytics Windows DLL SHA256 hashes.
40-
const int FirebaseAnalytics_KnownWindowsDllHashCount = 4;
41+
const int FirebaseAnalytics_KnownWindowsDllHashCount = 5;
4142
#endif // defined(_WIN32)
4243

4344
// --- Stub Function Definitions ---

analytics/src/analytics_desktop_dynamic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ typedef enum GoogleAnalytics_LogLevel {
113113
*
114114
* @param[in] message The log message string.
115115
*/
116-
typedef void (*GoogleAnalytics_LogCallback)(GoogleAnalytics_LogLevel log_level,
116+
typedef void (*GoogleAnalytics_LogCallback)(int32_t log_level,
117117
const char* message);
118118

119119
/**
611 KB
Binary file not shown.

analytics/windows/include/public/analytics.h

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ class Analytics {
132132
* The path must pre-exist and the app has read and write access to it.
133133
*/
134134
std::optional<std::string> app_data_directory;
135+
/**
136+
* @brief The duration of inactivity in seconds after which a session
137+
* terminates.
138+
*
139+
* If a user interacts with the app after this timeout period, a new session
140+
* is initiated. If this field is not set or a negative value is
141+
* provided, the SDK's default timeout duration is used.
142+
*/
143+
std::optional<int64_t> session_timeout_duration_seconds;
135144
};
136145

137146
/**
@@ -169,6 +178,8 @@ class Analytics {
169178
options.app_data_directory.value_or("").empty()
170179
? nullptr
171180
: options.app_data_directory.value().c_str();
181+
google_analytics_options->session_timeout_duration_seconds =
182+
options.session_timeout_duration_seconds.value_or(-1);
172183
return GoogleAnalytics_Initialize(google_analytics_options);
173184
}
174185

@@ -373,35 +384,49 @@ class Analytics {
373384
return;
374385
}
375386

376-
GoogleAnalytics_SetLogCallback(
377-
[](GoogleAnalytics_LogLevel log_level, const char* message) {
378-
LogLevel cpp_log_level;
379-
switch (log_level) {
380-
case GoogleAnalytics_LogLevel_kDebug:
381-
cpp_log_level = LogLevel::kDebug;
382-
break;
383-
case GoogleAnalytics_LogLevel_kInfo:
384-
cpp_log_level = LogLevel::kInfo;
385-
break;
386-
case GoogleAnalytics_LogLevel_kWarning:
387-
cpp_log_level = LogLevel::kWarning;
388-
break;
389-
case GoogleAnalytics_LogLevel_kError:
390-
cpp_log_level = LogLevel::kError;
391-
break;
392-
default:
393-
cpp_log_level = LogLevel::kInfo;
394-
}
395-
LogCallback local_callback;
396-
Analytics& self = Analytics::GetInstance();
397-
{
398-
std::lock_guard<std::mutex> lock(self.mutex_);
399-
local_callback = self.current_callback_;
400-
}
401-
if (local_callback) {
402-
local_callback(cpp_log_level, std::string(message));
403-
}
404-
});
387+
GoogleAnalytics_SetLogCallback([](int32_t log_level, const char* message) {
388+
LogLevel cpp_log_level;
389+
switch (log_level) {
390+
case GoogleAnalytics_LogLevel_kDebug:
391+
cpp_log_level = LogLevel::kDebug;
392+
break;
393+
case GoogleAnalytics_LogLevel_kInfo:
394+
cpp_log_level = LogLevel::kInfo;
395+
break;
396+
case GoogleAnalytics_LogLevel_kWarning:
397+
cpp_log_level = LogLevel::kWarning;
398+
break;
399+
case GoogleAnalytics_LogLevel_kError:
400+
cpp_log_level = LogLevel::kError;
401+
break;
402+
default:
403+
cpp_log_level = LogLevel::kInfo;
404+
}
405+
LogCallback local_callback;
406+
Analytics& self = Analytics::GetInstance();
407+
{
408+
std::lock_guard<std::mutex> lock(self.mutex_);
409+
local_callback = self.current_callback_;
410+
}
411+
if (local_callback) {
412+
local_callback(cpp_log_level, std::string(message));
413+
}
414+
});
415+
}
416+
417+
/**
418+
* @brief Sets the duration of inactivity in seconds after which a session
419+
* terminates.
420+
*
421+
* If a user interacts with the app after this timeout period, a new session
422+
* is initiated. If set to a negative value, the value is ignored. The default
423+
* value is 1800 seconds (30 minutes).
424+
*
425+
* @param[in] session_timeout_duration_seconds The session timeout duration in
426+
* seconds.
427+
*/
428+
void SetSessionTimeoutInterval(int64_t session_timeout_duration_seconds) {
429+
GoogleAnalytics_SetSessionTimeoutInterval(session_timeout_duration_seconds);
405430
}
406431

407432
/**

analytics/windows/include/public/c/analytics.h

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ typedef struct ANALYTICS_API GoogleAnalytics_Options {
8282
*/
8383
const char* app_data_directory;
8484

85+
/**
86+
* @brief The duration of inactivity in seconds after which a session
87+
* terminates.
88+
*
89+
* If a user interacts with the app after this timeout period,
90+
* a new session is initiated. If set to a negative value, the SDK's
91+
* default timeout duration is used.
92+
*/
93+
int64_t session_timeout_duration_seconds;
94+
8595
/**
8696
* @brief Reserved for internal use by the SDK.
8797
*/
@@ -137,9 +147,15 @@ typedef enum GoogleAnalytics_LogLevel {
137147
/**
138148
* @brief Function pointer type for a log callback.
139149
*
140-
* @param[in] message The log message string.
150+
* @param[in] message The log message string. Pass a value from the
151+
* #GoogleAnalytics_LogLevel enum.
152+
*
153+
* @note The parameters are defined as `int32_t` to ensure ABI stability across
154+
* different compilers, but callers should use the enum constants directly.
155+
*
156+
* @see GoogleAnalytics_LogLevel
141157
*/
142-
typedef void (*GoogleAnalytics_LogCallback)(GoogleAnalytics_LogLevel log_level,
158+
typedef void (*GoogleAnalytics_LogCallback)(int32_t log_level,
143159
const char* message);
144160

145161
/**
@@ -525,6 +541,20 @@ ANALYTICS_API void GoogleAnalytics_SetAnalyticsCollectionEnabled(bool enabled);
525541
ANALYTICS_API void GoogleAnalytics_SetLogCallback(
526542
GoogleAnalytics_LogCallback callback);
527543

544+
/**
545+
* @brief Sets the duration of inactivity in seconds after which a session
546+
* terminates.
547+
*
548+
* If a user interacts with the app after this timeout period, a new session is
549+
* initiated. If set to a negative value, the value is ignored. The default
550+
* value is 1800 seconds (30 minutes).
551+
*
552+
* @param[in] session_timeout_duration_seconds The session timeout duration in
553+
* seconds.
554+
*/
555+
ANALYTICS_API void GoogleAnalytics_SetSessionTimeoutInterval(
556+
int64_t session_timeout_duration_seconds);
557+
528558
/**
529559
* @brief Notifies the current state of the app's lifecycle.
530560
*
@@ -537,10 +567,15 @@ ANALYTICS_API void GoogleAnalytics_SetLogCallback(
537567
* data is uploaded or an error occurs. The caller must ensure the OS does not
538568
* terminate background threads before the call returns.
539569
*
540-
* @param[in] state The current state of the app's lifecycle.
570+
* @param[in] state The current state of the app's lifecycle. Pass a value from
571+
* the #GoogleAnalytics_AppLifecycleState enum.
572+
*
573+
* @note The parameters are defined as `int32_t` to ensure ABI stability across
574+
* different compilers, but callers should use the enum constants directly.
575+
*
576+
* @see GoogleAnalytics_AppLifecycleState
541577
*/
542-
ANALYTICS_API void GoogleAnalytics_NotifyAppLifecycleChange(
543-
GoogleAnalytics_AppLifecycleState state);
578+
ANALYTICS_API void GoogleAnalytics_NotifyAppLifecycleChange(int32_t state);
544579

545580
#ifdef __cplusplus
546581
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
c1b9ff6e9119c30bbeb7472326dcde418f45682e6b822e25eed922fe6e3cc698
22
13ae5f9349b24186f1f3667b52832076e8d14ad9656c3546b1b7fca79ac8144b
33
3f1fb1bb21bce0061c4b89bb674d3b6c94eaea2c8de98802198a35ea94c97900
4-
1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5
4+
1e944cd4a2b8d115a32d01f4cc900f23805934b5587b55305df9cd189f9d78d5
5+
9127cffeb617f07197e13b40b09f756ae856f3a4f066115e6fc9d45d33293e7d

0 commit comments

Comments
 (0)