SDK  23.9.2
For IoT System Software Development
Public Member Functions | Public Attributes | List of all members
BLEServer Class Reference

The model of a BLE server. More...

#include <BLEServer.hpp>

Public Member Functions

uint32_t getConnectedCount ()
 Return the number of connected clients. More...
 
BLEServicecreateService (const char *uuid)
 Create a BLE Service. More...
 
BLEServicecreateService (BLEUUID uuid, uint32_t numHandles=15, uint8_t inst_id=0)
 Create a BLE Service. More...
 
BLEAdvertisinggetAdvertising ()
 Retrieve the advertising object that can be used to advertise the existence of the server. More...
 
void setCallbacks (BLEServerCallbacks *pCallbacks)
 Set the server callbacks. More...
 
void startAdvertising ()
 
void removeService (BLEService *service)
 
BLEServicegetServiceByUUID (const char *uuid)
 Get a BLE Service by its UUID. More...
 
BLEServicegetServiceByUUID (BLEUUID uuid)
 Get a BLE Service by its UUID. More...
 
bool connect (BLEAddress address)
 
void disconnect (uint16_t connId)
 
void updateConnParams (BLEAddress &remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout)
 

Public Attributes

uint16_t m_appId
 

Detailed Description

The model of a BLE server.

Member Function Documentation

◆ createService() [1/2]

BLEService * BLEServer::createService ( BLEUUID  uuid,
uint32_t  numHandles = 15,
uint8_t  inst_id = 0 
)

Create a BLE Service.

With a BLE server, we can host one or more services. Invoking this function causes the creation of a definition of a new service. Every service must have a unique UUID.

Parameters
[in]uuidThe UUID of the new service.
[in]numHandlesThe maximum number of handles associated with this service.
[in]inst_idWith multiple services with the same UUID we need to provide inst_id value different for each service.
Returns
A reference to the new service object.
66  {
67  _debug_print_s(TAG, ">> createService", uuid.toString().c_str());
68 #ifndef SOFTDEVICE_PRESENT
69  m_spinlockCreateEvt.take();
70 #endif
71 
72  // Check that a service with the supplied UUID does not already exist.
73  if (m_serviceMap.getByUUID(uuid) != nullptr) {
74  _debug_print_s(TAG, "<< Attempt to create a new service with uuid %s but a service with that UUID already exists.",
75  uuid.toString().c_str());
76  }
77 
78  BLEService* pService = new BLEService(uuid, numHandles);
79  pService->m_instId = inst_id;
80  m_serviceMap.setByUUID(uuid, pService); // Save a reference to this service being on this server.
81  pService->executeCreate(this); // Perform the API calls to actually create the service.
82 #ifndef SOFTDEVICE_PRESENT
83  m_spinlockCreateEvt.wait();
84 #endif
85  debug_print(TAG, "<< createService");
86  return pService;
87 } // createService

◆ createService() [2/2]

BLEService * BLEServer::createService ( const char *  uuid)

Create a BLE Service.

With a BLE server, we can host one or more services. Invoking this function causes the creation of a definition of a new service. Every service must have a unique UUID.

Parameters
[in]uuidThe UUID of the new service.
Returns
A reference to the new service object.
51  {
52  return createService(BLEUUID(uuid));
53 }

◆ getAdvertising()

BLEAdvertising * BLEServer::getAdvertising ( )

Retrieve the advertising object that can be used to advertise the existence of the server.

Returns
An advertising object.
113  {
114  return BLEDevice::getAdvertising();
115 }

◆ getConnectedCount()

uint32_t BLEServer::getConnectedCount ( )

Return the number of connected clients.

Returns
The number of connected clients.
122  {
123  return m_connectedServersMap.size();
124 } // getConnectedCount

◆ getServiceByUUID() [1/2]

BLEService * BLEServer::getServiceByUUID ( BLEUUID  uuid)

Get a BLE Service by its UUID.

Parameters
[in]uuidThe UUID of the new service.
Returns
A reference to the service object.
104  {
105  return m_serviceMap.getByUUID(uuid);
106 }

◆ getServiceByUUID() [2/2]

BLEService * BLEServer::getServiceByUUID ( const char *  uuid)

Get a BLE Service by its UUID.

Parameters
[in]uuidThe UUID of the new service.
Returns
A reference to the service object.
95  {
96  return m_serviceMap.getByUUID(uuid);
97 }

◆ setCallbacks()

void BLEServer::setCallbacks ( BLEServerCallbacks pCallbacks)

Set the server callbacks.

As a BLE server operates, it will generate server level events such as a new client connecting or a previous client disconnecting. This function can be called to register a callback handler that will be invoked when these events are detected.

Parameters
[in]pCallbacksThe callbacks to be invoked.
141  {
142  m_pServerCallbacks = pCallbacks;
143 } // setCallbacks

The documentation for this class was generated from the following files:
BLEUUID::toString
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:317
BLEServiceMap::getByUUID
BLEService * getByUUID(const char *uuid)
Return the service by UUID.
Definition: BLEServiceMap.cpp:36
BLEUUID
A model of a BLE UUID.
Definition: BLEUUID.hpp:41
BLEService
The model of a BLE service.
Definition: BLEService.hpp:70
BLEServer::createService
BLEService * createService(const char *uuid)
Create a BLE Service.
Definition: BLEServer.cpp:51