IEventsAdapter.h#
Fully qualified name: carb/events/IEventsAdapter.h
File members: carb/events/IEventsAdapter.h
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.
#pragma once
#include "../Interface.h"
#include "../IObject.h"
#include "../RString.h"
#include "../cpp/Span.h"
#include "../eventdispatcher/EventDispatcherTypes.h"
#include "IEvents.h"
#include "../../omni/Expected.h"
#include "../../omni/core/Result.h"
#define carb_events_IEventsAdapter_latest CARB_HEXVERSION(1, 1)
#ifndef carb_events_IEventsAdapter
#    define carb_events_IEventsAdapter carb_events_IEventsAdapter_latest
#endif
namespace carb
{
namespace eventdispatcher
{
class IMessageQueue;
}
namespace events
{
enum class AdapterType
{
    eDispatch,
    ePushPump,
    eFull,
#if CARB_VERSION_ATLEAST(carb_events_IEventsAdapter, 1, 1)
    eFullAlias,
#endif
    // Must be last. Also this value can vary by version, so it is not considered ABI safe and should therefore not be
    // passed back from the API.
    eCount
};
struct MappingEntry
{
    EventType type;
    RString dispatchName;
    RString pushName;
    constexpr MappingEntry(EventType type, RString dispatchName, RString pushName = RString()) noexcept
        : type(type), dispatchName(dispatchName), pushName(pushName)
    {
    }
};
struct MappingEntry2 : public MappingEntry
{
    cpp::span<const eventdispatcher::NamedVariant> filters;
    constexpr MappingEntry2(EventType type, RString dispatchName, RString pushName = RString()) noexcept
        : MappingEntry(type, dispatchName, pushName)
    {
    }
    constexpr MappingEntry2(EventType type,
                            RString dispatchName,
                            cpp::span<const eventdispatcher::NamedVariant> filters) noexcept
        : MappingEntry(type, dispatchName), filters(filters)
    {
    }
    constexpr MappingEntry2(EventType type,
                            RString dispatchName,
                            RString pushName,
                            cpp::span<const eventdispatcher::NamedVariant> filters) noexcept
        : MappingEntry(type, dispatchName, pushName), filters(filters)
    {
    }
};
struct AdapterDesc
{
    uint32_t sizeOf{ uint32_t(sizeof(AdapterDesc)) };
    AdapterType type;
    const char* name;
    cpp::span<const MappingEntry> mappings;
    eventdispatcher::IMessageQueue* messageQueue;
    cpp::span<const MappingEntry2> mappings2;
    constexpr AdapterDesc(AdapterType type,
                          const char* name,
                          cpp::span<const MappingEntry> mappings,
                          eventdispatcher::IMessageQueue* messageQueue = nullptr) noexcept
        : type(type), name(name), mappings(mappings), messageQueue(messageQueue)
    {
    }
    constexpr AdapterDesc(AdapterType type,
                          cpp::span<const MappingEntry2> mappings,
                          const char* name,
                          eventdispatcher::IMessageQueue* messageQueue = nullptr) noexcept
        : type(type), name(name), messageQueue(messageQueue), mappings2(mappings)
    {
    }
};
class IEventsAdapter
{
public:
    // 1.0 - Initial release
    CARB_PLUGIN_INTERFACE_EX("carb::events::IEventsAdapter", carb_events_IEventsAdapter_latest, carb_events_IEventsAdapter);
    virtual IEventStream* internalCreateAdapter(const AdapterDesc& desc, omni::core::Result& result) noexcept = 0;
    omni::expected<IEventStreamPtr, omni::core::Result> createAdapter(const AdapterDesc& desc) noexcept
    {
        omni::core::Result result;
        if (auto p = internalCreateAdapter(desc, result))
        {
            return omni::expected<IEventStreamPtr, omni::core::Result>(carb::stealObject(p));
        }
        return omni::unexpected<omni::core::Result>(result);
    }
};
} // namespace events
} // namespace carb