Skip to content

Commit

Permalink
Set/Reset on CHIPoBLEConState (#4095)
Browse files Browse the repository at this point in the history
Encapsulate setting ESP32's BLEManagerImpl::CHIPoBLEConState.

(Requested in review comments on PR #4011. Other existing `BLEManagerImpl`s
don't use this pattern.)
  • Loading branch information
kpschoedel authored Dec 7, 2020
1 parent 5813d4a commit cf1cd59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/platform/ESP32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ class BLEManagerImpl final : public BLEManager,
uint16_t Allocated : 1;
uint16_t Subscribed : 1;
uint16_t Unused : 4;

void Set(uint16_t conId)
{
PendingIndBuf = nullptr;
ConId = conId;
MTU = 0;
Allocated = 1;
Subscribed = 0;
Unused = 0;
}
void Reset()
{
PendingIndBuf = nullptr;
ConId = BLE_CONNECTION_UNINITIALIZED;
MTU = 0;
Allocated = 0;
Subscribed = 0;
Unused = 0;
}
};

CHIPoBLEConState mCons[kMaxConnections];
Expand Down
10 changes: 2 additions & 8 deletions src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,7 @@ BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::GetConnectionState(uint16_t c
{
if (freeIndex < kMaxConnections)
{
mCons[freeIndex].PendingIndBuf = nullptr;
mCons[freeIndex].ConId = conId;
mCons[freeIndex].MTU = 0;
mCons[freeIndex].Allocated = 1;
mCons[freeIndex].Subscribed = 0;
mCons[freeIndex].Unused = 0;
mCons[freeIndex].Set(conId);
return &mCons[freeIndex];
}

Expand All @@ -1167,8 +1162,7 @@ bool BLEManagerImpl::ReleaseConnectionState(uint16_t conId)
{
if (mCons[i].Allocated && mCons[i].ConId == conId)
{
mCons[i].PendingIndBuf = nullptr;
mCons[i].Allocated = 0;
mCons[i].Reset();
return true;
}
}
Expand Down

0 comments on commit cf1cd59

Please sign in to comment.