2 #include "hmbdc/app/utils/ConsoleClient.hpp" 3 #include "hmbdc/os/Signals.hpp" 4 #include "hmbdc/numeric/BitMath.hpp" 6 #include <boost/program_options.hpp> 11 namespace hmbdc {
namespace app {
namespace utils {
18 namespace consolerunner_detail {
25 using LoggerContext = HMBDC_LOG_CONTEXT;
27 using MyLogger = LoggerT<LoggerContext>;
29 template <
typename NetContext>
30 void run(ptree
const& configIn) {
31 Config config(configIn);
33 using namespace boost;
37 auto maxMessageSize = config.get<uint16_t>(
"maxMessageSize");
39 MyContext ctx(config.get<uint16_t>(
"inBufferSizePower2")
40 , config.get_child(
"transports").size() * 2 + 1
46 auto coreBitMask = config.getHex<uint64_t>(
"coreBitMask");
49 if (coreBitMask == 0) {
50 coreBitMask = (1ul << std::thread::hardware_concurrency()) - 1ul;
54 ctx.start(setBitsCount(coreBitMask), coreBitMask);
57 for (
auto const& t : config.get_child(
"transports")) {
58 Config tconf(config, t.second);
59 auto poolThreadAffinity = 1ul;
60 if (t.second.get(
"tx",
false)) {
61 auto sengine = NetContext::instance().createSendTransportEngine(
62 tconf, maxMessageSize);
64 ctx.addToPool(*sengine, poolThreadAffinity);
66 if (t.second.get(
"rx",
false)) {
67 auto rengine = NetContext::instance().createRecvTransportEngine(
69 ctx.addToPool(*rengine, poolThreadAffinity);
71 poolThreadAffinity <<= 1ul;
73 if (poolThreadAffinity == (1ul << setBitsCount(coreBitMask))) {
74 poolThreadAffinity = 1ul;
78 std::unordered_set<uint16_t> attTags;
80 config(attTags,
"allowRecvMemoryAttachment");
83 ConsoleClient<NetContext> client(ctx
87 , config.get(
"initCmd",
"")
90 ctx.addToPool(client);
96 client.waitUntilFinish();
97 sleep(config.get(
"secWaitAfterInputDone", 1));
103 template <
typename NetContext>
104 int startConsole(
char const* helpStrIn,
int argc,
char** argv) {
107 cout << helpStrIn << endl;
112 string userCfg(argv[1]);
113 std::ifstream cs(userCfg);
114 read_json(cs, config);
115 run<NetContext>(config);
121 using consolerunner_detail::startConsole;
Definition: TypedString.hpp:74
Definition: BitMath.hpp:6
RAII representing the lifespan of the underlying Singleton which also ganrantees the singularity of u...
Definition: GuardedSingleton.hpp:20
Definition: GuardedSingleton.hpp:9
static void onTermIntDo(std::function< void()> doThis)
specfy what to do when SIGTERM or SIGINT is received
Definition: Signals.hpp:27
A Context is like a media object that facilitates the communications for the Clients that it is holdi...
Definition: Context.hpp:402