-
Notifications
You must be signed in to change notification settings - Fork 16
/
manager.cpp
129 lines (107 loc) · 3 KB
/
manager.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
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
/*
* satip: session manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <string.h>
#include <list>
#include <string>
#include "manager.h"
#include "session.h"
#include "option.h"
#include "log.h"
const char* default_port = "554";
sessionManager::sessionManager()
{
DEBUG(MSG_MAIN,"Create resource manager.\n");
}
sessionManager::~sessionManager()
{
DEBUG(MSG_MAIN,"Destruct resource manager.\n");
if (m_sessions.size())
{
for (std::list<Session*>::iterator it = m_sessions.begin(); it != m_sessions.end(); ++it)
{
Session* session = *it;
delete session;
}
}
}
int sessionManager::satipStart()
{
if (m_satip_opt.isEmpty())
return -1;
std::map<int, vtunerOpt> *data = m_satip_opt.getData();
for (std::map<int, vtunerOpt>::iterator it(data->begin()); it!=data->end(); it++)
{
if (it->second.isAvailable())
{
DEBUG(MSG_MAIN, "try connect : [%d] type : %s, ip : %s, fe_type : %d\n", it->first, it->second.m_vtuner_type.c_str(), it->second.m_ipaddr.c_str(), it->second.m_fe_type);
satipSessionCreate(it->second.m_ipaddr.c_str(), it->second.m_fe_type, it->second.m_port.c_str(), &(it->second));
}
}
return 0;
}
int sessionManager::satipSessionCreate(const char* ipaddr, int fe_type, const char *port, vtunerOpt* settings)
{
int ok = 0;
Session* session;
session = new satipSession( ipaddr, (port[0] == 0) ? default_port: port , fe_type, settings, ok);
if (!ok)
{
DEBUG(MSG_MAIN, "Session init failed!\n");
delete session;
return -1;
}
addSession(session);
DEBUG(MSG_MAIN, "Create satip session ok (%s , %d)\n", ipaddr, fe_type);
session->start();
DEBUG(MSG_MAIN, "Satip session start (%s , %d)\n", ipaddr, fe_type);
return 0;
}
void sessionManager::sessionStart()
{
DEBUG(MSG_MAIN, "sessionManager::sessionStart, %d\n", m_sessions.size());
if (m_sessions.size())
{
for (std::list<Session*>::iterator it = m_sessions.begin(); it != m_sessions.end(); ++it)
{
Session* session = *it;
session->start();
}
}
}
void sessionManager::sessionJoin()
{
if (m_sessions.size())
{
for (std::list<Session*>::iterator it = m_sessions.begin(); it != m_sessions.end(); ++it)
{
Session* session = *it;
session->join();
}
}
}
void sessionManager::sessionStop()
{
if (m_sessions.size())
{
for (std::list<Session*>::iterator it = m_sessions.begin(); it != m_sessions.end(); ++it)
{
Session* session = *it;
session->stop();
}
}
}