Skip to content

Commit d1d97e4

Browse files
authored
Refactor RemoteConfig ConfigInfo swig generation (#961)
1 parent a7ab6b5 commit d1d97e4

File tree

4 files changed

+60
-53
lines changed

4 files changed

+60
-53
lines changed

remote_config/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(firebase_remote_config_swig
2323

2424
# Firebase RemoteConfig CSharp files
2525
set(firebase_remote_config_src
26+
src/ConfigInfo.cs
2627
src/ConfigSettings.cs
2728
src/ConfigUpdateEventArgs.cs
2829
src/ConfigValue.cs

remote_config/src/ConfigInfo.cs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
namespace Firebase.RemoteConfig {
18+
19+
/// @brief Describes the state of the most recent Fetch() call.
20+
/// Normally returned as a result of the GetInfo() function.
21+
public sealed class ConfigInfo {
22+
23+
private System.DateTime UnixEpochUtc =
24+
new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
25+
26+
/// @brief The time when the last fetch operation completed.
27+
public System.DateTime FetchTime { internal set; get; }
28+
29+
/// @brief The time when Remote Config data refreshes will no longer
30+
/// be throttled.
31+
public System.DateTime ThrottledEndTime { internal set; get; }
32+
33+
/// @brief The status of the last fetch request.
34+
public LastFetchStatus LastFetchStatus { internal set; get; }
35+
36+
/// @brief The reason the most recent fetch failed.
37+
public FetchFailureReason LastFetchFailureReason { internal set; get; }
38+
39+
internal ConfigInfo(ConfigInfoInternal configInfoInternal) {
40+
FetchTime = UnixEpochUtc.AddMilliseconds(configInfoInternal.fetch_time);
41+
ThrottledEndTime = UnixEpochUtc.AddMilliseconds(configInfoInternal.throttled_end_time);
42+
LastFetchStatus = configInfoInternal.last_fetch_status;
43+
LastFetchFailureReason = configInfoInternal.last_fetch_failure_reason;
44+
}
45+
}
46+
47+
}

remote_config/src/FirebaseRemoteConfig.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ public static FirebaseRemoteConfig DefaultInstance {
169169
/// Use this method to ensure Set/Get call not being blocked.
170170
///
171171
/// @returns A Task contains ConfigInfo.
172-
public System.Threading.Tasks.Task<ConfigInfo> EnsureInitializedAsync() {
172+
public async System.Threading.Tasks.Task<ConfigInfo> EnsureInitializedAsync() {
173173
ThrowIfNull();
174-
return remoteConfigInternal.EnsureInitializedAsync();
174+
ConfigInfoInternal configInfoInternal = await remoteConfigInternal.EnsureInitializedAsync();
175+
return new ConfigInfo(configInfoInternal);
175176
}
176177

177178
/// @brief Asynchronously activates the most recently fetched configs,
@@ -323,11 +324,11 @@ public IDictionary<string, ConfigValue> AllValues {
323324
}
324325

325326
/// @brief Returns information about the last fetch request, in the form
326-
/// of a @ref ConfigInfo struct.
327+
/// of a @ref ConfigInfo object.
327328
public ConfigInfo Info {
328329
get {
329330
ThrowIfNull();
330-
return remoteConfigInternal.GetInfo();
331+
return new ConfigInfo(remoteConfigInternal.GetInfo());
331332
}
332333
}
333334

remote_config/src/swig/remote_config.i

+7-49
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
%pragma(csharp) moduleclassmodifiers="internal sealed class"
1919
%feature("flatnested");
2020

21+
// Change the default class modifier to internal, so that new classes are not accidentally exposed
22+
%typemap(csclassmodifiers) SWIGTYPE "internal class"
23+
2124
%include "std_vector.i"
2225
%include "stdint.i"
2326

@@ -116,57 +119,12 @@ void SetConfigUpdateCallback(RemoteConfig* rc, firebase::remote_config::ConfigUp
116119
%ignore firebase::remote_config::RemoteConfigError;
117120
%ignore firebase::remote_config::ConfigUpdateListenerRegistration;
118121

119-
// Configure the ConfigInfo class
120-
%csmethodmodifiers fetch_time "internal";
121-
%rename(FetchTimeInternal) fetch_time;
122-
%csmethodmodifiers throttled_end_time "internal";
123-
%rename(ThrottledEndTimeInternal) throttled_end_time;
124-
125-
%typemap(cscode) firebase::remote_config::ConfigInfo %{
126-
private System.DateTime UnixEpochUtc =
127-
new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
128-
129-
/// @brief The time when the last fetch operation completed.
130-
public System.DateTime FetchTime {
131-
get {
132-
return UnixEpochUtc.AddMilliseconds(FetchTimeInternal);
133-
}
134-
}
135-
136-
/// @brief The time when Remote Config data refreshes will no longer
137-
/// be throttled.
138-
public System.DateTime ThrottledEndTime {
139-
get {
140-
return UnixEpochUtc.AddMilliseconds(ThrottledEndTimeInternal);
141-
}
142-
}
143-
%}
144-
145-
%immutable firebase::remote_config::ConfigInfo::last_fetch_status;
146-
%immutable firebase::remote_config::ConfigInfo::last_fetch_failure_reason;
147-
148-
// These are here instead of the header due to b/35780150
149-
%csmethodmodifiers firebase::remote_config::ConfigInfo::last_fetch_status "
150-
/// @brief The status of the last fetch request.
151-
public";
152-
%csmethodmodifiers firebase::remote_config::ConfigInfo::last_fetch_failure_reason "
153-
/// @brief The reason the most recent fetch failed.
154-
public";
155-
156-
// Make snake_case properties into CamelCase.
157-
// ConfigInfo
158-
%rename(LastFetchFailureReason) last_fetch_failure_reason;
159-
%rename(LastFetchStatus) last_fetch_status;
160-
161-
%typemap(csclassmodifiers) firebase::remote_config::ConfigInfo
162-
"public sealed class";
163-
164-
%SWIG_FUTURE(Future_ConfigInfo, ConfigInfo, internal, firebase::remote_config::ConfigInfo, FirebaseException) // Future<ConfigInfo>
165-
122+
// Rename the generated classes to *Internal
123+
%rename (ConfigInfoInternal) firebase::remote_config::ConfigInfo;
124+
%SWIG_FUTURE(Future_ConfigInfo, ConfigInfoInternal, internal,
125+
firebase::remote_config::ConfigInfo, FirebaseException) // Future<ConfigInfoInternal>
166126
%rename (FirebaseRemoteConfigInternal) firebase::remote_config::RemoteConfig;
167-
168127
%rename (ConfigSettingsInternal) firebase::remote_config::ConfigSettings;
169-
170128
%rename (ConfigUpdateInternal) firebase::remote_config::ConfigUpdate;
171129

172130
// Configure properties for get / set methods on the FirebaseRemoteConfigInternal class.

0 commit comments

Comments
 (0)