Refactor BLE plugin structure and rename to 'ble' for consistency across platforms

This commit is contained in:
TonyLu
2026-05-07 17:22:39 +08:00
parent d670143817
commit 020abb118f
19 changed files with 163 additions and 121 deletions
+5 -5
View File
@@ -1,17 +1,17 @@
cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME "ble_relay_host")
set(PROJECT_NAME "ble")
project(${PROJECT_NAME} LANGUAGES CXX)
cmake_policy(VERSION 3.14...3.25)
set(PLUGIN_NAME "ble_relay_host_plugin")
set(PLUGIN_NAME "ble_plugin")
list(APPEND PLUGIN_SOURCES
"ble_relay_host_plugin.cpp"
"ble_plugin.cpp"
)
add_library(${PLUGIN_NAME} SHARED
"include/ble_relay_host/ble_relay_host_plugin_c_api.h"
"include/ble/ble_plugin_c_api.h"
${PLUGIN_SOURCES}
)
@@ -22,7 +22,7 @@ target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
set(ble_relay_host_bundled_libraries
set(ble_bundled_libraries
""
PARENT_SCOPE
)
@@ -1,20 +1,20 @@
#include "ble_relay_host_plugin.h"
#include "ble_plugin.h"
// Windows stub BLE peripheral not yet implemented.
// Windows stub - BLE peripheral not yet implemented.
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
namespace ble_relay_host {
namespace ble {
class BleRelayHostPlugin : public flutter::Plugin {
class BlePlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar) {
auto channel = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "com.dalimaster.ble_relay_host",
registrar->messenger(), "com.dalimaster.ble",
&flutter::StandardMethodCodec::GetInstance());
auto plugin = std::make_unique<BleRelayHostPlugin>();
auto plugin = std::make_unique<BlePlugin>();
channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto& call, auto result) {
plugin_pointer->HandleMethodCall(call, std::move(result));
@@ -22,8 +22,8 @@ class BleRelayHostPlugin : public flutter::Plugin {
registrar->AddPlugin(std::move(plugin));
}
BleRelayHostPlugin() {}
virtual ~BleRelayHostPlugin() {}
BlePlugin() {}
virtual ~BlePlugin() {}
private:
void HandleMethodCall(
@@ -37,11 +37,11 @@ class BleRelayHostPlugin : public flutter::Plugin {
}
};
} // namespace ble_relay_host
} // namespace ble
void BleRelayHostPluginCApiRegisterWithRegistrar(
void BlePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
ble_relay_host::BleRelayHostPlugin::RegisterWithRegistrar(
ble::BlePlugin::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}
}
@@ -1,5 +1,5 @@
#ifndef FLUTTER_PLUGIN_BLE_RELAY_HOST_PLUGIN_H_
#define FLUTTER_PLUGIN_BLE_RELAY_HOST_PLUGIN_H_
#ifndef FLUTTER_PLUGIN_BLE_PLUGIN_H_
#define FLUTTER_PLUGIN_BLE_PLUGIN_H_
#include <flutter/plugin_registrar_windows.h>
@@ -13,11 +13,11 @@
extern "C" {
#endif
FLUTTER_PLUGIN_EXPORT void BleRelayHostPluginCApiRegisterWithRegistrar(
FLUTTER_PLUGIN_EXPORT void BlePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_BLE_RELAY_HOST_PLUGIN_H_
#endif // FLUTTER_PLUGIN_BLE_PLUGIN_H_
+23
View File
@@ -0,0 +1,23 @@
#ifndef FLUTTER_PLUGIN_BLE_PLUGIN_C_API_H_
#define FLUTTER_PLUGIN_BLE_PLUGIN_C_API_H_
#include <flutter_plugin_registrar.h>
#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 BlePluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_BLE_PLUGIN_C_API_H_