* draft: 临时提交 * feat: 实现扫描功能 * fix: 优化广播逻辑 * feat: 添加协程方法 * fix: 修改宏定义 * draft: 临时提交 * feat: 调整接口 * fix: 修改版本号 * feat: 4.1.1 * draft: 临时提交 * feat: 5.0.0-dev.2 * fix: 修复版本号错误 * draft: 临时提交 * fix: 修复连接断开异常 * fix: 修复问题 * fix: 优化代码 * fix: 优化 short UUID 格式化逻辑 * fix: 尝试实现 read_rssi 接口,当前此接口不可用,会报异常 * feat: 删除 getMaximumWriteLength 方法 * fix: 更新 CHANGELOG.md * feat: 5.0.0-dev.1 * fix: 更新依赖项 * feat: linux-5.0.0-dev.1 * fix: 更新 CHANGELOG.md * fix: 开始搜索设备时清空设备列表 * fix: 开始扫描时清空设备列表 * feat: 5.0.0-dev.2 * fix: 优化 MyGattService 和 MyGattCharacteristic * feat: 更新 interface 版本 -> 5.0.0-dev.4 * feat: 更新 interface 版本 -> 5.0.0-dev.4 * feat: 实现 flutter 部分 5.0.0 * fix: 移除 maximumWriteLength * fix: 移除 rssi * feat: 5.0.0-dev.1 * feat: 5.0.0-dev.2 * fix: 更新依赖项 * fix: 5.0.0-dev.4 * fix: 更新依赖项 * draft: 临时提交 * feat: 5.0.0-dev.5 * draft: 删除 MyCentralManager 和 MyPeripheralManager * fix: 更新依赖项 * fix: 更新依赖项 * feat: 适配新接口 * feat: 5.0.0-dev.6 * draft: 临时提交 * feat: 5.0.0-dev.7 * fix: 修改版本号 * feat: 5.0.0-dev.8 * feat: 5.0.0-dev.9 * fix: 修复 trimGATT 错误 * feat: 5.0.0-dev.6 * feat: 5.0.0-dev.3 * feat: 5.0.0-dev.4 * fix: 更新 pubspec.lock * feat: 5.0.0-dev.7 * feat: 5.0.0-dev.3 * fix: balabala * fix: balabala * draft: 5.0.0-dev.1 * fix: trim GATT when call the `writeCharacteristic` method. * fix: make difference of `trim` and `fragment`. * feat: 5.0.0-dev.1 * feat: 5.0.0-dev.1 * feat: 优化示例程序 * fix: 更新 README.md * fix: 修复插件引用 * draft: XXXX * feat: 增加调试信息 * fix: 更新 pubspec.lock * feat: 5.0.0-dev.4 * feat: 5.0.0-dev.3 * feat: 5.0.0 * feat: 5.0.0 * feat: 5.0.0 * feat: 5.0.0 * feat: 5.0.0 * feat: 5.0.0
1552 lines
62 KiB
C++
1552 lines
62 KiB
C++
// Autogenerated from Pigeon (v15.0.2), do not edit directly.
|
|
// See also: https://pub.dev/packages/pigeon
|
|
|
|
#undef _HAS_EXCEPTIONS
|
|
|
|
#include "my_api.g.h"
|
|
|
|
#include <flutter/basic_message_channel.h>
|
|
#include <flutter/binary_messenger.h>
|
|
#include <flutter/encodable_value.h>
|
|
#include <flutter/standard_message_codec.h>
|
|
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace bluetooth_low_energy_windows {
|
|
using flutter::BasicMessageChannel;
|
|
using flutter::CustomEncodableValue;
|
|
using flutter::EncodableList;
|
|
using flutter::EncodableMap;
|
|
using flutter::EncodableValue;
|
|
|
|
FlutterError CreateConnectionError(const std::string channel_name) {
|
|
return FlutterError(
|
|
"channel-error",
|
|
"Unable to establish connection on channel: '" + channel_name + "'.",
|
|
EncodableValue(""));
|
|
}
|
|
|
|
// MyManufacturerSpecificDataArgs
|
|
|
|
MyManufacturerSpecificDataArgs::MyManufacturerSpecificDataArgs(
|
|
int64_t id_args,
|
|
const std::vector<uint8_t>& data_args)
|
|
: id_args_(id_args),
|
|
data_args_(data_args) {}
|
|
|
|
int64_t MyManufacturerSpecificDataArgs::id_args() const {
|
|
return id_args_;
|
|
}
|
|
|
|
void MyManufacturerSpecificDataArgs::set_id_args(int64_t value_arg) {
|
|
id_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::vector<uint8_t>& MyManufacturerSpecificDataArgs::data_args() const {
|
|
return data_args_;
|
|
}
|
|
|
|
void MyManufacturerSpecificDataArgs::set_data_args(const std::vector<uint8_t>& value_arg) {
|
|
data_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyManufacturerSpecificDataArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(2);
|
|
list.push_back(EncodableValue(id_args_));
|
|
list.push_back(EncodableValue(data_args_));
|
|
return list;
|
|
}
|
|
|
|
MyManufacturerSpecificDataArgs MyManufacturerSpecificDataArgs::FromEncodableList(const EncodableList& list) {
|
|
MyManufacturerSpecificDataArgs decoded(
|
|
list[0].LongValue(),
|
|
std::get<std::vector<uint8_t>>(list[1]));
|
|
return decoded;
|
|
}
|
|
|
|
// MyAdvertisementArgs
|
|
|
|
MyAdvertisementArgs::MyAdvertisementArgs(
|
|
const EncodableList& service_u_u_i_ds_args,
|
|
const EncodableMap& service_data_args)
|
|
: service_u_u_i_ds_args_(service_u_u_i_ds_args),
|
|
service_data_args_(service_data_args) {}
|
|
|
|
MyAdvertisementArgs::MyAdvertisementArgs(
|
|
const std::string* name_args,
|
|
const EncodableList& service_u_u_i_ds_args,
|
|
const EncodableMap& service_data_args,
|
|
const MyManufacturerSpecificDataArgs* manufacturer_specific_data_args)
|
|
: name_args_(name_args ? std::optional<std::string>(*name_args) : std::nullopt),
|
|
service_u_u_i_ds_args_(service_u_u_i_ds_args),
|
|
service_data_args_(service_data_args),
|
|
manufacturer_specific_data_args_(manufacturer_specific_data_args ? std::optional<MyManufacturerSpecificDataArgs>(*manufacturer_specific_data_args) : std::nullopt) {}
|
|
|
|
const std::string* MyAdvertisementArgs::name_args() const {
|
|
return name_args_ ? &(*name_args_) : nullptr;
|
|
}
|
|
|
|
void MyAdvertisementArgs::set_name_args(const std::string_view* value_arg) {
|
|
name_args_ = value_arg ? std::optional<std::string>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void MyAdvertisementArgs::set_name_args(std::string_view value_arg) {
|
|
name_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableList& MyAdvertisementArgs::service_u_u_i_ds_args() const {
|
|
return service_u_u_i_ds_args_;
|
|
}
|
|
|
|
void MyAdvertisementArgs::set_service_u_u_i_ds_args(const EncodableList& value_arg) {
|
|
service_u_u_i_ds_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableMap& MyAdvertisementArgs::service_data_args() const {
|
|
return service_data_args_;
|
|
}
|
|
|
|
void MyAdvertisementArgs::set_service_data_args(const EncodableMap& value_arg) {
|
|
service_data_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const MyManufacturerSpecificDataArgs* MyAdvertisementArgs::manufacturer_specific_data_args() const {
|
|
return manufacturer_specific_data_args_ ? &(*manufacturer_specific_data_args_) : nullptr;
|
|
}
|
|
|
|
void MyAdvertisementArgs::set_manufacturer_specific_data_args(const MyManufacturerSpecificDataArgs* value_arg) {
|
|
manufacturer_specific_data_args_ = value_arg ? std::optional<MyManufacturerSpecificDataArgs>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void MyAdvertisementArgs::set_manufacturer_specific_data_args(const MyManufacturerSpecificDataArgs& value_arg) {
|
|
manufacturer_specific_data_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyAdvertisementArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(4);
|
|
list.push_back(name_args_ ? EncodableValue(*name_args_) : EncodableValue());
|
|
list.push_back(EncodableValue(service_u_u_i_ds_args_));
|
|
list.push_back(EncodableValue(service_data_args_));
|
|
list.push_back(manufacturer_specific_data_args_ ? EncodableValue(manufacturer_specific_data_args_->ToEncodableList()) : EncodableValue());
|
|
return list;
|
|
}
|
|
|
|
MyAdvertisementArgs MyAdvertisementArgs::FromEncodableList(const EncodableList& list) {
|
|
MyAdvertisementArgs decoded(
|
|
std::get<EncodableList>(list[1]),
|
|
std::get<EncodableMap>(list[2]));
|
|
auto& encodable_name_args = list[0];
|
|
if (!encodable_name_args.IsNull()) {
|
|
decoded.set_name_args(std::get<std::string>(encodable_name_args));
|
|
}
|
|
auto& encodable_manufacturer_specific_data_args = list[3];
|
|
if (!encodable_manufacturer_specific_data_args.IsNull()) {
|
|
decoded.set_manufacturer_specific_data_args(MyManufacturerSpecificDataArgs::FromEncodableList(std::get<EncodableList>(encodable_manufacturer_specific_data_args)));
|
|
}
|
|
return decoded;
|
|
}
|
|
|
|
// MyCentralArgs
|
|
|
|
MyCentralArgs::MyCentralArgs(int64_t address_args)
|
|
: address_args_(address_args) {}
|
|
|
|
int64_t MyCentralArgs::address_args() const {
|
|
return address_args_;
|
|
}
|
|
|
|
void MyCentralArgs::set_address_args(int64_t value_arg) {
|
|
address_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyCentralArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(1);
|
|
list.push_back(EncodableValue(address_args_));
|
|
return list;
|
|
}
|
|
|
|
MyCentralArgs MyCentralArgs::FromEncodableList(const EncodableList& list) {
|
|
MyCentralArgs decoded(
|
|
list[0].LongValue());
|
|
return decoded;
|
|
}
|
|
|
|
// MyPeripheralArgs
|
|
|
|
MyPeripheralArgs::MyPeripheralArgs(int64_t address_args)
|
|
: address_args_(address_args) {}
|
|
|
|
int64_t MyPeripheralArgs::address_args() const {
|
|
return address_args_;
|
|
}
|
|
|
|
void MyPeripheralArgs::set_address_args(int64_t value_arg) {
|
|
address_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyPeripheralArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(1);
|
|
list.push_back(EncodableValue(address_args_));
|
|
return list;
|
|
}
|
|
|
|
MyPeripheralArgs MyPeripheralArgs::FromEncodableList(const EncodableList& list) {
|
|
MyPeripheralArgs decoded(
|
|
list[0].LongValue());
|
|
return decoded;
|
|
}
|
|
|
|
// MyGattDescriptorArgs
|
|
|
|
MyGattDescriptorArgs::MyGattDescriptorArgs(
|
|
int64_t handle_args,
|
|
const std::string& uuid_args)
|
|
: handle_args_(handle_args),
|
|
uuid_args_(uuid_args) {}
|
|
|
|
MyGattDescriptorArgs::MyGattDescriptorArgs(
|
|
int64_t handle_args,
|
|
const std::string& uuid_args,
|
|
const std::vector<uint8_t>* value_args)
|
|
: handle_args_(handle_args),
|
|
uuid_args_(uuid_args),
|
|
value_args_(value_args ? std::optional<std::vector<uint8_t>>(*value_args) : std::nullopt) {}
|
|
|
|
int64_t MyGattDescriptorArgs::handle_args() const {
|
|
return handle_args_;
|
|
}
|
|
|
|
void MyGattDescriptorArgs::set_handle_args(int64_t value_arg) {
|
|
handle_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::string& MyGattDescriptorArgs::uuid_args() const {
|
|
return uuid_args_;
|
|
}
|
|
|
|
void MyGattDescriptorArgs::set_uuid_args(std::string_view value_arg) {
|
|
uuid_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::vector<uint8_t>* MyGattDescriptorArgs::value_args() const {
|
|
return value_args_ ? &(*value_args_) : nullptr;
|
|
}
|
|
|
|
void MyGattDescriptorArgs::set_value_args(const std::vector<uint8_t>* value_arg) {
|
|
value_args_ = value_arg ? std::optional<std::vector<uint8_t>>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void MyGattDescriptorArgs::set_value_args(const std::vector<uint8_t>& value_arg) {
|
|
value_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyGattDescriptorArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(3);
|
|
list.push_back(EncodableValue(handle_args_));
|
|
list.push_back(EncodableValue(uuid_args_));
|
|
list.push_back(value_args_ ? EncodableValue(*value_args_) : EncodableValue());
|
|
return list;
|
|
}
|
|
|
|
MyGattDescriptorArgs MyGattDescriptorArgs::FromEncodableList(const EncodableList& list) {
|
|
MyGattDescriptorArgs decoded(
|
|
list[0].LongValue(),
|
|
std::get<std::string>(list[1]));
|
|
auto& encodable_value_args = list[2];
|
|
if (!encodable_value_args.IsNull()) {
|
|
decoded.set_value_args(std::get<std::vector<uint8_t>>(encodable_value_args));
|
|
}
|
|
return decoded;
|
|
}
|
|
|
|
// MyGattCharacteristicArgs
|
|
|
|
MyGattCharacteristicArgs::MyGattCharacteristicArgs(
|
|
int64_t handle_args,
|
|
const std::string& uuid_args,
|
|
const EncodableList& property_numbers_args,
|
|
const EncodableList& descriptors_args)
|
|
: handle_args_(handle_args),
|
|
uuid_args_(uuid_args),
|
|
property_numbers_args_(property_numbers_args),
|
|
descriptors_args_(descriptors_args) {}
|
|
|
|
int64_t MyGattCharacteristicArgs::handle_args() const {
|
|
return handle_args_;
|
|
}
|
|
|
|
void MyGattCharacteristicArgs::set_handle_args(int64_t value_arg) {
|
|
handle_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::string& MyGattCharacteristicArgs::uuid_args() const {
|
|
return uuid_args_;
|
|
}
|
|
|
|
void MyGattCharacteristicArgs::set_uuid_args(std::string_view value_arg) {
|
|
uuid_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableList& MyGattCharacteristicArgs::property_numbers_args() const {
|
|
return property_numbers_args_;
|
|
}
|
|
|
|
void MyGattCharacteristicArgs::set_property_numbers_args(const EncodableList& value_arg) {
|
|
property_numbers_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableList& MyGattCharacteristicArgs::descriptors_args() const {
|
|
return descriptors_args_;
|
|
}
|
|
|
|
void MyGattCharacteristicArgs::set_descriptors_args(const EncodableList& value_arg) {
|
|
descriptors_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyGattCharacteristicArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(4);
|
|
list.push_back(EncodableValue(handle_args_));
|
|
list.push_back(EncodableValue(uuid_args_));
|
|
list.push_back(EncodableValue(property_numbers_args_));
|
|
list.push_back(EncodableValue(descriptors_args_));
|
|
return list;
|
|
}
|
|
|
|
MyGattCharacteristicArgs MyGattCharacteristicArgs::FromEncodableList(const EncodableList& list) {
|
|
MyGattCharacteristicArgs decoded(
|
|
list[0].LongValue(),
|
|
std::get<std::string>(list[1]),
|
|
std::get<EncodableList>(list[2]),
|
|
std::get<EncodableList>(list[3]));
|
|
return decoded;
|
|
}
|
|
|
|
// MyGattServiceArgs
|
|
|
|
MyGattServiceArgs::MyGattServiceArgs(
|
|
int64_t handle_args,
|
|
const std::string& uuid_args,
|
|
const EncodableList& characteristics_args)
|
|
: handle_args_(handle_args),
|
|
uuid_args_(uuid_args),
|
|
characteristics_args_(characteristics_args) {}
|
|
|
|
int64_t MyGattServiceArgs::handle_args() const {
|
|
return handle_args_;
|
|
}
|
|
|
|
void MyGattServiceArgs::set_handle_args(int64_t value_arg) {
|
|
handle_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::string& MyGattServiceArgs::uuid_args() const {
|
|
return uuid_args_;
|
|
}
|
|
|
|
void MyGattServiceArgs::set_uuid_args(std::string_view value_arg) {
|
|
uuid_args_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableList& MyGattServiceArgs::characteristics_args() const {
|
|
return characteristics_args_;
|
|
}
|
|
|
|
void MyGattServiceArgs::set_characteristics_args(const EncodableList& value_arg) {
|
|
characteristics_args_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList MyGattServiceArgs::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(3);
|
|
list.push_back(EncodableValue(handle_args_));
|
|
list.push_back(EncodableValue(uuid_args_));
|
|
list.push_back(EncodableValue(characteristics_args_));
|
|
return list;
|
|
}
|
|
|
|
MyGattServiceArgs MyGattServiceArgs::FromEncodableList(const EncodableList& list) {
|
|
MyGattServiceArgs decoded(
|
|
list[0].LongValue(),
|
|
std::get<std::string>(list[1]),
|
|
std::get<EncodableList>(list[2]));
|
|
return decoded;
|
|
}
|
|
|
|
|
|
MyCentralManagerHostApiCodecSerializer::MyCentralManagerHostApiCodecSerializer() {}
|
|
|
|
EncodableValue MyCentralManagerHostApiCodecSerializer::ReadValueOfType(
|
|
uint8_t type,
|
|
flutter::ByteStreamReader* stream) const {
|
|
switch (type) {
|
|
case 128:
|
|
return CustomEncodableValue(MyGattCharacteristicArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 129:
|
|
return CustomEncodableValue(MyGattDescriptorArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 130:
|
|
return CustomEncodableValue(MyGattServiceArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
default:
|
|
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
|
}
|
|
}
|
|
|
|
void MyCentralManagerHostApiCodecSerializer::WriteValue(
|
|
const EncodableValue& value,
|
|
flutter::ByteStreamWriter* stream) const {
|
|
if (const CustomEncodableValue* custom_value = std::get_if<CustomEncodableValue>(&value)) {
|
|
if (custom_value->type() == typeid(MyGattCharacteristicArgs)) {
|
|
stream->WriteByte(128);
|
|
WriteValue(EncodableValue(std::any_cast<MyGattCharacteristicArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyGattDescriptorArgs)) {
|
|
stream->WriteByte(129);
|
|
WriteValue(EncodableValue(std::any_cast<MyGattDescriptorArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyGattServiceArgs)) {
|
|
stream->WriteByte(130);
|
|
WriteValue(EncodableValue(std::any_cast<MyGattServiceArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
}
|
|
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
|
}
|
|
|
|
/// The codec used by MyCentralManagerHostApi.
|
|
const flutter::StandardMessageCodec& MyCentralManagerHostApi::GetCodec() {
|
|
return flutter::StandardMessageCodec::GetInstance(&MyCentralManagerHostApiCodecSerializer::GetInstance());
|
|
}
|
|
|
|
// Sets up an instance of `MyCentralManagerHostApi` to handle messages through the `binary_messenger`.
|
|
void MyCentralManagerHostApi::SetUp(
|
|
flutter::BinaryMessenger* binary_messenger,
|
|
MyCentralManagerHostApi* api) {
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.setUp", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
api->SetUp([reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.startDiscovery", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
std::optional<FlutterError> output = api->StartDiscovery();
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.stopDiscovery", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
std::optional<FlutterError> output = api->StopDiscovery();
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.connect", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
api->Connect(address_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.disconnect", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
std::optional<FlutterError> output = api->Disconnect(address_args_arg);
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.discoverServices", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
api->DiscoverServices(address_args_arg, [reply](ErrorOr<EncodableList>&& output) {
|
|
if (output.has_error()) {
|
|
reply(WrapError(output.error()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.discoverCharacteristics", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
api->DiscoverCharacteristics(address_args_arg, handle_args_arg, [reply](ErrorOr<EncodableList>&& output) {
|
|
if (output.has_error()) {
|
|
reply(WrapError(output.error()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.discoverDescriptors", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
api->DiscoverDescriptors(address_args_arg, handle_args_arg, [reply](ErrorOr<EncodableList>&& output) {
|
|
if (output.has_error()) {
|
|
reply(WrapError(output.error()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.readCharacteristic", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
api->ReadCharacteristic(address_args_arg, handle_args_arg, [reply](ErrorOr<std::vector<uint8_t>>&& output) {
|
|
if (output.has_error()) {
|
|
reply(WrapError(output.error()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.writeCharacteristic", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
const auto& encodable_value_args_arg = args.at(2);
|
|
if (encodable_value_args_arg.IsNull()) {
|
|
reply(WrapError("value_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& value_args_arg = std::get<std::vector<uint8_t>>(encodable_value_args_arg);
|
|
const auto& encodable_type_number_args_arg = args.at(3);
|
|
if (encodable_type_number_args_arg.IsNull()) {
|
|
reply(WrapError("type_number_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t type_number_args_arg = encodable_type_number_args_arg.LongValue();
|
|
api->WriteCharacteristic(address_args_arg, handle_args_arg, value_args_arg, type_number_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.setCharacteristicNotifyState", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
const auto& encodable_state_number_args_arg = args.at(2);
|
|
if (encodable_state_number_args_arg.IsNull()) {
|
|
reply(WrapError("state_number_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t state_number_args_arg = encodable_state_number_args_arg.LongValue();
|
|
api->SetCharacteristicNotifyState(address_args_arg, handle_args_arg, state_number_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.readDescriptor", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
api->ReadDescriptor(address_args_arg, handle_args_arg, [reply](ErrorOr<std::vector<uint8_t>>&& output) {
|
|
if (output.has_error()) {
|
|
reply(WrapError(output.error()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerHostApi.writeDescriptor", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
const auto& encodable_value_args_arg = args.at(2);
|
|
if (encodable_value_args_arg.IsNull()) {
|
|
reply(WrapError("value_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& value_args_arg = std::get<std::vector<uint8_t>>(encodable_value_args_arg);
|
|
api->WriteDescriptor(address_args_arg, handle_args_arg, value_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
}
|
|
|
|
EncodableValue MyCentralManagerHostApi::WrapError(std::string_view error_message) {
|
|
return EncodableValue(EncodableList{
|
|
EncodableValue(std::string(error_message)),
|
|
EncodableValue("Error"),
|
|
EncodableValue()
|
|
});
|
|
}
|
|
|
|
EncodableValue MyCentralManagerHostApi::WrapError(const FlutterError& error) {
|
|
return EncodableValue(EncodableList{
|
|
EncodableValue(error.code()),
|
|
EncodableValue(error.message()),
|
|
error.details()
|
|
});
|
|
}
|
|
|
|
|
|
MyCentralManagerFlutterApiCodecSerializer::MyCentralManagerFlutterApiCodecSerializer() {}
|
|
|
|
EncodableValue MyCentralManagerFlutterApiCodecSerializer::ReadValueOfType(
|
|
uint8_t type,
|
|
flutter::ByteStreamReader* stream) const {
|
|
switch (type) {
|
|
case 128:
|
|
return CustomEncodableValue(MyAdvertisementArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 129:
|
|
return CustomEncodableValue(MyManufacturerSpecificDataArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 130:
|
|
return CustomEncodableValue(MyPeripheralArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
default:
|
|
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
|
}
|
|
}
|
|
|
|
void MyCentralManagerFlutterApiCodecSerializer::WriteValue(
|
|
const EncodableValue& value,
|
|
flutter::ByteStreamWriter* stream) const {
|
|
if (const CustomEncodableValue* custom_value = std::get_if<CustomEncodableValue>(&value)) {
|
|
if (custom_value->type() == typeid(MyAdvertisementArgs)) {
|
|
stream->WriteByte(128);
|
|
WriteValue(EncodableValue(std::any_cast<MyAdvertisementArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyManufacturerSpecificDataArgs)) {
|
|
stream->WriteByte(129);
|
|
WriteValue(EncodableValue(std::any_cast<MyManufacturerSpecificDataArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyPeripheralArgs)) {
|
|
stream->WriteByte(130);
|
|
WriteValue(EncodableValue(std::any_cast<MyPeripheralArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
}
|
|
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
|
}
|
|
|
|
// Generated class from Pigeon that represents Flutter messages that can be called from C++.
|
|
MyCentralManagerFlutterApi::MyCentralManagerFlutterApi(flutter::BinaryMessenger* binary_messenger)
|
|
: binary_messenger_(binary_messenger) {}
|
|
|
|
const flutter::StandardMessageCodec& MyCentralManagerFlutterApi::GetCodec() {
|
|
return flutter::StandardMessageCodec::GetInstance(&MyCentralManagerFlutterApiCodecSerializer::GetInstance());
|
|
}
|
|
|
|
void MyCentralManagerFlutterApi::OnStateChanged(
|
|
int64_t state_number_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerFlutterApi.onStateChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(state_number_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
void MyCentralManagerFlutterApi::OnDiscovered(
|
|
const MyPeripheralArgs& peripheral_args_arg,
|
|
int64_t rssi_args_arg,
|
|
const MyAdvertisementArgs& advertisement_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerFlutterApi.onDiscovered";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
CustomEncodableValue(peripheral_args_arg),
|
|
EncodableValue(rssi_args_arg),
|
|
CustomEncodableValue(advertisement_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
void MyCentralManagerFlutterApi::OnConnectionStateChanged(
|
|
int64_t address_args_arg,
|
|
bool state_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerFlutterApi.onConnectionStateChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(address_args_arg),
|
|
EncodableValue(state_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
void MyCentralManagerFlutterApi::OnCharacteristicNotified(
|
|
int64_t address_args_arg,
|
|
int64_t handle_args_arg,
|
|
const std::vector<uint8_t>& value_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyCentralManagerFlutterApi.onCharacteristicNotified";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(address_args_arg),
|
|
EncodableValue(handle_args_arg),
|
|
EncodableValue(value_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
MyPeripheralManagerHostApiCodecSerializer::MyPeripheralManagerHostApiCodecSerializer() {}
|
|
|
|
EncodableValue MyPeripheralManagerHostApiCodecSerializer::ReadValueOfType(
|
|
uint8_t type,
|
|
flutter::ByteStreamReader* stream) const {
|
|
switch (type) {
|
|
case 128:
|
|
return CustomEncodableValue(MyAdvertisementArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 129:
|
|
return CustomEncodableValue(MyGattCharacteristicArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 130:
|
|
return CustomEncodableValue(MyGattDescriptorArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 131:
|
|
return CustomEncodableValue(MyGattServiceArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 132:
|
|
return CustomEncodableValue(MyManufacturerSpecificDataArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
default:
|
|
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
|
}
|
|
}
|
|
|
|
void MyPeripheralManagerHostApiCodecSerializer::WriteValue(
|
|
const EncodableValue& value,
|
|
flutter::ByteStreamWriter* stream) const {
|
|
if (const CustomEncodableValue* custom_value = std::get_if<CustomEncodableValue>(&value)) {
|
|
if (custom_value->type() == typeid(MyAdvertisementArgs)) {
|
|
stream->WriteByte(128);
|
|
WriteValue(EncodableValue(std::any_cast<MyAdvertisementArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyGattCharacteristicArgs)) {
|
|
stream->WriteByte(129);
|
|
WriteValue(EncodableValue(std::any_cast<MyGattCharacteristicArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyGattDescriptorArgs)) {
|
|
stream->WriteByte(130);
|
|
WriteValue(EncodableValue(std::any_cast<MyGattDescriptorArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyGattServiceArgs)) {
|
|
stream->WriteByte(131);
|
|
WriteValue(EncodableValue(std::any_cast<MyGattServiceArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(MyManufacturerSpecificDataArgs)) {
|
|
stream->WriteByte(132);
|
|
WriteValue(EncodableValue(std::any_cast<MyManufacturerSpecificDataArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
}
|
|
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
|
}
|
|
|
|
/// The codec used by MyPeripheralManagerHostApi.
|
|
const flutter::StandardMessageCodec& MyPeripheralManagerHostApi::GetCodec() {
|
|
return flutter::StandardMessageCodec::GetInstance(&MyPeripheralManagerHostApiCodecSerializer::GetInstance());
|
|
}
|
|
|
|
// Sets up an instance of `MyPeripheralManagerHostApi` to handle messages through the `binary_messenger`.
|
|
void MyPeripheralManagerHostApi::SetUp(
|
|
flutter::BinaryMessenger* binary_messenger,
|
|
MyPeripheralManagerHostApi* api) {
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.setUp", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
api->SetUp([reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.addService", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_service_args_arg = args.at(0);
|
|
if (encodable_service_args_arg.IsNull()) {
|
|
reply(WrapError("service_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& service_args_arg = std::any_cast<const MyGattServiceArgs&>(std::get<CustomEncodableValue>(encodable_service_args_arg));
|
|
api->AddService(service_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.removeService", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_handle_args_arg = args.at(0);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
std::optional<FlutterError> output = api->RemoveService(handle_args_arg);
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.clearServices", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
std::optional<FlutterError> output = api->ClearServices();
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.startAdvertising", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_advertisement_args_arg = args.at(0);
|
|
if (encodable_advertisement_args_arg.IsNull()) {
|
|
reply(WrapError("advertisement_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& advertisement_args_arg = std::any_cast<const MyAdvertisementArgs&>(std::get<CustomEncodableValue>(encodable_advertisement_args_arg));
|
|
api->StartAdvertising(advertisement_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.stopAdvertising", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
std::optional<FlutterError> output = api->StopAdvertising();
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.sendReadCharacteristicReply", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
const auto& encodable_status_args_arg = args.at(2);
|
|
if (encodable_status_args_arg.IsNull()) {
|
|
reply(WrapError("status_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& status_args_arg = std::get<bool>(encodable_status_args_arg);
|
|
const auto& encodable_value_args_arg = args.at(3);
|
|
if (encodable_value_args_arg.IsNull()) {
|
|
reply(WrapError("value_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& value_args_arg = std::get<std::vector<uint8_t>>(encodable_value_args_arg);
|
|
std::optional<FlutterError> output = api->SendReadCharacteristicReply(address_args_arg, handle_args_arg, status_args_arg, value_args_arg);
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.sendWriteCharacteristicReply", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
const auto& encodable_status_args_arg = args.at(2);
|
|
if (encodable_status_args_arg.IsNull()) {
|
|
reply(WrapError("status_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& status_args_arg = std::get<bool>(encodable_status_args_arg);
|
|
std::optional<FlutterError> output = api->SendWriteCharacteristicReply(address_args_arg, handle_args_arg, status_args_arg);
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerHostApi.notifyCharacteristic", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
const auto& args = std::get<EncodableList>(message);
|
|
const auto& encodable_address_args_arg = args.at(0);
|
|
if (encodable_address_args_arg.IsNull()) {
|
|
reply(WrapError("address_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t address_args_arg = encodable_address_args_arg.LongValue();
|
|
const auto& encodable_handle_args_arg = args.at(1);
|
|
if (encodable_handle_args_arg.IsNull()) {
|
|
reply(WrapError("handle_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t handle_args_arg = encodable_handle_args_arg.LongValue();
|
|
const auto& encodable_value_args_arg = args.at(2);
|
|
if (encodable_value_args_arg.IsNull()) {
|
|
reply(WrapError("value_args_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& value_args_arg = std::get<std::vector<uint8_t>>(encodable_value_args_arg);
|
|
api->NotifyCharacteristic(address_args_arg, handle_args_arg, value_args_arg, [reply](std::optional<FlutterError>&& output) {
|
|
if (output.has_value()) {
|
|
reply(WrapError(output.value()));
|
|
return;
|
|
}
|
|
EncodableList wrapped;
|
|
wrapped.push_back(EncodableValue());
|
|
reply(EncodableValue(std::move(wrapped)));
|
|
});
|
|
} catch (const std::exception& exception) {
|
|
reply(WrapError(exception.what()));
|
|
}
|
|
});
|
|
} else {
|
|
channel->SetMessageHandler(nullptr);
|
|
}
|
|
}
|
|
}
|
|
|
|
EncodableValue MyPeripheralManagerHostApi::WrapError(std::string_view error_message) {
|
|
return EncodableValue(EncodableList{
|
|
EncodableValue(std::string(error_message)),
|
|
EncodableValue("Error"),
|
|
EncodableValue()
|
|
});
|
|
}
|
|
|
|
EncodableValue MyPeripheralManagerHostApi::WrapError(const FlutterError& error) {
|
|
return EncodableValue(EncodableList{
|
|
EncodableValue(error.code()),
|
|
EncodableValue(error.message()),
|
|
error.details()
|
|
});
|
|
}
|
|
|
|
|
|
MyPeripheralManagerFlutterApiCodecSerializer::MyPeripheralManagerFlutterApiCodecSerializer() {}
|
|
|
|
EncodableValue MyPeripheralManagerFlutterApiCodecSerializer::ReadValueOfType(
|
|
uint8_t type,
|
|
flutter::ByteStreamReader* stream) const {
|
|
switch (type) {
|
|
case 128:
|
|
return CustomEncodableValue(MyCentralArgs::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
default:
|
|
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
|
}
|
|
}
|
|
|
|
void MyPeripheralManagerFlutterApiCodecSerializer::WriteValue(
|
|
const EncodableValue& value,
|
|
flutter::ByteStreamWriter* stream) const {
|
|
if (const CustomEncodableValue* custom_value = std::get_if<CustomEncodableValue>(&value)) {
|
|
if (custom_value->type() == typeid(MyCentralArgs)) {
|
|
stream->WriteByte(128);
|
|
WriteValue(EncodableValue(std::any_cast<MyCentralArgs>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
}
|
|
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
|
}
|
|
|
|
// Generated class from Pigeon that represents Flutter messages that can be called from C++.
|
|
MyPeripheralManagerFlutterApi::MyPeripheralManagerFlutterApi(flutter::BinaryMessenger* binary_messenger)
|
|
: binary_messenger_(binary_messenger) {}
|
|
|
|
const flutter::StandardMessageCodec& MyPeripheralManagerFlutterApi::GetCodec() {
|
|
return flutter::StandardMessageCodec::GetInstance(&MyPeripheralManagerFlutterApiCodecSerializer::GetInstance());
|
|
}
|
|
|
|
void MyPeripheralManagerFlutterApi::OnStateChanged(
|
|
int64_t state_number_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerFlutterApi.onStateChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(state_number_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
void MyPeripheralManagerFlutterApi::OnReadCharacteristicCommandReceived(
|
|
const MyCentralArgs& central_args_arg,
|
|
int64_t handle_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerFlutterApi.onReadCharacteristicCommandReceived";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
CustomEncodableValue(central_args_arg),
|
|
EncodableValue(handle_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
void MyPeripheralManagerFlutterApi::OnWriteCharacteristicCommandReceived(
|
|
const MyCentralArgs& central_args_arg,
|
|
int64_t handle_args_arg,
|
|
const std::vector<uint8_t>& value_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerFlutterApi.onWriteCharacteristicCommandReceived";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
CustomEncodableValue(central_args_arg),
|
|
EncodableValue(handle_args_arg),
|
|
EncodableValue(value_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
void MyPeripheralManagerFlutterApi::OnCharacteristicNotifyStateChanged(
|
|
const MyCentralArgs& central_args_arg,
|
|
int64_t handle_args_arg,
|
|
bool state_args_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.bluetooth_low_energy_windows.MyPeripheralManagerFlutterApi.onCharacteristicNotifyStateChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
CustomEncodableValue(central_args_arg),
|
|
EncodableValue(handle_args_arg),
|
|
EncodableValue(state_args_arg),
|
|
});
|
|
channel->Send(encoded_api_arguments, [channel_name, on_success = std::move(on_success), on_error = std::move(on_error)](const uint8_t* reply, size_t reply_size) {
|
|
std::unique_ptr<EncodableValue> response = GetCodec().DecodeMessage(reply, reply_size);
|
|
const auto& encodable_return_value = *response;
|
|
const auto* list_return_value = std::get_if<EncodableList>(&encodable_return_value);
|
|
if (list_return_value) {
|
|
if (list_return_value->size() > 1) {
|
|
on_error(FlutterError(std::get<std::string>(list_return_value->at(0)), std::get<std::string>(list_return_value->at(1)), list_return_value->at(2)));
|
|
} else {
|
|
on_success();
|
|
}
|
|
} else {
|
|
on_error(CreateConnectionError(channel_name));
|
|
}
|
|
});
|
|
}
|
|
|
|
} // namespace bluetooth_low_energy_windows
|