forked from BarGabriel/SipServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (43 loc) · 1.23 KB
/
main.cpp
File metadata and controls
51 lines (43 loc) · 1.23 KB
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
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include "SipServer.hpp"
#include "cxxopts.hpp"
void signal_handler(int s){
printf("Caught signal %d\n",s);
exit(1);
}
int main(int argc, char** argv)
{
cxxopts::Options options("SipServer", "Open source server for handling voip calls based on sip.");
options.add_options()
("h,help", "Print usage")
("i,ip", "Sip server ip", cxxopts::value<std::string>())
("p,port", "Sip server ip.", cxxopts::value<int>()->default_value(std::to_string(5060)));
auto result = options.parse(argc, argv);
if (result.count("help"))
{
std::cout << options.help() << std::endl;
exit(0);
}
// Register signal and signal handler
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = signal_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
try
{
std::string ip = result["ip"].as<std::string>();
int port = result["port"].as<int>();
SipServer server(std::move(ip), port);
std::cout << "Server has been started. Listening..." << std::endl;
pause();
}
catch (const cxxopts::OptionException&)
{
std::cout << "Please enter ip and port." << std::endl;
}
return 0;
}