VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
conf.h File Reference

Abstract transport configuration base class and associated helper macros. More...

#include <map>
#include <memory>
#include <shared_mutex>
#include <string>
#include <utility>
#include "../base/macros.h"
#include "./types.h"
Include dependency graph for conf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

 Abstract base class for VLink transport configuration objects. More...

Namespaces

Macros

#define VLINK_DECLARE_CONF_FRIEND()
 Macro Definitions.
#define VLINK_CONF_IMPL(classname)
 Standard boilerplate for concrete Conf subclass declarations.
#define VLINK_ALLOW_IMPL_TYPE(type)
 Declares a static constexpr bitmask of supported ImplType values.
#define VLINK_DECLARE_GLOBAL_PROPERTY()
 Declares per-transport global state: thread count and property storage.
#define VLINK_DEFINE_GLOBAL_PROPERTY(classname)
 Provides definitions for the static members declared by VLINK_DECLARE_GLOBAL_PROPERTY.

Detailed Description

Abstract transport configuration base class and associated helper macros.

Conf is the pure-virtual base for every transport backend configuration object (e.g. DdsConf, ShmConf, IntraConf). It acts as a bridge between the URL parsing layer and the concrete NodeImpl factories:

  1. A Url object parses the transport from the URL string and constructs the corresponding Conf subclass.
  2. When a Publisher<T> / Subscriber<T> / etc. calls init(), the node template calls Conf::parse(impl_type) followed by Conf::create_publisher() / create_subscriber() / etc. to obtain a transport-specific NodeImpl instance.
  3. The NodeImpl carries out the actual IPC/DDS/SHM operations.
Macro Overview
Several helper macros reduce boilerplate in concrete Conf subclasses:
Macro Purpose
VLINK_DECLARE_CONF_FRIEND() Grants friendship to all six Node<> template specialisations.
VLINK_CONF_IMPL(classname) Declares the private Conf interface inside a concrete class.
VLINK_ALLOW_IMPL_TYPE(type) Declares which ImplType bitmask the Conf supports.
VLINK_DECLARE_GLOBAL_PROPERTY() Declares per-class thread count and global property storage.
VLINK_DEFINE_GLOBAL_PROPERTY() Defines the static members declared by the above macro.

Macro Definition Documentation

◆ VLINK_ALLOW_IMPL_TYPE

#define VLINK_ALLOW_IMPL_TYPE ( type)
Value:
public: \
[[nodiscard]] static constexpr int get_allow_impl_type() { return type; }

Declares a static constexpr bitmask of supported ImplType values.

Expands to a public get_allow_impl_type() that returns type, allowing the Node<> template to assert at compile time that the conf supports the requested node role. Use bitwise-OR to combine multiple roles, e.g.:

VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
#define VLINK_ALLOW_IMPL_TYPE(type)
Declares a static constexpr bitmask of supported ImplType values.
Definition conf.h:268
Parameters
typeBitmask of ImplType values this conf supports.

◆ VLINK_CONF_IMPL

#define VLINK_CONF_IMPL ( classname)
Value:
private: \
VLINK_DECLARE_CONF_FRIEND() \
\
[[nodiscard]] bool parse_protocol(struct Protocol* protocol) override; \
\
[[nodiscard]] std::unique_ptr<class ServerImpl> create_server() const override; \
\
[[nodiscard]] std::unique_ptr<class ClientImpl> create_client() const override; \
\
[[nodiscard]] std::unique_ptr<class PublisherImpl> create_publisher() const override; \
\
[[nodiscard]] std::unique_ptr<class SubscriberImpl> create_subscriber() const override; \
\
[[nodiscard]] std::unique_ptr<class SetterImpl> create_setter() const override; \
\
[[nodiscard]] std::unique_ptr<class GetterImpl> create_getter() const override; \
\
VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const classname& conf) noexcept; \
\
public: \
classname() = default; \
\
~classname() = default; \
\
[[nodiscard]] bool is_valid() const override;
#define VLINK_EXPORT
Definition macros.h:85

Standard boilerplate for concrete Conf subclass declarations.

Adds to the class:

  • VLINK_DECLARE_CONF_FRIEND() – friend access for Node<> templates.
  • Overrides for all six protected Conf factory methods.
  • operator<<(ostream, classname) for debug printing.
  • A public default constructor.
  • bool is_valid() const override – subclass must define the body.
Parameters
classnameThe name of the concrete Conf subclass.

◆ VLINK_DECLARE_CONF_FRIEND

#define VLINK_DECLARE_CONF_FRIEND ( )
Value:
template <typename, typename, SecurityType> \
friend class Server; \
template <typename, typename, SecurityType> \
friend class Client; \
template <typename, SecurityType> \
friend class Publisher; \
template <typename, SecurityType> \
friend class Subscriber; \
template <typename, SecurityType> \
friend class Setter; \
template <typename, SecurityType> \
friend class Getter;

Macro Definitions.

Declares all six VLink Node template specialisations as friends.

Placed inside a concrete Conf subclass declaration to allow Server<>, Client<>, Publisher<>, Subscriber<>, Setter<>, and Getter<> to access the protected create_*() factory methods and parse_protocol(). Use VLINK_CONF_IMPL(classname) which already expands this macro; only include this macro directly when you need friend access without the full VLINK_CONF_IMPL boilerplate.

◆ VLINK_DECLARE_GLOBAL_PROPERTY

#define VLINK_DECLARE_GLOBAL_PROPERTY ( )
Value:
private: \
static size_t thread_count_; \
static PropertiesMap global_properties_; \
static std::shared_mutex global_mtx_; \
\
public: \
[[nodiscard]] static size_t get_thread_count() { return thread_count_; } \
\
static void set_thread_count(size_t thread_count) { thread_count_ = thread_count; } \
\
static void set_global_property(const std::string& prop, const std::string& value) { \
std::lock_guard lock(global_mtx_); \
global_properties_[prop] = value; \
} \
\
[[nodiscard]] static std::string get_global_property(const std::string& prop) { \
std::shared_lock lock(global_mtx_); \
auto iter = global_properties_.find(prop); \
return iter != global_properties_.end() ? iter->second : std::string(); \
} \
\
[[nodiscard]] static PropertiesMap get_global_all_properties() { \
std::shared_lock lock(global_mtx_); \
return global_properties_; \
} \
\
static void global_init();

Declares per-transport global state: thread count and property storage.

Intended for use inside a concrete Conf subclass body. Declares:

  • thread_count_ – number of I/O threads for this transport.
  • global_properties_ – default properties applied to every node of this transport.
  • global_mtx_ – shared mutex protecting global_properties_.

Also injects:

  • get_thread_count() – retrieve current thread count.
  • set_thread_count() – set thread count (must be called before global_init()).
  • set_global_property(prop, value) – set a default property for all nodes.
  • get_global_property(prop) – retrieve a default property.
  • get_global_all_properties() – retrieve a snapshot of all properties.
  • global_init() declaration – must be defined by the subclass.

Pair with VLINK_DEFINE_GLOBAL_PROPERTY(classname) in the .cc file.

◆ VLINK_DEFINE_GLOBAL_PROPERTY

#define VLINK_DEFINE_GLOBAL_PROPERTY ( classname)
Value:
size_t classname::thread_count_{1}; \
Conf::PropertiesMap classname::global_properties_; \
std::shared_mutex classname::global_mtx_;

Provides definitions for the static members declared by VLINK_DECLARE_GLOBAL_PROPERTY.

Place once in the .cc file of the corresponding Conf subclass. Initialises thread_count_ to 1, global_properties_ to an empty map, and default-constructs global_mtx_.

Parameters
classnameThe name of the concrete Conf subclass.