omni/structuredlog/StructuredLogCommon.h
File members: omni/structuredlog/StructuredLogCommon.h
// Copyright (c) 2021-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.
//
#pragma once
#include "../core/IObject.h"
#include "../extras/ForceLink.h"
namespace omni
{
namespace structuredlog
{
#define OMNI_STRUCTURED_LOG_EVENT_ID(schemaName, eventName, schemaVersion, parserVersion)                              \
    CARB_HASH_STRING(schemaName "-" eventName "-" schemaVersion "." parserVersion)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// used internally in OMNI_STRUCTURED_LOG_ADD_SCHEMA().  Do not call directly.
#    define OMNI_STRUCTURED_LOG_SCHEMA_ADDED_NAME(name_, version_, parser_, line_)                                     \
        OMNI_STRUCTURED_LOG_SCHEMA_ADDED_NAME_INNER(name_, version_, parser_, line_)
// used internally in OMNI_STRUCTURED_LOG_SCHEMA_ADDED_NAME().  Do not call directly.
#    define OMNI_STRUCTURED_LOG_SCHEMA_ADDED_NAME_INNER(name_, version_, parser_, line_)                               \
        sSchema_##name_##_##version_##_##parser_##_##line_
#endif
#define OMNI_STRUCTURED_LOG_ADD_SCHEMA(schemaType_, schemaName_, version_, parser_)                                    \
    CARB_ATTRIBUTE(weak)                                                                                               \
    CARB_DECLSPEC(selectany)                                                                                           \
    bool OMNI_STRUCTURED_LOG_SCHEMA_ADDED_NAME(schemaName_, version_, parser_, __LINE__) = []() {                      \
        omni::structuredlog::getModuleSchemas().push_back(&schemaType_::registerSchema);                               \
        return true;                                                                                                   \
    }();                                                                                                               \
    OMNI_FORCE_SYMBOL_LINK(                                                                                            \
        OMNI_STRUCTURED_LOG_SCHEMA_ADDED_NAME(schemaName_, version_, parser_, __LINE__), schemaRegistration)
enum class SchemaResult
{
    eSuccess,
    eAlreadyExists,
    eEventIdCollision,
    eFlagsDiffer,
    eOutOfEvents,
    eInvalidParameter,
    eEventNotInBlock,
    eOutOfMemory,
};
using EventId = uint64_t;
constexpr EventId kBadEventId = ~1ull;
constexpr const char* getSchemaResultName(SchemaResult result)
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#    define OMNI_STRUCTUREDLOG_GETNAME(r, prefix)                                                                      \
        case r:                                                                                                        \
            return &(#r)[sizeof(#prefix) - 1]
    switch (result)
    {
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eSuccess, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eAlreadyExists, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eEventIdCollision, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eFlagsDiffer, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eOutOfEvents, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eInvalidParameter, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eEventNotInBlock, SchemaResult::e);
        OMNI_STRUCTUREDLOG_GETNAME(SchemaResult::eOutOfMemory, SchemaResult::e);
        default:
            return "<unknown_result>";
    }
#    undef OMNI_STRUCTUREDLOG_GETNAME
#endif
}
} // namespace structuredlog
} // namespace omni