// 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.
//
// --------- Warning: This is a build system generated file. ----------
//

//! @file
//!
//! @brief This file was generated by <i>omni.bind</i>.

#include <omni/core/Interface.h>
#include <omni/core/OmniAttr.h>
#include <omni/core/ResultError.h>

#include <functional>
#include <type_traits>
#include <utility>

#ifndef OMNI_BIND_INCLUDE_INTERFACE_IMPL


//! Factory for creating instances of @ref omni::kit::exec::core::unstable::IExecutionController.
//!
//! This interface also stores the "default" @ref omni::kit::exec::core::unstable::IExecutionController, which is
//! associated with Kit's "default" @c UsdContext.
//!
//! The factory is a singleton.  Access the singleton with @ref
//! omni::kit::exec::core::unstable::getExecutionControllerFactory().
template <>
class omni::core::Generated<omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>
    : public omni::kit::exec::core::unstable::IExecutionControllerFactory_abi
{
public:
    OMNI_PLUGIN_INTERFACE("omni::kit::exec::core::unstable::IExecutionControllerFactory")

    //! Creates an @ref omni::kit::exec::core::unstable::IExecutionController.
    //!
    //! The given name should match the name of the @c UsdContext.
    //!
    //! Throws an exception on all errors.
    omni::core::ObjectPtr<omni::kit::exec::core::unstable::IExecutionController> createExecutionController(const char* name);

    //! Sets the "default" @ref omni::kit::exec::core::unstable::IExecutionController which should be owned by Kit's
    //! "default"
    //! @c UsdContext.
    //!
    //! Throws an exception if the controller has already been set.
    //!
    //! Throws an exception on all errors.
    void setDefaultExecutionController(
        omni::core::ObjectParam<omni::kit::exec::core::unstable::IExecutionController> controller);

    //! Returns the "default" @ref omni::kit::exec::core::unstable::IExecutionController associated with the "default"
    //! @c UsdContext.
    //!
    //! The returned pointer may be @c nullptr.
    //!
    //! Prefer calling @ref getDefaultExecutionController() rather than directly calling this method.
    omni::core::ObjectPtr<omni::kit::exec::core::unstable::IExecutionController> getDefaultExecutionController() noexcept;

    //! Attempts to release references to all objects when unloading DLLs.
    //!
    //! State managed by controllers may store references to objects emanating from many DLLs.  As long as a controller
    //! stores a reference to an object, it will not be destructed.  This causes a problem when unloading DLLs. If a
    //! controller's graph/context stores a reference to an object created by "foo.dll" and "foo.dll" is unloaded, when
    //! the controller later releases its reference to the object, the object's @c release() method will call into
    //! unloaded code, causing a crash.
    //!
    //! The fix for this disastrous scenario is ensure that no outstanding references to objects created in "foo.dll"
    //! are present in the process.  This method attempts to do just that by releasing *all* references stored within
    //! all controllers/graphs/contexts.
    //!
    //! A plugin may choose to store references to execution framework objects originating from other modules.  In such
    //! a case, the plugin can be notified when this @c clear() method is called by invoking @ref
    //! omni::kit::exec::core::unstable::addClearCallback when the plugin/module is loaded.
    //!
    //! Upon completion of this method, pointers to controllers created by this factory will remain valid, though
    //! references within the controllers to objects potentially created by other DLLs will have been released.
    //!
    //! This method is not thread safe.
    void clear() noexcept;

    //! Adds a callback that will be invoked when @ref
    //! omni::kit::exec::core::unstable::IExecutionControllerFactory::clear() is called.
    //!
    //! @ref omni::kit::exec::core::unstable::IExecutionControllerFactory::clear() is called when a .dll/.so providing
    //! execution framework functionality is unloaded (e.g. a plugin that provides a pass or node definition). The
    //! purpose of the given callback is to provide the plugin calling this method an opportunity to remove pointers to
    //! code that may be unloaded.  For example, OmniGraph uses this callback to remove any @ref
    //! omni::graph::exec::unstable::IDef pointers in its plugins.
    //!
    //! Do not call this method directly.  Rather, call @ref OMNI_KIT_EXEC_CORE_ON_MODULE_STARTED in either a plugin's
    //! @ref carbOnPluginStartup or @c onStarted.
    void addClearCallback(omni::core::ObjectParam<omni::kit::exec::core::unstable::IClearCallback> callback) noexcept;

    //! Removes a callback registered with @ref
    //! omni::kit::exec::core::unstable::IExecutionControllerFactory::addClearCallback.
    //!
    //! If @p callback is @c nullptr or was not registered, this function silently fails.
    //!
    //! This method should not be explicitly called, rather call @ref OMNI_KIT_EXEC_CORE_ON_MODULE_UNLOAD during
    //! plugin/module shutdown.
    void removeClearCallback(omni::core::ObjectParam<omni::kit::exec::core::unstable::IClearCallback> callback) noexcept;
};

#endif

#ifndef OMNI_BIND_INCLUDE_INTERFACE_DECL

inline omni::core::ObjectPtr<omni::kit::exec::core::unstable::IExecutionController> omni::core::Generated<
    omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>::createExecutionController(const char* name)
{
    OMNI_THROW_IF_ARG_NULL(name);
    omni::core::ObjectPtr<omni::kit::exec::core::unstable::IExecutionController> out;
    OMNI_THROW_IF_FAILED(createExecutionController_abi(name, out.put()));
    return out;
}

inline void omni::core::Generated<omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>::setDefaultExecutionController(
    omni::core::ObjectParam<omni::kit::exec::core::unstable::IExecutionController> controller)
{
    OMNI_THROW_IF_ARG_NULL(controller);
    OMNI_THROW_IF_FAILED(setDefaultExecutionController_abi(controller.get()));
}

inline omni::core::ObjectPtr<omni::kit::exec::core::unstable::IExecutionController> omni::core::Generated<
    omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>::getDefaultExecutionController() noexcept
{
    return omni::core::steal(getDefaultExecutionController_abi());
}

inline void omni::core::Generated<omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>::clear() noexcept
{
    clear_abi();
}

inline void omni::core::Generated<omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>::addClearCallback(
    omni::core::ObjectParam<omni::kit::exec::core::unstable::IClearCallback> callback) noexcept
{
    addClearCallback_abi(callback.get());
}

inline void omni::core::Generated<omni::kit::exec::core::unstable::IExecutionControllerFactory_abi>::removeClearCallback(
    omni::core::ObjectParam<omni::kit::exec::core::unstable::IClearCallback> callback) noexcept
{
    removeClearCallback_abi(callback.get());
}

#endif

#undef OMNI_BIND_INCLUDE_INTERFACE_DECL
#undef OMNI_BIND_INCLUDE_INTERFACE_IMPL
