-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSipLoadBalancer.cpp
More file actions
137 lines (113 loc) · 3.76 KB
/
SipLoadBalancer.cpp
File metadata and controls
137 lines (113 loc) · 3.76 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (C) 2012 Yee Young Han <websearch@naver.com> (http://blog.naver.com/websearch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "SipServer.h"
#include "SipServerMap.h"
#include "SipServerSetup.h"
#include "SipLoadBalancer.h"
#include "SipLoadBalancerVersion.h"
#include "ServerUtility.h"
#include "Log.h"
#include "ServerService.h"
#include "Monitor.h"
#include "MemoryDebug.h"
/**
* @ingroup SipLoadBalancer
* @brief C++ SIP stack 을 이용한 한국형 IP-PBX
* @returns 정상 종료하면 0 을 리턴하고 오류가 발생하면 -1 를 리턴한다.
*/
int ServiceMain( )
{
if( gclsSetup.Read( GetConfigFileName() ) == false )
{
printf( "config filename(%s) read error\n", GetConfigFileName() );
return -1;
}
CLog::SetDirectory( gclsSetup.m_strLogFolder.c_str() );
CLog::Print( LOG_SYSTEM, "SipLoadBalancer is started ( version-%s %s %s )", SIP_LOAD_BALANCER_VERSION, __DATE__, __TIME__ );
CSipStackSetup clsSetup;
if( gclsSetup.m_strLocalIp.empty() )
{
// N개의 IP주소를 사용하는 호스트에서는 SIP 프로토콜로 사용할 IP주소를 직접 입력해 주세요.
// Vmware 등을 사용하는 경우 N개의 IP주소가 호스트에 존재합니다.
GetLocalIp( clsSetup.m_strLocalIp );
gclsSetup.m_strLocalIp = clsSetup.m_strLocalIp;
}
else
{
clsSetup.m_strLocalIp = gclsSetup.m_strLocalIp;
}
clsSetup.m_iLocalUdpPort = gclsSetup.m_iUdpPort;
clsSetup.m_iUdpThreadCount = gclsSetup.m_iUdpThreadCount;
clsSetup.m_iLocalTcpPort = gclsSetup.m_iTcpPort;
clsSetup.m_iTcpThreadCount = gclsSetup.m_iTcpThreadCount;
clsSetup.m_iLocalTlsPort = gclsSetup.m_iTlsPort;
clsSetup.m_iTlsAcceptTimeout = gclsSetup.m_iTlsAcceptTimeout;
clsSetup.m_strCertFile = gclsSetup.m_strCertFile;
clsSetup.m_strUserAgent = "SipLoadBalancer_";
clsSetup.m_strUserAgent.append( SIP_LOAD_BALANCER_VERSION );
Fork( true );
SetCoreDumpEnable();
ServerSignal();
if( gclsSipServer.Start( clsSetup ) == false )
{
CLog::Print( LOG_ERROR, "SipServer start error\n" );
return -1;
}
if( gclsSetup.m_iMonitorPort > 0 )
{
gclsMonitor.m_iMonitorPort = gclsSetup.m_iMonitorPort;
StartMonitorServerThread( &gclsMonitor );
}
int iSecond = 0;
while( gbStop == false )
{
sleep(1);
++iSecond;
if( iSecond == 3600 )
{
iSecond = 0;
}
if( gclsSetup.IsChange() )
{
gclsSetup.Read();
}
}
gclsSipStack.Final();
CLog::Print( LOG_SYSTEM, "SipLoadBalancer is terminated" );
CLog::Release();
return 0;
}
/**
* @ingroup SipLoadBalancer
* @brief C++ SIP stack 을 이용한 SIP 로드밸런서
* @param argc
* @param argv
* @returns 정상 종료하면 0 을 리턴하고 오류가 발생하면 -1 를 리턴한다.
*/
int main( int argc, char * argv[] )
{
CServerService clsService;
clsService.m_strName = SERVICE_NAME;
clsService.m_strDisplayName = SERVICE_DISPLAY_NAME;
clsService.m_strDescription = SERVICE_DESCRIPTION_STRING;
clsService.m_strConfigFileName = CONFIG_FILENAME;
clsService.m_strVersion = SIP_LOAD_BALANCER_VERSION;
clsService.SetBuildDate( __DATE__, __TIME__ );
ServerMain( argc, argv, clsService, ServiceMain );
return 0;
}