#!/bin/bash

################################################################################
# Copyright 2023-2025 by NI SP Software GmbH, All rights reserved.
# Copyright 1999-2023 by Nice, srl., All rights reserved.
#
# This software includes confidential and proprietary information
# of NI SP Software GmbH ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with NI SP Software.
################################################################################


# "spooler" scheme is a special case and maps to the "file" backend
if [ "${FM_VROOT_SCHEME}" = "spooler" ]; then
  _backend="file"
else
  _backend="${FM_VROOT_SCHEME}"
fi
if [ -r "${EF_ROOT}/plugins/fm/fm/backends/${_backend}/conf/fm.${_backend}.conf" ]; then
    source "${EF_ROOT}/plugins/fm/fm/backends/${_backend}/conf/fm.${_backend}.conf"
fi


#-------------------------------------------------------------------------------
# Function used to delegate to the backend implementation
#-------------------------------------------------------------------------------
call_backend () {
    BACKEND_COMMAND=$(basename "$0")
    [ -z "${BACKEND_COMMAND}" ] && return

    if [ -n "${FM_VROOT_SCHEME}" ] && \
       [ -d "${EF_ROOT}/plugins/fm/fm/backends/${_backend}" ] && \
       [ -x "${EF_ROOT}/plugins/fm/fm/backends/${_backend}/${BACKEND_COMMAND}" ];
    then
        "${EF_ROOT}/plugins/fm/fm/backends/${_backend}/${BACKEND_COMMAND}" "$@" || exit $?
    fi
}

# ex:ts=4:et:
