// 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 #include #include #include #include #include #include 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* manufacturer_data, const std::vector* manufacturer_data_head) : device_id_(device_id), name_(name ? std::optional(*name) : std::nullopt), is_paired_(is_paired ? std::optional(*is_paired) : std::nullopt), rssi_(rssi ? std::optional(*rssi) : std::nullopt), manufacturer_data_(manufacturer_data ? std::optional>(*manufacturer_data) : std::nullopt), manufacturer_data_head_(manufacturer_data_head ? std::optional>(*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(*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(*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(*value_arg) : std::nullopt; } void UniversalBleScanResult::set_rssi(int64_t value_arg) { rssi_ = value_arg; } const std::vector* UniversalBleScanResult::manufacturer_data() const { return manufacturer_data_ ? &(*manufacturer_data_) : nullptr; } void UniversalBleScanResult::set_manufacturer_data(const std::vector* value_arg) { manufacturer_data_ = value_arg ? std::optional>(*value_arg) : std::nullopt; } void UniversalBleScanResult::set_manufacturer_data(const std::vector& value_arg) { manufacturer_data_ = value_arg; } const std::vector* UniversalBleScanResult::manufacturer_data_head() const { return manufacturer_data_head_ ? &(*manufacturer_data_head_) : nullptr; } void UniversalBleScanResult::set_manufacturer_data_head(const std::vector* value_arg) { manufacturer_data_head_ = value_arg ? std::optional>(*value_arg) : std::nullopt; } void UniversalBleScanResult::set_manufacturer_data_head(const std::vector& 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(list[0])); auto& encodable_name = list[1]; if (!encodable_name.IsNull()) { decoded.set_name(std::get(encodable_name)); } auto& encodable_is_paired = list[2]; if (!encodable_is_paired.IsNull()) { decoded.set_is_paired(std::get(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>(encodable_manufacturer_data)); } auto& encodable_manufacturer_data_head = list[5]; if (!encodable_manufacturer_data_head.IsNull()) { decoded.set_manufacturer_data_head(std::get>(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(*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(*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(list[0])); auto& encodable_characteristics = list[1]; if (!encodable_characteristics.IsNull()) { decoded.set_characteristics(std::get(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(list[0]), std::get(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(ReadValue(stream)))); case 129: return CustomEncodableValue(UniversalBleScanResult::FromEncodableList(std::get(ReadValue(stream)))); case 130: return CustomEncodableValue(UniversalBleService::FromEncodableList(std::get(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(&value)) { if (custom_value->type() == typeid(UniversalBleCharacteristic)) { stream->WriteByte(128); WriteValue(EncodableValue(std::any_cast(*custom_value).ToEncodableList()), stream); return; } if (custom_value->type() == typeid(UniversalBleScanResult)) { stream->WriteByte(129); WriteValue(EncodableValue(std::any_cast(*custom_value).ToEncodableList()), stream); return; } if (custom_value->type() == typeid(UniversalBleService)) { stream->WriteByte(130); WriteValue(EncodableValue(std::any_cast(*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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { api->GetBluetoothAvailabilityState([reply](ErrorOr&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { api->EnableBluetooth([reply](ErrorOr&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { std::optional 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { std::optional 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_device_id_arg); std::optional 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_device_id_arg); std::optional 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(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(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(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 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_device_id_arg); api->DiscoverServices(device_id_arg, [reply](ErrorOr&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(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(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(encodable_characteristic_arg); api->ReadValue(device_id_arg, service_arg, characteristic_arg, [reply](ErrorOr>&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(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&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(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(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(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>(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&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_device_id_arg); api->IsPaired(device_id_arg, [reply](ErrorOr&& 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_device_id_arg); std::optional 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_device_id_arg); std::optional 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>(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices", &GetCodec()); if (api != nullptr) { channel->SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply& reply) { try { const auto& args = std::get(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(encodable_with_services_arg); api->GetConnectedDevices(with_services_arg, [reply](ErrorOr&& 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(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(&value)) { if (custom_value->type() == typeid(UniversalBleScanResult)) { stream->WriteByte(128); WriteValue(EncodableValue(std::any_cast(*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&& on_success, std::function&& on_error) { const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged"; auto channel = std::make_unique>(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 response = GetCodec().DecodeMessage(reply, reply_size); const auto& encodable_return_value = *response; const auto* list_return_value = std::get_if(&encodable_return_value); if (list_return_value) { if (list_return_value->size() > 1) { on_error(FlutterError(std::get(list_return_value->at(0)), std::get(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&& on_success, std::function&& on_error) { const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange"; auto channel = std::make_unique>(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 response = GetCodec().DecodeMessage(reply, reply_size); const auto& encodable_return_value = *response; const auto* list_return_value = std::get_if(&encodable_return_value); if (list_return_value) { if (list_return_value->size() > 1) { on_error(FlutterError(std::get(list_return_value->at(0)), std::get(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&& on_success, std::function&& on_error) { const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult"; auto channel = std::make_unique>(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 response = GetCodec().DecodeMessage(reply, reply_size); const auto& encodable_return_value = *response; const auto* list_return_value = std::get_if(&encodable_return_value); if (list_return_value) { if (list_return_value->size() > 1) { on_error(FlutterError(std::get(list_return_value->at(0)), std::get(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& value_arg, std::function&& on_success, std::function&& on_error) { const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged"; auto channel = std::make_unique>(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 response = GetCodec().DecodeMessage(reply, reply_size); const auto& encodable_return_value = *response; const auto* list_return_value = std::get_if(&encodable_return_value); if (list_return_value) { if (list_return_value->size() > 1) { on_error(FlutterError(std::get(list_return_value->at(0)), std::get(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&& on_success, std::function&& on_error) { const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged"; auto channel = std::make_unique>(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 response = GetCodec().DecodeMessage(reply, reply_size); const auto& encodable_return_value = *response; const auto* list_return_value = std::get_if(&encodable_return_value); if (list_return_value) { if (list_return_value->size() > 1) { on_error(FlutterError(std::get(list_return_value->at(0)), std::get(list_return_value->at(1)), list_return_value->at(2))); } else { on_success(); } } else { on_error(CreateConnectionError(channel_name)); } }); } } // namespace universal_ble