Loading system/gd/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -637,6 +637,8 @@ cc_library_host_shared{ "packet/python3_module.cc", "l2cap/fcs.cc", ":BluetoothPacketSources", "hci/address.cc", "hci/class_of_device.cc", ], generated_headers: [ "BluetoothGeneratedPackets_h", Loading system/gd/hci/address.cc +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <sstream> #include <vector> #include "os/log.h" namespace bluetooth { namespace hci { Loading system/gd/hci/address_pybind11_type_caster.h 0 → 100644 +55 −0 Original line number Diff line number Diff line /****************************************************************************** * * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #pragma once #include <cstring> #include <string> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "hci/address.h" namespace py = pybind11; namespace pybind11 { namespace detail { template <> struct type_caster<::bluetooth::hci::Address> { public: // Set the Python name of Address and declare "value" PYBIND11_TYPE_CASTER(::bluetooth::hci::Address, _("Address")); // Convert from Python->C++ bool load(handle src, bool) { PyObject* source = src.ptr(); if (py::isinstance<py::str>(src)) { bool conversion_successful = bluetooth::hci::Address::FromString(PyUnicode_AsUTF8(source), value); return conversion_successful && !PyErr_Occurred(); } return false; } // Convert from C++->Python static handle cast(bluetooth::hci::Address src, return_value_policy, handle) { return PyUnicode_FromString(src.ToString().c_str()); } }; } // namespace detail } // namespace pybind11 system/gd/hci/class_of_device_pybind11_type_caster.h 0 → 100644 +55 −0 Original line number Diff line number Diff line /****************************************************************************** * * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #pragma once #include <cstring> #include <string> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "hci/class_of_device.h" namespace py = pybind11; namespace pybind11 { namespace detail { template <> struct type_caster<::bluetooth::hci::ClassOfDevice> { public: // Set the Python name of ClassOfDevice and declare "value" PYBIND11_TYPE_CASTER(::bluetooth::hci::ClassOfDevice, _("ClassOfDevice")); // Convert from Python->C++ bool load(handle src, bool) { PyObject* source = src.ptr(); if (py::isinstance<py::str>(src)) { bool conversion_successful = bluetooth::hci::ClassOfDevice::FromString(PyUnicode_AsUTF8(source), value); return conversion_successful && !PyErr_Occurred(); } return false; } // Convert from C++->Python static handle cast(bluetooth::hci::ClassOfDevice src, return_value_policy, handle) { return PyUnicode_FromString(src.ToString().c_str()); } }; } // namespace detail } // namespace pybind11 system/gd/packet/parser/custom_field_def.cc +4 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,10 @@ void CustomFieldDef::GenInclude(std::ostream& s) const { s << "#include \"" << include_ << util::CamelCaseToUnderScore(GetTypeName()) << ".h\"\n"; } void CustomFieldDef::GenPyBind11Include(std::ostream& s) const { s << "#include \"" << include_ << util::CamelCaseToUnderScore(GetTypeName()) << "_pybind11_type_caster.h\"\n"; } void CustomFieldDef::GenUsing(std::ostream& s) const { s << "using ::bluetooth::"; for (const auto& c : include_) { Loading Loading
system/gd/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -637,6 +637,8 @@ cc_library_host_shared{ "packet/python3_module.cc", "l2cap/fcs.cc", ":BluetoothPacketSources", "hci/address.cc", "hci/class_of_device.cc", ], generated_headers: [ "BluetoothGeneratedPackets_h", Loading
system/gd/hci/address.cc +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <sstream> #include <vector> #include "os/log.h" namespace bluetooth { namespace hci { Loading
system/gd/hci/address_pybind11_type_caster.h 0 → 100644 +55 −0 Original line number Diff line number Diff line /****************************************************************************** * * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #pragma once #include <cstring> #include <string> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "hci/address.h" namespace py = pybind11; namespace pybind11 { namespace detail { template <> struct type_caster<::bluetooth::hci::Address> { public: // Set the Python name of Address and declare "value" PYBIND11_TYPE_CASTER(::bluetooth::hci::Address, _("Address")); // Convert from Python->C++ bool load(handle src, bool) { PyObject* source = src.ptr(); if (py::isinstance<py::str>(src)) { bool conversion_successful = bluetooth::hci::Address::FromString(PyUnicode_AsUTF8(source), value); return conversion_successful && !PyErr_Occurred(); } return false; } // Convert from C++->Python static handle cast(bluetooth::hci::Address src, return_value_policy, handle) { return PyUnicode_FromString(src.ToString().c_str()); } }; } // namespace detail } // namespace pybind11
system/gd/hci/class_of_device_pybind11_type_caster.h 0 → 100644 +55 −0 Original line number Diff line number Diff line /****************************************************************************** * * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #pragma once #include <cstring> #include <string> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "hci/class_of_device.h" namespace py = pybind11; namespace pybind11 { namespace detail { template <> struct type_caster<::bluetooth::hci::ClassOfDevice> { public: // Set the Python name of ClassOfDevice and declare "value" PYBIND11_TYPE_CASTER(::bluetooth::hci::ClassOfDevice, _("ClassOfDevice")); // Convert from Python->C++ bool load(handle src, bool) { PyObject* source = src.ptr(); if (py::isinstance<py::str>(src)) { bool conversion_successful = bluetooth::hci::ClassOfDevice::FromString(PyUnicode_AsUTF8(source), value); return conversion_successful && !PyErr_Occurred(); } return false; } // Convert from C++->Python static handle cast(bluetooth::hci::ClassOfDevice src, return_value_policy, handle) { return PyUnicode_FromString(src.ToString().c_str()); } }; } // namespace detail } // namespace pybind11
system/gd/packet/parser/custom_field_def.cc +4 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,10 @@ void CustomFieldDef::GenInclude(std::ostream& s) const { s << "#include \"" << include_ << util::CamelCaseToUnderScore(GetTypeName()) << ".h\"\n"; } void CustomFieldDef::GenPyBind11Include(std::ostream& s) const { s << "#include \"" << include_ << util::CamelCaseToUnderScore(GetTypeName()) << "_pybind11_type_caster.h\"\n"; } void CustomFieldDef::GenUsing(std::ostream& s) const { s << "using ::bluetooth::"; for (const auto& c : include_) { Loading