Skip to content

Question About Using QASM_IS_IN() Without Q_SPY #59

@kzorer

Description

@kzorer

Hello,

I have a question regarding the usage of QASM_IS_IN() / QHsm_isIn_() in QP/C.

I noticed that QASM_IS_IN() is only available when Q_SPY is enabled:

#ifdef Q_SPY
    #define QASM_IS_IN(me_, stateHndl_) \
        (*((QAsm *)(me_))->vptr->isIn)((QAsm *)(me_), (stateHndl_))
#endif

Internally, this calls QHsm_isIn_():

bool QHsm_isIn_(QAsm * const me,
    QStateHandler const stateHndl)

My use case is very simple:
I would like to check whether an HSM is currently inside a specific state (or substate hierarchy) during runtime, for example:

if (QASM_IS_IN(&myHsm.super, &SomeState)) {
    ...
}

However, I do not want to enable Q_SPY in production builds just to use this functionality.

I also noticed comments in the headers mentioning that this API is protected/private/internal, so I wanted to ask:

  1. Is there any technical or architectural reason why QASM_IS_IN() is restricted to Q_SPY builds?
  2. Is using QHsm_isIn_() directly considered unsafe or unsupported?
  3. Is there a recommended public API for checking the current state/substate membership of an HSM?
  4. Would it be acceptable to expose QASM_IS_IN() outside of Q_SPY, or is there a hidden invariant/performance concern behind this design?

From reading the implementation, it seems to only walk the superstate hierarchy and restore the invariant afterwards, so I wanted to understand whether there are any side effects or design reasons I might be missing.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions