ed3852a5c9
* Improve windows device name discovery * Imrove classes and folders structuring * rename generated files * Improve windows threads and other fixes * More optimizations * Cleanups * Update .vscode/settings.json Co-authored-by: Foti Dim <foti@navideck.com> * Resolve comments * Performance improvements --------- Co-authored-by: Foti Dim <foti@navideck.com> Co-authored-by: Foti Dim <fdimanidis@gmail.com>
953 lines
38 KiB
C++
953 lines
38 KiB
C++
// Autogenerated from Pigeon (v16.0.5), do not edit directly.
|
|
// See also: https://pub.dev/packages/pigeon
|
|
|
|
#undef _HAS_EXCEPTIONS
|
|
|
|
#include "universal_ble.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 universal_ble {
|
|
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(""));
|
|
}
|
|
|
|
// UniversalBleScanResult
|
|
|
|
UniversalBleScanResult::UniversalBleScanResult(const std::string& device_id)
|
|
: device_id_(device_id) {}
|
|
|
|
UniversalBleScanResult::UniversalBleScanResult(
|
|
const std::string& device_id,
|
|
const std::string* name,
|
|
const bool* is_paired,
|
|
const int64_t* rssi,
|
|
const std::vector<uint8_t>* manufacturer_data,
|
|
const std::vector<uint8_t>* manufacturer_data_head)
|
|
: device_id_(device_id),
|
|
name_(name ? std::optional<std::string>(*name) : std::nullopt),
|
|
is_paired_(is_paired ? std::optional<bool>(*is_paired) : std::nullopt),
|
|
rssi_(rssi ? std::optional<int64_t>(*rssi) : std::nullopt),
|
|
manufacturer_data_(manufacturer_data ? std::optional<std::vector<uint8_t>>(*manufacturer_data) : std::nullopt),
|
|
manufacturer_data_head_(manufacturer_data_head ? std::optional<std::vector<uint8_t>>(*manufacturer_data_head) : std::nullopt) {}
|
|
|
|
const std::string& UniversalBleScanResult::device_id() const {
|
|
return device_id_;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_device_id(std::string_view value_arg) {
|
|
device_id_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::string* UniversalBleScanResult::name() const {
|
|
return name_ ? &(*name_) : nullptr;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_name(const std::string_view* value_arg) {
|
|
name_ = value_arg ? std::optional<std::string>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_name(std::string_view value_arg) {
|
|
name_ = value_arg;
|
|
}
|
|
|
|
|
|
const bool* UniversalBleScanResult::is_paired() const {
|
|
return is_paired_ ? &(*is_paired_) : nullptr;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_is_paired(const bool* value_arg) {
|
|
is_paired_ = value_arg ? std::optional<bool>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_is_paired(bool value_arg) {
|
|
is_paired_ = value_arg;
|
|
}
|
|
|
|
|
|
const int64_t* UniversalBleScanResult::rssi() const {
|
|
return rssi_ ? &(*rssi_) : nullptr;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_rssi(const int64_t* value_arg) {
|
|
rssi_ = value_arg ? std::optional<int64_t>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_rssi(int64_t value_arg) {
|
|
rssi_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::vector<uint8_t>* UniversalBleScanResult::manufacturer_data() const {
|
|
return manufacturer_data_ ? &(*manufacturer_data_) : nullptr;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_manufacturer_data(const std::vector<uint8_t>* value_arg) {
|
|
manufacturer_data_ = value_arg ? std::optional<std::vector<uint8_t>>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_manufacturer_data(const std::vector<uint8_t>& value_arg) {
|
|
manufacturer_data_ = value_arg;
|
|
}
|
|
|
|
|
|
const std::vector<uint8_t>* UniversalBleScanResult::manufacturer_data_head() const {
|
|
return manufacturer_data_head_ ? &(*manufacturer_data_head_) : nullptr;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_manufacturer_data_head(const std::vector<uint8_t>* value_arg) {
|
|
manufacturer_data_head_ = value_arg ? std::optional<std::vector<uint8_t>>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void UniversalBleScanResult::set_manufacturer_data_head(const std::vector<uint8_t>& value_arg) {
|
|
manufacturer_data_head_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList UniversalBleScanResult::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(6);
|
|
list.push_back(EncodableValue(device_id_));
|
|
list.push_back(name_ ? EncodableValue(*name_) : EncodableValue());
|
|
list.push_back(is_paired_ ? EncodableValue(*is_paired_) : EncodableValue());
|
|
list.push_back(rssi_ ? EncodableValue(*rssi_) : EncodableValue());
|
|
list.push_back(manufacturer_data_ ? EncodableValue(*manufacturer_data_) : EncodableValue());
|
|
list.push_back(manufacturer_data_head_ ? EncodableValue(*manufacturer_data_head_) : EncodableValue());
|
|
return list;
|
|
}
|
|
|
|
UniversalBleScanResult UniversalBleScanResult::FromEncodableList(const EncodableList& list) {
|
|
UniversalBleScanResult decoded(
|
|
std::get<std::string>(list[0]));
|
|
auto& encodable_name = list[1];
|
|
if (!encodable_name.IsNull()) {
|
|
decoded.set_name(std::get<std::string>(encodable_name));
|
|
}
|
|
auto& encodable_is_paired = list[2];
|
|
if (!encodable_is_paired.IsNull()) {
|
|
decoded.set_is_paired(std::get<bool>(encodable_is_paired));
|
|
}
|
|
auto& encodable_rssi = list[3];
|
|
if (!encodable_rssi.IsNull()) {
|
|
decoded.set_rssi(encodable_rssi.LongValue());
|
|
}
|
|
auto& encodable_manufacturer_data = list[4];
|
|
if (!encodable_manufacturer_data.IsNull()) {
|
|
decoded.set_manufacturer_data(std::get<std::vector<uint8_t>>(encodable_manufacturer_data));
|
|
}
|
|
auto& encodable_manufacturer_data_head = list[5];
|
|
if (!encodable_manufacturer_data_head.IsNull()) {
|
|
decoded.set_manufacturer_data_head(std::get<std::vector<uint8_t>>(encodable_manufacturer_data_head));
|
|
}
|
|
return decoded;
|
|
}
|
|
|
|
// UniversalBleService
|
|
|
|
UniversalBleService::UniversalBleService(const std::string& uuid)
|
|
: uuid_(uuid) {}
|
|
|
|
UniversalBleService::UniversalBleService(
|
|
const std::string& uuid,
|
|
const EncodableList* characteristics)
|
|
: uuid_(uuid),
|
|
characteristics_(characteristics ? std::optional<EncodableList>(*characteristics) : std::nullopt) {}
|
|
|
|
const std::string& UniversalBleService::uuid() const {
|
|
return uuid_;
|
|
}
|
|
|
|
void UniversalBleService::set_uuid(std::string_view value_arg) {
|
|
uuid_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableList* UniversalBleService::characteristics() const {
|
|
return characteristics_ ? &(*characteristics_) : nullptr;
|
|
}
|
|
|
|
void UniversalBleService::set_characteristics(const EncodableList* value_arg) {
|
|
characteristics_ = value_arg ? std::optional<EncodableList>(*value_arg) : std::nullopt;
|
|
}
|
|
|
|
void UniversalBleService::set_characteristics(const EncodableList& value_arg) {
|
|
characteristics_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList UniversalBleService::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(2);
|
|
list.push_back(EncodableValue(uuid_));
|
|
list.push_back(characteristics_ ? EncodableValue(*characteristics_) : EncodableValue());
|
|
return list;
|
|
}
|
|
|
|
UniversalBleService UniversalBleService::FromEncodableList(const EncodableList& list) {
|
|
UniversalBleService decoded(
|
|
std::get<std::string>(list[0]));
|
|
auto& encodable_characteristics = list[1];
|
|
if (!encodable_characteristics.IsNull()) {
|
|
decoded.set_characteristics(std::get<EncodableList>(encodable_characteristics));
|
|
}
|
|
return decoded;
|
|
}
|
|
|
|
// UniversalBleCharacteristic
|
|
|
|
UniversalBleCharacteristic::UniversalBleCharacteristic(
|
|
const std::string& uuid,
|
|
const EncodableList& properties)
|
|
: uuid_(uuid),
|
|
properties_(properties) {}
|
|
|
|
const std::string& UniversalBleCharacteristic::uuid() const {
|
|
return uuid_;
|
|
}
|
|
|
|
void UniversalBleCharacteristic::set_uuid(std::string_view value_arg) {
|
|
uuid_ = value_arg;
|
|
}
|
|
|
|
|
|
const EncodableList& UniversalBleCharacteristic::properties() const {
|
|
return properties_;
|
|
}
|
|
|
|
void UniversalBleCharacteristic::set_properties(const EncodableList& value_arg) {
|
|
properties_ = value_arg;
|
|
}
|
|
|
|
|
|
EncodableList UniversalBleCharacteristic::ToEncodableList() const {
|
|
EncodableList list;
|
|
list.reserve(2);
|
|
list.push_back(EncodableValue(uuid_));
|
|
list.push_back(EncodableValue(properties_));
|
|
return list;
|
|
}
|
|
|
|
UniversalBleCharacteristic UniversalBleCharacteristic::FromEncodableList(const EncodableList& list) {
|
|
UniversalBleCharacteristic decoded(
|
|
std::get<std::string>(list[0]),
|
|
std::get<EncodableList>(list[1]));
|
|
return decoded;
|
|
}
|
|
|
|
|
|
UniversalBlePlatformChannelCodecSerializer::UniversalBlePlatformChannelCodecSerializer() {}
|
|
|
|
EncodableValue UniversalBlePlatformChannelCodecSerializer::ReadValueOfType(
|
|
uint8_t type,
|
|
flutter::ByteStreamReader* stream) const {
|
|
switch (type) {
|
|
case 128:
|
|
return CustomEncodableValue(UniversalBleCharacteristic::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 129:
|
|
return CustomEncodableValue(UniversalBleScanResult::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
case 130:
|
|
return CustomEncodableValue(UniversalBleService::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
default:
|
|
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
|
}
|
|
}
|
|
|
|
void UniversalBlePlatformChannelCodecSerializer::WriteValue(
|
|
const EncodableValue& value,
|
|
flutter::ByteStreamWriter* stream) const {
|
|
if (const CustomEncodableValue* custom_value = std::get_if<CustomEncodableValue>(&value)) {
|
|
if (custom_value->type() == typeid(UniversalBleCharacteristic)) {
|
|
stream->WriteByte(128);
|
|
WriteValue(EncodableValue(std::any_cast<UniversalBleCharacteristic>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(UniversalBleScanResult)) {
|
|
stream->WriteByte(129);
|
|
WriteValue(EncodableValue(std::any_cast<UniversalBleScanResult>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
if (custom_value->type() == typeid(UniversalBleService)) {
|
|
stream->WriteByte(130);
|
|
WriteValue(EncodableValue(std::any_cast<UniversalBleService>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
}
|
|
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
|
}
|
|
|
|
/// The codec used by UniversalBlePlatformChannel.
|
|
const flutter::StandardMessageCodec& UniversalBlePlatformChannel::GetCodec() {
|
|
return flutter::StandardMessageCodec::GetInstance(&UniversalBlePlatformChannelCodecSerializer::GetInstance());
|
|
}
|
|
|
|
// Sets up an instance of `UniversalBlePlatformChannel` to handle messages through the `binary_messenger`.
|
|
void UniversalBlePlatformChannel::SetUp(
|
|
flutter::BinaryMessenger* binary_messenger,
|
|
UniversalBlePlatformChannel* api) {
|
|
{
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
api->GetBluetoothAvailabilityState([reply](ErrorOr<int64_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.universal_ble.UniversalBlePlatformChannel.enableBluetooth", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
api->EnableBluetooth([reply](ErrorOr<bool>&& 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.universal_ble.UniversalBlePlatformChannel.startScan", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
std::optional<FlutterError> output = api->StartScan();
|
|
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.universal_ble.UniversalBlePlatformChannel.stopScan", &GetCodec());
|
|
if (api != nullptr) {
|
|
channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
|
try {
|
|
std::optional<FlutterError> output = api->StopScan();
|
|
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.universal_ble.UniversalBlePlatformChannel.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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
std::optional<FlutterError> output = api->Connect(device_id_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.universal_ble.UniversalBlePlatformChannel.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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
std::optional<FlutterError> output = api->Disconnect(device_id_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.universal_ble.UniversalBlePlatformChannel.setNotifiable", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
const auto& encodable_service_arg = args.at(1);
|
|
if (encodable_service_arg.IsNull()) {
|
|
reply(WrapError("service_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& service_arg = std::get<std::string>(encodable_service_arg);
|
|
const auto& encodable_characteristic_arg = args.at(2);
|
|
if (encodable_characteristic_arg.IsNull()) {
|
|
reply(WrapError("characteristic_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& characteristic_arg = std::get<std::string>(encodable_characteristic_arg);
|
|
const auto& encodable_ble_input_property_arg = args.at(3);
|
|
if (encodable_ble_input_property_arg.IsNull()) {
|
|
reply(WrapError("ble_input_property_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t ble_input_property_arg = encodable_ble_input_property_arg.LongValue();
|
|
std::optional<FlutterError> output = api->SetNotifiable(device_id_arg, service_arg, characteristic_arg, ble_input_property_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.universal_ble.UniversalBlePlatformChannel.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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
api->DiscoverServices(device_id_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.universal_ble.UniversalBlePlatformChannel.readValue", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
const auto& encodable_service_arg = args.at(1);
|
|
if (encodable_service_arg.IsNull()) {
|
|
reply(WrapError("service_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& service_arg = std::get<std::string>(encodable_service_arg);
|
|
const auto& encodable_characteristic_arg = args.at(2);
|
|
if (encodable_characteristic_arg.IsNull()) {
|
|
reply(WrapError("characteristic_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& characteristic_arg = std::get<std::string>(encodable_characteristic_arg);
|
|
api->ReadValue(device_id_arg, service_arg, characteristic_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.universal_ble.UniversalBlePlatformChannel.requestMtu", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
const auto& encodable_expected_mtu_arg = args.at(1);
|
|
if (encodable_expected_mtu_arg.IsNull()) {
|
|
reply(WrapError("expected_mtu_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t expected_mtu_arg = encodable_expected_mtu_arg.LongValue();
|
|
api->RequestMtu(device_id_arg, expected_mtu_arg, [reply](ErrorOr<int64_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.universal_ble.UniversalBlePlatformChannel.writeValue", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
const auto& encodable_service_arg = args.at(1);
|
|
if (encodable_service_arg.IsNull()) {
|
|
reply(WrapError("service_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& service_arg = std::get<std::string>(encodable_service_arg);
|
|
const auto& encodable_characteristic_arg = args.at(2);
|
|
if (encodable_characteristic_arg.IsNull()) {
|
|
reply(WrapError("characteristic_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& characteristic_arg = std::get<std::string>(encodable_characteristic_arg);
|
|
const auto& encodable_value_arg = args.at(3);
|
|
if (encodable_value_arg.IsNull()) {
|
|
reply(WrapError("value_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& value_arg = std::get<std::vector<uint8_t>>(encodable_value_arg);
|
|
const auto& encodable_ble_output_property_arg = args.at(4);
|
|
if (encodable_ble_output_property_arg.IsNull()) {
|
|
reply(WrapError("ble_output_property_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const int64_t ble_output_property_arg = encodable_ble_output_property_arg.LongValue();
|
|
api->WriteValue(device_id_arg, service_arg, characteristic_arg, value_arg, ble_output_property_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.universal_ble.UniversalBlePlatformChannel.isPaired", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
api->IsPaired(device_id_arg, [reply](ErrorOr<bool>&& 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.universal_ble.UniversalBlePlatformChannel.pair", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
std::optional<FlutterError> output = api->Pair(device_id_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.universal_ble.UniversalBlePlatformChannel.unPair", &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_device_id_arg = args.at(0);
|
|
if (encodable_device_id_arg.IsNull()) {
|
|
reply(WrapError("device_id_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
|
std::optional<FlutterError> output = api->UnPair(device_id_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.universal_ble.UniversalBlePlatformChannel.getConnectedDevices", &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_with_services_arg = args.at(0);
|
|
if (encodable_with_services_arg.IsNull()) {
|
|
reply(WrapError("with_services_arg unexpectedly null."));
|
|
return;
|
|
}
|
|
const auto& with_services_arg = std::get<EncodableList>(encodable_with_services_arg);
|
|
api->GetConnectedDevices(with_services_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);
|
|
}
|
|
}
|
|
}
|
|
|
|
EncodableValue UniversalBlePlatformChannel::WrapError(std::string_view error_message) {
|
|
return EncodableValue(EncodableList{
|
|
EncodableValue(std::string(error_message)),
|
|
EncodableValue("Error"),
|
|
EncodableValue()
|
|
});
|
|
}
|
|
|
|
EncodableValue UniversalBlePlatformChannel::WrapError(const FlutterError& error) {
|
|
return EncodableValue(EncodableList{
|
|
EncodableValue(error.code()),
|
|
EncodableValue(error.message()),
|
|
error.details()
|
|
});
|
|
}
|
|
|
|
|
|
UniversalBleCallbackChannelCodecSerializer::UniversalBleCallbackChannelCodecSerializer() {}
|
|
|
|
EncodableValue UniversalBleCallbackChannelCodecSerializer::ReadValueOfType(
|
|
uint8_t type,
|
|
flutter::ByteStreamReader* stream) const {
|
|
switch (type) {
|
|
case 128:
|
|
return CustomEncodableValue(UniversalBleScanResult::FromEncodableList(std::get<EncodableList>(ReadValue(stream))));
|
|
default:
|
|
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
|
}
|
|
}
|
|
|
|
void UniversalBleCallbackChannelCodecSerializer::WriteValue(
|
|
const EncodableValue& value,
|
|
flutter::ByteStreamWriter* stream) const {
|
|
if (const CustomEncodableValue* custom_value = std::get_if<CustomEncodableValue>(&value)) {
|
|
if (custom_value->type() == typeid(UniversalBleScanResult)) {
|
|
stream->WriteByte(128);
|
|
WriteValue(EncodableValue(std::any_cast<UniversalBleScanResult>(*custom_value).ToEncodableList()), stream);
|
|
return;
|
|
}
|
|
}
|
|
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
|
}
|
|
|
|
// Generated class from Pigeon that represents Flutter messages that can be called from C++.
|
|
UniversalBleCallbackChannel::UniversalBleCallbackChannel(flutter::BinaryMessenger* binary_messenger)
|
|
: binary_messenger_(binary_messenger) {}
|
|
|
|
const flutter::StandardMessageCodec& UniversalBleCallbackChannel::GetCodec() {
|
|
return flutter::StandardMessageCodec::GetInstance(&UniversalBleCallbackChannelCodecSerializer::GetInstance());
|
|
}
|
|
|
|
void UniversalBleCallbackChannel::OnAvailabilityChanged(
|
|
int64_t state_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(state_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 UniversalBleCallbackChannel::OnPairStateChange(
|
|
const std::string& device_id_arg,
|
|
bool is_paired_arg,
|
|
const std::string* error_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(device_id_arg),
|
|
EncodableValue(is_paired_arg),
|
|
error_arg ? EncodableValue(*error_arg) : EncodableValue(),
|
|
});
|
|
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 UniversalBleCallbackChannel::OnScanResult(
|
|
const UniversalBleScanResult& result_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
CustomEncodableValue(result_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 UniversalBleCallbackChannel::OnValueChanged(
|
|
const std::string& device_id_arg,
|
|
const std::string& characteristic_id_arg,
|
|
const std::vector<uint8_t>& value_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(device_id_arg),
|
|
EncodableValue(characteristic_id_arg),
|
|
EncodableValue(value_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 UniversalBleCallbackChannel::OnConnectionChanged(
|
|
const std::string& device_id_arg,
|
|
int64_t state_arg,
|
|
std::function<void(void)>&& on_success,
|
|
std::function<void(const FlutterError&)>&& on_error) {
|
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged";
|
|
auto channel = std::make_unique<BasicMessageChannel<>>(binary_messenger_, channel_name, &GetCodec());
|
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
|
EncodableValue(device_id_arg),
|
|
EncodableValue(state_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 universal_ble
|