Skip to content

Commit b719a39

Browse files
committed
Revert #697277f and replace with stack checks.
Replaces `NimBLEDevice::setConnectionInProgress` and `NimBLEDevice::isConnectionInProgress()` with lower level checks to avoid potential incorrect state reporting. `NimBLEClient::connect` will instead call `NimBLEScan::stop` if it stopped the scan to release any resources waiting, the call the callback if set.
1 parent 78cce34 commit b719a39

File tree

4 files changed

+1
-38
lines changed

4 files changed

+1
-38
lines changed

src/NimBLEClient.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,6 @@ bool NimBLEClient::connect(const NimBLEAddress& address, bool deleteAttributes,
176176
return false;
177177
}
178178

179-
if (NimBLEDevice::isConnectionInProgress()) {
180-
NIMBLE_LOGE(LOG_TAG, "Connection already in progress");
181-
return false;
182-
}
183-
184179
const ble_addr_t* peerAddr = address.getBase();
185180
if (ble_gap_conn_find_by_addr(peerAddr, NULL) == 0) {
186181
NIMBLE_LOGE(LOG_TAG, "A connection to %s already exists", address.toString().c_str());
@@ -202,9 +197,6 @@ bool NimBLEClient::connect(const NimBLEAddress& address, bool deleteAttributes,
202197
m_config.asyncConnect = asyncConnect;
203198
m_config.exchangeMTU = exchangeMTU;
204199

205-
// Set the connection in progress flag to prevent a scan from starting while connecting.
206-
NimBLEDevice::setConnectionInProgress(true);
207-
208200
do {
209201
# if CONFIG_BT_NIMBLE_EXT_ADV
210202
rc = ble_gap_ext_connect(NimBLEDevice::m_ownAddrType,
@@ -258,7 +250,6 @@ bool NimBLEClient::connect(const NimBLEAddress& address, bool deleteAttributes,
258250

259251
if (rc != 0) {
260252
m_lastErr = rc;
261-
NimBLEDevice::setConnectionInProgress(false);
262253
return false;
263254
}
264255

@@ -985,7 +976,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
985976
return 0;
986977
}
987978

988-
NimBLEDevice::setConnectionInProgress(false);
989979
rc = event->connect.status;
990980
if (rc == 0) {
991981
pClient->m_connHandle = event->connect.conn_handle;

src/NimBLEDevice.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ std::vector<NimBLEAddress> NimBLEDevice::m_ignoreList{};
101101
std::vector<NimBLEAddress> NimBLEDevice::m_whiteList{};
102102
uint8_t NimBLEDevice::m_ownAddrType{BLE_OWN_ADDR_PUBLIC};
103103

104-
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
105-
bool NimBLEDevice::m_connectionInProgress{false};
106-
# endif
107-
108104
# ifdef ESP_PLATFORM
109105
# ifdef CONFIG_BTDM_BLE_SCAN_DUPL
110106
uint16_t NimBLEDevice::m_scanDuplicateSize{CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE};
@@ -1238,23 +1234,6 @@ bool NimBLEDevice::setCustomGapHandler(gap_event_handler handler) {
12381234
return rc == 0;
12391235
} // setCustomGapHandler
12401236

1241-
/**
1242-
* @brief Set the connection in progress flag.
1243-
* @param [in] inProgress The connection in progress flag.
1244-
* @details This is used to prevent a scan from starting while a connection is in progress.
1245-
*/
1246-
void NimBLEDevice::setConnectionInProgress(bool inProgress) {
1247-
m_connectionInProgress = inProgress;
1248-
} // setConnectionInProgress
1249-
1250-
/**
1251-
* @brief Check if a connection is in progress.
1252-
* @return True if a connection is in progress.
1253-
*/
1254-
bool NimBLEDevice::isConnectionInProgress() {
1255-
return m_connectionInProgress;
1256-
} // isConnectionInProgress
1257-
12581237
/**
12591238
* @brief Return a string representation of the address of this device.
12601239
* @return A string representation of this device address.

src/NimBLEDevice.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ class NimBLEDevice {
184184
static bool isBonded(const NimBLEAddress& address);
185185
static bool deleteAllBonds();
186186
static NimBLEAddress getBondedAddress(int index);
187-
static void setConnectionInProgress(bool inProgress);
188-
static bool isConnectionInProgress();
189187
# endif
190188

191189
private:
@@ -197,10 +195,6 @@ class NimBLEDevice {
197195
static uint8_t m_ownAddrType;
198196
static std::vector<NimBLEAddress> m_whiteList;
199197

200-
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
201-
static bool m_connectionInProgress;
202-
# endif
203-
204198
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
205199
static NimBLEScan* m_pScan;
206200
# endif

src/NimBLEScan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ bool NimBLEScan::isScanning() {
291291
bool NimBLEScan::start(uint32_t duration, bool is_continue) {
292292
NIMBLE_LOGD(LOG_TAG, ">> start: duration=%" PRIu32, duration);
293293

294-
if (NimBLEDevice::isConnectionInProgress()) {
294+
if (ble_gap_conn_active()) {
295295
NIMBLE_LOGE(LOG_TAG, "Connection in progress, cannot start scan");
296296
return false;
297297
}

0 commit comments

Comments
 (0)