Skip to content

Commit

Permalink
feat(core, windows): Add api to access firebase cpp objects (#11254)
Browse files Browse the repository at this point in the history
* add api to get cpp firebase objects

* add missing extra lib to cmake file
  • Loading branch information
cynthiajoan committed Jul 12, 2023
1 parent 3163724 commit c26f9d8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
10 changes: 6 additions & 4 deletions packages/firebase_core/firebase_core/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# customers of the plugin.
cmake_minimum_required(VERSION 3.14)

set(FIREBASE_SDK_VERSION "10.5.0")
set(FIREBASE_SDK_VERSION "11.2.0")

if (EXISTS $ENV{FIREBASE_CPP_SDK_DIR}/include/firebase/version.h)
file(READ "$ENV{FIREBASE_CPP_SDK_DIR}/include/firebase/version.h" existing_version)
Expand Down Expand Up @@ -90,8 +90,8 @@ set(MSVC_RUNTIME_MODE MD)
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${FIREBASE_CPP_SDK_DIR}/include")
set(firebase_libs firebase_auth firebase_database firebase_app)
foreach(firebase_lib IN ITEMS ${firebase_libs})
set(FIREBASE_LIBS firebase_app firebase_auth firebase_remote_config)
foreach(firebase_lib IN ITEMS ${FIREBASE_LIBS})
get_target_property(firebase_lib_path ${firebase_lib} IMPORTED_LOCATION)
string(REPLACE "Debug" "Release" firebase_lib_release_path ${firebase_lib_path})
set_target_properties(${firebase_lib} PROPERTIES
Expand All @@ -100,7 +100,9 @@ foreach(firebase_lib IN ITEMS ${firebase_libs})
)
endforeach()

target_link_libraries(${PLUGIN_NAME} PRIVATE "${firebase_libs}")
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 rpcrt4 ole32 icu)

target_link_libraries(${PLUGIN_NAME} PRIVATE "${FIREBASE_LIBS}" "${ADDITIONAL_LIBS}")

target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <windows.h>

#include "firebase/app.h"
#include "firebase/auth.h"
#include "firebase/remote_config.h"
#include "messages.g.h"

// For getPlatformVersion; remove unless needed for your plugin implementation.
Expand All @@ -24,6 +26,8 @@
#include <string>
#include <vector>
using ::firebase::App;
using ::firebase::auth::Auth;
using ::firebase::remote_config::RemoteConfig;

namespace firebase_core_windows {

Expand All @@ -38,6 +42,26 @@ void FirebaseCorePlugin::RegisterWithRegistrar(
registrar->AddPlugin(std::move(plugin));
}

void *FirebaseCorePlugin::GetFirebaseApp(std::string appName) {
return App::GetInstance(appName.c_str());
}

void *FirebaseCorePlugin::GetFirebaseAuth(std::string appName) {
App *app = App::GetInstance(appName.c_str());
if (app == nullptr) {
return nullptr;
}
return Auth::GetAuth(app);
}

void *FirebaseCorePlugin::GetFirebaseRemoteConfig(std::string appName) {
App *app = App::GetInstance(appName.c_str());
if (app == nullptr) {
return nullptr;
}
return RemoteConfig::GetInstance(app);
}

FirebaseCorePlugin::FirebaseCorePlugin() {}

FirebaseCorePlugin::~FirebaseCorePlugin() = default;
Expand Down Expand Up @@ -107,14 +131,17 @@ void FirebaseCorePlugin::InitializeCore(
std::function<void(ErrorOr<flutter::EncodableList> reply)> result) {
// TODO: Missing function to get the list of currently initialized apps
std::vector<PigeonInitializeResponse> initializedApps;
std::vector<App *> all_apps = App::GetApps();
for (const App *app : all_apps) {
initializedApps.push_back(AppToPigeonInitializeResponse(*app));
}

flutter::EncodableList encodableList;

// Insert the contents of the vector into the EncodableList
// for (const auto &item : initializedApps) {
// encodableList.push_back(flutter::EncodableValue(item));
//}
result(flutter::EncodableList());
for (const auto &item : initializedApps) {
encodableList.push_back(flutter::CustomEncodableValue(item));
}
result(encodableList);
}

void FirebaseCorePlugin::OptionsFromResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class FirebaseCorePlugin : public flutter::Plugin,
public FirebaseAppHostApi {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
static void *GetFirebaseApp(std::string appName);
static void *GetFirebaseAuth(std::string appName);
static void *GetFirebaseRemoteConfig(std::string appName);

FirebaseCorePlugin();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ void FirebaseCorePluginCApiRegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}

void* GetFirebaseApp(std::string appName) {
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseApp(appName);
}

void* GetFirebaseAuth(std::string appName) {
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseAuth(appName);
}

void* GetFirebaseRemoteConfig(std::string appName) {
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseRemoteConfig(
appName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <flutter_plugin_registrar.h>

#include <string>

#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
#else
Expand All @@ -22,6 +24,12 @@ extern "C" {
FLUTTER_PLUGIN_EXPORT void FirebaseCorePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);

FLUTTER_PLUGIN_EXPORT void* GetFirebaseApp(std::string appName);

FLUTTER_PLUGIN_EXPORT void* GetFirebaseAuth(std::string appName);

FLUTTER_PLUGIN_EXPORT void* GetFirebaseRemoteConfig(std::string appName);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down

0 comments on commit c26f9d8

Please sign in to comment.