hmbdc
simplify-high-performance-messaging-programming
Public Member Functions | Private Member Functions | Friends | List of all members
hmbdc::app::tcpcast::NetContext Class Reference

a singleton that holding tcpcast resources More...

#include <NetContext.hpp>

Inheritance diagram for hmbdc::app::tcpcast::NetContext:
hmbdc::pattern::GuardedSingleton< NetContext > hmbdc::app::utils::NetContextUtil

Public Member Functions

SendTransportEnginecreateSendTransportEngine (Config const &cfgIn, size_t maxMessageSize)
 construct a send transport enngine (and remember it) More...
 
SendTransportEnginecreateSendTransportEngineTuply (Config const &cfg, size_t maxMessageSize, std::tuple< size_t > args)
 same as above but provide an unified interface - not preferred More...
 
template<typename Buffer , typename MsgArbitrator = RecvTransport::NoOpArb>
auto createRecvTransportEngine (Config const &cfgIn, Buffer &buffer, MsgArbitrator &&arb=RecvTransport::NoOpArb())
 construct a recv transport and remember it More...
 
template<typename Buffer , typename ArgsTuple >
auto createRecvTransportEngineTuply (Config const &cfg, Buffer &buffer, ArgsTuple &&args)
 same as above but to provide a unified interface - not preferred More...
 
SendergetSender (comm::Topic const &t)
 get (or create for the first time) a Sender - whose function is to send messages on its associated Topic More...
 
void listenTo (comm::Topic const &t)
 This process is interested in a Topic. More...
 
void stopListenTo (comm::Topic const &t)
 undo the subscription More...
 

Private Member Functions

template<typename CcContext >
 NetContext (CcContext &ctx, Config::Base cfgIn=Config::Base{}, char const *sendSec=nullptr, char const *recvSec=nullptr, size_t maxMessageSize=0, uint8_t runningUsingThreadIndex=0, char const *listenToTopic="_")
 this ctor is to create some commonly used basic engine setup to start with. This is private and only meant to be used through SingletonGuardian, see in example chat.cpp

Config config; //other config values are default
config.put("ifaceAddr", ifaceAddr);//which interface to use for communication
config.put("loopback", true); //could be chatting on the same machine
Context<sizeof(ChatMessage)> ctx; //large enough to hold ChatMessage's
//create NetContext with initial tx/rx capabilities, and listen to the default topic "_"
//received network messages goes to ctx. this launches a thread to power the above engines
SingletonGuardian<tcpcast::NetContext> g(ctx, config); //RAII for tcpcast::NetContext resources
More...
 
 NetContext ()
 this is for users that want finer control of engine creation - from a blank NetContext. More...
 

Friends

struct hmbdc::pattern::SingletonGuardian< NetContext >
 

Detailed Description

a singleton that holding tcpcast resources

it manages transport engines

see perf-tcpcast.cpp chat.cpp for usage.

Constructor & Destructor Documentation

◆ NetContext() [1/2]

template<typename CcContext >
hmbdc::app::tcpcast::NetContext::NetContext ( CcContext &  ctx,
Config::Base  cfgIn = Config::Base{},
char const *  sendSec = nullptr,
char const *  recvSec = nullptr,
size_t  maxMessageSize = 0,
uint8_t  runningUsingThreadIndex = 0,
char const *  listenToTopic = "_" 
)
inlineprivate

this ctor is to create some commonly used basic engine setup to start with. This is private and only meant to be used through SingletonGuardian, see in example chat.cpp

Config config; //other config values are default
config.put("ifaceAddr", ifaceAddr);//which interface to use for communication
config.put("loopback", true); //could be chatting on the same machine
Context<sizeof(ChatMessage)> ctx; //large enough to hold ChatMessage's
//create NetContext with initial tx/rx capabilities, and listen to the default topic "_"
//received network messages goes to ctx. this launches a thread to power the above engines
SingletonGuardian<tcpcast::NetContext> g(ctx, config); //RAII for tcpcast::NetContext resources

It creates one send transport engine and/or one recv transport engine based on cfgIn. and run them using a single OS thread indicated by runningUsingThreadIndex If recv engine is created, this method also automaticallly makes the NetContext listen to a default topic (listenToTopic).

Parameters
ctxa Context that manages the send / recv transport engines, and hold the received messages
cfgInoptional Config for the send AND recv transport engines
sendSecthe section name for send transport engine in above cfgIn, special values: nullptr - create send engine using no section config values "" - do not create send engine
recvSecthe section name for recv transport engine in above cfgIn nullptr - create recv engine using no section config values "" - do not create recv engine
maxMessageSizemax message size in bytes to be sent, if 0, uses ctx's maxMessageSize()
runningUsingThreadIndexsee details above
Template Parameters
CcContextctx Context type

◆ NetContext() [2/2]

hmbdc::app::tcpcast::NetContext::NetContext ( )
inlineprivate

this is for users that want finer control of engine creation - from a blank NetContext.

it does not do anything that the previous ctor does

Member Function Documentation

◆ createRecvTransportEngine()

template<typename Buffer , typename MsgArbitrator = RecvTransport::NoOpArb>
auto hmbdc::app::tcpcast::NetContext::createRecvTransportEngine ( Config const &  cfgIn,
Buffer &  buffer,
MsgArbitrator &&  arb = RecvTransport::NoOpArb() 
)
inline

construct a recv transport and remember it

After this, user is respoonsible to get it started within a hmbdc Context, or rotated continously.

Parameters
cfgInjason specifing the transport - see perf-tcpcast.cpp and hmbdc/app/tcpcast/DefaultUserConfig.hpp
bufferbuffer that recv messages go, normally the one returned by app::Context::buffer()
arboptonally an arbitrator to decide which messages to keep and drop if arb is an rvalue, it is passed in value, if an lvalue, passed in as reference; it supports ONLY hmbdc message level (AFTER topic filtering) arbitration if int operator()(TransportMessageHeader const* header) presents in the arb passed in. (NO packet level since it is tcp)
Returns
a pointer to the Engine

◆ createRecvTransportEngineTuply()

template<typename Buffer , typename ArgsTuple >
auto hmbdc::app::tcpcast::NetContext::createRecvTransportEngineTuply ( Config const &  cfg,
Buffer &  buffer,
ArgsTuple &&  args 
)
inline

same as above but to provide a unified interface - not preferred

use forward_as_tuple to make the tuple passed in

Returns
a pointer to the Engine

◆ createSendTransportEngine()

SendTransportEngine* hmbdc::app::tcpcast::NetContext::createSendTransportEngine ( Config const &  cfgIn,
size_t  maxMessageSize 
)
inline

construct a send transport enngine (and remember it)

After this, user is responsible to get it started within a hmbdc Context, or rotated continously. Don't create the same thing twice.

Parameters
cfgInjason specifing the transport - see perf-tcpcast.cpp and hmbdc/app/tcpcast/DefaultUserConfig.hpp
maxMessageSizemax messafe size in bytes to be sent hold the message in buffer
Returns
a pointer to the Engine

◆ createSendTransportEngineTuply()

SendTransportEngine* hmbdc::app::tcpcast::NetContext::createSendTransportEngineTuply ( Config const &  cfg,
size_t  maxMessageSize,
std::tuple< size_t >  args 
)
inline

same as above but provide an unified interface - not preferred

Returns
a pointer to the Engine - don't delete it

◆ getSender()

Sender* hmbdc::app::tcpcast::NetContext::getSender ( comm::Topic const &  t)
inline

get (or create for the first time) a Sender - whose function is to send messages on its associated Topic

this operation typically might be slow, so caching the return value is recommended.

Parameters
t- the Topic that the Sender is for

◆ listenTo()

void hmbdc::app::tcpcast::NetContext::listenTo ( comm::Topic const &  t)
inline

This process is interested in a Topic.

Normally the receiving transport covering this topic needs to be created - not necessarily running - before calling this

Parameters
tTopic interested

◆ stopListenTo()

void hmbdc::app::tcpcast::NetContext::stopListenTo ( comm::Topic const &  t)
inline

undo the subscription

Parameters
tTopic

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