NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
NimBLERemoteService.h
1/*
2 * Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_REMOTE_SERVICE_H_
19#define NIMBLE_CPP_REMOTE_SERVICE_H_
20
21#include "nimconfig.h"
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
23
24# include "NimBLEAttribute.h"
25# include <vector>
26
28class NimBLEClient;
29class NimBLEAttValue;
30
35 public:
36 NimBLERemoteCharacteristic* getCharacteristic(const char* uuid) const;
38 void deleteCharacteristics() const;
39 size_t deleteCharacteristic(const NimBLEUUID& uuid) const;
40 NimBLEClient* getClient(void) const;
41 NimBLEAttValue getValue(const NimBLEUUID& characteristicUuid) const;
42 bool setValue(const NimBLEUUID& characteristicUuid, const NimBLEAttValue& value) const;
43 std::string toString(void) const;
44 uint16_t getStartHandle() const { return getHandle(); }
45 uint16_t getEndHandle() const { return m_endHandle; }
46
47 const std::vector<NimBLERemoteCharacteristic*>& getCharacteristics(bool refresh = false) const;
48 std::vector<NimBLERemoteCharacteristic*>::iterator begin() const;
49 std::vector<NimBLERemoteCharacteristic*>::iterator end() const;
50
51 private:
52 friend class NimBLEClient;
53
54 NimBLERemoteService(NimBLEClient* pClient, const struct ble_gatt_svc* service);
56 bool retrieveCharacteristics(const NimBLEUUID* uuidFilter = nullptr) const;
57 static int characteristicDiscCB(uint16_t conn_handle,
58 const struct ble_gatt_error* error,
59 const struct ble_gatt_chr* chr,
60 void* arg);
61
62 mutable std::vector<NimBLERemoteCharacteristic*> m_vChars{};
63 NimBLEClient* m_pClient{nullptr};
64 uint16_t m_endHandle{0};
65}; // NimBLERemoteService
66
67#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
68#endif /* NIMBLE_CPP_REMOTE_SERVICE_H_*/
A specialized container class to hold BLE attribute values.
Definition NimBLEAttValue.h:72
A base class for BLE attributes.
Definition NimBLEAttribute.h:29
uint16_t getHandle() const
Get the handle of the attribute.
Definition NimBLEAttribute.h:40
A model of a BLE client.
Definition NimBLEClient.h:49
A model of a remote BLE characteristic.
Definition NimBLERemoteCharacteristic.h:34
A model of a remote BLE service.
Definition NimBLERemoteService.h:34
bool setValue(const NimBLEUUID &characteristicUuid, const NimBLEAttValue &value) const
Set the value of a characteristic.
Definition NimBLERemoteService.cpp:244
NimBLEClient * getClient(void) const
Get the client associated with this service.
Definition NimBLERemoteService.cpp:220
std::string toString(void) const
Create a string representation of this remote service.
Definition NimBLERemoteService.cpp:287
std::vector< NimBLERemoteCharacteristic * >::iterator end() const
Get iterator to the end of the vector of remote characteristic pointers.
Definition NimBLERemoteService.cpp:59
const std::vector< NimBLERemoteCharacteristic * > & getCharacteristics(bool refresh=false) const
Get a pointer to the vector of found characteristics.
Definition NimBLERemoteService.cpp:133
void deleteCharacteristics() const
Delete the characteristics in the characteristics vector.
Definition NimBLERemoteService.cpp:259
size_t deleteCharacteristic(const NimBLEUUID &uuid) const
Delete characteristic by UUID.
Definition NimBLERemoteService.cpp:271
std::vector< NimBLERemoteCharacteristic * >::iterator begin() const
Get iterator to the beginning of the vector of remote characteristic pointers.
Definition NimBLERemoteService.cpp:51
NimBLEAttValue getValue(const NimBLEUUID &characteristicUuid) const
Read the value of a characteristic associated with this service.
Definition NimBLERemoteService.cpp:229
NimBLERemoteCharacteristic * getCharacteristic(const char *uuid) const
Get the remote characteristic object for the characteristic UUID.
Definition NimBLERemoteService.cpp:68
A model of a BLE UUID.
Definition NimBLEUUID.h:41