-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.cpp
103 lines (76 loc) · 3.19 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "PjsuaCommunicator.hpp"
#include "MumbleCommunicator.hpp"
#include "IncomingConnectionValidator.hpp"
#include "MumbleChannelJoiner.hpp"
#include "Configuration.hpp"
#include <log4cpp/FileAppender.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/PatternLayout.hh>
#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);
}
int main(int argc, char *argv[]) {
signal(SIGSEGV, sigsegv_handler);
log4cpp::OstreamAppender appender("console", &std::cout);
log4cpp::PatternLayout layout;
layout.setConversionPattern("%d [%p] %c: %m%n");
appender.setLayout(&layout);
log4cpp::Category &logger = log4cpp::Category::getRoot();
logger.setPriority(log4cpp::Priority::NOTICE);
logger.addAppender(appender);
if (argc == 1) {
logger.crit("No configuration file provided. Use %s {config file}", argv[0]);
std::exit(1);
}
config::Configuration conf(argv[1]);
logger.setPriority(log4cpp::Priority::getPriorityValue(conf.getString("general.logLevel")));
sip::IncomingConnectionValidator connectionValidator(conf.getString("sip.validUriExpression"));
boost::asio::io_service ioService;
sip::PjsuaCommunicator pjsuaCommunicator(connectionValidator, conf.getInt("sip.frameLength"));
mumble::MumbleCommunicator mumbleCommunicator(ioService);
mumble::MumbleChannelJoiner mumbleChannelJoiner(conf.getString("mumble.channelNameExpression"));
using namespace std::placeholders;
pjsuaCommunicator.onIncomingPcmSamples = std::bind(
&mumble::MumbleCommunicator::sendPcmSamples,
&mumbleCommunicator,
_1, _2);
pjsuaCommunicator.onStateChange = std::bind(
&mumble::MumbleCommunicator::sendTextMessage,
&mumbleCommunicator, _1);
mumbleCommunicator.onIncomingPcmSamples = std::bind(
&sip::PjsuaCommunicator::sendPcmSamples,
&pjsuaCommunicator,
_1, _2, _3, _4);
mumbleCommunicator.onIncomingChannelState = std::bind(
&mumble::MumbleChannelJoiner::checkChannel,
&mumbleChannelJoiner,
_1, _2);
mumbleCommunicator.onServerSync = std::bind(
&mumble::MumbleChannelJoiner::maybeJoinChannel,
&mumbleChannelJoiner,
&mumbleCommunicator);
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);
pjsuaCommunicator.connect(
conf.getString("sip.host"),
conf.getString("sip.user"),
conf.getString("sip.password"),
conf.getInt("sip.port"));
logger.info("Application started.");
ioService.run();
return 0;
}