Skip to content

Latest commit

 

History

History
148 lines (111 loc) · 3.9 KB

File metadata and controls

148 lines (111 loc) · 3.9 KB

🔗 Gattlib C++

License: LGPL v3 Platform C++

A modern C++ wrapper for BlueZ's GATT library

📖 Overview (work in progress)

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.

✨ Features

🔄 Modern C++ Design

  • RAII-compliant resource management
  • Smart pointer usage throughout
  • Exception-safe error handling
  • PIMPL idiom for ABI stability

🛠️ Core Functionality

  • ✅ BLE Scanner
    • Asynchronous device discovery
    • MAC address filtering
    • Signal-based abort mechanism
  • 🔄 Connection Manager (In Progress)
    • GATT operations
    • Service discovery
    • Characteristic read/write

🧪 Quality Assurance

  • 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

🚀 Getting Started

Prerequisites

  • Linux system with BlueZ
  • CMake 3.16 or higher
  • C++17 compiler
  • Development packages:
    sudo apt install libglib2.0-dev libbluetooth-dev

Build Instructions

  1. Clone the Repository

    git clone https://github.com/your-username/gattlib.git
    cd gattlib
  2. Create Build Directory

    mkdir build && cd build
  3. Configure and Build

    cmake ..
    make -j$(nproc)
  4. Run Tests (Optional)

    ctest --output-on-failure

📚 Documentation

Example Usage

#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;
}

🤝 Contributing

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.

📄 License

This project is licensed under the LGPL-3.0 License - see the LICENSE file for details.

🙏 Acknowledgments

  • Original gattlib developers
  • BlueZ project team
  • All contributors to this modern C++ fork

📁 Project Structure

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

⚖️ Why This Fork?

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.

📫 Contact

Cristian Troncoso LinkedIn


“Built on the shoulders of giants.” — Thanks to the original gattlib authors.