// Copyright (c) 2022-2023, 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.
//

//! @file Module.h
//!
//! @brief Helpers for writing modules/plugins based on @ref omni::graph::exec.
#pragma once

#include <omni/graph/exec/unstable/PassRegistry.h>

//! Helper macro to ensure EF features are enabled in the current module/plugin.
//!
//! This macro should be called from either @c carbOnPluginStartup or @c onStarted.
//!
//! If your module/plugin registers EF nodes or passes, you must call this macro.
//!
//! For Kit-based extensions, rather than calling this macro, call OMNI_KIT_EXEC_CORE_ON_MODULE_STARTED(), which will
//! call this macro on your behalf.
#define OMNI_GRAPH_EXEC_ON_MODULE_STARTED(moduleName_)                                                                 \
    try                                                                                                                \
    {                                                                                                                  \
        omni::graph::exec::unstable::registerModulePasses();                                                           \
    }                                                                                                                  \
    catch (std::exception & e)                                                                                         \
    {                                                                                                                  \
        CARB_LOG_ERROR("failed to register %s's passes: %s", moduleName_, e.what());                                   \
    }

//! Helper macro to ensure EF features are safely disabled when the current module/plugin unloads.
//!
//! This macro should be called from either @c carbOnPluginShutdown or @c onUnload.
//!
//! If your module/plugin registers EF nodes or passes, you must call this macro.
//!
//! For Kit-based extensions, rather than calling this macro, call OMNI_KIT_EXEC_CORE_ON_MODULE_UNLOAD(), which will
//! call this macro on your behalf.
#define OMNI_GRAPH_EXEC_ON_MODULE_UNLOAD()                                                                             \
    do                                                                                                                 \
    {                                                                                                                  \
        omni::graph::exec::unstable::deregisterModulePasses();                                                         \
    } while (0)
