1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/app/utils/NetContextUtil.hpp" 4 #include "hmbdc/app/Config.hpp" 5 #include "hmbdc/app/udpcast/Messages.hpp" 6 #include "hmbdc/app/udpcast/Sender.hpp" 7 #include "hmbdc/app/udpcast/SendTransportEngine.hpp" 8 #include "hmbdc/app/udpcast/RecvTransportEngine.hpp" 9 #include "hmbdc/app/udpcast/DefaultUserConfig.hpp" 10 #include "hmbdc/comm/Topic.hpp" 11 #include "hmbdc/pattern/GuardedSingleton.hpp" 13 #include <boost/regex.hpp> 23 namespace hmbdc {
namespace app {
namespace udpcast {
56 ,
size_t maxMessageSize) {
57 Config dft(DefaultUserConfig,
"tx");
61 std::lock_guard<std::mutex> tlock(sendTransportsLock_);
63 sendTransports_.emplace_back(res);
72 ,
size_t maxMessageSize
73 , std::tuple<> args) {
97 template <
typename Buffer,
typename MsgArbitrator = RecvTransport::NoOpArb>
101 Config dft(DefaultUserConfig,
"rx");
105 std::lock_guard<std::mutex> tlock(recvTransportsLock_);
108 , std::forward<MsgArbitrator>(arb));
109 recvTransports_.emplace_back(res);
118 template <
typename Buffer,
typename ArgsTuple>
122 , ArgsTuple&& args) {
137 std::lock_guard<std::mutex> lock(sendersLock_);
138 auto sender = senders_.find(t);
139 if ( sender != senders_.end()) {
140 return sender->second.get();
142 std::lock_guard<std::mutex> slock(sendTransportsLock_);
144 i < sendTransports_.size();
146 auto st = sendTransports_[i];
148 auto newSender =
new Sender(st, t);
149 senders_[t].reset(newSender);
166 std::lock_guard<std::mutex> tlock(recvTransportsLock_);
167 for (
auto ptr : recvTransports_) {
178 std::lock_guard<std::mutex> tlock(recvTransportsLock_);
179 for (
auto ptr : recvTransports_) {
180 ptr->stopListenTo(t);
207 template <
typename CcContext>
209 , Config::Base
const* cfgIn =
nullptr 210 ,
char const* sendSec =
nullptr 211 ,
char const* recvSec =
nullptr 212 ,
size_t maxMessageSize = 0
213 , uint8_t runningUsingThreadIndex = 0
214 ,
char const* listenToTopic =
"_")
215 : runningCtx(0u, 2ul) {
216 checkEpollTaskInitialization();
217 createMinimumNetContext(
218 *
this, runningCtx, ctx, cfgIn, sendSec, recvSec, maxMessageSize, runningUsingThreadIndex, listenToTopic);
226 checkEpollTaskInitialization();
232 std::vector<SendTransport::ptr> sendTransports_;
233 std::mutex sendTransportsLock_;
235 std::vector<RecvTransport::ptr> recvTransports_;
236 std::mutex recvTransportsLock_;
238 std::map<Topic, Sender::ptr> senders_;
239 std::mutex sendersLock_;
void setDefaultUserConfig(Config const &c)
internal use
Definition: Config.hpp:140
class to hold an hmbdc configuration
Definition: Config.hpp:46
a singleton that holding udpcast resources
Definition: NetContext.hpp:38
topic as in the publish / subscribe communication paradigm
Definition: Topic.hpp:14
NetContext()
this is for users that want finer control of engine creation - from a blank NetContext.
Definition: NetContext.hpp:225
a take all arbitrator (no arbitration at all)
Definition: RecvTransportEngine.hpp:34
void listenTo(Topic const &t)
This process is interested in a Topic.
Definition: NetContext.hpp:165
SendTransportEngine * createSendTransportEngine(Config const &cfgIn, size_t maxMessageSize)
construct a send transport engine (and remember it within the class)
Definition: NetContext.hpp:55
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
auto createRecvTransportEngine(Config const &cfgIn, Buffer &buffer, MsgArbitrator &&arb=RecvTransport::NoOpArb())
construct a send transport and remember it
Definition: NetContext.hpp:98
fascade class for sending network messages
Definition: Sender.hpp:14
void stopListenTo(Topic const &t)
undo the subscription
Definition: NetContext.hpp:177
SendTransportEngine * createSendTransportEngineTuply(Config const &cfg, size_t maxMessageSize, std::tuple<> args)
same as above but provide a unified interface - not preferred
Definition: NetContext.hpp:71
Definition: SendTransportEngine.hpp:146
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:208
Definition: RecvTransportEngine.hpp:270
A Context is like a media object that facilitates the communications for the Clients that it is holdi...
Definition: Context.hpp:461
auto createRecvTransportEngineTuply(Config const &cfg, Buffer &buffer, ArgsTuple &&args)
same as above but to provide a unified interface - not preferred
Definition: NetContext.hpp:119
Sender * getSender(Topic const &t=Topic("_"))
get (or create for the first time) a Sender - whose function is to send messages on its associated To...
Definition: NetContext.hpp:136