carb/PluginUtils.h

File members: carb/PluginUtils.h

// Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

#pragma once

#include "ClientUtils.h"
#include "PluginInitializers.h"
#include "PluginCoreUtils.h"

namespace omni
{
namespace structuredlog
{
void addModulesSchemas() noexcept;
}
} // namespace omni

#define CARB_DEFAULT_INITIALIZERS()                                                                                    \
    CARB_EXPORT void carbOnPluginPreStartup()                                                                          \
    {                                                                                                                  \
        carb::pluginInitialize();                                                                                      \
        omni::structuredlog::addModulesSchemas();                                                                      \
    }                                                                                                                  \
                                                                                                                       \
    CARB_EXPORT void carbOnPluginPostShutdown()                                                                        \
    {                                                                                                                  \
        carb::pluginDeinitialize();                                                                                    \
    }

#define CARB_PLUGIN_IMPL(impl, ...)                                                                                    \
    CARB_GLOBALS_EX(impl.name, impl.description)                                                                       \
    OMNI_MODULE_GLOBALS_FOR_PLUGIN()                                                                                   \
    CARB_PLUGIN_IMPL_WITH_INIT_0_5(impl, __VA_ARGS__) /* for backwards compatibility */                                \
    CARB_PLUGIN_IMPL_WITH_INIT(impl, __VA_ARGS__)                                                                      \
    CARB_DEFAULT_INITIALIZERS()

#define CARB_PLUGIN_IMPL_EX(impl, ...)                                                                                 \
    CARB_GLOBALS_EX(impl.name, impl.description)                                                                       \
    OMNI_MODULE_GLOBALS_FOR_PLUGIN()                                                                                   \
    CARB_PLUGIN_IMPL_WITH_INIT_EX(impl, __VA_ARGS__)                                                                   \
    CARB_PLUGIN_IMPL_WITH_INIT_0_5_EX(impl, __VA_ARGS__) /* for backwards compatibility */                             \
    CARB_DEFAULT_INITIALIZERS()

#define CARB_PLUGIN_IMPL_DEPS(...)                                                                                     \
    template <typename... Types>                                                                                       \
    static void getPluginDepsTyped(struct carb::InterfaceDesc** deps, size_t* count)                                   \
    {                                                                                                                  \
        static carb::InterfaceDesc depends[] = { Types::getLatestInterfaceDesc()... };                                 \
        *deps = depends;                                                                                               \
        *count = sizeof(depends) / sizeof(depends[0]);                                                                 \
    }                                                                                                                  \
                                                                                                                       \
    CARB_EXPORT void carbGetPluginDeps(struct carb::InterfaceDesc** deps, size_t* count)                               \
    {                                                                                                                  \
        getPluginDepsTyped<__VA_ARGS__>(deps, count);                                                                  \
    }

#define CARB_PLUGIN_IMPL_NO_DEPS()                                                                                     \
    CARB_EXPORT void carbGetPluginDeps(struct carb::InterfaceDesc** deps, size_t* count)                               \
    {                                                                                                                  \
        *deps = nullptr;                                                                                               \
        *count = 0;                                                                                                    \
    }

#define CARB_PLUGIN_IMPL_MINIMAL(impl, ...)                                                                            \
    CARB_FRAMEWORK_GLOBALS(kPluginImpl.name)                                                                           \
    CARB_PLUGIN_IMPL_WITH_INIT(impl, __VA_ARGS__)