2015-09-28 23:25:12 +02:00
|
|
|
#include "PjsuaCommunicator.hpp"
|
|
|
|
#include "MumbleCommunicator.hpp"
|
2015-11-09 00:51:51 +01:00
|
|
|
#include "IncomingConnectionValidator.hpp"
|
2015-11-30 23:24:41 +01:00
|
|
|
#include "MumbleChannelJoiner.hpp"
|
2015-10-17 22:27:37 +02:00
|
|
|
#include "Configuration.hpp"
|
2015-07-13 18:14:35 +02:00
|
|
|
|
2015-11-05 01:15:20 +01:00
|
|
|
#include <log4cpp/FileAppender.hh>
|
|
|
|
#include <log4cpp/OstreamAppender.hh>
|
2015-11-09 00:51:51 +01:00
|
|
|
#include <log4cpp/PatternLayout.hh>
|
2015-11-05 01:15:20 +01:00
|
|
|
|
2015-12-14 22:58:31 +01:00
|
|
|
#include <execinfo.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code from http://stackoverflow.com/a/77336/5419223
|
|
|
|
*/
|
|
|
|
static void sigsegv_handler(int sig) {
|
|
|
|
constexpr int STACK_DEPTH = 10;
|
|
|
|
void *array[STACK_DEPTH];
|
|
|
|
|
|
|
|
size_t size = backtrace(array, STACK_DEPTH);
|
|
|
|
|
|
|
|
fprintf(stderr, "ERROR: signal %d:\n", sig);
|
|
|
|
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-07-20 21:09:22 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2015-12-14 22:58:31 +01:00
|
|
|
signal(SIGSEGV, sigsegv_handler);
|
2015-07-20 21:09:22 +02:00
|
|
|
|
2016-01-20 21:47:44 +01:00
|
|
|
log4cpp::OstreamAppender appender("console", &std::cout);
|
2015-11-09 00:51:51 +01:00
|
|
|
log4cpp::PatternLayout layout;
|
|
|
|
layout.setConversionPattern("%d [%p] %c: %m%n");
|
2016-01-20 21:47:44 +01:00
|
|
|
appender.setLayout(&layout);
|
2015-09-29 02:26:45 +02:00
|
|
|
log4cpp::Category &logger = log4cpp::Category::getRoot();
|
2015-11-04 00:53:52 +01:00
|
|
|
logger.setPriority(log4cpp::Priority::NOTICE);
|
2016-01-20 21:47:44 +01:00
|
|
|
logger.addAppender(appender);
|
2015-07-20 21:09:22 +02:00
|
|
|
|
2015-10-17 22:27:37 +02:00
|
|
|
if (argc == 1) {
|
|
|
|
logger.crit("No configuration file provided. Use %s {config file}", argv[0]);
|
2016-01-20 21:47:44 +01:00
|
|
|
std::exit(1);
|
2015-10-17 22:27:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
config::Configuration conf(argv[1]);
|
2015-10-16 22:41:37 +02:00
|
|
|
|
2016-04-18 01:30:10 +02:00
|
|
|
logger.setPriority(log4cpp::Priority::getPriorityValue(conf.getString("general.logLevel")));
|
|
|
|
|
2015-11-09 00:51:51 +01:00
|
|
|
sip::IncomingConnectionValidator connectionValidator(conf.getString("sip.validUriExpression"));
|
|
|
|
|
2015-10-30 13:43:06 +01:00
|
|
|
boost::asio::io_service ioService;
|
|
|
|
|
2016-04-18 02:12:27 +02:00
|
|
|
sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator, conf.getInt("sip.frameLength"));
|
2015-07-13 18:14:35 +02:00
|
|
|
|
2015-11-03 02:13:15 +01:00
|
|
|
mumble::MumbleCommunicator mumbleCommunicator(ioService);
|
2015-07-20 21:09:22 +02:00
|
|
|
|
2015-11-30 23:24:41 +01:00
|
|
|
mumble::MumbleChannelJoiner mumbleChannelJoiner(conf.getString("mumble.channelNameExpression"));
|
|
|
|
|
2015-11-02 23:41:49 +01:00
|
|
|
using namespace std::placeholders;
|
2015-11-03 02:13:15 +01:00
|
|
|
pjsuaCommunicator.onIncomingPcmSamples = std::bind(
|
|
|
|
&mumble::MumbleCommunicator::sendPcmSamples,
|
2015-11-02 23:41:49 +01:00
|
|
|
&mumbleCommunicator,
|
|
|
|
_1, _2);
|
|
|
|
|
2015-11-04 00:53:52 +01:00
|
|
|
pjsuaCommunicator.onStateChange = std::bind(
|
|
|
|
&mumble::MumbleCommunicator::sendTextMessage,
|
|
|
|
&mumbleCommunicator, _1);
|
|
|
|
|
2015-11-03 02:13:15 +01:00
|
|
|
mumbleCommunicator.onIncomingPcmSamples = std::bind(
|
|
|
|
&sip::PjsuaCommunicator::sendPcmSamples,
|
|
|
|
&pjsuaCommunicator,
|
2015-11-18 00:17:25 +01:00
|
|
|
_1, _2, _3, _4);
|
2015-11-03 02:13:15 +01:00
|
|
|
|
2015-11-30 23:24:41 +01:00
|
|
|
mumbleCommunicator.onIncomingChannelState = std::bind(
|
2015-12-14 22:58:31 +01:00
|
|
|
&mumble::MumbleChannelJoiner::checkChannel,
|
|
|
|
&mumbleChannelJoiner,
|
|
|
|
_1, _2);
|
2015-11-30 23:24:41 +01:00
|
|
|
|
|
|
|
mumbleCommunicator.onServerSync = std::bind(
|
2015-12-14 22:58:31 +01:00
|
|
|
&mumble::MumbleChannelJoiner::maybeJoinChannel,
|
|
|
|
&mumbleChannelJoiner,
|
|
|
|
&mumbleCommunicator);
|
2015-11-30 23:24:41 +01:00
|
|
|
|
2016-04-18 01:22:36 +02:00
|
|
|
mumble::MumbleCommunicatorConfig mumbleConf;
|
|
|
|
mumbleConf.host = conf.getString("mumble.host");
|
|
|
|
mumbleConf.port = conf.getInt("mumble.port");
|
|
|
|
mumbleConf.user = conf.getString("mumble.user");
|
|
|
|
mumbleConf.password = conf.getString("mumble.password");
|
|
|
|
mumbleConf.opusEncoderBitrate = conf.getInt("mumble.opusEncoderBitrate");
|
|
|
|
|
|
|
|
mumbleCommunicator.connect(mumbleConf);
|
2015-11-03 02:13:15 +01:00
|
|
|
|
2015-11-02 23:41:49 +01:00
|
|
|
pjsuaCommunicator.connect(
|
|
|
|
conf.getString("sip.host"),
|
|
|
|
conf.getString("sip.user"),
|
|
|
|
conf.getString("sip.password"),
|
|
|
|
conf.getInt("sip.port"));
|
|
|
|
|
2015-09-29 02:26:45 +02:00
|
|
|
logger.info("Application started.");
|
2015-07-13 18:14:35 +02:00
|
|
|
|
2015-10-30 13:43:06 +01:00
|
|
|
ioService.run();
|
2015-10-16 22:41:37 +02:00
|
|
|
|
2015-07-20 21:09:22 +02:00
|
|
|
return 0;
|
2015-07-13 18:14:35 +02:00
|
|
|
}
|
|
|
|
|