Loading src/client.cpp +10 −4 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ std::map<std::string, std::string> p3::client::command_shorthands { {"x", "exit"} }; p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false) { p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), verbose(false) { argv.pop_front(); auto i = std::find(argv.begin(), argv.end(), "-I"); if (i != argv.end()) { Loading @@ -51,6 +51,12 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false) { argv.erase(i); } i = std::find(argv.begin(), argv.end(), "-v"); if (i != argv.end()) { verbose = true; argv.erase(i); } std::random_device rd; std::default_random_engine e(rd()); std::uniform_int_distribution<int> uniform_dist(200, 900); Loading @@ -58,10 +64,10 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false) { connection = nullptr; try { std::cout << "connecting..." << std::endl; p3::mQueue ma(p3::mQueue::DefaultId, false); if (verbose) std::cout << "connecting..." << std::endl; p3::mQueue ma(p3::mQueue::DefaultId, false, verbose); connection = new mQueue(id, true); connection = new mQueue(id, true, verbose); ma.send(p3::protocol::HELLO, id); p3::mQueueMessage m = connection->receive(30); Loading src/client.h +1 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ namespace p3 { }; bool interactive; bool verbose; std::string get_input(std::string question, inputType is_command); Loading src/main.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,8 @@ void print_usage() { << "p3 t ransfer [id] [nr] - forward call" << std::endl << "p3 d tmf [dgts] [id] - dial dtfm digits" << std::endl << "p3 r ecord [file] - record" << std::endl << "-I for an interactive shell" << std::endl; << "-I for an interactive shell" << std::endl << "-v for verbose output (not with serve)" << std::endl; } int run_server() { Loading src/msgq.cpp +7 −5 Original line number Diff line number Diff line Loading @@ -27,9 +27,11 @@ const bool p3::mQueue::Create = true; const int p3::mQueue::DefaultSendTimeout = 10; /* 10sec timeout... */ const char * p3::mQueue::DefaultId = "p3Main"; p3::mQueue::mQueue(const std::string& id, bool c) { delOnDestruct = c; key = "/p3::mQueue!" + id; p3::mQueue::mQueue(const std::string& id, bool c, bool p) : key("/p3::mQueue!" + id), delOnDestruct(c), printConversation(p) { int flags = 0; if (c) { Loading Loading @@ -98,7 +100,7 @@ void p3::mQueue::send(p3::protocol c, const std::string& v) { void p3::mQueue::send(const p3::mQueueMessage & qmsg) { std::string msg = qmsg.get_str(); std::cout << "S: " << key << ": " << msg << std::endl; if (printConversation) std::cout << "S: " << key << ": " << msg << std::endl; timespec tsp; tsp.tv_sec = time(NULL) + DefaultSendTimeout; tsp.tv_nsec = 0; Loading Loading @@ -132,7 +134,7 @@ p3::mQueueMessage p3::mQueue::receive(int timeout) { if (ret != -1) { buf[ret] = '\0'; p3::mQueueMessage ret(buf); std::cout << "R: " << key << ": " << ret.get_value() << std::endl; if (printConversation) std::cout << "R: " << key << ": " << ret.get_value() << std::endl; return ret; } else { switch (errno) { Loading src/msgq.h +3 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ namespace p3 { bool delOnDestruct; bool printConversation; public: static const bool Create; static const int DefaultSendTimeout; Loading @@ -73,7 +75,7 @@ namespace p3 { // create implies delete on destruct, only use it on // one side of the connection. Remember to inform // the other party before closing a connection mQueue(const std::string& id, bool create = false); mQueue(const std::string& id, bool create = false, bool printConversation = true); ~mQueue(); Loading Loading
src/client.cpp +10 −4 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ std::map<std::string, std::string> p3::client::command_shorthands { {"x", "exit"} }; p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false) { p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), verbose(false) { argv.pop_front(); auto i = std::find(argv.begin(), argv.end(), "-I"); if (i != argv.end()) { Loading @@ -51,6 +51,12 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false) { argv.erase(i); } i = std::find(argv.begin(), argv.end(), "-v"); if (i != argv.end()) { verbose = true; argv.erase(i); } std::random_device rd; std::default_random_engine e(rd()); std::uniform_int_distribution<int> uniform_dist(200, 900); Loading @@ -58,10 +64,10 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false) { connection = nullptr; try { std::cout << "connecting..." << std::endl; p3::mQueue ma(p3::mQueue::DefaultId, false); if (verbose) std::cout << "connecting..." << std::endl; p3::mQueue ma(p3::mQueue::DefaultId, false, verbose); connection = new mQueue(id, true); connection = new mQueue(id, true, verbose); ma.send(p3::protocol::HELLO, id); p3::mQueueMessage m = connection->receive(30); Loading
src/client.h +1 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ namespace p3 { }; bool interactive; bool verbose; std::string get_input(std::string question, inputType is_command); Loading
src/main.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,8 @@ void print_usage() { << "p3 t ransfer [id] [nr] - forward call" << std::endl << "p3 d tmf [dgts] [id] - dial dtfm digits" << std::endl << "p3 r ecord [file] - record" << std::endl << "-I for an interactive shell" << std::endl; << "-I for an interactive shell" << std::endl << "-v for verbose output (not with serve)" << std::endl; } int run_server() { Loading
src/msgq.cpp +7 −5 Original line number Diff line number Diff line Loading @@ -27,9 +27,11 @@ const bool p3::mQueue::Create = true; const int p3::mQueue::DefaultSendTimeout = 10; /* 10sec timeout... */ const char * p3::mQueue::DefaultId = "p3Main"; p3::mQueue::mQueue(const std::string& id, bool c) { delOnDestruct = c; key = "/p3::mQueue!" + id; p3::mQueue::mQueue(const std::string& id, bool c, bool p) : key("/p3::mQueue!" + id), delOnDestruct(c), printConversation(p) { int flags = 0; if (c) { Loading Loading @@ -98,7 +100,7 @@ void p3::mQueue::send(p3::protocol c, const std::string& v) { void p3::mQueue::send(const p3::mQueueMessage & qmsg) { std::string msg = qmsg.get_str(); std::cout << "S: " << key << ": " << msg << std::endl; if (printConversation) std::cout << "S: " << key << ": " << msg << std::endl; timespec tsp; tsp.tv_sec = time(NULL) + DefaultSendTimeout; tsp.tv_nsec = 0; Loading Loading @@ -132,7 +134,7 @@ p3::mQueueMessage p3::mQueue::receive(int timeout) { if (ret != -1) { buf[ret] = '\0'; p3::mQueueMessage ret(buf); std::cout << "R: " << key << ": " << ret.get_value() << std::endl; if (printConversation) std::cout << "R: " << key << ": " << ret.get_value() << std::endl; return ret; } else { switch (errno) { Loading
src/msgq.h +3 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ namespace p3 { bool delOnDestruct; bool printConversation; public: static const bool Create; static const int DefaultSendTimeout; Loading @@ -73,7 +75,7 @@ namespace p3 { // create implies delete on destruct, only use it on // one side of the connection. Remember to inform // the other party before closing a connection mQueue(const std::string& id, bool create = false); mQueue(const std::string& id, bool create = false, bool printConversation = true); ~mQueue(); Loading