main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "PjsuaCommunicator.hpp"
  2. #include "MumbleCommunicator.hpp"
  3. #include "IncomingConnectionValidator.hpp"
  4. #include "MumbleChannelJoiner.hpp"
  5. #include "Configuration.hpp"
  6. #include <log4cpp/FileAppender.hh>
  7. #include <log4cpp/OstreamAppender.hh>
  8. #include <log4cpp/PatternLayout.hh>
  9. #include <execinfo.h>
  10. /*
  11. * Code from http://stackoverflow.com/a/77336/5419223
  12. */
  13. static void sigsegv_handler(int sig) {
  14. constexpr int STACK_DEPTH = 10;
  15. void *array[STACK_DEPTH];
  16. size_t size = backtrace(array, STACK_DEPTH);
  17. fprintf(stderr, "ERROR: signal %d:\n", sig);
  18. backtrace_symbols_fd(array, size, STDERR_FILENO);
  19. exit(1);
  20. }
  21. int main(int argc, char *argv[]) {
  22. signal(SIGSEGV, sigsegv_handler);
  23. log4cpp::OstreamAppender appender("console", &std::cout);
  24. log4cpp::PatternLayout layout;
  25. layout.setConversionPattern("%d [%p] %c: %m%n");
  26. appender.setLayout(&layout);
  27. log4cpp::Category &logger = log4cpp::Category::getRoot();
  28. logger.setPriority(log4cpp::Priority::NOTICE);
  29. logger.addAppender(appender);
  30. if (argc == 1) {
  31. logger.crit("No configuration file provided. Use %s {config file}", argv[0]);
  32. std::exit(1);
  33. }
  34. config::Configuration conf(argv[1]);
  35. sip::IncomingConnectionValidator connectionValidator(conf.getString("sip.validUriExpression"));
  36. boost::asio::io_service ioService;
  37. sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator);
  38. mumble::MumbleCommunicator mumbleCommunicator(ioService);
  39. mumble::MumbleChannelJoiner mumbleChannelJoiner(conf.getString("mumble.channelNameExpression"));
  40. using namespace std::placeholders;
  41. pjsuaCommunicator.onIncomingPcmSamples = std::bind(
  42. &mumble::MumbleCommunicator::sendPcmSamples,
  43. &mumbleCommunicator,
  44. _1, _2);
  45. pjsuaCommunicator.onStateChange = std::bind(
  46. &mumble::MumbleCommunicator::sendTextMessage,
  47. &mumbleCommunicator, _1);
  48. mumbleCommunicator.onIncomingPcmSamples = std::bind(
  49. &sip::PjsuaCommunicator::sendPcmSamples,
  50. &pjsuaCommunicator,
  51. _1, _2, _3, _4);
  52. mumbleCommunicator.onIncomingChannelState = std::bind(
  53. &mumble::MumbleChannelJoiner::checkChannel,
  54. &mumbleChannelJoiner,
  55. _1, _2);
  56. mumbleCommunicator.onServerSync = std::bind(
  57. &mumble::MumbleChannelJoiner::maybeJoinChannel,
  58. &mumbleChannelJoiner,
  59. &mumbleCommunicator);
  60. mumble::MumbleCommunicatorConfig mumbleConf;
  61. mumbleConf.host = conf.getString("mumble.host");
  62. mumbleConf.port = conf.getInt("mumble.port");
  63. mumbleConf.user = conf.getString("mumble.user");
  64. mumbleConf.password = conf.getString("mumble.password");
  65. mumbleConf.opusEncoderBitrate = conf.getInt("mumble.opusEncoderBitrate");
  66. mumbleCommunicator.connect(mumbleConf);
  67. pjsuaCommunicator.connect(
  68. conf.getString("sip.host"),
  69. conf.getString("sip.user"),
  70. conf.getString("sip.password"),
  71. conf.getInt("sip.port"));
  72. logger.info("Application started.");
  73. ioService.run();
  74. return 0;
  75. }