8 #ifndef _SAG_CONNECTIVITY_CHAIN_MANAGERS_HPP_
9 #define _SAG_CONNECTIVITY_CHAIN_MANAGERS_HPP_
13 #include <unordered_map>
21 namespace softwareag {
22 namespace connectivity {
23 namespace chainmanagers {
102 template<
typename TRANSPORT>
105 template<
typename TRANSPORT>
114 std::string pluginName;
120 pluginName = other.pluginName;
121 config=other.config.
copy();
150 typedef std::vector<PluginConfiguration> vector_t;
157 return back().getConfiguration();
161 typedef std::unordered_map<std::string, ChainDefinition> ChainDefinitions;
163 namespace converters_impl {
164 ChainDefinitions convertChainDefinitions(
const map_t &chainDefinitions);
165 list_t convertChainDefinition(
const ChainDefinition& chainDefinition);
175 template<
typename TRANSPORT>
182 Chain &operator=(
const Chain &other) =
delete;
184 Chain &operator=(
const Chain &&other) =
delete;
185 void startImpl()
const;
231 if (!transport)
throw std::runtime_error(
"Cannot call getTransport after chain has been destroyed");
238 typedef std::shared_ptr<Chain> ptr_t;
242 Chain(TRANSPORT* transport,
void* connectivityManager,
const std::string &chainId,
const std::string &managerName)
243 :transport(transport), connectivityManager(connectivityManager), chainId(chainId), managerName(managerName)
246 TRANSPORT* transport;
247 void* connectivityManager;
250 std::string managerName;
258 template<
typename TRANSPORT>
259 class ChainManagerHost
262 friend class AbstractChainManager<TRANSPORT>;
265 ChainManagerHost(
void *connectivityManager,
const AbstractChainManager<TRANSPORT> *chainManager): connectivityManager(connectivityManager), chainManager(chainManager) {}
288 template<
typename ... ARGS>
289 typename Chain<TRANSPORT>::ptr_t
createChain(
const std::string &chainInstanceIdSuffix,
const std::string &defaultChannelTowardsHost,
const list_t &subscribeChannels,
const ChainDefinition &chainDefinition,
const map_t &substitutions, ARGS ... transportConstructorArgs)
const;
305 template<
typename TUPLE>
306 typename Chain<TRANSPORT>::ptr_t createChainImpl(
const std::string &chainInstanceIdSuffix,
const std::string &defaultChannelTowardsHost,
const list_t &subscribeChannels,
const ChainDefinition &chainDefinition,
const map_t &substitutions,
const TUPLE& tuple)
const;
309 static sag_error_t deleteChannelLifecycleListener(sag_plugin_t callback);
311 static sag_error_t callOnChannelCreated(
const char *managerLogName, sag_plugin_t callback,
const char*,
bool);
313 static sag_error_t callOnChannelDestroyed(
const char *managerLogName, sag_plugin_t callback,
const char*,
bool);
315 void *connectivityManager;
317 const AbstractChainManager<TRANSPORT> *chainManager;
351 const std::string &defaultChannelTowardsHost,
const list_t subscribeChannels,
void* reserved)
352 : TransportConstructorParameters(pluginName, chainId, config, connectivityManager, reserved),
353 defaultChannelTowardsHost(defaultChannelTowardsHost), subscribeChannels(subscribeChannels.copy())
357 std::string defaultChannelTowardsHost;
394 : managerName(managerName), transportPluginName(transportPluginName), managerConfig(managerConfig), chainDefs(chainDefs), connectivityManager(connectivityManager), reserved(reserved)
398 std::string managerName;
399 std::string transportPluginName;
400 const map_t &managerConfig;
401 const map_t &chainDefs;
403 void* connectivityManager;
426 template<
typename TRANSPORT>
427 class AbstractChainManager
438 logger(
"connectivity." + params.getManagerName() +
"." + (params.getManagerName() == params.getTransportPluginName() ?
"manager" : params.getTransportPluginName())),
441 host(params.connectivityManager, this),
442 config(params.getManagerConfig().copy()),
475 return *statusReporter;
501 typedef typename Chain<TRANSPORT>::ptr_t
chain_t;
520 if(chainDefinitions.size() != 1)
throw std::runtime_error(
"This manager only supports a single chain definition, but there was not exactly one specified.");
521 return chainDefinitions.begin()->second;
528 auto it = chainDefinitions.find(str);
529 if(it == chainDefinitions.end())
throw std::runtime_error(
"Cannot find chain definition "+str);
534 std::unique_ptr<StatusReporter> statusReporter;
544 #include <sag_internal/chain_managers.hpp>
559 #define SAG_DECLARE_CONNECTIVITY_TRANSPORT_CHAIN_MANAGER_CLASS(Class) _SAG_DECLARE_CONNECTIVITY_TRANSPORT_CHAIN_MANAGER_CLASS(Class)
561 #endif // _SAG_CONNECTIVITY_CHAIN_MANAGERS_HPP_
API provided to Chain Managers for callbacks into the host, and for operations such as creating chain...
Definition: sag_connectivity_chain_managers.hpp:106
API for Chain Manager to listen for changes in channel subscriptions within the correlator.
Definition: sag_connectivity_chain_managers.hpp:42
const map_t & getTransportConfig() const
Definition: sag_connectivity_chain_managers.hpp:156
Chain & start()
Calls start on all of the plug-ins in the chain and connects the chain to receive events...
Definition: sag_connectivity_chain_managers.hpp:222
const std::string & getTransportPluginName() const
Definition: sag_connectivity_chain_managers.hpp:388
map_t config
The configuration of this plug-in.
Definition: sag_connectivity_chain_managers.hpp:514
Direction
The enumeration indicating the direction of message flow - towards the transport or towards the host...
Definition: sag_connectivity_plugins.hpp:69
AbstractChainManager< TRANSPORT > abstract_chain_manager_t
The base class.
Definition: sag_connectivity_chain_managers.hpp:503
Class for writing to the system logger.
Definition: sag_plugin_logging.hpp:72
virtual void onChannelCreated(const std::string &channel, Direction direction)=0
Called by host when a channel is created which starts with the prefix provided during listener regist...
ChainDefinitions chainDefinitions
string-> map of chain definitions
Definition: sag_connectivity_chain_managers.hpp:506
const std::string transportPluginName
The name used in the configuration for the transport plug-in that created this chain manager...
Definition: sag_connectivity_chain_managers.hpp:495
TRANSPORT transport_t
The transport that this host can create chains for.
Definition: sag_connectivity_chain_managers.hpp:433
A container for parameters passed to the constructor of a managed transport (i.e. ...
Definition: sag_connectivity_chain_managers.hpp:330
const Chain & start() const
Calls start on all of the plug-ins in the chain and connects the chain to receive events...
Definition: sag_connectivity_chain_managers.hpp:203
Chain< TRANSPORT >::ptr_t chain_t
The chain that this host can create.
Definition: sag_connectivity_chain_managers.hpp:501
virtual void shutdown()
Release any resources created by the connectivity plug-in, and terminate and join any background thre...
Definition: sag_connectivity_chain_managers.hpp:469
Definition: sag_connectivity_threading.h:178
const ChainDefinition & getChainDefinition(const std::string &str)
Helper method to get the chain definition containing the transport associated with this manager...
Definition: sag_connectivity_chain_managers.hpp:527
StatusReporter & getStatusReporter()
Allows reporting status information from this plug-in, such as connected/disconnected status and numb...
Definition: sag_connectivity_chain_managers.hpp:474
const std::string & getManagerName() const
Definition: sag_connectivity_chain_managers.hpp:383
A class allowing a plug-in to report status values to the host.
Definition: sag_connectivity_plugins.hpp:220
Chain< TRANSPORT >::ptr_t createChain(const std::string &chainInstanceIdSuffix, const std::string &defaultChannelTowardsHost, const list_t &subscribeChannels, const ChainDefinition &chainDefinition, const map_t &substitutions, ARGS...transportConstructorArgs) const
Create a chain instance programmatically.
A list class which implements many of the functions on std::vector.
Definition: sag_connectivity_cpp.hpp:34
A plug-in configuration.
Definition: sag_connectivity_chain_managers.hpp:113
Contains the headers needed to implement your own Connectivity Plug-ins.
virtual ~ChannelLifecycleListener()
Virtual destructor.
Definition: sag_connectivity_chain_managers.hpp:46
const map_t & getManagerConfig() const
Get the configuration for this plug-in.
Definition: sag_connectivity_chain_managers.hpp:378
Base class for transport chain manager plug-ins.
Definition: sag_connectivity_chain_managers.hpp:103
virtual ~AbstractChainManager()
Virtual destructor.
Definition: sag_connectivity_chain_managers.hpp:446
void addChannelLifecycleListener(ChannelLifecycleListener *listener, const std::string &channelPrefix) const
Register a callback handler for subscribe/unsubscribe and send-to notifications.
virtual void start()
Called after the chain manager is created to indicate that it can make external connections, create threads and create chains.
Definition: sag_connectivity_chain_managers.hpp:453
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:36
const std::string & getChainId()
Get the unique identifier of this chain.
Definition: sag_connectivity_chain_managers.hpp:236
TRANSPORT * getTransport() const
Get the transport plug-in at the end of the chain.
Definition: sag_connectivity_chain_managers.hpp:230
~PluginConfiguration()=default
while we override the copy behaviour, no change to move behaviour
const list_t & getSubscribeChannels() const
Get the channels that the chain containing this transport instance is subscribed to for receiving mes...
Definition: sag_connectivity_chain_managers.hpp:338
Represents a dynamic chain instance, created using ChainManagerHost.createChain.
Definition: sag_connectivity_chain_managers.hpp:176
const ChainDefinition & getChainDefinition()
Helper method to get the chain definition containing the transport associated with this manager...
Definition: sag_connectivity_chain_managers.hpp:519
A container for parameters passed to the constructor of a transport plug-in.
Definition: sag_connectivity_plugins.hpp:183
const std::string & getDefaultChannelTowardsHost() const
Get the default channel used on this chain for messages sent from the transport towards the host...
Definition: sag_connectivity_chain_managers.hpp:345
const Logger logger
A logger to be used by this manager for anything which needs to be written to the host's log...
Definition: sag_connectivity_chain_managers.hpp:485
const std::string & getPluginName() const
while we override the copy behaviour, no change to destructor
Definition: sag_connectivity_chain_managers.hpp:130
map_t copy() const
Return a deep copy of this map.
Definition: sag_connectivity_cpp.hpp:211
void destroy()
Shutdown and destroy a chain.
const std::string managerName
The name used in the configuration for this dynamic chain manager.
Definition: sag_connectivity_chain_managers.hpp:490
virtual void onChannelDestroyed(const std::string &channel, Direction direction)=0
Called by host when a channel is destroyed which starts with the prefix provided during listener regi...
const map_t & getConfiguration() const
Definition: sag_connectivity_chain_managers.hpp:133
A container for parameters passed to the constructor of a dynamic chain manager.
Definition: sag_connectivity_chain_managers.hpp:367
AbstractChainManager(const ChainManagerConstructorParameters ¶ms)
Give the manager instance name, a host object for callbacks, the configuration specified in managerCo...
Definition: sag_connectivity_chain_managers.hpp:436
A dynamic chain definition, providing the configuration for each plug-in in a chain.
Definition: sag_connectivity_chain_managers.hpp:149
const ChainManagerHost< TRANSPORT > host
The interface through which the host provides services required by chain managers.
Definition: sag_connectivity_chain_managers.hpp:511