examples/example.stats/plugins/carb.stats/Interfaces.cpp

File members: examples/example.stats/plugins/carb.stats/Interfaces.cpp

// Copyright (c) 2022-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.
//
#ifndef DOXYGEN_BUILD
#    include "Stats.h"

#    include <carb/InterfaceUtils.h>
#    include <carb/PluginUtils.h>

namespace
{

carb::stats::StatsImpl g_stats;

// *************************** public interface functions for IStats ******************************
carb::stats::StatId CARB_ABI addStat(const carb::stats::StatDesc& desc)
{
    return g_stats.addStat(desc);
}

bool CARB_ABI removeStat(carb::stats::StatId stat)
{
    return g_stats.removeStat(stat);
}

bool CARB_ABI addValue(carb::stats::StatId stat, const carb::stats::Value& value)
{
    return g_stats.addValue(stat, value);
}

bool CARB_ABI getValue(carb::stats::StatId stat, carb::stats::StatDesc& value)
{
    return g_stats.getValue(stat, value);
}

size_t CARB_ABI getCount()
{
    return g_stats.getCount();
}

} // namespace

#    if 1
// example-begin carbonite-interfaces-walkthrough-plugin-definition
const struct carb::PluginImplDesc kPluginImpl = { "example.carb.stats.plugin", "Example Carbonite Plugin", "NVIDIA",
                                                  carb::PluginHotReload::eDisabled, "dev" };

CARB_PLUGIN_IMPL_EX(kPluginImpl, carb::stats::IStats)

template <>
bool fillInterface<carb::stats::IStats>(carb::Version* v, void* iface)
{
    using namespace carb::stats;
    switch (v->major)
    {
        case IStats::getLatestInterfaceDesc().version.major:
            *v = IStats::getLatestInterfaceDesc().version;
            *static_cast<IStats*>(iface) = { addStat, removeStat, addValue, getValue, getCount };
            return true;

        default:
            return false;
    }
}
// example-end carbonite-interfaces-walkthrough-plugin-definition
#    else
// example-begin carbonite-interfaces-walkthrough-plugin-definition2
const struct carb::PluginImplDesc kPluginImpl = { "example.carb.stats.plugin", "Example Carbonite Plugin", "NVIDIA",
                                                  carb::PluginHotReload::eDisabled, "dev" };

CARB_PLUGIN_IMPL(kPluginImpl, carb::stats::IStats)

void fillInterface(carb::stats::IStats& iface)
{
    using namespace carb::stats;
    iface = { addStat, removeStat, addValue, getValue, getCount };
}
// example-end carbonite-interfaces-walkthrough-plugin-definition2
#    endif

// example-begin carbonite-interfaces-walkthrough-plugin-dependencies
CARB_PLUGIN_IMPL_NO_DEPS()
// example-end carbonite-interfaces-walkthrough-plugin-dependencies

// example-begin carbonite-interfaces-walkthrough-plugin-callbacks
CARB_EXPORT void carbOnPluginStartup()
{
}

CARB_EXPORT void carbOnPluginShutdown()
{

    g_stats.clear();
}
// example-end carbonite-interfaces-walkthrough-plugin-callbacks
#endif