This project is fork of the original C implementation labapart/gattlib. Implements modern C++ wrapper to Bluetooth Low Energy (BLE) library on Linux. Built on top of BlueZ and Dbus, it provides a safe, efficient, and idiomatic C++ interface for BLE operations.
- RAII-compliant resource management
- Smart pointer usage throughout
- Exception-safe error handling
- PIMPL idiom for ABI stability
- ✅ BLE Scanner
- Asynchronous device discovery
- MAC address filtering
- Signal-based abort mechanism
- 🔄 Connection Manager (In Progress)
- GATT operations
- Service discovery
- Characteristic read/write
- Comprehensive test suite
- Unit tests with Google Test
- Mock BLE adapter support
- CI/CD integration ready
- Memory safety improvements
- Fixed memory leaks in C core
- RAII-based cleanup
- Linux system with BlueZ
- CMake 3.16 or higher
- C++17 compiler
- Development packages:
sudo apt install libglib2.0-dev libbluetooth-dev
-
Clone the Repository
git clone https://github.com/your-username/gattlib.git cd gattlib -
Create Build Directory
mkdir build && cd build
-
Configure and Build
cmake .. make -j$(nproc) -
Run Tests (Optional)
ctest --output-on-failure
#include <gattlib_scanner.hpp>
int main() {
try {
// Create scanner instance
blecpp::GattlibScanner scanner;
// Scan for devices (5 second timeout)
scanner.scan(5);
// Or scan for specific device
scanner.scan(5, "00:11:22:33:44:55");
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the LGPL-3.0 License - see the LICENSE file for details.
- Original gattlib developers
- BlueZ project team
- All contributors to this modern C++ fork
gattlib/
├── cpp/ # Modern C++ wrapper for BLE APIs
│ ├── include/
│ ├── src/
│ └── tests/
├── bluez/ # BlueZ-related backend logic
├── dbus/ # D-Bus integration for BlueZ v5
├── examples/ # Example programs
├── gattlib-py/ # Python bindings
└── CMakeLists.txt # Build configuration
The goal of this fork is to provide:
- A modern, idiomatic C++ API for BLE development
- Cleaner, safer abstractions over the C-based
gattlib - Easier integration in modern CMake-based C++ projects
- Fix memory leaks and improve maintainability of the original C core
I hope this helps developers who want the power of gattlib in a more modern form.
Cristian Troncoso LinkedIn
“Built on the shoulders of giants.” — Thanks to the original
gattlibauthors.