carb/ClientUtils.h
File members: carb/ClientUtils.h
// Copyright (c) 2018-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 "Framework.h"
#include "assert/AssertUtils.h"
#include "crashreporter/CrashReporterUtils.h"
#include "l10n/L10nUtils.h"
#include "logging/Log.h"
#include "logging/StandardLogger.h"
#include "profiler/Profile.h"
#include "../omni/core/Omni.h"
#include <vector>
namespace carb
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
inline void registerBuiltinFileSystem(Framework* f)
{
f->registerPlugin(g_carbClientName, f->getBuiltinFileSystemDesc());
}
inline void registerBuiltinLogging(Framework* f)
{
f->registerPlugin(g_carbClientName, f->getBuiltinLoggingDesc());
}
inline void registerBuiltinAssert(Framework* f)
{
f->registerPlugin(g_carbClientName, f->getBuiltinAssertDesc());
}
inline void registerBuiltinThreadUtil(Framework* f)
{
f->registerPlugin(g_carbClientName, f->getBuiltinThreadUtilDesc());
}
#endif
inline Framework* acquireFrameworkAndRegisterBuiltins(const OmniCoreStartArgs* args = nullptr)
{
// Acquire framework and set into global variable
Framework* framework = acquireFramework(g_carbClientName);
if (framework)
{
g_carbFramework = framework;
static_assert(
kFrameworkVersion.major == 0,
"The framework automatically registers builtins now; the registerXXX functions can be removed once the framework version changes.");
// Starting up logging
registerBuiltinLogging(framework);
logging::registerLoggingForClient();
// Starting up filesystem
registerBuiltinFileSystem(framework);
registerBuiltinAssert(framework);
registerBuiltinThreadUtil(framework);
// grab the assertion helper interface.
assert::registerAssertForClient();
// grab the l10n interface.
l10n::registerLocalizationForClient();
// start up ONI
OMNI_CORE_START(args);
}
return framework;
}
inline void releaseFrameworkAndDeregisterBuiltins()
{
if (isFrameworkValid())
{
logging::deregisterLoggingForClient();
assert::deregisterAssertForClient();
l10n::deregisterLocalizationForClient();
// Release structured log before unloading plugins
omniReleaseStructuredLog();
g_carbFramework->unloadAllPlugins();
OMNI_CORE_STOP();
releaseFramework();
}
g_carbFramework = nullptr;
}
} // namespace carb
#define CARB_GLOBALS(clientName) CARB_GLOBALS_EX(clientName, nullptr)
#define CARB_GLOBALS_EX(clientName, clientDescription) \
CARB_FRAMEWORK_GLOBALS(clientName) \
CARB_LOG_GLOBALS() \
CARB_PROFILER_GLOBALS() \
CARB_ASSERT_GLOBALS() \
CARB_LOCALIZATION_GLOBALS() \
CARB_CRASH_REPORTER_GLOBALS() \
OMNI_GLOBALS_ADD_DEFAULT_CHANNEL(clientName, clientDescription)