CClients::m_Clients is a list

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

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015. // Created by Jean-Luc Deltombe (LX3JL) on 31/10/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.
@ -33,7 +34,6 @@
CClients::CClients() CClients::CClients()
{ {
m_Clients.reserve(100);
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@ -42,14 +42,11 @@ CClients::CClients()
CClients::~CClients() CClients::~CClients()
{ {
m_Mutex.lock(); m_Mutex.lock();
for ( auto it=begin(); it!=end(); it++ )
{ {
for ( int i = 0; i < m_Clients.size(); i++ ) delete *it;
{
delete m_Clients[i];
} }
m_Clients.clear(); m_Clients.clear();
}
m_Mutex.unlock(); m_Mutex.unlock();
} }
@ -59,29 +56,19 @@ CClients::~CClients()
void CClients::AddClient(CClient *client) void CClients::AddClient(CClient *client)
{ {
// first check if client already exists // first check if client already exists
bool found = false; for ( auto it=begin(); it!=end(); it++ )
for ( int i = 0; (i < m_Clients.size()) && !found; i++ )
{ {
found = (*client == *m_Clients[i]); if (*client == *(*it))
// if found, just do nothing // if found, just do nothing
// so *client keep pointing on a valid object // so *client keep pointing on a valid object
// on function return // on function return
if ( found )
{ {
// delete new one // delete new one
delete client; delete client;
//std::cout << "Adding existing client " << client->GetCallsign() << " at " << client->GetIp() << std::endl; return;
} }
} }
// if not, append to the vector
if ( !found )
{
// grow vector capacity if needed
if ( m_Clients.capacity() == m_Clients.size() )
{
m_Clients.reserve(m_Clients.capacity()+10);
}
// and append // and append
m_Clients.push_back(client); m_Clients.push_back(client);
std::cout << "New client " << client->GetCallsign() << " at " << client->GetIp() std::cout << "New client " << client->GetCallsign() << " at " << client->GetIp()
@ -94,58 +81,44 @@ void CClients::AddClient(CClient *client)
// notify // notify
g_Reflector.OnClientsChanged(); g_Reflector.OnClientsChanged();
} }
}
void CClients::RemoveClient(CClient *client) void CClients::RemoveClient(CClient *client)
{ {
// look for the client // look for the client
bool found = false; bool found = false;
for ( int i = 0; (i < m_Clients.size()) && !found; i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
// compare objetc pointers // compare objetc pointers
if ( (m_Clients[i]) == client ) if ( *it == client )
{ {
// found it ! // found it !
if ( !m_Clients[i]->IsAMaster() ) if ( !(*it)->IsAMaster() )
{ {
// remove it // remove it
std::cout << "Client " << m_Clients[i]->GetCallsign() << " at " << m_Clients[i]->GetIp() std::cout << "Client " << (*it)->GetCallsign() << " at " << (*it)->GetIp() << " removed with protocol " << (*it)->GetProtocolName();
<< " removed with protocol " << client->GetProtocolName(); if ( (*it)->GetReflectorModule() != ' ' )
if ( client->GetReflectorModule() != ' ' )
{ {
std::cout << " on module " << client->GetReflectorModule(); std::cout << " on module " << (*it)->GetReflectorModule();
} }
std::cout << std::endl; std::cout << std::endl;
delete m_Clients[i]; delete *it;
m_Clients.erase(m_Clients.begin()+i); m_Clients.erase(it);
found = true;
// notify // notify
g_Reflector.OnClientsChanged(); g_Reflector.OnClientsChanged();
break;
} }
} }
} }
} }
CClient *CClients::GetClient(int i)
{
if ( (i >= 0) && (i < m_Clients.size()) )
{
return m_Clients[i];
}
else
{
return NULL;
}
}
bool CClients::IsClient(CClient *client) const bool CClients::IsClient(CClient *client) const
{ {
bool found = false; for ( auto it=cbegin(); it!=cend(); it++ )
for ( int i = 0; (i < m_Clients.size()) && !found; i++ )
{ {
found = (m_Clients[i] == client); if (*it == client)
return true;
} }
return found; return false;
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@ -153,171 +126,140 @@ bool CClients::IsClient(CClient *client) const
CClient *CClients::FindClient(const CIp &Ip) CClient *CClients::FindClient(const CIp &Ip)
{ {
CClient *client = NULL;
// find client // find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
if ( m_Clients[i]->GetIp() == Ip ) if ( (*it)->GetIp() == Ip )
{ {
client = m_Clients[i]; return *it;
} }
} }
// done // done
return client; return NULL;
} }
CClient *CClients::FindClient(const CIp &Ip, int Protocol) CClient *CClients::FindClient(const CIp &Ip, int Protocol)
{ {
CClient *client = NULL;
// find client // find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
if ( (m_Clients[i]->GetIp() == Ip) && (m_Clients[i]->GetProtocol() == Protocol)) if ( ((*it)->GetIp() == Ip) && ((*it)->GetProtocol() == Protocol))
{ {
client = m_Clients[i]; return *it;
} }
} }
// done // done
return client; return NULL;
} }
CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule)
{ {
CClient *client = NULL;
// find client // find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
if ( (m_Clients[i]->GetIp() == Ip) && if ( ((*it)->GetIp() == Ip) &&
(m_Clients[i]->GetReflectorModule() == ReflectorModule) && ((*it)->GetReflectorModule() == ReflectorModule) &&
(m_Clients[i]->GetProtocol() == Protocol) ) ((*it)->GetProtocol() == Protocol) )
{ {
client = m_Clients[i]; return *it;
} }
} }
// done // done
return client; return NULL;
} }
CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol) CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol)
{ {
CClient *client = NULL;
// find client // find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
if ( m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) && if ( (*it)->GetCallsign().HasSameCallsign(Callsign) &&
(m_Clients[i]->GetIp() == Ip) && ((*it)->GetIp() == Ip) &&
(m_Clients[i]->GetProtocol() == Protocol) ) ((*it)->GetProtocol() == Protocol) )
{ {
client = m_Clients[i]; return *it;
} }
} }
// done return NULL;
return client;
} }
CClient *CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol) CClient *CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol)
{ {
CClient *client = NULL;
// find client // find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
if ( m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) && if ( (*it)->GetCallsign().HasSameCallsign(Callsign) &&
(m_Clients[i]->GetModule() == module) && ((*it)->GetModule() == module) &&
(m_Clients[i]->GetIp() == Ip) && ((*it)->GetIp() == Ip) &&
(m_Clients[i]->GetProtocol() == Protocol) ) ((*it)->GetProtocol() == Protocol) )
{ {
client = m_Clients[i]; return *it;
} }
} }
// done return NULL;
return client;
} }
CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol) CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol)
{ {
CClient *client = NULL;
// find client // find client
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) for ( auto it=begin(); it!=end(); it++ )
{ {
if ( (m_Clients[i]->GetProtocol() == Protocol) && if ( ((*it)->GetProtocol() == Protocol) &&
m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) ) (*it)->GetCallsign().HasSameCallsign(Callsign) )
{ {
client = m_Clients[i]; return *it;
} }
} }
// done return NULL;
return client;
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// iterate on clients // iterate on clients
CClient *CClients::FindNextClient(int Protocol, int *index) CClient *CClients::FindNextClient(int Protocol, std::list<CClient *>::iterator &it)
{ {
CClient *client = NULL; while ( it != end() )
// find next client
bool found = false;
for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ )
{ {
if ( m_Clients[i]->GetProtocol() == Protocol ) if ( (*it)->GetProtocol() == Protocol )
{ {
found = true; return *it++;
client = m_Clients[i];
*index = i;
} }
it++;
} }
return client; return NULL;
} }
CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, int *index) CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, std::list<CClient *>::iterator &it)
{ {
CClient *client = NULL; while ( it != end() )
// find next client
bool found = false;
for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ )
{ {
if ( (m_Clients[i]->GetProtocol() == Protocol) && if ( ((*it)->GetProtocol() == Protocol) &&
(m_Clients[i]->GetIp() == Ip) ) ((*it)->GetIp() == Ip) )
{ {
found = true; return *it++;
client = m_Clients[i];
*index = i;
} }
it++;
} }
return client; return NULL;
} }
CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, int *index) CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, std::list<CClient *>::iterator &it)
{ {
CClient *client = NULL; while ( it != end() )
// find next client
bool found = false;
for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ )
{ {
if ( (m_Clients[i]->GetProtocol() == Protocol) && if ( ((*it)->GetProtocol() == Protocol) &&
(m_Clients[i]->GetIp() == Ip) && ((*it)->GetIp() == Ip) &&
m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) ) (*it)->GetCallsign().HasSameCallsign(Callsign) )
{ {
found = true; return *it++;
client = m_Clients[i];
*index = i;
} }
it++;
} }
return client; return NULL;
} }

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015. // Created by Jean-Luc Deltombe (LX3JL) on 31/10/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.
@ -52,9 +53,14 @@ public:
int GetSize(void) const { return (int)m_Clients.size(); } int GetSize(void) const { return (int)m_Clients.size(); }
void AddClient(CClient *); void AddClient(CClient *);
void RemoveClient(CClient *); void RemoveClient(CClient *);
CClient *GetClient(int);
bool IsClient(CClient *) const; bool IsClient(CClient *) const;
// pass-thru
std::list<CClient *>::iterator begin() { return m_Clients.begin(); }
std::list<CClient *>::iterator end() { return m_Clients.end(); }
std::list<CClient *>::const_iterator cbegin() const { return m_Clients.cbegin(); }
std::list<CClient *>::const_iterator cend() const { return m_Clients.cend(); }
// find clients // find clients
CClient *FindClient(const CIp &); CClient *FindClient(const CIp &);
CClient *FindClient(const CIp &, int); CClient *FindClient(const CIp &, int);
@ -64,14 +70,14 @@ public:
CClient *FindClient(const CCallsign &, int); CClient *FindClient(const CCallsign &, int);
// iterate on clients // iterate on clients
CClient *FindNextClient(int, int*); CClient *FindNextClient(int, std::list<CClient *>::iterator &);
CClient *FindNextClient(const CIp &, int, int *); CClient *FindNextClient(const CIp &, int, std::list<CClient *>::iterator &);
CClient *FindNextClient(const CCallsign &, const CIp &, int, int *); CClient *FindNextClient(const CCallsign &, const CIp &, int, std::list<CClient *>::iterator &);
protected: protected:
// data // data
std::mutex m_Mutex; std::mutex m_Mutex;
std::vector<CClient *> m_Clients; std::list<CClient *> m_Clients;
}; };

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 07/11/2015. // Created by Jean-Luc Deltombe (LX3JL) on 07/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.
@ -162,9 +163,9 @@ void CDcsProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, &index)) != NULL ) while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != NULL )
{ {
client->Alive(); client->Alive();
} }
@ -301,9 +302,9 @@ void CDcsProtocol::HandleQueue(void)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DCS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -336,9 +337,9 @@ void CDcsProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DCS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL )
{ {
// encode client's specific keepalive packet // encode client's specific keepalive packet
CBuffer keepalive2; CBuffer keepalive2;

@ -200,9 +200,9 @@ void CDextraProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, &index)) != NULL ) while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != NULL )
{ {
client->Alive(); client->Alive();
} }
@ -260,9 +260,9 @@ void CDextraProtocol::HandleQueue(void)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -298,9 +298,9 @@ void CDextraProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL )
{ {
// send keepalive // send keepalive
m_Socket.Send(keepalive, client->GetIp()); m_Socket.Send(keepalive, client->GetIp());
@ -339,7 +339,7 @@ void CDextraProtocol::HandleKeepalives(void)
// iterate on peers // iterate on peers
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
index = -1; int index = -1;
CPeer *peer = NULL; CPeer *peer = NULL;
while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, &index)) != NULL ) while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, &index)) != NULL )
{ {

@ -217,9 +217,9 @@ void CDmrmmdvmProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, &index)) != NULL ) while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != NULL )
{ {
// acknowledge // acknowledge
EncodeKeepAlivePacket(&Buffer, client); EncodeKeepAlivePacket(&Buffer, client);
@ -441,9 +441,9 @@ void CDmrmmdvmProtocol::HandleQueue(void)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -473,9 +473,9 @@ void CDmrmmdvmProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( client->IsAMaster() ) if ( client->IsAMaster() )

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 10/01/2016. // Created by Jean-Luc Deltombe (LX3JL) on 10/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.
@ -315,9 +316,9 @@ void CDmrplusProtocol::HandleQueue(void)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -344,9 +345,9 @@ void CDmrplusProtocol::SendBufferToClients(const CBuffer &buffer, uint8 module)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == module) )
@ -374,9 +375,9 @@ void CDmrplusProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( client->IsAMaster() ) if ( client->IsAMaster() )

@ -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.
@ -160,9 +161,9 @@ void CDplusProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, &index)) != NULL ) while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != NULL )
{ {
client->Alive(); client->Alive();
} }
@ -294,9 +295,9 @@ void CDplusProtocol::HandleQueue(void)
// note that for dplus protocol, all stream of all modules are push to all clients // note that for dplus protocol, all stream of all modules are push to all clients
// it's client who decide which stream he's interrrested in // it's client who decide which stream he's interrrested in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() ) if ( !client->IsAMaster() )
@ -388,9 +389,9 @@ void CDplusProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL )
{ {
// send keepalive // send keepalive
//std::cout << "Sending DPlus packet @ " << client->GetIp() << std::endl; //std::cout << "Sending DPlus packet @ " << client->GetIp() << std::endl;

@ -4,6 +4,7 @@
// //
// Created by Marius Petrescu (YO2LOJ) on 03/06/2019. // Created by Marius Petrescu (YO2LOJ) on 03/06/2019.
// Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved. // Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
// //
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// This file is part of xlxd. // This file is part of xlxd.
@ -183,10 +184,9 @@ void CG3Protocol::PresenceTask(void)
} }
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin();
int index = -1;
CClient *extant = NULL; CClient *extant = NULL;
while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
CIp ClIp = extant->GetIp(); CIp ClIp = extant->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr()) if (ClIp.GetAddr() == Ip.GetAddr())
@ -197,10 +197,10 @@ void CG3Protocol::PresenceTask(void)
if (extant == NULL) if (extant == NULL)
{ {
index = -1; it = clients->begin();
// do we already have a client with the same call (IP changed)? // do we already have a client with the same call (IP changed)?
while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
{ {
if (extant->GetCallsign().HasSameCallsign(Terminal)) if (extant->GetCallsign().HasSameCallsign(Terminal))
@ -359,10 +359,9 @@ void CG3Protocol::IcmpTask(void)
if (iIcmpType == ICMP_DEST_UNREACH) if (iIcmpType == ICMP_DEST_UNREACH)
{ {
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin();
int index = -1;
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
CIp ClientIp = client->GetIp(); CIp ClientIp = client->GetIp();
if (ClientIp.GetAddr() == Ip.GetAddr()) if (ClientIp.GetAddr() == Ip.GetAddr())
@ -396,9 +395,9 @@ void CG3Protocol::Task(void)
CIp ClIp; CIp ClIp;
CIp *BaseIp = NULL; CIp *BaseIp = NULL;
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
ClIp = client->GetIp(); ClIp = client->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr()) if (ClIp.GetAddr() == Ip.GetAddr())
@ -498,9 +497,9 @@ void CG3Protocol::HandleQueue(void)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -534,9 +533,9 @@ void CG3Protocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
if (!client->IsAlive()) if (!client->IsAlive())
{ {
@ -568,10 +567,9 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find this client // find this client
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin();
int index = -1;
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
CIp ClIp = client->GetIp(); CIp ClIp = client->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr()) if (ClIp.GetAddr() == Ip.GetAddr())
@ -785,9 +783,9 @@ void CG3Protocol::NeedReload(void)
// we have new options - iterate on clients for potential removal // we have new options - iterate on clients for potential removal
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL )
{ {
char module = client->GetReflectorModule(); char module = client->GetReflectorModule();
if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*'))
@ -858,4 +856,3 @@ void CG3Protocol::ReadOptions(void)
} }
} }
} }

@ -630,11 +630,11 @@ void CReflector::WriteXmlFile(std::ofstream &xmlFile)
// lock // lock
CClients *clients = GetClients(); CClients *clients = GetClients();
// iterate on clients // iterate on clients
for ( int i = 0; i < clients->GetSize(); i++ ) for ( auto it=clients->cbegin(); it!=clients->cend(); it++ )
{ {
if ( clients->GetClient(i)->IsNode() ) if ( (*it)->IsNode() )
{ {
clients->GetClient(i)->WriteXml(xmlFile); (*it)->WriteXml(xmlFile);
} }
} }
// unlock // unlock
@ -696,10 +696,10 @@ void CReflector::SendJsonNodesObject(CUdpSocket &Socket, CIp &Ip)
// lock // lock
CClients *clients = GetClients(); CClients *clients = GetClients();
// iterate on clients // iterate on clients
for ( int i = 0; (i < clients->GetSize()) && (i < JSON_NBMAX_NODES); i++ ) for ( auto it=clients->cbegin(); it!=clients->cend(); )
{ {
clients->GetClient(i)->GetJsonObject(Buffer); (*it++)->GetJsonObject(Buffer);
if ( i < clients->GetSize()-1 ) if ( it != clients->cend() )
{ {
::strcat(Buffer, ","); ::strcat(Buffer, ",");
} }

@ -271,9 +271,9 @@ void CXlxProtocol::HandleQueue(void)
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_XLX, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )

@ -4,6 +4,7 @@
// //
// Created by Jean-Luc Deltombe (LX3JL) on 20/05/2018. // Created by Jean-Luc Deltombe (LX3JL) on 20/05/2018.
// 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.
@ -350,9 +351,9 @@ void CYsfProtocol::HandleQueue(void)
{ {
// and push it to all our clients linked to the module and who are not streaming in // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_YSF, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -382,9 +383,9 @@ void CYsfProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
int index = -1; auto it = clients->begin();
CClient *client = NULL; CClient *client = NULL;
while ( (client = clients->FindNextClient(PROTOCOL_YSF, &index)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL )
{ {
// is this client busy ? // is this client busy ?
if ( client->IsAMaster() ) if ( client->IsAMaster() )

Loading…
Cancel
Save

Powered by TurnKey Linux.