VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::ServiceExchange Class Reference

Typed view of the host's table of interfaces plugins publish to each other. More...

#include <ServiceExchange.hpp>

Public Member Functions

 ServiceExchange (IPluginServices &services)
 
template<class T >
Subscription Publish (T *impl)
 
template<class T >
Subscription Publish (T *impl, std::string_view key)
 
template<class T >
T * Get () const
 
template<class T >
T * Get (std::string_view key) const
 

Detailed Description

Typed view of the host's table of interfaces plugins publish to each other.

An interface is a pure-virtual struct with a versioned InterfaceName ("bans.IBanService/2"). Bump the version whenever the vtable or a parameter's meaning changes, so a stale consumer gets nullptr instead of a mismatched vtable. Each plugin has its own allocator: never transfer ownership through an interface, and let no exception escape one.

Definition at line 19 of file ServiceExchange.hpp.

Constructor & Destructor Documentation

◆ ServiceExchange()

VoltMod::ServiceExchange::ServiceExchange ( IPluginServices &  services)
inlineexplicit

services is the host's table; it outlives the exchange.

Definition at line 23 of file ServiceExchange.hpp.

Member Function Documentation

◆ Get() [1/2]

template<class T >
T * VoltMod::ServiceExchange::Get ( ) const
inline

What any plugin published for T, or nullptr. Ask where you use it and do not keep it: the publisher can unload between callbacks, never inside one.

Definition at line 44 of file ServiceExchange.hpp.

References VoltMod::T.

◆ Get() [2/2]

template<class T >
T * VoltMod::ServiceExchange::Get ( std::string_view  key) const
inline

What a plugin published for T under key, or nullptr.

Definition at line 51 of file ServiceExchange.hpp.

References VoltMod::ReadFile(), and VoltMod::T.

◆ Publish() [1/2]

template<class T >
Subscription VoltMod::ServiceExchange::Publish ( T *  impl)
inline

Offer impl while the returned Subscription lives. Name T explicitly, Publish<IBanService>(&_bans), so the stored pointer is the interface subobject the consumer casts back to. Keep the Subscription below impl, so the entry goes first.

Definition at line 29 of file ServiceExchange.hpp.

References VoltMod::ReadFile().

◆ Publish() [2/2]

template<class T >
Subscription VoltMod::ServiceExchange::Publish ( T *  impl,
std::string_view  key 
)
inline

Offer impl as one of several T, told apart by key: Publish<IMenuSection>(this, "admin").

Definition at line 36 of file ServiceExchange.hpp.

References VoltMod::ReadFile().


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