CCallsignList is a std::list

pull/1/head
Tom Early 6 years ago
parent cadad0aeef
commit b7a77491a4

9
.gitignore vendored

@ -1,4 +1,7 @@
*.o
src/xlxd
ambed/ambed
ambedtest/ambedtest
*.d
.vscode
xlxd
xrfd
ambed
main.h

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 30/12/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -53,7 +54,7 @@ bool CCallsignList::LoadFromFile(const char *filename)
Lock();
// empty list
clear();
m_Callsigns.clear();
// fill with file content
while ( file.getline(sz, sizeof(sz)).good() )
{
@ -75,7 +76,7 @@ bool CCallsignList::LoadFromFile(const char *filename)
szt = szStar;
}
// and add to list
push_back(CCallsignListItem(callsign, CIp(), szt));
m_Callsigns.push_back(CCallsignListItem(callsign, CIp(), szt));
}
}
}
@ -91,7 +92,7 @@ bool CCallsignList::LoadFromFile(const char *filename)
// and done
Unlock();
ok = true;
std::cout << "Gatekeeper loaded " << size() << " lines from " << filename << std::endl;
std::cout << "Gatekeeper loaded " << m_Callsigns.size() << " lines from " << filename << std::endl;
}
else
{
@ -129,57 +130,46 @@ bool CCallsignList::NeedReload(void)
bool CCallsignList::IsCallsignListedWithWildcard(const CCallsign &callsign) const
{
bool listed = false;
for ( int i = 0; (i < size()) && !listed; i++ )
for ( const auto &item : m_Callsigns )
{
listed = (data()[i]).HasSameCallsignWithWildcard(callsign);
if (item.HasSameCallsignWithWildcard(callsign))
return true;
}
return listed;
return false;
}
bool CCallsignList::IsCallsignListedWithWildcard(const CCallsign &callsign, char module) const
{
bool listed = false;
for ( int i = 0; (i < size()) && !listed; i++ )
for ( const auto &item : m_Callsigns )
{
const CCallsignListItem *item = &(data()[i]);
listed = (item->HasSameCallsignWithWildcard(callsign) &&
((module == ' ') || item->HasModuleListed(module)) );
if (item.HasSameCallsignWithWildcard(callsign) && ((module == ' ') || item.HasModuleListed(module)) )
return true;
}
return listed;
return false;
}
bool CCallsignList::IsCallsignListed(const CCallsign &callsign, char module) const
{
bool listed = false;
for ( int i = 0; (i < size()) && !listed; i++ )
for ( const auto &item : m_Callsigns )
{
const CCallsignListItem *item = &(data()[i]);
listed = (item->HasSameCallsign(callsign) && item->HasModuleListed(module));
if (item.HasSameCallsign(callsign) && item.HasModuleListed(module))
return true;
}
return listed;
return false;
}
bool CCallsignList::IsCallsignListed(const CCallsign &callsign, char *modules) const
{
bool listed = false;
for ( int i = 0; (i < size()) && !listed; i++ )
for ( const auto &item : m_Callsigns )
{
const CCallsignListItem *item = &(data()[i]);
listed = (item->HasSameCallsign(callsign) && item->CheckListedModules(modules));
if (item.HasSameCallsign(callsign) && item.CheckListedModules(modules))
return true;
}
return listed;
return false;
}
////////////////////////////////////////////////////////////////////////////////////////
@ -187,19 +177,15 @@ bool CCallsignList::IsCallsignListed(const CCallsign &callsign, char *modules) c
CCallsignListItem *CCallsignList::FindListItem(const CCallsign &Callsign)
{
CCallsignListItem *item = NULL;
// find client
for ( int i = 0; (i < size()) && (item == NULL); i++ )
for ( auto &item : m_Callsigns )
{
if ( (data()[i]).GetCallsign().HasSameCallsign(Callsign) )
if ( item.GetCallsign().HasSameCallsign(Callsign) )
{
item = &(data()[i]);
return &item;
}
}
// done
return item;
return NULL;
}

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 30/12/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -32,7 +33,7 @@
////////////////////////////////////////////////////////////////////////////////////////
// class
class CCallsignList : public std::vector<CCallsignListItem>
class CCallsignList
{
public:
// constructor
@ -56,19 +57,23 @@ public:
bool IsCallsignListed(const CCallsign &, char) const;
bool IsCallsignListed(const CCallsign &, char*) const;
// pass-thru
bool empty() const { return m_Callsigns.empty(); }
std::list<CCallsignListItem>::iterator begin() { return m_Callsigns.begin(); }
std::list<CCallsignListItem>::iterator end() { return m_Callsigns.end(); }
// find
CCallsignListItem *FindListItem(const CCallsign &);
protected:
//
bool GetLastModTime(time_t *);
char *TrimWhiteSpaces(char *);
protected:
// data
std::mutex m_Mutex;
const char * m_Filename;
time_t m_LastModTime;
std::list<CCallsignListItem> m_Callsigns;
};

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 01/11/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -395,21 +396,20 @@ void CDextraProtocol::HandlePeerLinks(void)
// check if all ours peers listed by gatekeeper are connected
// if not, connect or reconnect
for ( int i = 0; i < list->size(); i++ )
for ( auto it=list->begin(); it!=list->end(); it++ )
{
CCallsignListItem *item = &((list->data())[i]);
if ( !item->GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
if ( !(*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue;
if ( strlen(item->GetModules()) != 2 )
if ( strlen((*it).GetModules()) != 2 )
continue;
if ( peers->FindPeer(item->GetCallsign(), PROTOCOL_DEXTRA) == NULL )
if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_DEXTRA) == NULL )
{
// resolve again peer's IP in case it's a dynamic IP
item->ResolveIp();
(*it).ResolveIp();
// send connect packet to re-initiate peer link
EncodeConnectPacket(&buffer, item->GetModules());
m_Socket.Send(buffer, item->GetIp(), DEXTRA_PORT);
std::cout << "Sending connect packet to XRF peer " << item->GetCallsign() << " @ " << item->GetIp() << " for module " << item->GetModules()[1] << " (module " << item->GetModules()[0] << ")" << std::endl;
EncodeConnectPacket(&buffer, (*it).GetModules());
m_Socket.Send(buffer, (*it).GetIp(), DEXTRA_PORT);
std::cout << "Sending connect packet to XRF peer " << (*it).GetCallsign() << " @ " << (*it).GetIp() << " for module " << (*it).GetModules()[1] << " (module " << (*it).GetModules()[0] << ")" << std::endl;
}
}
@ -697,4 +697,3 @@ bool CDextraProtocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet,
return true;
}

@ -42,7 +42,7 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
Lock();
// empty list
clear();
m_Callsigns.clear();
// fill with file content
while ( file.getline(sz, sizeof(sz)).good() )
{
@ -64,7 +64,7 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
if ( (szt = ::strtok(NULL, " ,\t")) != NULL )
{
// and load
push_back(CCallsignListItem(callsign, szip, szt));
m_Callsigns.push_back(CCallsignListItem(callsign, szip, szt));
}
}
}
@ -82,7 +82,7 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
// and done
Unlock();
ok = true;
std::cout << "Gatekeeper loaded " << size() << " lines from " << filename << std::endl;
std::cout << "Gatekeeper loaded " << m_Callsigns.size() << " lines from " << filename << std::endl;
}
else
{
@ -91,5 +91,3 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
return ok;
}

@ -37,10 +37,10 @@ class CPeerCallsignList : public CCallsignList
{
public:
// constructor
CPeerCallsignList() {};
CPeerCallsignList() {}
// destructor
virtual ~CPeerCallsignList() {};
virtual ~CPeerCallsignList() {}
// file io
bool LoadFromFile(const char *);

@ -4,6 +4,7 @@
//
// Created by Jean-Luc Deltombe (LX3JL) on 28/01/2016.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of xlxd.
@ -381,19 +382,18 @@ void CXlxProtocol::HandlePeerLinks(void)
// check if all ours peers listed by gatekeeper are connected
// if not, connect or reconnect
for ( int i = 0; i < list->size(); i++ )
for ( auto it=list->begin(); it!=list->end(); it++ )
{
CCallsignListItem *item = &((list->data())[i]);
if ( item->GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue;
if ( peers->FindPeer(item->GetCallsign(), PROTOCOL_XLX) == NULL )
if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_XLX) == NULL )
{
// resolve again peer's IP in case it's a dynamic IP
item->ResolveIp();
(*it).ResolveIp();
// send connect packet to re-initiate peer link
EncodeConnectPacket(&buffer, item->GetModules());
m_Socket.Send(buffer, item->GetIp(), XLX_PORT);
std::cout << "Sending connect packet to XLX peer " << item->GetCallsign() << " @ " << item->GetIp() << " for modules " << item->GetModules() << std::endl;
EncodeConnectPacket(&buffer, (*it).GetModules());
m_Socket.Send(buffer, (*it).GetIp(), XLX_PORT);
std::cout << "Sending connect packet to XLX peer " << (*it).GetCallsign() << " @ " << (*it).GetIp() << " for modules " << (*it).GetModules() << std::endl;
}
}
@ -765,4 +765,3 @@ CPeer *CXlxProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, cha
// done
return peer;
}

@ -27,6 +27,7 @@
#include <vector>
#include <array>
#include <list>
#include <map>
#include <queue>
#include <chrono>
@ -54,17 +55,21 @@
// global ------------------------------------------------------
#define RUN_AS_DAEMON
#define JSON_MONITOR
//#define JSON_MONITOR
// debug -------------------------------------------------------
//#define DEBUG_NO_ERROR_ON_XML_OPEN_FAIL
//#define DEBUG_DUMPFILE
// system constants ---------------------------------------------
#define NB_MODULES_MAX 26
// reflector ---------------------------------------------------
#define NB_OF_MODULES 10
//#define NB_OF_MODULES NB_MODULES_MAX
//#define NB_OF_MODULES 10
#define NB_OF_MODULES NB_MODULES_MAX
// protocols ---------------------------------------------------
@ -176,10 +181,6 @@
#define TERMINALOPTIONS_PATH "/xlxd/xlxd.terminal"
#define DEBUGDUMP_PATH "/var/log/xlxd.debug"
// system constants ---------------------------------------------
#define NB_MODULES_MAX 26
////////////////////////////////////////////////////////////////////////////////////////
// typedefs

Loading…
Cancel
Save

Powered by TurnKey Linux.