mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-27 15:40:55 +01:00
Add NimBLEClientCallbacks::onConnectFail callback
Adds a callback that is called when the connection attempt fail while connecting asynchronously.
This commit is contained in:
parent
41a7aa8eb5
commit
a4043e3f04
2 changed files with 26 additions and 15 deletions
|
@ -977,28 +977,28 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
|
||||||
rc = event->connect.status;
|
rc = event->connect.status;
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
pClient->m_connHandle = event->connect.conn_handle;
|
pClient->m_connHandle = event->connect.conn_handle;
|
||||||
|
|
||||||
|
if (pClient->m_config.asyncConnect) {
|
||||||
|
pClient->m_pClientCallbacks->onConnect(pClient);
|
||||||
|
}
|
||||||
|
|
||||||
if (pClient->m_config.exchangeMTU) {
|
if (pClient->m_config.exchangeMTU) {
|
||||||
if (!pClient->exchangeMTU() && !pClient->m_config.asyncConnect) {
|
if (!pClient->exchangeMTU()) {
|
||||||
rc = pClient->m_lastErr; // sets the error in the task data
|
rc = pClient->m_lastErr; // sets the error in the task data
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE;
|
pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE;
|
||||||
if (!pClient->m_config.asyncConnect) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pClient->m_config.deleteOnConnectFail) { // async connect
|
|
||||||
delete pClient;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pClient->m_config.asyncConnect) {
|
if (pClient->m_config.asyncConnect) {
|
||||||
pClient->m_pClientCallbacks->onConnect(pClient);
|
pClient->m_pClientCallbacks->onConnectFail(pClient, rc);
|
||||||
} else if (!pClient->m_config.exchangeMTU) {
|
if (pClient->m_config.deleteOnConnectFail) {
|
||||||
break; // not waiting for MTU exchange so release the task now.
|
NimBLEDevice::deleteClient(pClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1236,8 +1236,12 @@ void NimBLEClientCallbacks::onConnect(NimBLEClient* pClient) {
|
||||||
NIMBLE_LOGD(CB_TAG, "onConnect: default");
|
NIMBLE_LOGD(CB_TAG, "onConnect: default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NimBLEClientCallbacks::onConnectFail(NimBLEClient* pClient, int reason) {
|
||||||
|
NIMBLE_LOGD(CB_TAG, "onConnectFail: default, reason: %d", reason);
|
||||||
|
}
|
||||||
|
|
||||||
void NimBLEClientCallbacks::onDisconnect(NimBLEClient* pClient, int reason) {
|
void NimBLEClientCallbacks::onDisconnect(NimBLEClient* pClient, int reason) {
|
||||||
NIMBLE_LOGD(CB_TAG, "onDisconnect: default");
|
NIMBLE_LOGD(CB_TAG, "onDisconnect: default, reason: %d", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NimBLEClientCallbacks::onConnParamsUpdateRequest(NimBLEClient* pClient, const ble_gap_upd_params* params) {
|
bool NimBLEClientCallbacks::onConnParamsUpdateRequest(NimBLEClient* pClient, const ble_gap_upd_params* params) {
|
||||||
|
|
|
@ -148,10 +148,17 @@ class NimBLEClientCallbacks {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called after client connects.
|
* @brief Called after client connects.
|
||||||
* @param [in] pClient A pointer to the calling client object.
|
* @param [in] pClient A pointer to the connecting client object.
|
||||||
*/
|
*/
|
||||||
virtual void onConnect(NimBLEClient* pClient);
|
virtual void onConnect(NimBLEClient* pClient);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when a connection attempt fails.
|
||||||
|
* @param [in] pClient A pointer to the connecting client object.
|
||||||
|
* @param [in] reason Contains the reason code for the connection failure.
|
||||||
|
*/
|
||||||
|
virtual void onConnectFail(NimBLEClient* pClient, int reason);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when disconnected from the server.
|
* @brief Called when disconnected from the server.
|
||||||
* @param [in] pClient A pointer to the calling client object.
|
* @param [in] pClient A pointer to the calling client object.
|
||||||
|
|
Loading…
Reference in a new issue