ircDDBGateway/Common/CacheManager.h

183 lines
4 KiB
C
Raw Normal View History

2018-05-09 20:23:17 +02:00
/*
2020-11-15 20:57:49 +01:00
* Copyright (C) 2010,2011,2012,2020 by Jonathan Naylor G4KLX
2018-05-09 20:23:17 +02:00
*
* 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.
*/
#ifndef CacheManager_H
#define CacheManager_H
#include <wx/wx.h>
#if defined(__WINDOWS__)
#include "Inaddr.h"
#else
#include <netinet/in.h>
#endif
#include "RepeaterCache.h"
#include "GatewayCache.h"
#include "UserCache.h"
class CUserData {
public:
2020-11-15 20:57:49 +01:00
CUserData(const wxString& user, const wxString& repeater, const wxString& gateway, const sockaddr_storage& addr, unsigned int addrLen) :
2018-05-09 20:23:17 +02:00
m_user(user),
m_repeater(repeater),
m_gateway(gateway),
2020-11-15 20:57:49 +01:00
m_addr(addr),
m_addrLen(addrLen)
2018-05-09 20:23:17 +02:00
{
}
wxString getUser() const
{
return m_user;
}
wxString getRepeater() const
{
return m_repeater;
}
wxString getGateway() const
{
return m_gateway;
}
2020-11-15 20:57:49 +01:00
sockaddr_storage getAddr() const
2018-05-09 20:23:17 +02:00
{
2020-11-15 20:57:49 +01:00
return m_addr;
}
unsigned int getAddrLen() const
{
2020-11-15 21:40:09 +01:00
return m_addrLen;
2018-05-09 20:23:17 +02:00
}
private:
2020-11-15 20:57:49 +01:00
wxString m_user;
wxString m_repeater;
wxString m_gateway;
sockaddr_storage m_addr;
unsigned int m_addrLen;
2018-05-09 20:23:17 +02:00
};
class CRepeaterData {
public:
2020-11-15 20:57:49 +01:00
CRepeaterData(const wxString& repeater, const wxString& gateway, const sockaddr_storage& addr, unsigned int addrLen, DSTAR_PROTOCOL protocol) :
2018-05-09 20:23:17 +02:00
m_repeater(repeater),
m_gateway(gateway),
2020-11-15 20:57:49 +01:00
m_addr(addr),
m_addrLen(addrLen),
m_protocol(protocol)
2018-05-09 20:23:17 +02:00
{
}
wxString getRepeater() const
{
return m_repeater;
}
wxString getGateway() const
{
return m_gateway;
}
2020-11-15 20:57:49 +01:00
sockaddr_storage getAddr() const
2018-05-09 20:23:17 +02:00
{
2020-11-15 20:57:49 +01:00
return m_addr;
}
unsigned int getAddrLen() const
{
return m_addrLen;
2018-05-09 20:23:17 +02:00
}
DSTAR_PROTOCOL getProtocol() const
{
return m_protocol;
}
private:
2020-11-15 20:57:49 +01:00
wxString m_repeater;
wxString m_gateway;
sockaddr_storage m_addr;
unsigned int m_addrLen;
DSTAR_PROTOCOL m_protocol;
2018-05-09 20:23:17 +02:00
};
class CGatewayData {
public:
2020-11-15 20:57:49 +01:00
CGatewayData(const wxString& gateway, const sockaddr_storage& addr, unsigned int addrLen, DSTAR_PROTOCOL protocol) :
2018-05-09 20:23:17 +02:00
m_gateway(gateway),
2020-11-15 20:57:49 +01:00
m_addr(addr),
m_addrLen(addrLen),
m_protocol(protocol)
2018-05-09 20:23:17 +02:00
{
}
wxString getGateway() const
{
return m_gateway;
}
2020-11-15 20:57:49 +01:00
sockaddr_storage getAddr() const
{
return m_addr;
}
unsigned int getAddrLen() const
2018-05-09 20:23:17 +02:00
{
2020-11-15 20:57:49 +01:00
return m_addrLen;
2018-05-09 20:23:17 +02:00
}
DSTAR_PROTOCOL getProtocol() const
{
return m_protocol;
}
private:
2020-11-15 20:57:49 +01:00
wxString m_gateway;
sockaddr_storage m_addr;
unsigned int m_addrLen;
DSTAR_PROTOCOL m_protocol;
2018-05-09 20:23:17 +02:00
};
class CCacheManager {
public:
CCacheManager();
~CCacheManager();
CUserData* findUser(const wxString& user);
CGatewayData* findGateway(const wxString& gateway);
CRepeaterData* findRepeater(const wxString& repeater);
void updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, const wxString& timeStamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock);
2020-11-16 16:13:57 +01:00
2018-05-09 20:23:17 +02:00
void updateRepeater(const wxString& repeater, const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock);
2020-11-16 16:13:57 +01:00
void updateGateway(const wxString& gateway, const sockaddr_storage& addr, unsigned int addrLen, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock);
void updateGateway(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock);
2018-05-09 20:23:17 +02:00
private:
wxMutex m_mutex;
CUserCache m_userCache;
CGatewayCache m_gatewayCache;
CRepeaterCache m_repeaterCache;
};
#endif