-
Notifications
You must be signed in to change notification settings - Fork 1
/
GroupHandler.h
201 lines (161 loc) · 5.64 KB
/
GroupHandler.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Copyright (C) 2011-2014 by Jonathan Naylor G4KLX
* Copyright (c) 2017,2018 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.
*/
#pragma once
#include <netinet/in.h>
#include <string>
#include <map>
#include <list>
#include <set>
#include "RemoteGroup.h"
#include "G2ProtocolHandler.h"
#include "ReflectorCallback.h" // DEXTRA_LINK || DCS_LINK
#include "RepeaterCallback.h"
#include "TextCollector.h"
#include "CacheManager.h"
#include "DStarDefines.h"
#include "HeaderData.h"
#include "AMBEData.h"
#include "IRCDDB.h"
#include "Timer.h"
#include "AudioUnit.h"
enum LOGUSER {
LU_ON,
LU_OFF
};
class CSGSXLUser {
public:
CSGSXLUser(const std::string& callsign, unsigned int timeout);
~CSGSXLUser();
void reset();
bool clock(unsigned int ms);
bool hasExpired();
std::string getCallsign() const;
CTimer getTimer() const;
private:
std::string m_callsign;
CTimer m_timer;
};
class CSGSXLId {
public:
CSGSXLId(unsigned int id, unsigned int timeout, CSGSXLUser* user);
~CSGSXLId();
unsigned int getId() const;
void reset();
void setLogin();
void setInfo();
void setLogoff();
void setEnd();
bool clock(unsigned int ms);
bool hasExpired();
bool isLogin() const;
bool isInfo() const;
bool isLogoff() const;
bool isEnd() const;
CSGSXLUser* getUser() const;
CTextCollector& getTextCollector();
private:
unsigned int m_id;
CTimer m_timer;
bool m_login;
bool m_info;
bool m_logoff;
bool m_end;
CSGSXLUser *m_user;
CTextCollector m_textCollector;
};
class CSGSRepeater {
public:
std::string m_destination;
std::string m_repeater;
std::string m_gateway;
in_addr m_address;
};
class CGroupHandler : public IReflectorCallback, IRepeaterCallback
{
public:
static void add(const std::string &callsign, const std::string &logoff, const std::string &repeater, const std::string &infoText, const std::string &permanent,
unsigned int userTimeout, CALLSIGN_SWITCH callsignSwitch, bool txMsgSwitch, const std::string & eflector);
static void setG2Handler(CG2ProtocolHandler *handler);
static void setIRC(CIRCDDB *irc);
static void setCache(CCacheManager *cache);
static void setGateway(const std::string &gateway);
static void link();
static std::list<std::string> listGroups();
static CGroupHandler *findGroup(const std::string &callsign);
static CGroupHandler *findGroup(const CHeaderData &header);
static CGroupHandler *findGroup(const CAMBEData &data);
static void findGroupsByLogoff(const CHeaderData &header, std::list<CGroupHandler*> & groups);
static void finalise();
static void clock(unsigned int ms);
void process(CHeaderData &header);
void process(CAMBEData &data);
bool remoteLink(const std::string &reflector);
void updateReflectorInfo();
DSTAR_LINKTYPE getLinkType();
void setLinkType(DSTAR_LINKTYPE linkType);
void clearReflector();
CRemoteGroup *getInfo() const;
bool logoff(const std::string& callsign);
virtual bool process(CHeaderData &header, DIRECTION direction, AUDIO_SOURCE source);
virtual bool process(CAMBEData &data, DIRECTION direction, AUDIO_SOURCE source);
virtual void linkUp(DSTAR_PROTOCOL protocol, const std::string &callsign);
virtual void linkRefused(DSTAR_PROTOCOL protocol, const std::string &callsign);
virtual bool linkFailed(DSTAR_PROTOCOL protocol, const std::string &callsign, bool isRecoverable);
virtual bool singleHeader();
protected:
CGroupHandler(const std::string &callsign, const std::string &logoff, const std::string &repeater, const std::string &infoText, const std::string &permanent,
unsigned int userTimeout, CALLSIGN_SWITCH callsignSwitch, bool txMsgSwitch, const std::string &reflector);
virtual ~CGroupHandler();
bool linkInt();
void clockInt(unsigned int ms);
private:
static std::list<CGroupHandler *> m_Groups;
static CG2ProtocolHandler *m_g2Handler;
static CIRCDDB *m_irc;
static CCacheManager *m_cache;
static std::string m_gateway;
static std::string m_name;
// Group info
std::string m_groupCallsign;
std::string m_offCallsign;
std::string m_shortCallsign;
std::string m_repeater;
std::string m_infoText;
std::set<std::string> m_permanent;
std::string m_linkReflector;
std::string m_linkGateway;
LINK_STATUS m_linkStatus;
LINK_STATUS m_oldlinkStatus;
CTimer m_linkTimer;
DSTAR_LINKTYPE m_linkType;
CAudioUnit *m_audioUnit;
unsigned int m_id;
CTimer m_announceTimer;
unsigned int m_userTimeout;
CALLSIGN_SWITCH m_callsignSwitch;
bool m_txMsgSwitch;
std::map<unsigned int, CSGSXLId *> m_ids;
std::map<std::string, CSGSXLUser *> m_users;
std::map<std::string, CSGSRepeater *> m_repeaters;
void sendFromText(const std::string &text) const;
void sendToRepeaters(CHeaderData &header) const;
void sendToRepeaters(CAMBEData &data) const;
void sendAck(const CUserData &user, ACK_TYPE ackType);
void logUser(LOGUSER lu, const std::string channel, const std::string user);
};