| 476 | } |
| 477 | |
| 478 | int MuseAthena::release_session () |
| 479 | { |
| 480 | if (initialized) |
| 481 | { |
| 482 | // repeat it multiple times, failure here may lead to a crash |
| 483 | for (int i = 0; i < 2; i++) |
| 484 | { |
| 485 | bool is_connected = true; |
| 486 | if ((muse_peripheral != NULL) && |
| 487 | (simpleble_peripheral_is_connected (muse_peripheral, &is_connected) == |
| 488 | SIMPLEBLE_SUCCESS) && |
| 489 | (!is_connected)) |
| 490 | { |
| 491 | break; |
| 492 | } |
| 493 | |
| 494 | stop_stream (); |
| 495 | if (muse_peripheral != NULL) |
| 496 | { |
| 497 | // need to wait for notifications to stop triggered before unsubscribing, otherwise |
| 498 | // macos fails inside simpleble with timeout |
| 499 | std::this_thread::sleep_for (std::chrono::seconds (2)); |
| 500 | for (auto notified : notified_characteristics) |
| 501 | { |
| 502 | if (simpleble_peripheral_unsubscribe ( |
| 503 | muse_peripheral, notified.first, notified.second) != SIMPLEBLE_SUCCESS) |
| 504 | { |
| 505 | safe_logger (spdlog::level::err, "failed to unsubscribe for {} {}", |
| 506 | notified.first.value, notified.second.value); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | free_packages (); |
| 512 | initialized = false; |
| 513 | notified_characteristics.clear (); |
| 514 | } |
| 515 | if (muse_peripheral != NULL) |
| 516 | { |
| 517 | bool is_connected = false; |
| 518 | if (simpleble_peripheral_is_connected (muse_peripheral, &is_connected) == SIMPLEBLE_SUCCESS) |
| 519 | { |
| 520 | if (is_connected) |
| 521 | { |
| 522 | simpleble_peripheral_disconnect (muse_peripheral); |
| 523 | } |
| 524 | } |
| 525 | simpleble_peripheral_release_handle (muse_peripheral); |
| 526 | muse_peripheral = NULL; |
| 527 | } |
| 528 | if (muse_adapter != NULL) |
| 529 | { |
| 530 | simpleble_adapter_release_handle (muse_adapter); |
| 531 | muse_adapter = NULL; |
| 532 | } |
| 533 | |
| 534 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 535 | } |
nothing calls this directly
no test coverage detected