Function AddService

Synopsis

#include <bta/gatt/database_builder.h>

void AddService(uint16_t handle, uint16_t end_handle, const bluetooth::Uuid &uuid, bool is_primary)

Description

No description yet.

Source

Lines 30-55 in bta/gatt/database_builder.cc. Line 33 in bta/gatt/database_builder.h.

void DatabaseBuilder::AddService(uint16_t handle, uint16_t end_handle,
                                 const Uuid& uuid, bool is_primary) {
  // general case optimization - we add services in order
  if (database.services.empty() ||
      database.services.back().end_handle < handle) {
    database.services.emplace_back(Service{.handle = handle,
                                           .end_handle = end_handle,
                                           .is_primary = is_primary,
                                           .uuid = uuid});
  } else {
    auto& vec = database.services;

    // Find first service whose start handle is bigger than new service handle
    auto it = std::lower_bound(
        vec.begin(), vec.end(), handle,
        [](Service s, uint16_t handle) { return s.end_handle < handle; });

    // Insert new service just before it
    vec.emplace(it, Service{.handle = handle,
                            .end_handle = end_handle,
                            .is_primary = is_primary,
                            .uuid = uuid});
  }

  services_to_discover.insert({handle, end_handle});
}





Add Discussion as Guest

Log in to DocsForge