-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathG2Handler.cpp
134 lines (112 loc) · 3.08 KB
/
G2Handler.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
128
129
130
131
132
133
134
/*
* Copyright (C) 2010-2014 by Jonathan Naylor G4KLX
* Copyright (c) 2017 by Thomas A. Early N7TAE
*
* 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <cassert>
#include "GroupHandler.h"
#include "G2Handler.h"
#include "Utils.h"
#include "Defs.h"
unsigned int CG2Handler::m_maxRoutes = 0U;
CG2Handler** CG2Handler::m_routes = NULL;
CG2ProtocolHandler* CG2Handler::m_handler = NULL;
CG2Handler::CG2Handler(const in_addr& address, unsigned int id) :
m_address(address),
m_id(id),
m_inactivityTimer(1000U, NETWORK_TIMEOUT)
{
m_inactivityTimer.start();
}
CG2Handler::~CG2Handler()
{
}
void CG2Handler::initialise(unsigned int maxRoutes)
{
m_maxRoutes = maxRoutes;
if (maxRoutes == 0U)
return;
m_routes = new CG2Handler*[m_maxRoutes];
for (unsigned int i = 0U; i < m_maxRoutes; i++)
m_routes[i] = NULL;
}
void CG2Handler::setG2ProtocolHandler(CG2ProtocolHandler* handler)
{
assert(handler != NULL);
m_handler = handler;
}
void CG2Handler::process(CHeaderData& header)
{
// Is this a busy reply?
unsigned char flag1 = header.getFlag1();
if (flag1 == 0x01) {
// Don't check the incoming stream
// printf("G2 busy message received\n"));
return;
}
std::list<CGroupHandler*> groups;
// Check to see if this is for Smart Group
CGroupHandler* group = CGroupHandler::findGroup(header);//look first for login group
if(group != NULL) {
groups.push_back(group);
}
else {
CGroupHandler::findGroupsByLogoff(header, groups);//get all groups having a matching logoff
}
for(auto it = groups.begin();it != groups.end(); it++)
{
if ((*it) != NULL) {
(*it)->process(header);
}
}
}
void CG2Handler::process(CAMBEData& data)
{
// Check to see if this is for Smart Group
CGroupHandler* handler = CGroupHandler::findGroup(data);
if (handler != NULL) {
handler->process(data);
return;
}
}
void CG2Handler::clock(unsigned int ms)
{
for (unsigned int i = 0U; i < m_maxRoutes; i++) {
CG2Handler* route = m_routes[i];
if (route != NULL) {
bool ret = route->clockInt(ms);
if (ret) {
delete route;
m_routes[i] = NULL;
}
}
}
}
void CG2Handler::finalise()
{
for (unsigned int i = 0U; i < m_maxRoutes; i++)
delete m_routes[i];
delete[] m_routes;
}
bool CG2Handler::clockInt(unsigned int ms)
{
m_inactivityTimer.clock(ms);
if (m_inactivityTimer.isRunning() && m_inactivityTimer.hasExpired()) {
printf("Inactivity timeout for a G2 route has expired\n");
return true;
}
return false;
}