1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/app/utils/NetContextUtil.hpp" 4 #include "hmbdc/app/Config.hpp" 5 #include "hmbdc/app/netmap/Messages.hpp" 6 #include "hmbdc/app/netmap/Sender.hpp" 7 #include "hmbdc/app/netmap/SendTransportEngine.hpp" 8 #include "hmbdc/app/netmap/RecvTransportEngine.hpp" 9 #include "hmbdc/app/netmap/DefaultUserConfig.hpp" 11 #include "hmbdc/comm/Topic.hpp" 12 #include "hmbdc/pattern/GuardedSingleton.hpp" 14 #include <boost/regex.hpp> 25 namespace hmbdc {
namespace app {
namespace netmap {
60 std::lock_guard<std::mutex> tlock(sendTransportEnginesLock_);
62 sendTransportEngines_.push_back(res);
71 ,
size_t maxMessageSize
72 , std::tuple<> args) {
93 template <
typename Buffer,
typename MsgArbitrator = RecvTransport::NoOpArb>
101 std::lock_guard<std::mutex> tlock(recvTransportEnginesLock_);
104 , std::forward<MsgArbitrator>(arb));
105 recvTransportEngines_.emplace_back(res);
113 template <
typename Buffer,
typename ArgsTuple>
117 , ArgsTuple&& args) {
132 std::lock_guard<std::mutex> lock(sendersLock_);
133 auto sender = senders_.find(t);
134 if ( sender != senders_.end()) {
135 return sender->second.get();
137 std::lock_guard<std::mutex> slock(sendTransportEnginesLock_);
139 i < sendTransportEngines_.size();
141 auto st = sendTransportEngines_[i];
143 auto newSender =
new Sender(st, t);
144 senders_[t].reset(newSender);
161 std::lock_guard<std::mutex> tlock(recvTransportEnginesLock_);
162 for (
auto ptr : recvTransportEngines_) {
173 std::lock_guard<std::mutex> tlock(recvTransportEnginesLock_);
174 for (
auto ptr : recvTransportEngines_) {
175 ptr->stopListenTo(t);
202 template <
typename CcContext>
204 , Config::Base
const* cfgIn =
nullptr 205 ,
char const* sendSec =
nullptr 206 ,
char const* recvSec =
nullptr 207 ,
size_t maxMessageSize = 0
208 , uint8_t runningUsingThreadIndex = 0
209 ,
char const* listenToTopic =
"_")
210 : runningCtx(0u, 2ul) {
211 createMinimumNetContext(
212 *
this, runningCtx, ctx, cfgIn, sendSec, recvSec, maxMessageSize, runningUsingThreadIndex, listenToTopic);
226 std::vector<SendTransportEngine::ptr> sendTransportEngines_;
227 std::mutex sendTransportEnginesLock_;
229 std::vector<RecvTransport::ptr> recvTransportEngines_;
230 std::mutex recvTransportEnginesLock_;
232 std::map<comm::Topic, Sender::ptr> senders_;
233 uint32_t sendTransportRotationIndex_;
234 std::mutex sendersLock_;
void setDefaultUserConfig(Config const &c)
internal use
Definition: Config.hpp:140
class to hold an hmbdc configuration
Definition: Config.hpp:46
NetContext()
this is for users that want finer control of engine creation - from a blank NetContext.
Definition: NetContext.hpp:219
topic as in the publish / subscribe communication paradigm
Definition: Topic.hpp:14
fascade class for sending network messages
Definition: Sender.hpp:10
Definition: NetContextUtil.hpp:10
base for the Singleton that works with SingletonGuardian
Definition: GuardedSingleton.hpp:35
RAII representing the lifespan of the underlying Singleton which also ganrantees the singularity of u...
Definition: GuardedSingleton.hpp:20
void listenTo(comm::Topic const &t)
This process is interested in a Topic.
Definition: NetContext.hpp:160
SendTransportEngine * createSendTransportEngineTuply(Config const &cfg, size_t maxMessageSize, std::tuple<> args)
same as above but provide an unified interface - not preferred
Definition: NetContext.hpp:70
auto createRecvTransportEngineTuply(Config const &cfg, Buffer &buffer, ArgsTuple &&args)
same as above but to provide a unified interface - not preferred
Definition: NetContext.hpp:114
power a netmap port sending functions
Definition: SendTransportEngine.hpp:43
SendTransportEngine * createSendTransportEngine(Config const &cfgIn, size_t maxMessageSize)
construct a send transport and remember it
Definition: NetContext.hpp:55
impl class,
Definition: RecvTransportEngine.hpp:70
A Context is like a media object that facilitates the communications for the Clients that it is holdi...
Definition: Context.hpp:461
auto createRecvTransportEngine(Config const &cfgIn, Buffer &buffer, MsgArbitrator &&arb=RecvTransport::NoOpArb())
construct a send transport and remember it
Definition: NetContext.hpp:94
char const *const DefaultUserConfig
Definition: DefaultUserConfig.hpp:10
a singleton that holding netmap resources
Definition: NetContext.hpp:38
a take all arbitrator (no arbitration at all)
Definition: RecvTransportEngine.hpp:50
void stopListenTo(comm::Topic const &t)
undo the subscription
Definition: NetContext.hpp:172
Sender * getSender(comm::Topic const &t)
get (or create for the first time) a Sender - whose function is to send messages on its associated To...
Definition: NetContext.hpp:131
NetContext(CcContext &ctx, Config::Base const *cfgIn=nullptr, 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 ...
Definition: NetContext.hpp:203