Skip to content

Commit

Permalink
Refactor RemoteConfig ConfigInfo swig generation (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-maurice authored May 8, 2024
1 parent a7ab6b5 commit d1d97e4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 53 deletions.
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

0 comments on commit d1d97e4

Please sign in to comment.