// 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


//! Class representing a result of asynchronous computation.
//!
//! Create via @ref omni::graph::exec::unstable::IBackgroundTask::getBackgroundResult().
//!
//! Call @ref omni::graph::exec::unstable::IBackgroundResult::isReady() or @ref
//! omni::graph::exec::unstable::IBackgroundResult::waitFor() to make sure the result is ready.  Once the result is
//! ready, call @ref omni::graph::exec::unstable::IBackgroundResult::write() to make the result visible.
//!
//! Operates much like `std::future`.
template <>
class omni::core::Generated<omni::graph::exec::unstable::IBackgroundResult_abi>
    : public omni::graph::exec::unstable::IBackgroundResult_abi
{
public:
    OMNI_PLUGIN_INTERFACE("omni::graph::exec::unstable::IBackgroundResult")

    //! Check if background computation has a result available for consumption.
    //!
    //! @return @c true when it is safe to call omni::graph::exec::unstable::IBackgroundResult::write(), @c false
    //! otherwise.
    //!
    //! Once @ref omni::graph::exec::unstable::IBackgroundResult::write() has been called, this method will return an
    //! error.
    //!
    //! This method is not thread safe.
    //!
    //! May throw.
    bool isReady();

    //! Request background processing cancellation
    //!
    //! @param blocking If @c true, this call won't exit until background processing is completed.
    //!
    //! This method is not thread safe.
    //!
    //! May throw.
    void cancel(bool blocking);

    //! Write the result.
    //!
    //! This method is not thread safe.
    //!
    //! An error is returned if this method is called more than once.
    //!
    //! May throw.
    omni::graph::exec::unstable::Status write(omni::graph::exec::unstable::ExecutionTask& info);

    //! Waits for the specified time for the result to become ready.
    //!
    //! If the result becomes ready in the specified time (or is already ready) @ref
    //! omni::graph::exec::unstable::BackgroundResultStatus::eReady is returned. Otherwise, @ref
    //! omni::graph::exec::unstable::BackgroundResultStatus::eTimeout is returned.
    //!
    //! This method is not thread safe.
    //!
    //! Returns an error if the result has already been consumed.
    //!
    //! May throw.
    omni::graph::exec::unstable::BackgroundResultStatus waitFor(uint64_t nanoseconds);
};

#endif

#ifndef OMNI_BIND_INCLUDE_INTERFACE_DECL

inline bool omni::core::Generated<omni::graph::exec::unstable::IBackgroundResult_abi>::isReady()
{
    bool ready;
    OMNI_THROW_IF_FAILED(isReady_abi(&ready));
    return ready;
}

inline void omni::core::Generated<omni::graph::exec::unstable::IBackgroundResult_abi>::cancel(bool blocking)
{
    OMNI_THROW_IF_FAILED(cancel_abi(blocking));
}

inline omni::graph::exec::unstable::Status omni::core::Generated<omni::graph::exec::unstable::IBackgroundResult_abi>::write(
    omni::graph::exec::unstable::ExecutionTask& info)
{
    omni::graph::exec::unstable::Status out;
    OMNI_THROW_IF_FAILED(write_abi(&info, &out));
    return out;
}

inline omni::graph::exec::unstable::BackgroundResultStatus omni::core::Generated<
    omni::graph::exec::unstable::IBackgroundResult_abi>::waitFor(uint64_t nanoseconds)
{
    omni::graph::exec::unstable::BackgroundResultStatus out;
    OMNI_THROW_IF_FAILED(waitFor_abi(nanoseconds, &out));
    return out;
}

#endif

#undef OMNI_BIND_INCLUDE_INTERFACE_DECL
#undef OMNI_BIND_INCLUDE_INTERFACE_IMPL
