Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ersa::services::BluetoothManager Class Reference

#include <bluetooth_manager.h>

Collaboration diagram for ersa::services::BluetoothManager:
Collaboration graph
[legend]

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
 

Detailed Description

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.

Member Typedef Documentation

◆ WakeCallback

using ersa::services::BluetoothManager::WakeCallback = void (*)(void* user)

Constructor & Destructor Documentation

◆ BluetoothManager()

ersa::services::BluetoothManager::BluetoothManager ( hal::IBluetooth &  ble,
hal::ICompanionSource &  source,
events::EventBus &  bus 
)

Compose independently injected transport, provider, and event contracts.

Member Function Documentation

◆ acceptCall()

bool ersa::services::BluetoothManager::acceptCall ( )

Ask the provider to answer the current call; false means unsupported/rejected.

◆ addNotification()

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.

◆ addRecentCall()

void ersa::services::BluetoothManager::addRecentCall ( const char *  name,
const char *  number 
)

Insert or refresh a history record while respecting fixed history capacity.

◆ apply()

void ersa::services::BluetoothManager::apply ( const events::Event &  event)
private

◆ bleConnected()

bool ersa::services::BluetoothManager::bleConnected ( ) const
inline

Return BLE transport link state.

◆ canDial()

bool ersa::services::BluetoothManager::canDial ( ) const
inline

Check both provider availability and current dial capability.

◆ canHangup()

bool ersa::services::BluetoothManager::canHangup ( ) const
inline

Check current hangup support rather than assuming all peers support it.

◆ clearNotifications()

void ersa::services::BluetoothManager::clearNotifications ( )

Clear all retained notifications and dismissed UID state.

◆ companionCapabilities()

hal::CompanionCapabilities ersa::services::BluetoothManager::companionCapabilities ( ) const
inline

Return the active source's current capabilities.

◆ companionSourceAvailable()

bool ersa::services::BluetoothManager::companionSourceAvailable ( ) const
inline

Return whether the active source is available.

◆ companionSourceId()

const char * ersa::services::BluetoothManager::companionSourceId ( ) const
inline

Return the active source's stable machine-readable identifier.

◆ dial()

bool ersa::services::BluetoothManager::dial ( const char *  number,
const char *  name = nullptr 
)

Request dialing and optionally associate a display name locally.

Returns
True if the provider accepted the command for processing.

◆ dialRecent()

bool ersa::services::BluetoothManager::dialRecent ( size_t  index = 0)

Dial one retained history record, returning false for an invalid index.

◆ dismissNotification()

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.

◆ getCallDurationSec()

uint32_t ersa::services::BluetoothManager::getCallDurationSec ( ) const

Return elapsed seconds for the current active call.

◆ getCallerName()

const char * ersa::services::BluetoothManager::getCallerName ( ) const
inline

Return the current caller name, if provided by the source.

◆ getCallerNumber()

const char * ersa::services::BluetoothManager::getCallerNumber ( ) const
inline

Return the current caller number, if provided by the source.

◆ getCallState()

CallState ersa::services::BluetoothManager::getCallState ( ) const
inline

Return normalized call state.

◆ getDeviceAddress()

const char * ersa::services::BluetoothManager::getDeviceAddress ( ) const

Return the local BLE address.

◆ getDeviceName()

const char * ersa::services::BluetoothManager::getDeviceName ( ) const

Return the local BLE device name.

◆ getMediaArtist()

const char * ersa::services::BluetoothManager::getMediaArtist ( ) const
inline

Return the latest companion artist name.

◆ getMediaTitle()

const char * ersa::services::BluetoothManager::getMediaTitle ( ) const
inline

Return the latest companion track title.

◆ getNotification()

const AppNotification & ersa::services::BluetoothManager::getNotification ( size_t  index) const

Return a notification entry by index.

◆ getNotificationCount()

size_t ersa::services::BluetoothManager::getNotificationCount ( ) const
inline

Return the number of retained notification entries.

◆ getRecentCall()

const RecentCall & ersa::services::BluetoothManager::getRecentCall ( size_t  index) const

Return a recent-call entry by index.

◆ getRecentCallCount()

size_t ersa::services::BluetoothManager::getRecentCallCount ( ) const
inline

Return the number of retained recent-call entries.

◆ hangupCall()

bool ersa::services::BluetoothManager::hangupCall ( )

End the current call through the provider; acceptance is not remote execution.

◆ init()

Result< void > ersa::services::BluetoothManager::init ( )

Initialize the transport, source, and event callbacks.

◆ instance()

BluetoothManager & ersa::services::BluetoothManager::instance ( )
static

Return the installed process-wide Bluetooth manager.

◆ isAdvertising()

bool ersa::services::BluetoothManager::isAdvertising ( ) const
inline

Return BLE advertising state.

◆ isConnected()

bool ersa::services::BluetoothManager::isConnected ( ) const

Return link-up state; this is not equivalent to source readiness.

◆ isPlaying()

bool ersa::services::BluetoothManager::isPlaying ( ) const
inline

Return whether the latest companion media state is playing.

◆ mediaNext()

bool ersa::services::BluetoothManager::mediaNext ( )

Request the next media item.

◆ mediaPause()

bool ersa::services::BluetoothManager::mediaPause ( )

Request media pause.

◆ mediaPlay()

bool ersa::services::BluetoothManager::mediaPlay ( )

Request media playback.

◆ mediaPrevious()

bool ersa::services::BluetoothManager::mediaPrevious ( )

Request the previous media item.

◆ mediaReady()

bool ersa::services::BluetoothManager::mediaReady ( ) const
inline

Report feature readiness independently of BLE link state.

◆ mediaToggle()

bool ersa::services::BluetoothManager::mediaToggle ( )

Request media play/pause toggle.

◆ nextWakeDelayMs()

uint32_t ersa::services::BluetoothManager::nextWakeDelayMs ( uint32_t  nowMs) const
inline

Forward transport maintenance deadline for low-power wait scheduling.

◆ notificationsReady()

bool ersa::services::BluetoothManager::notificationsReady ( ) const
inline

Report feature readiness after provider discovery completes.

◆ onBleConnection()

void ersa::services::BluetoothManager::onBleConnection ( bool  connected,
void *  user 
)
staticprivate

◆ onSourceAvailability()

void ersa::services::BluetoothManager::onSourceAvailability ( bool  available,
void *  user 
)
staticprivate

◆ onSourceCall()

void ersa::services::BluetoothManager::onSourceCall ( hal::CompanionCallAction  action,
const char *  caller,
const char *  number,
void *  user 
)
staticprivate

◆ onSourceMedia()

void ersa::services::BluetoothManager::onSourceMedia ( bool  playing,
const char *  title,
const char *  artist,
void *  user 
)
staticprivate

◆ onSourceNotification()

void ersa::services::BluetoothManager::onSourceNotification ( const char *  title,
const char *  message,
const char *  app,
uint32_t  uid,
bool  canDismissRemotely,
void *  user 
)
staticprivate

◆ receive()

void ersa::services::BluetoothManager::receive ( const events::Event &  event)
private

◆ rejectCall()

bool ersa::services::BluetoothManager::rejectCall ( )

Reject the current incoming call when the provider supports the action.

◆ restartAdvertising()

void ersa::services::BluetoothManager::restartAdvertising ( )

Request the transport to restart advertising after disconnect/recovery.

◆ setInstance()

void ersa::services::BluetoothManager::setInstance ( BluetoothManager *  inst)
static

Install the process-wide Bluetooth manager.

◆ setWakeCallback()

void ersa::services::BluetoothManager::setWakeCallback ( WakeCallback  callback,
void *  user 
)
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.

◆ simulateIncomingCall()

void ersa::services::BluetoothManager::simulateIncomingCall ( const char *  name,
const char *  number 
)

Inject an incoming call event for host simulation.

◆ simulateMedia()

void ersa::services::BluetoothManager::simulateMedia ( const char *  title,
const char *  artist,
bool  playing 
)

Inject media metadata and state for host simulation.

◆ simulateNotification()

void ersa::services::BluetoothManager::simulateNotification ( const char *  title,
const char *  message,
const char *  app = "Messages" 
)

Inject a notification event for host simulation.

◆ tick()

void ersa::services::BluetoothManager::tick ( )

Drain callbacks and run bounded provider/transport maintenance.

Member Data Documentation

◆ ble_

hal::IBluetooth& ersa::services::BluetoothManager::ble_
private

◆ bus_

events::EventBus& ersa::services::BluetoothManager::bus_
private

◆ callStartMs_

uint32_t ersa::services::BluetoothManager::callStartMs_ {0}
private

◆ callState_

CallState ersa::services::BluetoothManager::callState_ {CallState::Idle}
private

◆ currentCaller_

char ersa::services::BluetoothManager::currentCaller_[32] {""}
private

◆ currentNumber_

char ersa::services::BluetoothManager::currentNumber_[20] {""}
private

◆ dismissedCount_

size_t ersa::services::BluetoothManager::dismissedCount_ {0}
private

◆ dismissedUids_

uint32_t ersa::services::BluetoothManager::dismissedUids_[MAX_DISMISSED_UIDS] {}
private

◆ initialized_

bool ersa::services::BluetoothManager::initialized_ {false}
private

◆ MAX_DISMISSED_UIDS

constexpr size_t ersa::services::BluetoothManager::MAX_DISMISSED_UIDS = 16
staticconstexprprivate

◆ MAX_NOTIFS

constexpr size_t ersa::services::BluetoothManager::MAX_NOTIFS = 10
staticconstexprprivate

◆ MAX_RECENTS

constexpr size_t ersa::services::BluetoothManager::MAX_RECENTS = 5
staticconstexprprivate

◆ mediaArtist_

char ersa::services::BluetoothManager::mediaArtist_[32] {"Bluetooth Idle"}
private

◆ mediaPlaying_

bool ersa::services::BluetoothManager::mediaPlaying_ {false}
private

◆ mediaTitle_

char ersa::services::BluetoothManager::mediaTitle_[32] {"No Media"}
private

◆ notifCount_

size_t ersa::services::BluetoothManager::notifCount_ {0}
private

◆ notifications_

AppNotification ersa::services::BluetoothManager::notifications_[MAX_NOTIFS]
private

◆ recentCount_

size_t ersa::services::BluetoothManager::recentCount_ {0}
private

◆ recents_

RecentCall ersa::services::BluetoothManager::recents_[MAX_RECENTS]
private

◆ source_

hal::ICompanionSource& ersa::services::BluetoothManager::source_
private

◆ wakeCallback_

WakeCallback ersa::services::BluetoothManager::wakeCallback_ {nullptr}
private

◆ wakeUserData_

void* ersa::services::BluetoothManager::wakeUserData_ {nullptr}
private

The documentation for this class was generated from the following files: