Skip to content
On this page

Session State

A measuring session is always in a "state". The session transitions between possible states either by following an API action called by the application, or via internal logic that is intended to prepare the session for performing measurements. The session state diagram appears in the figure below.

Session States

State Diagram

The table below provides a description of each session state:

State NameState Definition
initializingThe session is in its initial state, performing initialization actions. Please wait until you receive the message indicating that the session is in the ready state before starting to measure vital signs or before calling any session APIs.
readyThe session is now ready to be started. The application can display the camera preview, if using face/finger measurements. Refer to the Creating a Preview page for detailed instructions. On Polar sessions the SDK starts receiving data from the PPG device and optimized for a quick session start.
startingThe session is currently preparing to measure vital signs.
processingThe session is processing the data and calculating vital signs. For information on the handling of instantaneous vital signs, please refer to the Vital Signs page.
stoppingThe session has been stopped, and the measurement results are being calculated. For information on the handling the final results, please see the Vital Signs page.
terminatingThe session is currently being terminated. Please refrain from calling any session APIs.
terminatedThe session has been gracefully terminated, and a new session can now be initiated.

Session State Transitions

The table below describes the actions that cause a transition between the states:

StateNext StateTrigger
initializingreadyOnce all initialization actions are completed, the session transitions to the ready state.
readystartingCalling the start() method causes the session to transition to the starting state.
startingprocessingThe session's actions in the starting state were completed.
processingstoppingThe session will transition to the stopping state under the following circumstances:
*The measurement ends gracefully either because it reached the defined duration or due to a manual invocation of the stop() method.
*The measurement was stopped due to an error. Refer to the Alerts section for more information.
stoppingreadyThe SDK has finished performing the vital sign calculations.
readyterminatingBy calling the terminate() method, the session transitions to the terminating state.
terminatingterminatedThe termination actions have been completed.

Note

The starting, stopping and terminating states are 'transition states' that end automatically after a short period. Do not call any session methods while the session is in transition.

Receiving Session State Updates

The application can receive session state updates by implementing onSessionStateChange as part of SessionInfoListener:

Swift
func onSessionStateChange(sessionState: SessionState) { 
    // Receive session state updates
}

func onWarning(warningData: WarningData) {
    // Receive warnings
}

func onError(errorData: ErrorData) {
    // Receive errors
}

func onLicenseInfo(licenseInfo: LicenseInfo) {
    // Receive license info 
}

func onEnabledVitalSigns(enabledVitalSigns: SessionEnabledVitalSigns) {
    // Receive the enabled vital signs for the session
}
Objective-C
- (void)onSessionStateChangeWithSessionState:(BNHSessionState *)sessionState { 
    // Receive session state updates
}

- (void)onWarningWithData:(BNHWarningData *)warningData {
    // Receive warnings
}

- (void)onErrorWithData:(BNHErrorData *)errorData {
    // Receive errors
}

- (void)onLicenseInfoWithInfo:(BNHLicenseInfo *)licenseInfo {
    // Receive license info
}

- (void)onEnabledVitalSignsWithEnabledVitalSigns:(BNHEnabledVitalSigns *)enabledVitalSigns {
    // Receive the enabled vital signs for the session
}

Handling State Transitions

The code below is a simple example for handling session transitions updates by implementing onSessionStateChange as part of SessionInfoListener.

Swift
func onSessionStateChange(sessionState: SessionState) {
    DispatchQueue.main.async {
        switch (sessionState) {
            case .initializing:
                print("Session is initializing and NOT ready")
            case .ready: 
                print("Session is ready to start measuring")
            case .starting:
                print("Session is preparing for the measurement of vital signs")
            case .processing:
                print("Session is measuring vital signs")
            case .stopping:
                print("Session is stopping the measuring of vital signs")
            case .terminating:
                print("Session is preparing to terminate")
            case .terminated:
                print("Session is terminated")
        }
    }
}
Objective-C
- (void)onSessionStateChangeWithSessionState:(BNHSessionState)sessionState {
    dispatch_async(dispatch_get_main_queue(), ^{
        switch (sessionState) {
            case BNHSessionStateInitializing:
                NSLog(@"Session is initializing and NOT ready");
                break;
            case BNHSessionStateReady:
                NSLog(@"Session is ready to start measuring");
                break;
            case BNHSessionStateStarting:
                NSLog(@"Session is preparing for the measurement of vital signs");
                break;
            case BNHSessionStateProcessing:
                NSLog(@"Session is measuring vital signs");
                break;
            case BNHSessionStateStopping:
                NSLog(@"Session is stopping the measuring of vital signs");
                break;
            case BNHSessionStateTerminating:
                NSLog(@"Session is preparing to terminate");
                break;
            case BNHSessionStateTerminated:
                NSLog(@"Session is terminated");
                break;
        }
    });
}