diff --git a/remote_config/CMakeLists.txt b/remote_config/CMakeLists.txt index 5e6cd7ae..d4fcea0b 100644 --- a/remote_config/CMakeLists.txt +++ b/remote_config/CMakeLists.txt @@ -23,6 +23,7 @@ set(firebase_remote_config_swig # Firebase RemoteConfig CSharp files set(firebase_remote_config_src + src/ConfigInfo.cs src/ConfigSettings.cs src/ConfigUpdateEventArgs.cs src/ConfigValue.cs diff --git a/remote_config/src/ConfigInfo.cs b/remote_config/src/ConfigInfo.cs new file mode 100644 index 00000000..376f58a3 --- /dev/null +++ b/remote_config/src/ConfigInfo.cs @@ -0,0 +1,47 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Firebase.RemoteConfig { + +/// @brief Describes the state of the most recent Fetch() call. +/// Normally returned as a result of the GetInfo() function. +public sealed class ConfigInfo { + + private System.DateTime UnixEpochUtc = + new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); + + /// @brief The time when the last fetch operation completed. + public System.DateTime FetchTime { internal set; get; } + + /// @brief The time when Remote Config data refreshes will no longer + /// be throttled. + public System.DateTime ThrottledEndTime { internal set; get; } + + /// @brief The status of the last fetch request. + public LastFetchStatus LastFetchStatus { internal set; get; } + + /// @brief The reason the most recent fetch failed. + public FetchFailureReason LastFetchFailureReason { internal set; get; } + + internal ConfigInfo(ConfigInfoInternal configInfoInternal) { + FetchTime = UnixEpochUtc.AddMilliseconds(configInfoInternal.fetch_time); + ThrottledEndTime = UnixEpochUtc.AddMilliseconds(configInfoInternal.throttled_end_time); + LastFetchStatus = configInfoInternal.last_fetch_status; + LastFetchFailureReason = configInfoInternal.last_fetch_failure_reason; + } +} + +} diff --git a/remote_config/src/FirebaseRemoteConfig.cs b/remote_config/src/FirebaseRemoteConfig.cs index 908961ab..d70d1816 100644 --- a/remote_config/src/FirebaseRemoteConfig.cs +++ b/remote_config/src/FirebaseRemoteConfig.cs @@ -169,9 +169,10 @@ public static FirebaseRemoteConfig DefaultInstance { /// Use this method to ensure Set/Get call not being blocked. /// /// @returns A Task contains ConfigInfo. - public System.Threading.Tasks.Task EnsureInitializedAsync() { + public async System.Threading.Tasks.Task EnsureInitializedAsync() { ThrowIfNull(); - return remoteConfigInternal.EnsureInitializedAsync(); + ConfigInfoInternal configInfoInternal = await remoteConfigInternal.EnsureInitializedAsync(); + return new ConfigInfo(configInfoInternal); } /// @brief Asynchronously activates the most recently fetched configs, @@ -323,11 +324,11 @@ public IDictionary AllValues { } /// @brief Returns information about the last fetch request, in the form - /// of a @ref ConfigInfo struct. + /// of a @ref ConfigInfo object. public ConfigInfo Info { get { ThrowIfNull(); - return remoteConfigInternal.GetInfo(); + return new ConfigInfo(remoteConfigInternal.GetInfo()); } } diff --git a/remote_config/src/swig/remote_config.i b/remote_config/src/swig/remote_config.i index e6322262..4d1880e0 100644 --- a/remote_config/src/swig/remote_config.i +++ b/remote_config/src/swig/remote_config.i @@ -18,6 +18,9 @@ %pragma(csharp) moduleclassmodifiers="internal sealed class" %feature("flatnested"); +// Change the default class modifier to internal, so that new classes are not accidentally exposed +%typemap(csclassmodifiers) SWIGTYPE "internal class" + %include "std_vector.i" %include "stdint.i" @@ -116,57 +119,12 @@ void SetConfigUpdateCallback(RemoteConfig* rc, firebase::remote_config::ConfigUp %ignore firebase::remote_config::RemoteConfigError; %ignore firebase::remote_config::ConfigUpdateListenerRegistration; -// Configure the ConfigInfo class -%csmethodmodifiers fetch_time "internal"; -%rename(FetchTimeInternal) fetch_time; -%csmethodmodifiers throttled_end_time "internal"; -%rename(ThrottledEndTimeInternal) throttled_end_time; - -%typemap(cscode) firebase::remote_config::ConfigInfo %{ - private System.DateTime UnixEpochUtc = - new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); - - /// @brief The time when the last fetch operation completed. - public System.DateTime FetchTime { - get { - return UnixEpochUtc.AddMilliseconds(FetchTimeInternal); - } - } - - /// @brief The time when Remote Config data refreshes will no longer - /// be throttled. - public System.DateTime ThrottledEndTime { - get { - return UnixEpochUtc.AddMilliseconds(ThrottledEndTimeInternal); - } - } -%} - -%immutable firebase::remote_config::ConfigInfo::last_fetch_status; -%immutable firebase::remote_config::ConfigInfo::last_fetch_failure_reason; - -// These are here instead of the header due to b/35780150 -%csmethodmodifiers firebase::remote_config::ConfigInfo::last_fetch_status " - /// @brief The status of the last fetch request. - public"; -%csmethodmodifiers firebase::remote_config::ConfigInfo::last_fetch_failure_reason " - /// @brief The reason the most recent fetch failed. - public"; - -// Make snake_case properties into CamelCase. -// ConfigInfo -%rename(LastFetchFailureReason) last_fetch_failure_reason; -%rename(LastFetchStatus) last_fetch_status; - -%typemap(csclassmodifiers) firebase::remote_config::ConfigInfo - "public sealed class"; - -%SWIG_FUTURE(Future_ConfigInfo, ConfigInfo, internal, firebase::remote_config::ConfigInfo, FirebaseException) // Future - +// Rename the generated classes to *Internal +%rename (ConfigInfoInternal) firebase::remote_config::ConfigInfo; +%SWIG_FUTURE(Future_ConfigInfo, ConfigInfoInternal, internal, + firebase::remote_config::ConfigInfo, FirebaseException) // Future %rename (FirebaseRemoteConfigInternal) firebase::remote_config::RemoteConfig; - %rename (ConfigSettingsInternal) firebase::remote_config::ConfigSettings; - %rename (ConfigUpdateInternal) firebase::remote_config::ConfigUpdate; // Configure properties for get / set methods on the FirebaseRemoteConfigInternal class.