8000 added getServiceCount() to BLEServer.cpp by Donderda · Pull Request #700 · nkolban/esp32-snippets · GitHub
[go: up one dir, main page]

Skip to content

added getServiceCount() to BLEServer.cpp #700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cpp_utils/BLEServer.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ BLEService* BLEServer::getServiceByUUID(BLEUUID uuid) {
}


/**
* @brief Returns the amount of services registered to this server
* @param [in] includeDefaultServices Add the amount of default BluetoothLE services defined by the BLE standard
* @return The amount of registered services
*/
int BLEServer::getServiceCount(bool includeDefaultServices) {
if(includeDefaultServices){
return m_serviceMap.getRegisteredServiceCount() + 2;
}
return m_serviceMap.getRegisteredServiceCount();
}


/**
* @brief Retrieve the advertising object that can be used to advertise the existence of the server.
*
Expand Down
3 changes: 3 additions & 0 deletions cpp_utils/BLEServer.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class BLEServiceMap {
BLEService* getFirst();
BLEService* getNext();
void removeService(BLEService* service);
int getRegisteredServiceCount();


private:
std::map<uint16_t, BLEService*> m_handleMap;
Expand All @@ -66,6 +68,7 @@ class BLEServer {
BLEService* getServiceByUUID(const char* uuid);
BLEService* getServiceByUUID(BLEUUID uuid);
void removeService(BLEService* service);
int getServiceCount(bool includeDefaultServices);

private:
BLEServer();
Expand Down
30 changes: 21 additions & 9 deletions cpp_utils/BLEServiceMap.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* @return The characteristic.
*/
BLEService* BLEServiceMap::getByUUID(const char* uuid) {
return getByUUID(BLEUUID(uuid));
return getByUUID(BLEUUID(uuid));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use tabs instead of spaces

}

/**
* @brief Return the service by UUID.
* @param [in] UUID The UUID to look up the service.
Expand Down Expand Up @@ -53,8 +53,8 @@ BLEService* BLEServiceMap::getByHandle(uint16_t handle) {
* @return N/A.
*/
void BLEServiceMap::setByUUID(BLEUUID uuid,
BLEService* service) {
m_uuidMap.insert(std::pair<BLEService*, std::string>(service, uuid.toString()));
BLEService *service) {
m_uuidMap.insert(std::pair<BLEService *, std::string>(service, uuid.toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This edit is unnecessary.

} // setByUUID


Expand All @@ -66,7 +66,7 @@ void BLEServiceMap::setByUUID(BLEUUID uuid,
*/
void BLEServiceMap::setByHandle(uint16_t handle,
BLEService* service) {
m_handleMap.insert(std::pair<uint16_t, BLEService*>(handle, service));
m_handleMap.insert(std::pair<uint16_t, BLEService *>(handle, service));
} // setByHandle


Expand All @@ -86,7 +86,7 @@ std::string BLEServiceMap::toString() {
void BLEServiceMap::handleGATTServerEvent(
esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t* param) {
esp_ble_gatts_cb_param_t *param) {
// Invoke the handler for every Service we have.
for (auto &myPair : m_uuidMap) {
myPair.first->handleGATTServerEvent(event, gatts_if, param);
Expand All @@ -99,7 +99,9 @@ void BLEServiceMap::handleGATTServerEvent(
*/
BLEService* BLEServiceMap::getFirst() {
m_iterator = m_uuidMap.begin();
if (m_iterator == m_uuidMap.end()) return nullptr;
if (m_iterator == m_uuidMap.end()) {
return nullptr;
}
BLEService* pRet = m_iterator->first;
m_iterator++;
return pRet;
Expand All @@ -110,7 +112,9 @@ BLEService* BLEServiceMap::getFirst() {
* @return The next service in the map.
*/
BLEService* BLEServiceMap::getNext() {
if (m_iterator == m_uuidMap.end()) return nullptr;
if (m_iterator == m_uuidMap.end()) {
return nullptr;
}
BLEService* pRet = m_iterator->first;
m_iterator++;
return pRet;
Expand All @@ -120,9 +124,17 @@ BLEService* BLEServiceMap::getNext() {
* @brief Removes service from maps.
* @return N/A.
*/
void BLEServiceMap::removeService(BLEService* service) {
void BLEServiceMap::removeService(BLEService *service){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refrain from applying auto-formatting to the whole document when you only add\edit couple of lines.
Or, even better, set your IDE rules to conform to project's.

m_handleMap.erase(service->getHandle());
m_uuidMap.erase(service);
} // removeService

/**
* @brief Returns the amount of registered services
* @return amount of registered services
*/
int BLEServiceMap::getRegisteredServiceCount(){
return m_handleMap.size();
}

#endif /* CONFIG_BT_ENABLED */
0