VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::EventBus< EVENT_COUNT, EventId, MutexType > Class Template Reference

#include <TEventBus.hpp>

Collaboration diagram for tklb::EventBus< EVENT_COUNT, EventId, MutexType >:

Classes

class  BaseSubscription
 
class  Subscription
 

Public Member Functions

 EventBus ()
 
 ~EventBus ()
 
template<typename... Parameters>
void fireEvent (const EventId eventId, Parameters... param)
 

Private Types

using Subscriptions = HeapBuffer< BaseSubscription * >
 
using Lock = typename MutexType::Lock
 

Private Member Functions

void addSubscriber (BaseSubscription *sub, const EventId eventId)
 
void removeSubscriber (BaseSubscription *sub, const EventId eventId)
 

Private Attributes

Subscriptions mEvents [EVENT_COUNT]
 
MutexType mMutex
 

Detailed Description

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
class tklb::EventBus< EVENT_COUNT, EventId, MutexType >

Definition at line 15 of file TEventBus.hpp.

Member Typedef Documentation

◆ Lock

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
using tklb::EventBus< EVENT_COUNT, EventId, MutexType >::Lock = typename MutexType::Lock
private

Definition at line 21 of file TEventBus.hpp.

◆ Subscriptions

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
using tklb::EventBus< EVENT_COUNT, EventId, MutexType >::Subscriptions = HeapBuffer<BaseSubscription*>
private

Definition at line 17 of file TEventBus.hpp.

Constructor & Destructor Documentation

◆ EventBus()

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
tklb::EventBus< EVENT_COUNT, EventId, MutexType >::EventBus ( )
inline

Definition at line 41 of file TEventBus.hpp.

41{ }

◆ ~EventBus()

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
tklb::EventBus< EVENT_COUNT, EventId, MutexType >::~EventBus ( )
inline

Definition at line 42 of file TEventBus.hpp.

42{ }

Member Function Documentation

◆ addSubscriber()

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
void tklb::EventBus< EVENT_COUNT, EventId, MutexType >::addSubscriber ( BaseSubscription sub,
const EventId  eventId 
)
inlineprivate

Definition at line 23 of file TEventBus.hpp.

23 {
24 TKLB_ASSERT(eventId < EVENT_COUNT)
25 Lock lock(mMutex);
26 mEvents[eventId].push(sub);
27 }
#define TKLB_ASSERT(condition)
Wrap assertions.
Definition: TAssert.h:18
typename MutexType::Lock Lock
Definition: TEventBus.hpp:21
Subscriptions mEvents[EVENT_COUNT]
Definition: TEventBus.hpp:19
MutexType mMutex
Definition: TEventBus.hpp:20
bool push(const T &object)
Push the object to the back of the buffer TODO tklb move version.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireEvent()

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
template<typename... Parameters>
void tklb::EventBus< EVENT_COUNT, EventId, MutexType >::fireEvent ( const EventId  eventId,
Parameters...  param 
)
inline

Definition at line 57 of file TEventBus.hpp.

57 {
58 TKLB_ASSERT(eventId < EVENT_COUNT)
59 if (mEvents[eventId].size() == 0) { return; } // don't even wait for lock
60 Lock lock(mMutex);
61 for (typename Subscriptions::Size i = 0; i < mEvents[eventId].size(); i++) {
62 #ifdef TKLB_MEM_TRACE
63 auto sub = dynamic_cast<Subscription<Parameters...>*>(mEvents[eventId][i]);
64 TKLB_ASSERT(sub != nullptr)
65 #else
66 auto sub = reinterpret_cast<Subscription<Parameters...>*>(mEvents[eventId][i]);
67 #endif // TKLB_MEM_TRACE
68 sub->mCallback(param...);
69 }
70 }
Size size() const
Returns the amount of elements in the container.
unsigned int Size
everything using the heapbuffer uses this type Always needs to be unsigned!
Definition: THeapBuffer.hpp:55
Here is the call graph for this function:

◆ removeSubscriber()

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
void tklb::EventBus< EVENT_COUNT, EventId, MutexType >::removeSubscriber ( BaseSubscription sub,
const EventId  eventId 
)
inlineprivate

Definition at line 29 of file TEventBus.hpp.

29 {
30 TKLB_ASSERT(eventId < EVENT_COUNT)
31 Lock lock(mMutex);
32 mEvents[eventId].remove(sub);
33 }
bool remove(const Size index)
Removes the object at a given index and fills the gap with another Will never shrink the buffer/alloc...
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mEvents

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
Subscriptions tklb::EventBus< EVENT_COUNT, EventId, MutexType >::mEvents[EVENT_COUNT]
private

Definition at line 19 of file TEventBus.hpp.

◆ mMutex

template<int EVENT_COUNT, typename EventId = int, class MutexType = MutexDummy>
MutexType tklb::EventBus< EVENT_COUNT, EventId, MutexType >::mMutex
private

Definition at line 20 of file TEventBus.hpp.


The documentation for this class was generated from the following file: