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 *.o
src/xlxd *.d
ambed/ambed .vscode
ambedtest/ambedtest xlxd
xrfd
ambed
main.h

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

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

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 01/11/2015. // Created by Jean-Luc Deltombe (LX3JL) on 01/11/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
// //
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// This file is part of xlxd. // This file is part of xlxd.
@ -395,21 +396,20 @@ void CDextraProtocol::HandlePeerLinks(void)
// check if all ours peers listed by gatekeeper are connected // check if all ours peers listed by gatekeeper are connected
// if not, connect or reconnect // 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 ( !(*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
if ( !item->GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue; continue;
if ( strlen(item->GetModules()) != 2 ) if ( strlen((*it).GetModules()) != 2 )
continue; 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 // resolve again peer's IP in case it's a dynamic IP
item->ResolveIp(); (*it).ResolveIp();
// send connect packet to re-initiate peer link // send connect packet to re-initiate peer link
EncodeConnectPacket(&buffer, item->GetModules()); EncodeConnectPacket(&buffer, (*it).GetModules());
m_Socket.Send(buffer, item->GetIp(), DEXTRA_PORT); m_Socket.Send(buffer, (*it).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; 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; return true;
} }

@ -42,7 +42,7 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
Lock(); Lock();
// empty list // empty list
clear(); m_Callsigns.clear();
// fill with file content // fill with file content
while ( file.getline(sz, sizeof(sz)).good() ) while ( file.getline(sz, sizeof(sz)).good() )
{ {
@ -64,7 +64,7 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
if ( (szt = ::strtok(NULL, " ,\t")) != NULL ) if ( (szt = ::strtok(NULL, " ,\t")) != NULL )
{ {
// and load // 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 // and done
Unlock(); Unlock();
ok = true; 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 else
{ {
@ -91,5 +91,3 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
return ok; return ok;
} }

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

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 28/01/2016. // Created by Jean-Luc Deltombe (LX3JL) on 28/01/2016.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
// //
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// This file is part of xlxd. // This file is part of xlxd.
@ -381,19 +382,18 @@ void CXlxProtocol::HandlePeerLinks(void)
// check if all ours peers listed by gatekeeper are connected // check if all ours peers listed by gatekeeper are connected
// if not, connect or reconnect // 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 ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
if ( item->GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue; 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 // resolve again peer's IP in case it's a dynamic IP
item->ResolveIp(); (*it).ResolveIp();
// send connect packet to re-initiate peer link // send connect packet to re-initiate peer link
EncodeConnectPacket(&buffer, item->GetModules()); EncodeConnectPacket(&buffer, (*it).GetModules());
m_Socket.Send(buffer, item->GetIp(), XLX_PORT); m_Socket.Send(buffer, (*it).GetIp(), XLX_PORT);
std::cout << "Sending connect packet to XLX peer " << item->GetCallsign() << " @ " << item->GetIp() << " for modules " << item->GetModules() << std::endl; 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 // done
return peer; return peer;
} }

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

Loading…
Cancel
Save

Powered by TurnKey Linux.