Skip to content

Commit a6ff884

Browse files
cynthiajianga-maurice
authored andcommitted
[RemoteConfig]V2 - Initial API layouts
+ Create RemoteConfig class to handle RC instance for different apps + In RemoteConfig class listed out updated functions + create stub impl functions for android/ios/desktop go/new-rc-cpp-unity-design go/new-rc-cpp-unity-api PiperOrigin-RevId: 285472437
1 parent 56dd392 commit a6ff884

File tree

11 files changed

+860
-25
lines changed

11 files changed

+860
-25
lines changed

remote_config/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
# Common source files used by all platforms
1818
set(common_SRCS
19-
src/common.cc)
19+
src/common.cc
20+
src/remote_config.cc)
2021

2122
# Source files used by the Android implementation.
2223
set(android_SRCS
23-
src/remote_config_android.cc)
24+
src/android/remote_config_android.cc)
2425

2526
# Source files used by the iOS implementation.
2627
set(ios_SRCS
27-
src/remote_config_ios.mm)
28+
src/ios/remote_config_ios.mm)
2829

2930
if (NOT PROTOBUF_FOUND)
3031
# Only log a message if building for Desktop, since mobile doesn't care.
@@ -40,7 +41,7 @@ else()
4041
set(desktop_SRCS
4142
${PROTO_SRCS}
4243
${PROTO_HDRS}
43-
src/desktop/remote_config.cc
44+
src/desktop/remote_config_legacy.cc
4445
src/desktop/rest.cc
4546
src/desktop/config_data.cc
4647
src/desktop/file_manager.cc

remote_config/src/remote_config_android.cc renamed to remote_config/src/android/remote_config_android.cc

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "remote_config/src/android/remote_config_android.h"
16+
1517
#include <assert.h>
1618

1719
#include <set>
@@ -23,7 +25,6 @@
2325
#include "app/src/util.h"
2426
#include "app/src/util_android.h"
2527
#include "remote_config/src/common.h"
26-
#include "remote_config/src/include/firebase/remote_config.h"
2728

2829
namespace firebase {
2930
namespace remote_config {
@@ -757,5 +758,155 @@ const ConfigInfo& GetInfo() {
757758
return config_info;
758759
}
759760

761+
namespace internal {
762+
RemoteConfigInternal::RemoteConfigInternal(const firebase::App& app)
763+
: app_(app), future_impl_(kRemoteConfigFnCount) {
764+
LogInfo("%s API Initialized", kApiIdentifier);
765+
}
766+
767+
RemoteConfigInternal::~RemoteConfigInternal() {
768+
// TODO(cynthiajiang) android clean up
769+
}
770+
771+
bool RemoteConfigInternal::Initialized() const{
772+
// TODO(cynthiajiang) implement
773+
return true;
774+
}
775+
776+
void RemoteConfigInternal::Cleanup() {
777+
// TODO(cynthiajiang) implement
778+
}
779+
780+
Future<ConfigInfo> RemoteConfigInternal::EnsureInitialized() {
781+
const auto handle =
782+
future_impl_.SafeAlloc<ConfigInfo>(kRemoteConfigFnEnsureInitialized);
783+
// TODO(cynthiajiang) implement
784+
return MakeFuture<ConfigInfo>(&future_impl_, handle);
785+
}
786+
787+
Future<ConfigInfo> RemoteConfigInternal::EnsureInitializedLastResult() {
788+
return static_cast<const Future<ConfigInfo>&>(
789+
future_impl_.LastResult(kRemoteConfigFnEnsureInitialized));
790+
}
791+
792+
Future<bool> RemoteConfigInternal::Activate() {
793+
const auto handle = future_impl_.SafeAlloc<bool>(kRemoteConfigFnActivate);
794+
// TODO(cynthiajiang) implement
795+
return MakeFuture<bool>(&future_impl_, handle);
796+
}
797+
798+
Future<bool> RemoteConfigInternal::ActivateLastResult() {
799+
return static_cast<const Future<bool>&>(
800+
future_impl_.LastResult(kRemoteConfigFnActivate));
801+
}
802+
803+
Future<bool> RemoteConfigInternal::FetchAndActivate() {
804+
const auto handle =
805+
future_impl_.SafeAlloc<bool>(kRemoteConfigFnFetchAndActivate);
806+
// TODO(cynthiajiang) implement
807+
return MakeFuture<bool>(&future_impl_, handle);
808+
}
809+
810+
Future<bool> RemoteConfigInternal::FetchAndActivateLastResult() {
811+
return static_cast<const Future<bool>&>(
812+
future_impl_.LastResult(kRemoteConfigFnFetchAndActivate));
813+
}
814+
815+
Future<void> RemoteConfigInternal::Fetch(uint64_t cache_expiration_in_seconds) {
816+
const auto handle = future_impl_.SafeAlloc<void>(kRemoteConfigFnFetch);
817+
// TODO(cynthiajiang) implement
818+
return MakeFuture<void>(&future_impl_, handle);
819+
}
820+
821+
Future<void> RemoteConfigInternal::FetchLastResult() {
822+
return static_cast<const Future<void>&>(
823+
future_impl_.LastResult(kRemoteConfigFnFetch));
824+
}
825+
826+
Future<void> RemoteConfigInternal::SetDefaults(int defaults_resource_id) {
827+
const auto handle = future_impl_.SafeAlloc<void>(kRemoteConfigFnSetDefaults);
828+
// TODO(cynthiajiang) implement
829+
return MakeFuture<void>(&future_impl_, handle);
830+
}
831+
832+
Future<void> RemoteConfigInternal::SetDefaults(
833+
const ConfigKeyValueVariant* defaults, size_t number_of_defaults) {
834+
const auto handle = future_impl_.SafeAlloc<void>(kRemoteConfigFnSetDefaults);
835+
// TODO(cynthiajiang) implement
836+
return MakeFuture<void>(&future_impl_, handle);
837+
}
838+
839+
Future<void> RemoteConfigInternal::SetDefaults(const ConfigKeyValue* defaults,
840+
size_t number_of_defaults) {
841+
const auto handle = future_impl_.SafeAlloc<void>(kRemoteConfigFnSetDefaults);
842+
// TODO(cynthiajiang) implement
843+
return MakeFuture<void>(&future_impl_, handle);
844+
}
845+
846+
Future<void> RemoteConfigInternal::SetDefaultsLastResult() {
847+
return static_cast<const Future<void>&>(
848+
future_impl_.LastResult(kRemoteConfigFnSetDefaults));
849+
}
850+
851+
#ifdef FIREBASE_EARLY_ACCESS_PREVIEW
852+
Future<void> RemoteConfigInternal::SetConfigSettings(ConfigSettings settings) {
853+
const auto handle =
854+
future_impl_.SafeAlloc<void>(kRemoteConfigFnSetConfigSettings);
855+
// TODO(cynthiajiang) implement
856+
return MakeFuture<void>(&future_impl_, handle);
857+
}
858+
#endif // FIREBASE_EARLY_ACCESS_PREVIEW
859+
860+
Future<void> RemoteConfigInternal::SetConfigSettingsLastResult() {
861+
return static_cast<const Future<void>&>(
862+
future_impl_.LastResult(kRemoteConfigFnSetConfigSettings));
863+
}
864+
865+
bool RemoteConfigInternal::GetBoolean(const char* key, ValueInfo* info) {
866+
// TODO(cynthiajiang) implement
867+
return true;
868+
}
869+
870+
int64_t RemoteConfigInternal::GetLong(const char* key, ValueInfo* info) {
871+
// TODO(cynthiajiang) implement
872+
return 0;
873+
}
874+
875+
double RemoteConfigInternal::GetDouble(const char* key, ValueInfo* info) {
876+
// TODO(cynthiajiang) implement
877+
return 0.0f;
878+
}
879+
880+
std::string RemoteConfigInternal::GetString(const char* key, ValueInfo* info) {
881+
// TODO(cynthiajiang) implement
882+
return "";
883+
}
884+
885+
std::vector<unsigned char> RemoteConfigInternal::GetData(const char* key,
886+
ValueInfo* info) {
887+
std::vector<unsigned char> value;
888+
// TODO(cynthiajiang) implement
889+
return value;
890+
}
891+
892+
std::vector<std::string> RemoteConfigInternal::GetKeysByPrefix(
893+
const char* prefix) {
894+
std::vector<std::string> value;
895+
// TODO(cynthiajiang) implement
896+
return value;
897+
}
898+
899+
std::vector<std::string> RemoteConfigInternal::GetKeys() {
900+
std::vector<std::string> value;
901+
// TODO(cynthiajiang) implement
902+
return value;
903+
}
904+
905+
std::map<std::string, Variant> RemoteConfigInternal::GetAll() {
906+
std::map<std::string, Variant> value;
907+
// TODO(cynthiajiang) implement
908+
return value;
909+
}
910+
} // namespace internal
760911
} // namespace remote_config
761912
} // namespace firebase
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIREBASE_REMOTE_CONFIG_CLIENT_CPP_SRC_ANDROID_REMOTE_CONFIG_ANDROID_H_
16+
#define FIREBASE_REMOTE_CONFIG_CLIENT_CPP_SRC_ANDROID_REMOTE_CONFIG_ANDROID_H_
17+
18+
#include "firebase/app.h"
19+
#include "app/src/reference_counted_future_impl.h"
20+
#include "firebase/future.h"
21+
#include "remote_config/src/include/firebase/remote_config.h"
22+
23+
namespace firebase {
24+
namespace remote_config {
25+
namespace internal {
26+
// Remote Config Client implementation for Android.
27+
//
28+
// This class implements functions from `firebase/remote_config.h` header.
29+
// See `firebase/remote_config.h` for all public functions documentation.
30+
class RemoteConfigInternal {
31+
public:
32+
explicit RemoteConfigInternal(const firebase::App& app);
33+
~RemoteConfigInternal();
34+
35+
Future<ConfigInfo> EnsureInitialized();
36+
Future<ConfigInfo> EnsureInitializedLastResult();
37+
38+
Future<bool> Activate();
39+
Future<bool> ActivateLastResult();
40+
41+
Future<bool> FetchAndActivate();
42+
Future<bool> FetchAndActivateLastResult();
43+
44+
Future<void> Fetch(uint64_t cache_expiration_in_seconds);
45+
Future<void> FetchLastResult();
46+
47+
#ifndef SWIG
48+
Future<void> SetDefaults(const ConfigKeyValueVariant* defaults,
49+
size_t number_of_defaults);
50+
#endif // SWIG
51+
Future<void> SetDefaults(const ConfigKeyValue* defaults,
52+
size_t number_of_defaults);
53+
54+
Future<void> SetDefaults(int defaults_resource_id);
55+
56+
Future<void> SetDefaultsLastResult();
57+
#ifdef FIREBASE_EARLY_ACCESS_PREVIEW
58+
Future<void> SetConfigSettings(ConfigSettings settings);
59+
#endif // FIREBASE_EARLY_ACCESS_PREVIEW
60+
61+
Future<void> SetConfigSettingsLastResult();
62+
63+
bool GetBoolean(const char* key, ValueInfo* info);
64+
65+
std::string GetString(const char* key, ValueInfo* info);
66+
67+
int64_t GetLong(const char* key, ValueInfo* info);
68+
69+
double GetDouble(const char* key, ValueInfo* info);
70+
71+
std::vector<unsigned char> GetData(const char* key, ValueInfo* info);
72+
73+
std::vector<std::string> GetKeys();
74+
75+
std::vector<std::string> GetKeysByPrefix(const char* prefix);
76+
77+
std::map<std::string, Variant> GetAll();
78+
79+
const ConfigInfo& GetInfo() const;
80+
81+
bool Initialized() const;
82+
83+
void Cleanup();
84+
85+
private:
86+
// app
87+
const firebase::App& app_;
88+
89+
/// Handle calls from Futures that the API returns.
90+
ReferenceCountedFutureImpl future_impl_;
91+
92+
jobject* internal_obj_;
93+
};
94+
95+
} // namespace internal
96+
} // namespace remote_config
97+
} // namespace firebase
98+
99+
#endif // FIREBASE_REMOTE_CONFIG_CLIENT_CPP_SRC_ANDROID_REMOTE_CONFIG_ANDROID_H_

remote_config/src/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ namespace remote_config {
2222

2323
enum RemoteConfigFn {
2424
kRemoteConfigFnFetch,
25+
kRemoteConfigFnEnsureInitialized,
26+
kRemoteConfigFnActivate,
27+
kRemoteConfigFnFetchAndActivate,
28+
kRemoteConfigFnSetDefaults,
29+
kRemoteConfigFnSetConfigSettings,
2530
kRemoteConfigFnCount
2631
};
2732

0 commit comments

Comments
 (0)