carb/eventdispatcher/IEventDispatcher.h

File members: carb/eventdispatcher/IEventDispatcher.h

// Copyright (c) 2022, 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 "../Interface.h"
#include "EventDispatcherTypes.h"

namespace carb
{

namespace eventdispatcher
{

class ObserverGuard;

struct IEventDispatcher
{
    CARB_PLUGIN_INTERFACE("carb::eventdispatcher::IEventDispatcher", 0, 1)

    Observer(CARB_ABI* internalObserveEvent)(int order,
                                             RString eventName,
                                             size_t numVariants,
                                             NamedVariant const* variants,
                                             ObserverFn fn,
                                             CleanupFn cleanup,
                                             void* ud);

    bool(CARB_ABI* stopObserving)(Observer ob);

    bool(CARB_ABI* internalHasObservers)(RString eventName, size_t numVariants, NamedVariant const* variants);

    size_t(CARB_ABI* internalDispatch)(const EventData&);

    bool(CARB_ABI* isDispatching)(bool currentThread);

    template <class Invocable, class... Args>
    CARB_NODISCARD ObserverGuard observeEvent(int order, RString eventName, Invocable&& invocable, Args&&... filterArgs);

    template <class Invocable, class InIter>
    CARB_NODISCARD ObserverGuard
    observeEventIter(int order, RString eventName, Invocable&& invocable, InIter begin, InIter end);

    template <class... Args>
    bool hasObservers(RString eventName, Args&&... filterArgs);

    template <class InIter>
    bool hasObserversIter(RString eventName, InIter begin, InIter end);

    template <class... Args>
    size_t dispatchEvent(RString eventName, Args&&... payload);

    template <class InIter>
    size_t dispatchEventIter(RString eventName, InIter begin, InIter end);
};

} // namespace eventdispatcher
} // namespace carb

#include "IEventDispatcher.inl"