forked from h2zero/esp-nimble-cpp
[BREAKING] Refactor attributes
Refactor attributes to reduce code duplication and improve maintainability. * Add attribute base classes to provide common code. * Add const where possible to functions and parameters. * `NimBLECharacteristic::notify` no longer takes a `bool is_notification` parameter, instead `indicate()` should be called to send indications. * `NimBLECharacteristic::indicate` now takes the same parameters as `notify`. * `NimBLECharacteristicCallbacks` and `NimBLEDescriptorCallbacks` methods now take `const NimBLEConnInfo&` instead of non-const. * `NimBLECharacteristic::onNotify` callback removed as unnecessary, the library does not call notify without app input. * `NimBLERemoteCharacteristic::getRemoteService` now returns a `const NimBLERemoteService*` instead of non-const. * Add NimBLEUUID constructor that takes a reference to `ble_uuid_any_t`. * `NimBLERemoteService::getCharacteristics` now returns a `const std::vector<NimBLERemoteCharacteristic*>&` instead of non-const `std::vector<NimBLERemoteCharacteristic*>*` * `NimBLERemoteService::getValue` now returns `NimBLEAttValue` instead of `std::string` * `NimBLEService::getCharacteristics` now returns a `const std::vector<NimBLECharacteristic*>&` instead of a copy of std::vector<NimBLECharacteristic *>. * Remove const requirement for NimBLEConnInfo parameter in callbacks. Const is unnecessary as the data can't be changed by application code. * Change NimBLERemoteCharacteristic::getRemoteService to return const pointer.
This commit is contained in:
@@ -51,7 +51,7 @@ class MyClientCallback : public BLEClientCallbacks {
|
||||
}
|
||||
/***************** New - Security handled here ********************
|
||||
****** Note: these are the same return values as defaults ********/
|
||||
void onPassKeyEntry(const NimBLEConnInfo& connInfo){
|
||||
void onPassKeyEntry(NimBLEConnInfo& connInfo){
|
||||
printf("Server Passkey Entry\n");
|
||||
/** This should prompt the user to enter the passkey displayed
|
||||
* on the peer device.
|
||||
@@ -59,14 +59,14 @@ class MyClientCallback : public BLEClientCallbacks {
|
||||
NimBLEDevice::injectPassKey(connInfo, 123456);
|
||||
};
|
||||
|
||||
void onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
||||
};
|
||||
|
||||
/** Pairing process complete, we can check the results in connInfo */
|
||||
void onAuthenticationComplete(const NimBLEConnInfo& connInfo){
|
||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||
if(!connInfo.isEncrypted()) {
|
||||
printf("Encrypt connection failed - disconnecting\n");
|
||||
/** Find the client with the connection handle provided in desc */
|
||||
|
||||
@@ -65,13 +65,13 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
||||
return 123456;
|
||||
};
|
||||
|
||||
void onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
||||
};
|
||||
|
||||
void onAuthenticationComplete(const NimBLEConnInfo& connInfo){
|
||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||
/** Check that encryption was successful, if not we disconnect the client */
|
||||
if(!connInfo.isEncrypted()) {
|
||||
NimBLEDevice::getServer()->disconnect(connInfo.getConnHandle());
|
||||
|
||||
@@ -67,13 +67,13 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
||||
return 123456;
|
||||
};
|
||||
|
||||
void onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
||||
};
|
||||
|
||||
void onAuthenticationComplete(const NimBLEConnInfo& connInfo){
|
||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||
/** Check that encryption was successful, if not we disconnect the client */
|
||||
if(!connInfo.isEncrypted()) {
|
||||
NimBLEDevice::getServer()->disconnect(connInfo.getConnHandle());
|
||||
|
||||
Reference in New Issue
Block a user