Skip to content

Commit fbf61b2

Browse files
authored
fix(win): fix subscribe to characteristic on windows #58
1 parent a61d7bc commit fbf61b2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/win/src/ble_manager.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,11 @@ bool BLEManager::Notify(const std::string& uuid, const winrt::guid& serviceUuid,
703703
mEmit.Notify(uuid, serviceId, characteristicId, true);
704704
return;
705705
}
706+
707+
auto onChanged = bind2(this, &BLEManager::OnValueChanged, uuid);
708+
auto token = characteristic->ValueChanged(onChanged);
709+
mNotifyMap.Add(uuid, *characteristic, token);
710+
706711
auto descriptorValue =
707712
GetDescriptorValue(characteristic->CharacteristicProperties());
708713

@@ -750,18 +755,16 @@ void BLEManager::OnNotify(IAsyncOperation<GattWriteResult> asyncOp, AsyncStatus
750755
{
751756
if (status == AsyncStatus::Completed)
752757
{
753-
if (state == true)
754-
{
755-
auto onChanged = bind2(this, &BLEManager::OnValueChanged, uuid);
756-
auto token = characteristic.ValueChanged(onChanged);
757-
mNotifyMap.Add(uuid, characteristic, token);
758-
}
759758
mEmit.Notify(uuid, serviceId, characteristicId, state);
760759
}
761760
else
762761
{
763762
std::string error = "status: " + std::to_string((int)status);
764763
mEmit.Notify(uuid, serviceId, characteristicId, state, error);
764+
if (state == true)
765+
{
766+
mNotifyMap.Unsubscribe(uuid, characteristic);
767+
}
765768
}
766769
}
767770

0 commit comments

Comments
 (0)