|
Ersa Wearable Platform
Embedded smartwatch firmware and application framework
|
#include <bluetooth_manager.h>

Public Types | |
| using | WakeCallback = void(*)(void *user) |
Public Member Functions | |
| BluetoothManager (hal::IBluetooth &ble, hal::ICompanionSource &source, events::EventBus &bus) | |
| Result< void > | init () |
| Initialize the transport, source, and event callbacks. | |
| void | tick () |
| void | setWakeCallback (WakeCallback callback, void *user) |
| bool | canDial () const |
| bool | canHangup () const |
| bool | notificationsReady () const |
| bool | mediaReady () const |
| const char * | companionSourceId () const |
| Return the active source's stable machine-readable identifier. | |
| hal::CompanionCapabilities | companionCapabilities () const |
| Return the active source's current capabilities. | |
| bool | companionSourceAvailable () const |
| Return whether the active source is available. | |
| bool | bleConnected () const |
| Return BLE transport link state. | |
| bool | isConnected () const |
| bool | isAdvertising () const |
| Return BLE advertising state. | |
| uint32_t | nextWakeDelayMs (uint32_t nowMs) const |
| const char * | getDeviceName () const |
| Return the local BLE device name. | |
| const char * | getDeviceAddress () const |
| Return the local BLE address. | |
| void | restartAdvertising () |
| CallState | getCallState () const |
| Return normalized call state. | |
| const char * | getCallerName () const |
| Return the current caller name, if provided by the source. | |
| const char * | getCallerNumber () const |
| Return the current caller number, if provided by the source. | |
| uint32_t | getCallDurationSec () const |
| Return elapsed seconds for the current active call. | |
| bool | acceptCall () |
| bool | rejectCall () |
| bool | hangupCall () |
| bool | dial (const char *number, const char *name=nullptr) |
| bool | dialRecent (size_t index=0) |
| size_t | getRecentCallCount () const |
| Return the number of retained recent-call entries. | |
| const RecentCall & | getRecentCall (size_t index) const |
| Return a recent-call entry by index. | |
| void | addRecentCall (const char *name, const char *number) |
| bool | isPlaying () const |
| Return whether the latest companion media state is playing. | |
| const char * | getMediaTitle () const |
| Return the latest companion track title. | |
| const char * | getMediaArtist () const |
| Return the latest companion artist name. | |
| bool | mediaPlay () |
| Request media playback. | |
| bool | mediaPause () |
| Request media pause. | |
| bool | mediaToggle () |
| Request media play/pause toggle. | |
| bool | mediaNext () |
| Request the next media item. | |
| bool | mediaPrevious () |
| Request the previous media item. | |
| void | simulateIncomingCall (const char *name, const char *number) |
| Inject an incoming call event for host simulation. | |
| void | simulateMedia (const char *title, const char *artist, bool playing) |
| Inject media metadata and state for host simulation. | |
| void | simulateNotification (const char *title, const char *message, const char *app="Messages") |
| Inject a notification event for host simulation. | |
| size_t | getNotificationCount () const |
| Return the number of retained notification entries. | |
| const AppNotification & | getNotification (size_t index) const |
| Return a notification entry by index. | |
| bool | dismissNotification (size_t index) |
| void | addNotification (const char *title, const char *message, const char *app, uint32_t uid, bool canDismissRemotely=false) |
| Add or update a notification entry. | |
| void | clearNotifications () |
| Clear all retained notifications and dismissed UID state. | |
Static Public Member Functions | |
| static BluetoothManager & | instance () |
| Return the installed process-wide Bluetooth manager. | |
| static void | setInstance (BluetoothManager *inst) |
| Install the process-wide Bluetooth manager. | |
Private Member Functions | |
| void | receive (const events::Event &event) |
| void | apply (const events::Event &event) |
Static Private Member Functions | |
| static void | onSourceCall (hal::CompanionCallAction action, const char *caller, const char *number, void *user) |
| static void | onSourceMedia (bool playing, const char *title, const char *artist, void *user) |
| static void | onBleConnection (bool connected, void *user) |
| static void | onSourceAvailability (bool available, void *user) |
| static void | onSourceNotification (const char *title, const char *message, const char *app, uint32_t uid, bool canDismissRemotely, void *user) |
Private Attributes | |
| WakeCallback | wakeCallback_ {nullptr} |
| void * | wakeUserData_ {nullptr} |
| hal::IBluetooth & | ble_ |
| hal::ICompanionSource & | source_ |
| events::EventBus & | bus_ |
| CallState | callState_ {CallState::Idle} |
| char | currentCaller_ [32] {""} |
| char | currentNumber_ [20] {""} |
| uint32_t | callStartMs_ {0} |
| RecentCall | recents_ [MAX_RECENTS] |
| size_t | recentCount_ {0} |
| AppNotification | notifications_ [MAX_NOTIFS] |
| size_t | notifCount_ {0} |
| uint32_t | dismissedUids_ [MAX_DISMISSED_UIDS] {} |
| size_t | dismissedCount_ {0} |
| bool | mediaPlaying_ {false} |
| char | mediaTitle_ [32] {"No Media"} |
| char | mediaArtist_ [32] {"Bluetooth Idle"} |
| bool | initialized_ {false} |
Static Private Attributes | |
| static constexpr size_t | MAX_RECENTS = 5 |
| static constexpr size_t | MAX_NOTIFS = 10 |
| static constexpr size_t | MAX_DISMISSED_UIDS = 16 |
Normalizes companion events and commands over separate transport/source HALs.
The manager is the app-facing semantic layer: it copies callback strings, retains bounded recent-call/notification state, validates provider capabilities, and publishes normalized events. Transport link state and companion readiness remain separate because an encrypted BLE connection can exist before ANCS/AMS/CTS discovery finishes.
| using ersa::services::BluetoothManager::WakeCallback = void (*)(void* user) |
| ersa::services::BluetoothManager::BluetoothManager | ( | hal::IBluetooth & | ble, |
| hal::ICompanionSource & | source, | ||
| events::EventBus & | bus | ||
| ) |
Compose independently injected transport, provider, and event contracts.
| bool ersa::services::BluetoothManager::acceptCall | ( | ) |
Ask the provider to answer the current call; false means unsupported/rejected.
| void ersa::services::BluetoothManager::addNotification | ( | const char * | title, |
| const char * | message, | ||
| const char * | app, | ||
| uint32_t | uid, | ||
| bool | canDismissRemotely = false |
||
| ) |
Add or update a notification entry.
| void ersa::services::BluetoothManager::addRecentCall | ( | const char * | name, |
| const char * | number | ||
| ) |
Insert or refresh a history record while respecting fixed history capacity.
|
private |
|
inline |
Return BLE transport link state.
|
inline |
Check both provider availability and current dial capability.
|
inline |
Check current hangup support rather than assuming all peers support it.
| void ersa::services::BluetoothManager::clearNotifications | ( | ) |
Clear all retained notifications and dismissed UID state.
|
inline |
Return the active source's current capabilities.
|
inline |
Return whether the active source is available.
|
inline |
Return the active source's stable machine-readable identifier.
| bool ersa::services::BluetoothManager::dial | ( | const char * | number, |
| const char * | name = nullptr |
||
| ) |
Request dialing and optionally associate a display name locally.
| bool ersa::services::BluetoothManager::dialRecent | ( | size_t | index = 0 | ) |
Dial one retained history record, returning false for an invalid index.
| bool ersa::services::BluetoothManager::dismissNotification | ( | size_t | index | ) |
Remove a retained notification and request remote dismissal if its original provider session and capability still permit it.
| uint32_t ersa::services::BluetoothManager::getCallDurationSec | ( | ) | const |
Return elapsed seconds for the current active call.
|
inline |
Return the current caller name, if provided by the source.
|
inline |
Return the current caller number, if provided by the source.
|
inline |
Return normalized call state.
| const char * ersa::services::BluetoothManager::getDeviceAddress | ( | ) | const |
Return the local BLE address.
| const char * ersa::services::BluetoothManager::getDeviceName | ( | ) | const |
Return the local BLE device name.
|
inline |
Return the latest companion artist name.
|
inline |
Return the latest companion track title.
| const AppNotification & ersa::services::BluetoothManager::getNotification | ( | size_t | index | ) | const |
Return a notification entry by index.
|
inline |
Return the number of retained notification entries.
| const RecentCall & ersa::services::BluetoothManager::getRecentCall | ( | size_t | index | ) | const |
Return a recent-call entry by index.
|
inline |
Return the number of retained recent-call entries.
| bool ersa::services::BluetoothManager::hangupCall | ( | ) |
End the current call through the provider; acceptance is not remote execution.
| Result< void > ersa::services::BluetoothManager::init | ( | ) |
Initialize the transport, source, and event callbacks.
|
static |
Return the installed process-wide Bluetooth manager.
|
inline |
Return BLE advertising state.
| bool ersa::services::BluetoothManager::isConnected | ( | ) | const |
Return link-up state; this is not equivalent to source readiness.
|
inline |
Return whether the latest companion media state is playing.
| bool ersa::services::BluetoothManager::mediaNext | ( | ) |
Request the next media item.
| bool ersa::services::BluetoothManager::mediaPause | ( | ) |
Request media pause.
| bool ersa::services::BluetoothManager::mediaPlay | ( | ) |
Request media playback.
| bool ersa::services::BluetoothManager::mediaPrevious | ( | ) |
Request the previous media item.
|
inline |
Report feature readiness independently of BLE link state.
| bool ersa::services::BluetoothManager::mediaToggle | ( | ) |
Request media play/pause toggle.
|
inline |
Forward transport maintenance deadline for low-power wait scheduling.
|
inline |
Report feature readiness after provider discovery completes.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
| bool ersa::services::BluetoothManager::rejectCall | ( | ) |
Reject the current incoming call when the provider supports the action.
| void ersa::services::BluetoothManager::restartAdvertising | ( | ) |
Request the transport to restart advertising after disconnect/recovery.
|
static |
Install the process-wide Bluetooth manager.
|
inline |
Register the wake callback used when a radio worker enqueues new data. The callback should notify a task only; it must not render UI directly.
| void ersa::services::BluetoothManager::simulateIncomingCall | ( | const char * | name, |
| const char * | number | ||
| ) |
Inject an incoming call event for host simulation.
| void ersa::services::BluetoothManager::simulateMedia | ( | const char * | title, |
| const char * | artist, | ||
| bool | playing | ||
| ) |
Inject media metadata and state for host simulation.
| void ersa::services::BluetoothManager::simulateNotification | ( | const char * | title, |
| const char * | message, | ||
| const char * | app = "Messages" |
||
| ) |
Inject a notification event for host simulation.
| void ersa::services::BluetoothManager::tick | ( | ) |
Drain callbacks and run bounded provider/transport maintenance.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |