From 15cbed2afa159543f5c7f9e596ca3b476d655494 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Fri, 22 Sep 2023 08:24:22 +0800 Subject: [PATCH] first pass Windows implementation --- .../polyvox_filament_plugin_c_api.h | 23 ++++++++++ windows/polyvox_filament_plugin.h | 31 +++++++++++++ windows/polyvox_filament_plugin_c_api.cpp | 12 ++++++ windows/test/polyvox_filament_plugin_test.cpp | 43 +++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 windows/include/polyvox_filament/polyvox_filament_plugin_c_api.h create mode 100644 windows/polyvox_filament_plugin.h create mode 100644 windows/polyvox_filament_plugin_c_api.cpp create mode 100644 windows/test/polyvox_filament_plugin_test.cpp diff --git a/windows/include/polyvox_filament/polyvox_filament_plugin_c_api.h b/windows/include/polyvox_filament/polyvox_filament_plugin_c_api.h new file mode 100644 index 00000000..521bf547 --- /dev/null +++ b/windows/include/polyvox_filament/polyvox_filament_plugin_c_api.h @@ -0,0 +1,23 @@ +#ifndef FLUTTER_PLUGIN_POLYVOX_FILAMENT_PLUGIN_C_API_H_ +#define FLUTTER_PLUGIN_POLYVOX_FILAMENT_PLUGIN_C_API_H_ + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void PolyvoxFilamentPluginCApiRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // FLUTTER_PLUGIN_POLYVOX_FILAMENT_PLUGIN_C_API_H_ diff --git a/windows/polyvox_filament_plugin.h b/windows/polyvox_filament_plugin.h new file mode 100644 index 00000000..2159c264 --- /dev/null +++ b/windows/polyvox_filament_plugin.h @@ -0,0 +1,31 @@ +#ifndef FLUTTER_PLUGIN_POLYVOX_FILAMENT_PLUGIN_H_ +#define FLUTTER_PLUGIN_POLYVOX_FILAMENT_PLUGIN_H_ + +#include +#include + +#include + +namespace polyvox_filament { + +class PolyvoxFilamentPlugin : public flutter::Plugin { + public: + static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); + + PolyvoxFilamentPlugin(); + + virtual ~PolyvoxFilamentPlugin(); + + // Disallow copy and assign. + PolyvoxFilamentPlugin(const PolyvoxFilamentPlugin&) = delete; + PolyvoxFilamentPlugin& operator=(const PolyvoxFilamentPlugin&) = delete; + + // Called when a method is called on this plugin's channel from Dart. + void HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result); +}; + +} // namespace polyvox_filament + +#endif // FLUTTER_PLUGIN_POLYVOX_FILAMENT_PLUGIN_H_ diff --git a/windows/polyvox_filament_plugin_c_api.cpp b/windows/polyvox_filament_plugin_c_api.cpp new file mode 100644 index 00000000..d3e70b5f --- /dev/null +++ b/windows/polyvox_filament_plugin_c_api.cpp @@ -0,0 +1,12 @@ +#include "include/polyvox_filament/polyvox_filament_plugin_c_api.h" + +#include + +#include "polyvox_filament_plugin.h" + +void PolyvoxFilamentPluginCApiRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + polyvox_filament::PolyvoxFilamentPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); +} diff --git a/windows/test/polyvox_filament_plugin_test.cpp b/windows/test/polyvox_filament_plugin_test.cpp new file mode 100644 index 00000000..0167f616 --- /dev/null +++ b/windows/test/polyvox_filament_plugin_test.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "polyvox_filament_plugin.h" + +namespace polyvox_filament { +namespace test { + +namespace { + +using flutter::EncodableMap; +using flutter::EncodableValue; +using flutter::MethodCall; +using flutter::MethodResultFunctions; + +} // namespace + +TEST(PolyvoxFilamentPlugin, GetPlatformVersion) { + PolyvoxFilamentPlugin plugin; + // Save the reply value from the success callback. + std::string result_string; + plugin.HandleMethodCall( + MethodCall("getPlatformVersion", std::make_unique()), + std::make_unique>( + [&result_string](const EncodableValue* result) { + result_string = std::get(*result); + }, + nullptr, nullptr)); + + // Since the exact string varies by host, just ensure that it's a string + // with the expected format. + EXPECT_TRUE(result_string.rfind("Windows ", 0) == 0); +} + +} // namespace test +} // namespace polyvox_filament