//--------------------------------------------------------------------------------------------------
static void GenerateApiBindConfig
(
    std::ofstream& cfgStream,       ///< Stream to send the configuration to.
    legato::App& app,               ///< The application being built.
    const legato::ExeToExeApiBind& binding  ///< Binding to internal exe.component.interface.
)
//--------------------------------------------------------------------------------------------------
{
    const std::string& clientInterfaceId = binding.ClientInterface();

    std::string clientServiceName;

    // If the binding is a wildcard binding (applies to everything with a given service name),
    if (clientInterfaceId.compare(0, 2, "*.") == 0)
    {
        // Strip off the "*." wildcard specifier to get the service name.
        clientServiceName = clientInterfaceId.substr(2);
    }
    // Otherwise, look-up the client interface and take the service name from there.
    else
    {
        const auto& interface = app.FindClientInterface(clientInterfaceId);

        clientServiceName = interface.ExternalName();
    }

    GenerateSingleApiBindingToApp( cfgStream,
                                   clientServiceName,
                                   app.Name(),
                                   binding.ServerInterface() );
}
//--------------------------------------------------------------------------------------------------
static void GenerateApiBindConfig
(
    std::ofstream& cfgStream,       ///< Stream to send the configuration to.
    legato::App& app,               ///< The application being built.
    const legato::ExeToUserApiBind& binding  ///< Binding to external user name and service name.
)
//--------------------------------------------------------------------------------------------------
{
    const std::string& clientInterfaceId = binding.ClientInterface();

    std::string clientServiceName;

    // If the binding is a wildcard binding (applies to everything with a given service name),
    if (clientInterfaceId.compare(0, 2, "*.") == 0)
    {
        // Strip off the "*." wildcard specifier to get the service name.
        clientServiceName = clientInterfaceId.substr(2);
    }
    // Otherwise, look-up the client interface and take the service name from there.
    else
    {
        const auto& interface = app.FindClientInterface(clientInterfaceId);

        clientServiceName = interface.ExternalName();
    }

    // If there is no server user name,
    if (binding.ServerUserName().empty())
    {
        // Make sure there's a server app name.
        if (binding.ServerAppName().empty())
        {
            throw legato::Exception("INTERNAL ERROR: Neither user name nor app name provided"
                                    " for server in binding of '" + binding.ClientInterface()
                                    + "'.");
        }

        GenerateSingleApiBindingToApp( cfgStream,
                                       clientServiceName,
                                       binding.ServerAppName(),
                                       binding.ServerInterfaceName() );
    }
    // If there is a server user name,
    else
    {
        // Make sure there isn't also a server app name.
        if (!binding.ServerAppName().empty())
        {
            throw legato::Exception("INTERNAL ERROR: Both user name and app name provided"
                                    " for server in binding of '" + binding.ClientInterface()
                                    + "'.");
        }

        GenerateSingleApiBindingToUser( cfgStream,
                                        clientServiceName,
                                        binding.ServerUserName(),
                                        binding.ServerInterfaceName() );
    }
}