Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RemoteConfig ConfigInfo swig generation #961

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions remote_config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions remote_config/src/ConfigInfo.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
9 changes: 5 additions & 4 deletions remote_config/src/FirebaseRemoteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigInfo> EnsureInitializedAsync() {
public async System.Threading.Tasks.Task<ConfigInfo> EnsureInitializedAsync() {
ThrowIfNull();
return remoteConfigInternal.EnsureInitializedAsync();
ConfigInfoInternal configInfoInternal = await remoteConfigInternal.EnsureInitializedAsync();
return new ConfigInfo(configInfoInternal);
}

/// @brief Asynchronously activates the most recently fetched configs,
Expand Down Expand Up @@ -323,11 +324,11 @@ public IDictionary<string, ConfigValue> 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());
}
}

Expand Down
56 changes: 7 additions & 49 deletions remote_config/src/swig/remote_config.i
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<ConfigInfo>

// Rename the generated classes to *Internal
%rename (ConfigInfoInternal) firebase::remote_config::ConfigInfo;
%SWIG_FUTURE(Future_ConfigInfo, ConfigInfoInternal, internal,
firebase::remote_config::ConfigInfo, FirebaseException) // Future<ConfigInfoInternal>
%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.
Expand Down
Loading