static bool celix_dmComponent_performTransition()

in libs/framework/src/dm_component_impl.c [829:892]


static bool celix_dmComponent_performTransition(celix_dm_component_t *component, celix_dm_component_state_t currentState, celix_dm_component_state_t desiredState) {
    if (currentState == desiredState) {
        return false;
    }
    component->inTransition = true;

    celix_dmComponent_logTransition(component, currentState, desiredState);

    celix_status_t status = CELIX_SUCCESS;
    if (currentState == CELIX_DM_CMP_STATE_INACTIVE && desiredState == CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED) {
        celix_dmComponent_enableDependencies(component);
    } else if (currentState == CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED && desiredState == CELIX_DM_CMP_STATE_INITIALIZING) {
        //nop
    } else if (currentState == CELIX_DM_CMP_STATE_INITIALIZING && desiredState == CELIX_DM_CMP_STATE_INITIALIZED_AND_WAITING_FOR_REQUIRED) {
        if (component->callbackInit) {
            status = component->callbackInit(component->implementation);
        }
    } else if (currentState == CELIX_DM_CMP_STATE_INITIALIZED_AND_WAITING_FOR_REQUIRED && desiredState == CELIX_DM_CMP_STATE_DEINITIALIZING) {
        //nop
    } else if (currentState == CELIX_DM_CMP_STATE_DEINITIALIZING && desiredState == CELIX_DM_CMP_STATE_INACTIVE) {
        if (component->callbackDeinit) {
            status = component->callbackDeinit(component->implementation);
        }
        celix_dmComponent_disableDependencies(component);
    } else if (currentState == CELIX_DM_CMP_STATE_INITIALIZED_AND_WAITING_FOR_REQUIRED && desiredState == CELIX_DM_CMP_STATE_STARTING) {
        //nop
    } else if (currentState == CELIX_DM_CMP_STATE_STARTING && desiredState == CELIX_DM_CMP_STATE_TRACKING_OPTIONAL) {
        if (component->callbackStart) {
        	status = component->callbackStart(component->implementation);
        }
        if (status == CELIX_SUCCESS) {
            celix_dmComponent_registerServices(component, false);
            component->nrOfTimesStarted += 1;
        }
    } else if (currentState == CELIX_DM_CMP_STATE_TRACKING_OPTIONAL && desiredState == CELIX_DM_CMP_STATE_STOPPING) {
        //nop
    } else if (currentState == CELIX_DM_CMP_STATE_STOPPING && desiredState == CELIX_DM_CMP_STATE_INITIALIZED_AND_WAITING_FOR_REQUIRED) {
        celix_dmComponent_unregisterServices(component, false);
        if (component->callbackStop) {
        	status = component->callbackStop(component->implementation);
        }
    } else if (currentState == CELIX_DM_CMP_STATE_WAITING_FOR_REQUIRED && desiredState == CELIX_DM_CMP_STATE_INACTIVE) {
        celix_dmComponent_disableDependencies(component);
    } else {
        assert(false); //should not be reached.
    }

    bool transition = true;
    if (status != CELIX_SUCCESS) {
        celix_bundleContext_log(component->context, CELIX_LOG_LEVEL_ERROR,
                                "Error in component %s (uuid=%s) transition from %s to %s. Disabling component.",
                                component->name,
                                component->uuid,
                                celix_dmComponent_stateToString(currentState),
                                celix_dmComponent_stateToString(desiredState));

        //If a lifecycle method fails, the component will disable itself (but no higher level transition is needed anymore)
        transition = false;
        celix_dmComponent_disableDirectly(component);
    }

    component->inTransition = false;
    return transition;
}