omni/structuredlog/IStructuredLogSettings.h

File members: omni/structuredlog/IStructuredLogSettings.h

// Copyright (c) 2021-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 "StructuredLogCommon.h"

#include "../../carb/settings/ISettings.h"
#include "../core/IObject.h"
#include "../extras/PrivacySettings.h"

namespace omni
{
namespace structuredlog
{

class IStructuredLogSettings;

// ******************************* enums, types, and constants ************************************
using SessionId = uint64_t;

constexpr const char* kDefaultLogPathName = nullptr;

constexpr EventId kDefaultLogPathEvent = 0;

using PrivacyLoadFlags = uint32_t;

constexpr PrivacyLoadFlags fPrivacyLoadFlagResetSettings = 0x00000001;

enum class OMNI_ATTR("prefix=e") IdMode
{
    eRandom,

    eSequential,

    eFastSequential,
};

enum class OMNI_ATTR("prefix=e") IdType
{
    eUuid,

    eUint64,
};

// ****************************** IStructuredLogSettings interface ********************************
class IStructuredLogSettings_abi
    : public omni::core::Inherits<omni::core::IObject, OMNI_TYPE_ID("omni.structuredlog.IStructuredLogSettings")>
{
protected:
    // ****** host app structured log configuration accessor functions ******
    virtual size_t getEventQueueSize_abi() noexcept = 0;

    virtual int64_t getLogSizeLimit_abi() noexcept = 0;

    virtual size_t getLogRetentionCount_abi() noexcept = 0;

    virtual IdMode getEventIdMode_abi() noexcept = 0;

    virtual IdType getEventIdType_abi() noexcept = 0;

    virtual const char* getLogOutputPath_abi() noexcept = 0;

    virtual const char* getLogDefaultName_abi() noexcept = 0;

    virtual const char* getLogPathForEvent_abi(EventId eventId) noexcept = 0;

    virtual const char* getUserId_abi() noexcept = 0;

    virtual SessionId getSessionId_abi() noexcept = 0;

    virtual void setEventQueueSize_abi(size_t sizeInBytes) noexcept = 0;

    virtual void setLogSizeLimit_abi(int64_t limitInBytes) noexcept = 0;

    virtual void setLogRetentionCount_abi(size_t count) noexcept = 0;

    virtual void setEventIdMode_abi(IdMode mode, IdType type) noexcept = 0;

    virtual void setLogOutputPath_abi(OMNI_ATTR("c_str, in") const char* path) noexcept = 0;

    virtual void setLogDefaultName_abi(OMNI_ATTR("c_str, in") const char* name) noexcept = 0;

    virtual void setUserId_abi(OMNI_ATTR("c_str, in, not_null") const char* userId) noexcept = 0;

    virtual bool loadPrivacySettings_abi() noexcept = 0;

    virtual bool enableSchemasFromSettings_abi() noexcept = 0;
};

} // namespace structuredlog
} // namespace omni

#define OMNI_BIND_INCLUDE_INTERFACE_DECL
#include "IStructuredLogSettings.gen.h"

class omni::structuredlog::IStructuredLogSettings
    : public omni::core::Generated<omni::structuredlog::IStructuredLogSettings_abi>
{
public:
    bool loadPrivacySettingsFromFile(const char* filename, PrivacyLoadFlags flags)
    {
        carb::settings::ISettings* settings = carb::getCachedInterface<carb::settings::ISettings>();
        bool success;

        // The setting path to specify the path and filename of the privacy settings file to load.  If
        // this setting is specified, the privacy settings will be loaded from the named file instead
        // of the default location.  This file is expected to be TOML formatted and is expected to
        // provide the values for the "/privacy/" branch.  This should only be used for testing purposes.
        // This value defaults to not being defined.
        //
        // Note: this value needs to be redefined here since including `StructuredLogSettingsUtils.h`
        //       would introduce a dependency loop that would still leave this symbol undefined when
        //       this is parsed.
        constexpr const char* kPrivacyFileSetting = "/structuredLog/privacySettingsFile";

        if (settings == nullptr)
            return false;

        if (filename == nullptr)
            filename = "";

        // explicitly reset the values that can affect whether 'internal' diagnostic data can be
        // sent.  This prevents extra data from being inadvertently sent if the 'privacy.toml'
        // file is deleted and recreated, then reloaded by the running app.  If the newly loaded
        // file also contains these settings, these values will simply be replaced.
        if ((flags & fPrivacyLoadFlagResetSettings) != 0)
        {
            settings->setString(omni::extras::PrivacySettings::kExtraDiagnosticDataOptInKey, "");
            settings->setBool(omni::extras::PrivacySettings::kExternalBuildKey, true);
        }

        settings->setString(kPrivacyFileSetting, filename);
        success = loadPrivacySettings_abi();
        settings->setString(kPrivacyFileSetting, "");
        return success;
    }
};

#define OMNI_BIND_INCLUDE_INTERFACE_IMPL
#include "IStructuredLogSettings.gen.h"